private void salesRegisterToolStripMenuItem_Click(object sender, EventArgs e) { if (saleReport.IsDisposed) { saleReport = new frmSaleReport(); } saleReport.MdiParent = this; saleReport.Show(); saleReport.BringToFront(); }
private void btnSaleConfirm_Click(object sender, EventArgs e) { try { ep.Clear(); if (string.IsNullOrEmpty(CustomerID)) { ep.SetError(txtSearch, "Please Search Customer"); txtSearch.Focus(); return; } int customerid = 0; int.TryParse(CustomerID, out customerid); if (customerid == 0) { ep.SetError(txtSearch, "Please Search Customer"); txtSearch.Focus(); return; } if (lblCustomerName.Text.Trim().Length == 0) { ep.SetError(lblCustomerName, "Please Search Customer"); lblCustomerName.Focus(); return; } if (dgvSaleCart == null) { ep.SetError(btnADD, "Please Sale Some Products"); cmbProduct.Focus(); return; } if (dgvSaleCart.Rows.Count < 1) { ep.SetError(btnADD, "Please Customer Some Products"); cmbProduct.Focus(); return; } if (dgvSaleCart.Rows.Count > 0) { CalculateTotalAmount(); float totalamount = 0; float.TryParse(lblTotalCost.Text.Trim(), out totalamount); if (totalamount == 0) { ep.SetError(btnADD, "Please Purchase Some Products"); cmbProduct.Focus(); return; } string saleHeaderquery = string.Format(@"insert into saleTable (customerID, EmployeeID, saleDate, TotalAmount, Comments) values ('{0}', '{1}', '{2}', '{3}', '{4}')", customerid, UserInfo.EmployeeID, DateTime.Now.ToString("yyyy/MM/dd"), totalamount, txtComments.Text.Trim()); bool saleHeaderresult = DatabaseAccess.Insert(saleHeaderquery); string saleid = string.Empty; if (saleHeaderresult == true) { saleid = DatabaseAccess.Retrive("select max(saleID) from saleTable").Rows[0][0].ToString(); foreach (DataGridViewRow product in dgvSaleCart.Rows) { string productquery = string.Format(@"insert into saleDetailTable (saleID, itemID, Qty, unitPrice) values ('{0}', '{1}', '{2}', '{3}')", saleid, Convert.ToString(product.Cells[0].Value), Convert.ToString(product.Cells[4].Value), Convert.ToString(product.Cells[5].Value)); try { bool saledetailresult = DatabaseAccess.Insert(productquery); if (saledetailresult == false) { DeleteSale(saleid); MessageBox.Show("Un-Expected Issue is Occur Please Try-Again!!!", title, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string stockupdatequery = string.Format(@"update StockTable set Qty = Qty - '{0}', SaleUnitPrice = '{1}' where itemID = '{2}' ", Convert.ToString(product.Cells[3].Value), Convert.ToString(product.Cells[4].Value), Convert.ToString(product.Cells[0].Value)); DatabaseAccess.Update(stockupdatequery); } catch (Exception ex) { DeleteSale(saleid); MessageBox.Show("Un-Expected Issue is Occur Please Try-Again!!!", title, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } string message = "Sale is Confirmed..."; if (chkIsPaymentSucceed.Checked == true) { string paymentquery = string.Format(@"insert into customerPaymentTable (saleID, EmployeeID, paidDate, totalAmount, PaidAmount, BalanceAmount) values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", saleid, UserInfo.EmployeeID, DateTime.Now.ToString("yyyy/MM/dd"), totalamount, totalamount, "0"); bool result = DatabaseAccess.Insert(paymentquery); if (result == true) { message = message + " with Payment!"; } } frmSaleReport frm = new frmSaleReport(Convert.ToInt32(saleid)); frm.ShowDialog(); ResetForm(); CalculateTotalAmount(); txtComments.Text = ""; lblTotalCost.Text = ""; MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Please Provide Sale Correct Details/ Re-Login!", title, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { ep.SetError(btnADD, "Please Sale Some Products"); cmbProduct.Focus(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }