private void btnSave_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { try { if (txtCustID.Text == "") { MessageBox.Show("Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCustID.Focus(); return; } if (txtVAT.Text == "") { MessageBox.Show("Please enter VAT percentage", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtVAT.Focus(); return; } if (txtTotalPayment.Text == "") { MessageBox.Show("Please enter total payment", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtTotalPayment.Focus(); return; } if (listView1.Items.Count == 0) { MessageBox.Show("Sorry no product added", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } auto_generate_id(); BusinessManager BM = new BusinessManager(); BOSales BOS = new BOSales(); BOCustomer BOC = new BOCustomer(); BOProduct BOP = new BOProduct(); BOInventory BOI = new BOInventory(); BOS.InvoiceNo = txtInvoiceNo.Text; BOS.InvoiceDate = dtpInvoiceDate.Text; BOC.CustomerID = txtCustID.Text; BOS.SubTotal = txtSubTotal.Text; BOS.VATPercent = txtVAT.Text; BOS.VATAmount = txtVatAmount.Text; BOS.GrandTotal = txtGrandTotal.Text; BOS.TotalPayment = txtTotalPayment.Text; BOS.PaymentDue = txtPaymentDue.Text; BOS.Remarks = txtRemarks.Text; bool res = BM.BALVerifyInvoiceNumber(BOS); if (res == true) { MessageBox.Show("Invoice No. already exists", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { BM.BALInsertIntoSales(BOS, BOC); } for (int i = 0; i <= listView1.Items.Count - 1; i++) { BOS.InvoiceNo = txtInvoiceNo.Text; BOP.ConfigID = listView1.Items[i].SubItems[1].Text; BOP.ProductQuantity = listView1.Items[i].SubItems[4].Text; BOP.Price = listView1.Items[i].SubItems[3].Text; BOP.TotalAmount = listView1.Items[i].SubItems[5].Text; BM.BALInsertIntoProductSold(BOS, BOP); } for (int i = 0; i <= listView1.Items.Count - 1; i++) { BOI.Quantity = listView1.Items[i].SubItems[4].Text; BOP.ConfigID = listView1.Items[i].SubItems[1].Text; BM.BALUpdateInventoryQuantity(BOI, BOP); } for (int i = 0; i <= listView1.Items.Count - 1; i++) { BOI.TotalPrice = listView1.Items[i].SubItems[5].Text; BOP.ConfigID = listView1.Items[i].SubItems[1].Text; BM.BALUpdateInventoryTotalPrice(BOI, BOP); } btnSave.Enabled = false; btnPrint.Enabled = true; dataGridView1.DataSource = BM.BALGetInvoiceData(); MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }