private void btnSaveCal_Click(object sender, EventArgs e) { //Get the Values from PurchaseSales Form First TransactionsBLL transaction = new TransactionsBLL(); transaction.type = UserDashboard.TransactionType; //Get the ID of Dealer or Customer Here //Lets get name of the dealer or customer first string deaCustName = txtName.Text; DeaCustBLL dc = dcdal.GetDeaCustIDFromName(deaCustName); transaction.dea_cust_id = dc.id; transaction.grandTotal = Math.Round(decimal.Parse(txtGrandTotal.Text), 2); transaction.transaction_date = DateTime.Now; transaction.tax = decimal.Parse(txtVAT.Text); transaction.discount = decimal.Parse(txtDiscount.Text); //Get the Username of Logged in user string username = Login.loggedInUser; UserBLL u = udal.getIdFromUserName(username); transaction.added_by = u.id; transaction.transactionDetails = transactionDT; //Lets Create a Boolean Variable and set its value to false bool success = false; //Actual Code to Insert Transaction And Transaction Details using (TransactionScope scope = new TransactionScope()) { int transactionID = -1; //Create aboolean value and insert transaction bool w = Tdal.Insert_Transaction(transaction, out transactionID); //Use for loop to insert Transaction Details for (int i = 0; i < transactionDT.Rows.Count; i++) { //Get all the details of the product transactionDetailBLL transactionDetail = new transactionDetailBLL(); //Get the Product name and convert it to id string ProductName = transactionDT.Rows[i][0].ToString(); ProductsBLL p = pdal.GetProductIDFromName(ProductName); transactionDetail.product_id = p.id; transactionDetail.rate = decimal.Parse(transactionDT.Rows[i][1].ToString()); transactionDetail.qty = decimal.Parse(transactionDT.Rows[i][2].ToString()); transactionDetail.total = Math.Round(decimal.Parse(transactionDT.Rows[i][3].ToString()), 2); transactionDetail.dea_cust_id = dc.id; transactionDetail.added_date = DateTime.Now; transactionDetail.added_by = u.id; //Here Increase or Decrease Product Quantity based on Purchase or sales string transactionType = UserDashboard.TransactionType; //Lets check whether we are on Purchase or Sales bool x = false; if (transactionType == "Purchase") { //Increase the Product x = pdal.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty); } else if (transactionType == "Sales") { //Decrease the Product Quntiyt x = pdal.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty); } //Insert Transaction Details inside the database bool y = TDdal.InsertTransactionDetail(transactionDetail); success = w && x && y; } if (success == true) { //Transaction Complete scope.Complete(); Mymessage mymessage = new Mymessage("Transaction Completed Sucessfully"); mymessage.Show(); //Celar the Data Grid View and Clear all the TExtboxes GDVCustomer.DataSource = null; GDVCustomer.Rows.Clear(); txtDeaCustSearch.Text = ""; txtName.Text = ""; txtEMail.Text = ""; txtContact.Text = ""; txtAddress.Text = ""; txtPrdctSearch.Text = ""; txtPrdctName.Text = ""; txtPrdctInventory.Text = "0"; txtProductRate.Text = "0"; txtPrdctQty.Text = "0"; txtSubTotal.Text = "0"; txtDiscount.Text = "0"; txtVAT.Text = "0"; txtGrandTotal.Text = "0"; txtPaidAmt.Text = "0"; txtReturnAmount.Text = "0"; printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); } else { //Transaction Failed MessageBox.Show("Transaction Failed"); } } }
private void button1_Click(object sender, EventArgs e) { try { TransactionBll transaction = new TransactionBll(); transaction.type = lblPurchaseandsales.Text; string deacustman = txt_name.Text; CustomerBll dc = dl.GetCustomerIDFromname(deacustman); transaction.dea_cust_id = dc.id; transaction.grandTotal = decimal.Parse(txt_grand.Text); transaction.transaction_date = DateTime.Now; transaction.tax = decimal.Parse(txt_vat.Text); transaction.discount = decimal.Parse(txt_discount.Text); string loggedUser = Login.loggein; usebll usr = Dal.GetIDFromUsername(loggedUser); transaction.added_by = usr.id; transaction.transactionDetails = transactionDT; bool success = false; using (TransactionScope scope = new TransactionScope()) { int transactionID = -1; bool w = tdal.Insert_transaction(transaction, out transactionID); for (int i = 0; i < transactionDT.Rows.Count; i++) { TransactionDetailsBll transactiondetails = new TransactionDetailsBll(); string Productname = txt_productnname.Text; Productbll p = Pl.GetProductIDFromName(Productname); string transactionType = lblPurchaseandsales.Text; transactiondetails.ProductID = p.id; transactiondetails.rate = decimal.Parse(transactionDT.Rows[i][1].ToString()); transactiondetails.qty = decimal.Parse(transactionDT.Rows[i][2].ToString()); transactiondetails.total = decimal.Parse(transactionDT.Rows[i][3].ToString()); transactiondetails.dea_cust_id = dc.id; transactiondetails.added_date = DateTime.Now; transactiondetails.added_by = usr.id; bool x = false; if (transactionType == "Purchase") { x = Pl.IncreaseProduct(transactiondetails.ProductID, transactiondetails.qty); } else if (transactionType == "Sales") { x = Pl.DecreaseProduct(transactiondetails.ProductID, transactiondetails.qty); } bool y = tdetailDAL.insertTransactionDetails(transactiondetails); success = w & y; if (success == true) { scope.Complete(); MessageBox.Show("Transaction Completed Successfully"); } else { MessageBox.Show("Transaction Failed"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { //get the values from PurchaseSales from TransactionBLL transaction = new TransactionBLL(); transaction.type = lblTop.Text; //Get the Id of the Customer here //lets get name of the customer first string CustomerOrSellerName = txtName.Text; CustomerBLL customerbll = customerdal.GetCustomerOrSellerIDFromName(CustomerOrSellerName); //getting the transactionID transaction.CustomerID = customerbll.id; transaction.grandTotal = Math.Round(decimal.Parse(txtTotalPPrice.Text), 2); transaction.transaction_date = DateTime.Now; transaction.tax = decimal.Parse(txtVAT.Text); transaction.discount = decimal.Parse(txtDiscount.Text); //Get the userName of loggedin User string username = frmLogin.LoggedInUserName; UserBll userbll = userdal.GetIDFromUsername(username); transaction.added_by = userbll.id; transaction.transactionDetails = transactionDT; //lets Create a boolean variable to check if successful bool success = false; using (TransactionScope scope = new TransactionScope()) { int transactionID = -1; //create bool value and inset transaction bool w = transDal.InsertTransaction(transaction, out transactionID); for (int i = 0; i < transactionDT.Rows.Count; i++) { //Get all the Details of the Product TransactionDetailBLL transactionddetilbll = new TransactionDetailBLL(); //Get the productName and Conert it Id string productname = transactionDT.Rows[i][0].ToString(); ProductBLL producbll = productdal.GetProduuctIDFromName(productname); transactionddetilbll.product_id = producbll.Id; transactionddetilbll.rate = decimal.Parse(transactionDT.Rows[i][1].ToString()); transactionddetilbll.qty = decimal.Parse(transactionDT.Rows[i][2].ToString()); transactionddetilbll.total = Math.Round(decimal.Parse(transactionDT.Rows[i][3].ToString()), 2); //lets get id of the customer firt transactionddetilbll.Id = customerbll.id; transactionddetilbll.added_date = DateTime.Now; transactionddetilbll.added_by = userbll.id; //now before inserting we need to increasing or decrease Product Quantity Based on Purchase or Sales string TransactionType = lblTop.Text; //lets check whether we are on puchase o sales bool xpursal = false; if (TransactionType == "Purchase") { xpursal = productdal.IncreaseProduct(transactionddetilbll.product_id, transactionddetilbll.qty); if (xpursal == true) { MessageBox.Show("Product Increase is Successful"); } else { MessageBox.Show("Product Increase Falied !!!!!"); } } else if (TransactionType == "Sales") { xpursal = productdal.DecreaseProduct(transactionddetilbll.product_id, transactionddetilbll.qty); if (xpursal == true) { MessageBox.Show("Product Decrease is Successful"); } else { MessageBox.Show("Product Decrease Falied !!!!!"); } } //Finally insert TransactionDetails inside the DataBase bool y = transDetailDal.InsertTransaction(transactionddetilbll); success = w && y && xpursal; } if (success == true) { scope.Complete(); //Code To print Bill DGVPrinter print = new DGVPrinter(); print.Title = "\r\n\r\n SHADY'S Store Bill"; print.SubTitle = "Yemen,Taiz \r\n Phone:772816006"; print.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; print.PageNumbers = true; print.PageNumberInHeader = false; print.PorportionalColumns = true; print.HeaderCellAlignment = StringAlignment.Near; print.Footer = "Discount: " + txtDiscount.Text + "% \r\n ValueAddedTax: " + txtVAT.Text + "%\r\n" + "Total Price: " + txtTotalPPrice.Text + "\r\n Thanks For Your Visit."; print.FooterSpacing = 7; print.PrintDataGridView(dgvAddedproducts); //Transaction Compelte MessageBox.Show(" Transaction Compeleted Successfully"); //Clear of the DataGrid view dgvAddedproducts.DataSource = null; dgvAddedproducts.Rows.Clear(); txtCustomerSearch.Text = ""; txtName.Text = ""; txtEmail.Text = ""; txtContact.Text = ""; txtAddress.Text = ""; txtProductSearch.Text = ""; txtProductName.Text = ""; txtProdcutInventory.Text = "0"; txtProdcutQTY.Text = "0"; txtRowTotal.Text = "0"; txtDiscount.Text = "0"; txtVAT.Text = "0"; txtTotalPPrice.Text = "0"; txtPaidAmount.Text = ""; txtReturnAmount.Text = ""; } else { //Transaction Failed MessageBox.Show("Transaction Failed"); } } }