private void txtTenderAmount_KeyUp(object sender, KeyEventArgs e) { try { double subtot = double.Parse(txtTotalAmount.Text); double tender = double.Parse(txtTenderAmount.Text); DateTime today = DateTime.Now; int totqty = 0; if (e.KeyCode == Keys.Enter) { //MessageBox.Show(subtot.ToString()); //MessageBox.Show(tender.ToString()); if (tender >= subtot) { pnltenderAmount.Visible = false; txtTotalAmount.Size = new Size(150, 35); txtChange.Visible = true; txtAmountTender.Visible = true; lblamountTender.Visible = true; lblchange.Visible = true; foreach (DataGridViewRow row in dtgList.Rows) { pro.sqladd = "INSERT INTO tbltransaction (InvoiceNo,Barcode,TransactionDate,Price,TransVat,TransDiscount,TransactionQty,SubTotal,UserId) " + "Values (" + lblTransactionId.Text + ",'" + row.Cells[0].Value + "','" + today + "','" + row.Cells[3].Value + "','12','" + txtDiscount.Text + "','" + row.Cells[4].Value + "','" + row.Cells[5].Value + "','" + UserIdStatusStrip.Text + "')"; //pro.SaveDataMsg(pro.sqladd, "Transaction has been saved!"); pro.SaveData(pro.sqladd); pro.sqledit = "UPDATE tblproduct Set ProductQty=ProductQty-" + row.Cells[4].Value + " WHERE Barcode='" + row.Cells[0].Value + "'"; pro.SaveData(pro.sqledit); totqty += int.Parse(row.Cells[4].Value.ToString()); } pro.sqladd = "INSERT INTO tblsummary (InvoiceNo,TransactionDate,TotalQty,TransDiscount,TotalAmount,AmountTendered,Change) " + " VALUES (" + lblTransactionId.Text + ",'" + today + "','" + totqty + "','" + txtDiscount.Text + "','" + txtTotalAmount.Text + "','" + txtAmountTender.Text + "','" + txtChange.Text + "')"; pro.SaveData(pro.sqladd); pro.UpdateAutonumber(11); dtgList.Enabled = false; txtBarcode.Enabled = false; checkBox1.Enabled = false; btnVoid.Enabled = false; btnTender.Enabled = false; totqty = 0; frmInvoice frm = new frmInvoice(lblTransactionId.Text); frm.ShowDialog(); } else { MessageBox.Show("The amount you tendered is not valid.", "Not Valid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { // MessageBox.Show(ex.Message); //MessageBox.Show("The amount you tendered is not valid." + ex.Message); } }