private void txtQty_KeyPress(object sender, KeyPressEventArgs e) { try { if ((e.KeyChar == 13) && (txtQty.Text != String.Empty)) { connString.Open(); cm = new SqlCommand("INSERT INTO tblCart(transNo, proCode, proDesc, price, qty, sDate) VALUES (@transNo, @proCode, @proDesc, @price, @qty, @sDate)", connString); cm.Parameters.AddWithValue("@transNo", transNo); cm.Parameters.AddWithValue("@proCode", pCode); cm.Parameters.AddWithValue("@proDesc", pDesc); cm.Parameters.AddWithValue("@price", price); cm.Parameters.AddWithValue("@qty", int.Parse(txtQty.Text)); cm.Parameters.AddWithValue("@sDate", DateTime.Now); cm.ExecuteNonQuery(); connString.Close(); fPOS.txtSearch.Clear(); fPOS.txtSearch.Focus(); fPOS.loadCart(); this.Dispose(); } } catch (Exception ex) { connString.Close(); MessageBox.Show(ex.Message, eTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
// When bntEnter is pressed, it computes the amount // of total payment from the cart and dispalys the balance // to be given back. // qty row is also decreased by each amount of products purchased private void btnEnter_Click(object sender, EventArgs e) { try { if ((Double.Parse(txtChange.Text) < 0) || (txtCash.Text == String.Empty)) { MessageBox.Show("Insufficient funds. Enter the correct amount", eTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtCash.Clear(); txtCash.Focus(); return; } else { //Boolean saved = false; for (int i = 0; i < fPos.dataGridView1.Rows.Count; i++) { connString.Open(); cm = new SqlCommand("Update tblProduct set qty = qty - " + int.Parse(fPos.dataGridView1.Rows[i].Cells[5].Value.ToString()) + " where proCode = '" + fPos.dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", connString); cm.ExecuteNonQuery(); connString.Close(); connString.Open(); cm = new SqlCommand("Update tblCart set status = 'Sold' where id = '" + fPos.dataGridView1.Rows[i].Cells[1].Value.ToString() + "'", connString); cm.ExecuteNonQuery(); connString.Close(); //saved = true; } MessageBox.Show("Payment Successfully Saved", eTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); fPos.getTransNo(); fPos.loadCart(); this.Dispose(); } } catch (Exception ex) { MessageBox.Show("Enter the correct amount", eTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtCash.Clear(); txtCash.Focus(); } }
//Reducing the added discount amount from the original total private void btnSave_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Add discount?", eTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { connString.Open(); cm = new SqlCommand("Update tblCart set discount = @discount where id = @id", connString); cm.Parameters.AddWithValue("discount", Double.Parse(txtAmount.Text)); cm.Parameters.AddWithValue("id", int.Parse(lblID.Text)); cm.ExecuteNonQuery(); f.loadCart(); this.Dispose(); connString.Close(); } } catch (Exception ex) { connString.Close(); MessageBox.Show(ex.Message); } }