Esempio n. 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     conn.Open();
     cmd = new SqlCommand("update tblCart set disc = @disc where id = @id", conn);
     cmd.Parameters.AddWithValue("@disc", Double.Parse(txt_DiscountAmount.Text));
     cmd.Parameters.AddWithValue("@id", int.Parse(LBLID.Text));
     cmd.ExecuteNonQuery();
     conn.Close();
     cm.Loadcart();
     this.Dispose();
 }
        private void btnEnter_Click(object sender, EventArgs e)
        {
            try
            {
                if ((double.Parse(txt_change.Text) < 0) || (txt_cash.Text == String.Empty))
                {
                    MessageBox.Show("Insufficient amount. Please enter the correct amount!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    return;
                }
                else
                {
                    for (int i = 0; i < cm.dataGridView1.Rows.Count; i++)
                    {
                        conn.Open();
                        cmd = new SqlCommand("update  ProductTble set Quantity = Quantity - " + int.Parse(cm.dataGridView1.Rows[i].Cells[5].Value.ToString()) + " where  pcode = '" + cm.dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", conn);
                        cmd.ExecuteNonQuery();
                        conn.Close();

                        conn.Open();
                        cmd = new SqlCommand("update tblCart set status = 'Sold' where id ='" + cm.dataGridView1.Rows[i].Cells[1].Value.ToString() + "'", conn);
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }

                    Reciept rp = new Reciept(cm);
                    rp.Loadreport(txt_cash.Text, txt_change.Text);
                    rp.ShowDialog();
                    MessageBox.Show("Payment Saved Successfully");
                    cm.GetTransNo();
                    cm.Loadcart();
                    this.Dispose();
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show("Insufficient amount. Please enter the correct amount!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MessageBox.Show(ex.Message);
            }
        }
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar == 13) && (textBox1.Text != String.Empty))
            {
                String id    = "";
                bool   found = false;
                conn.Open();
                cmd = new SqlCommand("Select * from tblCart where transno = @transno and pcode =@pcode", conn);
                cmd.Parameters.AddWithValue("@transno", cashier.lblTransno.Text);
                cmd.Parameters.AddWithValue("@pcode", pcode);
                dr = cmd.ExecuteReader();
                dr.Read();
                if (dr.HasRows)
                {
                    found = true;
                    id    = dr["id"].ToString();
                }

                else
                {
                    found = false;
                }
                dr.Close();
                conn.Close();

                if (found == true)
                {
                    conn.Open();
                    cmd = new SqlCommand("update tblCart set Qty = (Qty + " + int.Parse(textBox1.Text) + ") where id = '" + id + "' ", conn);

                    cmd.ExecuteNonQuery();
                    conn.Close();


                    cashier.textBox1.Clear();
                    cashier.textBox1.Focus();
                    cashier.Loadcart();
                    this.Dispose();
                }
                else
                {
                    conn.Open();
                    cmd = new SqlCommand("insert into tblCart (transno,pcode,price,Qty,sdate,Cashier)Values(@transno,@pcode,@price,@Qty,@sdate,@Cashier)", conn);
                    cmd.Parameters.AddWithValue("@transno", transno);
                    cmd.Parameters.AddWithValue("@pcode", pcode);
                    cmd.Parameters.AddWithValue("@price", price);
                    cmd.Parameters.AddWithValue("@Qty", int.Parse(textBox1.Text));
                    cmd.Parameters.AddWithValue("@sdate", DateTime.Now);
                    cmd.Parameters.AddWithValue("@Cashier", cashier.label3.Text);

                    cmd.ExecuteNonQuery();
                    conn.Close();


                    cashier.textBox1.Clear();
                    cashier.textBox1.Focus();
                    cashier.Loadcart();
                    this.Dispose();
                }
            }
        }