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); } }