Пример #1
0
        private void btnenter_Click(object sender, EventArgs e)
        {
            try
            {
                if ((double.Parse(ChangeTxt.Text) < 0) || (CashTxt.Text == String.Empty))
                {
                    MessageBox.Show("Insufficient amount, please enter the correct amount!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    for (int i = 0; i < fpos.dataGridView1.Rows.Count; i++)
                    {
                        connect.Open();
                        command = new MySqlCommand("UPDATE producttbl SET qty = qty - " + int.Parse(fpos.dataGridView1.Rows[i].Cells[6].Value.ToString()) + " WHERE pcode =  '" + fpos.dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", connect);
                        command.Parameters.AddWithValue("@transno", fpos.TransNoLbl.Text);
                        command.ExecuteNonQuery();
                        connect.Close();

                        connect.Open();
                        command = new MySqlCommand("UPDATE cart_tbl SET status = 'Sold' WHERE id = '" + (fpos.dataGridView1.Rows[i].Cells[1].Value.ToString()) + "'", connect);
                        command.ExecuteNonQuery();
                        connect.Close();
                    }


                    if (fpos.seniornametxt.Text == String.Empty)
                    {
                        fpos.SoldTotal();
                        ReceiptForm rf = new ReceiptForm(fpos);
                        rf.LoadReport(CashTxt.Text, ChangeTxt.Text);
                        rf.ShowDialog();

                        MessageBox.Show("Payment successfully saved!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        fpos.GetTransNo();
                        fpos.TotalLbl.Text      = "0.00";
                        fpos.TotalSalestxt.Text = "0.00";
                        fpos.LoadCart();
                        this.Dispose();
                        fpos.senioridtxt.Visible = false; fpos.seniornametxt.Visible = false; fpos.label4.Visible = false; fpos.label5.Visible = false;
                    }
                    else
                    {
                        fpos.SoldTotal();
                        SeniorReceipt s = new SeniorReceipt(fpos);
                        s.LoadReport(CashTxt.Text, ChangeTxt.Text);
                        s.ShowDialog();

                        ReceiptForm r = new ReceiptForm(fpos);
                        r.LoadReport(CashTxt.Text, ChangeTxt.Text);
                        r.ShowDialog();

                        MessageBox.Show("Payment successfully saved!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        fpos.GetTransNo();
                        fpos.LoadCart();
                        this.Dispose();
                        fpos.senioridtxt.Visible = false; fpos.seniornametxt.Visible = false; fpos.label4.Visible = false; fpos.label5.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //MessageBox.Show("Insufficient amount, please enter the correct amount!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        private void ConfirmBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string sdate = DateTime.Now.ToString("yyyy-MM-dd");

                if (MessageBox.Show("Add Discount? click yes to confirm.", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (SeniorName.Text == String.Empty)
                    {
                        //connect.Open();
                        //command = new MySqlCommand("UPDATE cart_tbl SET discount = @discount WHERE id = @id", connect);
                        //command.Parameters.AddWithValue("@discount", Double.Parse(AmountTb.Text));
                        //command.Parameters.AddWithValue("@id", int.Parse(IDlbl.Text));
                        //command.ExecuteNonQuery();
                        //connect.Close();

                        //connect.Open();
                        //command = new MySqlCommand("UPDATE cart_tbl SET total = @total - @discount WHERE id = @id", connect);
                        //command.Parameters.AddWithValue("@total", double.Parse(PriceTb.Text));
                        //command.Parameters.AddWithValue("@discount", double.Parse(AmountTb.Text));
                        //command.Parameters.AddWithValue("@id", int.Parse(IDlbl.Text));
                        //command.ExecuteNonQuery();
                        //connect.Close();

                        connect.Open();
                        command = new MySqlCommand("INSERT INTO discounts (transno,discount,sdate) VALUES (@transno,@discount,@sdate)", connect);
                        command.Parameters.AddWithValue("@transno", f.TransNoLbl.Text);
                        command.Parameters.AddWithValue("@discount", AmountTb.Text);
                        command.Parameters.AddWithValue("@sdate", sdate);
                        command.ExecuteNonQuery();
                        connect.Close();

                        connect.Open();
                        command = new MySqlCommand("INSERT INTO discounted_tbl (transno,discount,discounted_price,sdate) VALUES (@transno,@discount,@discounted_price,@sdate)", connect);
                        command.Parameters.AddWithValue("@transno", f.TransNoLbl.Text);
                        command.Parameters.AddWithValue("@discount", double.Parse(PercentTb.Text) / 100);
                        command.Parameters.AddWithValue("@discounted_price", AmountTb.Text);
                        command.Parameters.AddWithValue("@sdate", sdate);
                        command.ExecuteNonQuery();
                        connect.Close();
                    }


                    else
                    {
                        //connect.Open();
                        //command = new MySqlCommand("UPDATE cart_tbl SET discount = @discount WHERE id = @id", connect);
                        //command.Parameters.AddWithValue("@discount", Double.Parse(AmountTb.Text));
                        //command.Parameters.AddWithValue("@id", int.Parse(IDlbl.Text));
                        //command.ExecuteNonQuery();
                        //connect.Close();

                        connect.Open();
                        command = new MySqlCommand("INSERT INTO discounts (transno,discount,sdate) VALUES (@transno,@discount,@sdate)", connect);
                        command.Parameters.AddWithValue("@transno", f.TransNoLbl.Text);
                        command.Parameters.AddWithValue("@discount", AmountTb.Text);
                        command.Parameters.AddWithValue("@sdate", sdate);
                        command.ExecuteNonQuery();
                        connect.Close();

                        connect.Open();
                        command = new MySqlCommand("INSERT INTO discounted_tbl (transno,name,id_no,discount,discounted_price,sdate) VALUES (@transno,@name,@id_no,@discount,@discounted_price,@sdate)", connect);
                        command.Parameters.AddWithValue("@transno", f.TransNoLbl.Text);
                        command.Parameters.AddWithValue("@name", SeniorName.Text);
                        command.Parameters.AddWithValue("@id_no", SeniorIdtxt.Text);
                        command.Parameters.AddWithValue("@discount", double.Parse(PercentTb.Text) / 100);
                        command.Parameters.AddWithValue("@discounted_price", AmountTb.Text);
                        command.Parameters.AddWithValue("@sdate", sdate);
                        command.ExecuteNonQuery();
                        connect.Close();

                        f.label4.Visible        = true;
                        f.label5.Visible        = true;
                        f.senioridtxt.Visible   = true;
                        f.seniornametxt.Visible = true;
                        f.seniornametxt.Text    = SeniorName.Text;
                        f.senioridtxt.Text      = SeniorIdtxt.Text;
                        //f.LoadCart();
                        //this.Dispose();
                    }

                    f.LoadCart();
                    this.Dispose();
                }
            }
            catch (Exception ex)
            {
                connect.Close();
                MessageBox.Show(ex.Message);
            }
            f.LoadCart();
            this.Dispose();
        }
Пример #3
0
        private void QtyTb_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if ((e.KeyChar == 13) && (QtyTb.Text != String.Empty))
                {
                    String id       = "";
                    int    cart_qty = 0;
                    bool   found    = false;


                    connect.Open();
                    command = new MySqlCommand("SELECT * FROM cart_tbl WHERE transno = @transno AND pcode = @pcode ", connect);
                    command.Parameters.AddWithValue("@transno", fpos.TransNoLbl.Text);
                    command.Parameters.AddWithValue("@pcode", pcode);
                    DataReader = command.ExecuteReader();
                    DataReader.Read();

                    if (DataReader.HasRows)
                    {
                        found    = true;
                        id       = DataReader["id"].ToString();
                        cart_qty = int.Parse(DataReader["qty"].ToString());
                    }
                    else
                    {
                        found = false;
                    }
                    DataReader.Close();
                    connect.Close();

                    if (found == true)
                    {
                        if (qty < (int.Parse(QtyTb.Text) + cart_qty))
                        {
                            MessageBox.Show("Unable to proceed. remaining qty on hand is " + qty, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        connect.Open();
                        command = new MySqlCommand("UPDATE cart_tbl SET qty = (qty + " + int.Parse(QtyTb.Text) + ") WHERE id =  '" + id + "'", connect);
                        command.ExecuteNonQuery();
                        connect.Close();

                        //total

                        connect.Open();
                        command = new MySqlCommand("UPDATE cart_tbl SET total = (price * qty)", connect);
                        command.ExecuteNonQuery();
                        connect.Close();

                        fpos.SearchTb.Clear();
                        fpos.SearchTb.Focus();
                        fpos.LoadCart();
                        this.Dispose();
                    }
                    else
                    {
                        if (qty < int.Parse(QtyTb.Text))
                        {
                            MessageBox.Show("Unable to proceed. remaining qty on hand is " + qty, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        connect.Open();
                        command = new MySqlCommand("INSERT INTO cart_tbl (transno, pcode, price, qty, sdate, cashier) VALUES (@transno, @pcode, @price, @qty, @sdate, @cashier)", connect);
                        command.Parameters.AddWithValue("@transno", transno);
                        command.Parameters.AddWithValue("@pcode", pcode);
                        command.Parameters.AddWithValue("@price", price);
                        command.Parameters.AddWithValue("@qty", int.Parse(QtyTb.Text));
                        command.Parameters.AddWithValue("@sdate", DateTime.Now);
                        command.Parameters.AddWithValue("@cashier", fpos.usernamelbl.Text);
                        command.ExecuteNonQuery();
                        connect.Close();

                        //total

                        connect.Open();
                        command = new MySqlCommand("UPDATE cart_tbl SET total = (price * qty)", connect);
                        command.ExecuteNonQuery();
                        connect.Close();

                        fpos.SearchTb.Clear();
                        fpos.SearchTb.Focus();
                        fpos.LoadCart();
                        this.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }