public bool insertpurchasedetails(purchasedetailsBLL st) { bool isSuccess = false; SqlConnection con = new SqlConnection(myconnstrng); try { //inserting transaction details string sql = "INSERT INTO Purchase_Transaction_Details(Purchase_ID,Product_ID,Sup_ID,Product_Name,Unit,Qty,Rate,Discount_Per,GST_Type,GST_Per,Total) VALUES(@Purchase_ID,@Product_ID,@Sup_ID,@Product_Name,@Unit,@Qty,@Purchase_Prise,@Discount_Per,@GST_Type,@GST_Per,@Total)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@Purchase_ID", st.Purchase_ID); cmd.Parameters.AddWithValue("@Product_ID", st.Product_ID); cmd.Parameters.AddWithValue("@Sup_ID", st.Sup_ID); cmd.Parameters.AddWithValue("@Product_Name", st.Product_Name); cmd.Parameters.AddWithValue("@Unit", st.Unit); cmd.Parameters.AddWithValue("@Qty", st.Qty); cmd.Parameters.AddWithValue("@Purchase_Prise", st.Rate); cmd.Parameters.AddWithValue("@Discount_Per", st.Discount_Per); cmd.Parameters.AddWithValue("@GST_Type", st.GST_Type); cmd.Parameters.AddWithValue("@GST_Per", st.GST_Per); cmd.Parameters.AddWithValue("@Total", st.Total); con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } return(isSuccess); }
public void save() { purchaseBLL purchaseBLL = new purchaseBLL(); string sname = textSupplierName.Text; if (comboPurchaseType.Text != "") { if (sname != "") { if (dgvAddedProducts.Rows.Count != 0) { SupplierMasterBLL s = smDAL.getSuplierIdFromName(sname); decimal subTotal, totalDiscount, totalSgst, totalCgst, totalIgst, grandTotal; string type = comboPurchaseType.Text; decimal.TryParse(textSubTotal.Text, out subTotal); decimal.TryParse(textSubDiscount.Text, out totalDiscount); decimal.TryParse(textSgst.Text, out totalSgst); decimal.TryParse(textCgst.Text, out totalCgst); decimal.TryParse(textIgst.Text, out totalIgst); decimal.TryParse(textGrandTotal.Text, out grandTotal); purchaseBLL.Transaction_Type = type; purchaseBLL.Sup_ID = s.SupplierID; purchaseBLL.Sub_Total = subTotal; purchaseBLL.TDiscount = totalDiscount; purchaseBLL.TSGST = totalSgst; purchaseBLL.TCGST = totalCgst; purchaseBLL.TIGST = totalIgst; purchaseBLL.Grand_Total = grandTotal; purchaseBLL.PurchaseDetails = purchasedt; bool isSuccess = false; // using (TransactionScope scope = new TransactionScope()) // int purchaseid = -1; already declaraed at the top as a global variable bool b = purchaseDAL.insertpurchase(purchaseBLL, out purchaseid); for (int i = 0; i < purchasedt.Rows.Count; i++) { purchasedetailsBLL pdBLL = new purchasedetailsBLL(); stockBLL stockBLL = new stockBLL(); string productName = purchasedt.Rows[i][1].ToString(); ProductMasterBLL p = ProductMasterDAL.GetProductIDFromName(productName); pdBLL.Purchase_ID = purchaseid; pdBLL.Product_ID = p.Product_ID; pdBLL.Sup_ID = s.SupplierID; pdBLL.Product_Name = purchasedt.Rows[i][1].ToString(); pdBLL.Unit = purchasedt.Rows[i][2].ToString(); pdBLL.Qty = Math.Round(decimal.Parse(purchasedt.Rows[i][3].ToString()), 2); pdBLL.Rate = Math.Round(decimal.Parse(purchasedt.Rows[i][4].ToString()), 2); pdBLL.Discount_Per = Math.Round(decimal.Parse(purchasedt.Rows[i][6].ToString()), 2); pdBLL.GST_Type = purchasedt.Rows[i][7].ToString(); pdBLL.GST_Per = Math.Round(decimal.Parse(purchasedt.Rows[i][8].ToString()), 2); pdBLL.Total = Math.Round(decimal.Parse(purchasedt.Rows[i][9].ToString()), 2); int Product_id = p.Product_ID; stockBLL.Product_Id = Product_id; stockBLL.Quantity = Math.Round(decimal.Parse(purchasedt.Rows[i][3].ToString()), 2); stockBLL.Unit = purchasedt.Rows[i][2].ToString(); bool y = pdetailsDAL.insertpurchasedetails(pdBLL); if (y == true) { stockBLL Padded = stockDAL.CheakeProductAddedOrNot(Product_id); //MessageBox.Show("Product is added",Padded.Product_Id.ToString()); if (Product_id == Padded.Product_Id) { bool x = stockDAL.Update(stockBLL); } else { bool z = stockDAL.InsertStockNewProduct(stockBLL); } } isSuccess = b && y; isSuccess = true; } if (isSuccess == true) { //scope.Complete(); MessageBox.Show("Transaction Completed"); //clear(); } else { MessageBox.Show("Transaction Failed"); } } else { MessageBox.Show("Please Add product Details"); } } else { MessageBox.Show("Please Select Customer Details"); } } else { MessageBox.Show("Please Select Purchase Type GST OR NOGST"); } }