private void comboItemName_SelectedIndexChanged(object sender, EventArgs e) { string keyword = comboItemName.Text; PurchaseReturnDetailsBLL crBLL = PurchaseReturnDetailsDAL.GetProductForPurchaseReturn(keyword); comboBoxUnit.Text = crBLL.Unit; textQuantity.Text = crBLL.Qty.ToString(); textRate.Text = crBLL.Rate.ToString(); textDiscount.Text = crBLL.Discount_Per.ToString(); comboGstType.Text = crBLL.GST_Type; textTotalAmount.Text = crBLL.Total.ToString(); }
public bool insertPurchaseReturnDetails(PurchaseReturnDetailsBLL prdBLL) { bool isSuccess = false; SqlConnection con = new SqlConnection(myconnstrng); try { //inserting transaction details string sql = "INSERT INTO Purchase_Return_Transaction_Details (Invoice_No,Product_ID,Sup_ID,Product_Name,Unit,Qty,Rate,Discount_Per,GST_Type,GST_Per,Total) VALUES(@Invoice_No,@Product_ID,@Sup_ID,@Product_Name,@Unit,@Qty,@Rate,@Discount_Per,@GST_Type,@GST_Per,@Total)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@Invoice_No", prdBLL.Invoice_No); cmd.Parameters.AddWithValue("@Product_ID", prdBLL.Product_ID); cmd.Parameters.AddWithValue("@Sup_ID", prdBLL.Sup_ID); cmd.Parameters.AddWithValue("@Product_Name", prdBLL.Product_Name); cmd.Parameters.AddWithValue("@Unit", prdBLL.Unit); cmd.Parameters.AddWithValue("@Qty", prdBLL.Qty); cmd.Parameters.AddWithValue("@Rate", prdBLL.Rate); cmd.Parameters.AddWithValue("@Discount_Per", prdBLL.Discount_Per); cmd.Parameters.AddWithValue("@GST_Type", prdBLL.GST_Type); cmd.Parameters.AddWithValue("@GST_Per", prdBLL.GST_Per); cmd.Parameters.AddWithValue("@Total", prdBLL.Total); //Unit,Qty,Rate,Discount_Per,GST_Type,GST_Per,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 PurchaseReturnDetailsBLL GetProductForPurchaseReturn(string keyword) { PurchaseReturnDetailsBLL prBLL = new PurchaseReturnDetailsBLL(); SqlConnection conn = new SqlConnection(myconnstrng); DataTable dt = new DataTable(); try { string sql = "select * from Purchase_Transaction_Details where Product_Name LIKE'%" + keyword + "%' "; SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); conn.Open(); adapter.Fill(dt); if (dt.Rows.Count > 0) { prBLL.Unit = dt.Rows[0]["Unit"].ToString(); prBLL.Qty = decimal.Parse(dt.Rows[0]["Qty"].ToString()); prBLL.Rate = decimal.Parse(dt.Rows[0]["Rate"].ToString()); prBLL.Discount_Per = decimal.Parse(dt.Rows[0]["Discount_Per"].ToString()); prBLL.GST_Type = dt.Rows[0]["GST_Type"].ToString(); prBLL.GST_Per = decimal.Parse(dt.Rows[0]["GST_Per"].ToString()); prBLL.Total = decimal.Parse(dt.Rows[0]["Total"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(prBLL); }
public void save() { string sname = textSupplierName.Text; if (comboPurchaseType.Text != "") { if (sname != "") { if (dgvAddedProducts.Rows.Count != 0) { if (comboReturnReson.Text != "") { SupplierMasterBLL c = sDAL.getSuplierIdFromName(sname); decimal subTotal, totalDiscount, totalSgst, totalCgst, totalIgst, grandTotal; int Purchase_ID; int.TryParse(comboPurchaseID.Text, out Purchase_ID); 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); string reson = comboReturnReson.Text; PurchaseReturnBLL.Purchase_ID = Purchase_ID; PurchaseReturnBLL.Transaction_Type = type; PurchaseReturnBLL.Sup_ID = c.SupplierID; PurchaseReturnBLL.Sub_Total = subTotal; PurchaseReturnBLL.TDiscount = totalDiscount; PurchaseReturnBLL.TSGST = totalSgst; PurchaseReturnBLL.TCGST = totalCgst; PurchaseReturnBLL.TIGST = totalIgst; PurchaseReturnBLL.Grand_Total = grandTotal; PurchaseReturnBLL.Reson = reson; PurchaseReturnBLL.PurchaseDetails = PurchaseReturnDT; bool isSuccess = false; // using (TransactionScope scope = new TransactionScope()) //int Invoice_No = -1; alredy declared on top bool b = PurchaseReturnDAL.insertPurchaseReturn(PurchaseReturnBLL, out RInvoice_No); for (int i = 0; i < PurchaseReturnDT.Rows.Count; i++) { PurchaseReturnDetailsBLL prdBLL = new PurchaseReturnDetailsBLL(); stockBLL stockBLL = new stockBLL(); string productName = PurchaseReturnDT.Rows[i][1].ToString(); ProductMasterBLL p = ProductMasterDAL.GetProductIDFromName(productName); prdBLL.Product_ID = p.Product_ID; prdBLL.Invoice_No = RInvoice_No; prdBLL.Sup_ID = c.SupplierID; prdBLL.Product_Name = PurchaseReturnDT.Rows[i][1].ToString(); prdBLL.Unit = PurchaseReturnDT.Rows[i][2].ToString(); prdBLL.Qty = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][3].ToString()), 2); prdBLL.Rate = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][4].ToString()), 2); prdBLL.Discount_Per = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][5].ToString()), 2); prdBLL.GST_Type = PurchaseReturnDT.Rows[i][6].ToString(); prdBLL.GST_Per = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][7].ToString()), 2); prdBLL.Total = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][9].ToString()), 2); int Product_id = p.Product_ID; stockBLL.Product_Id = Product_id; stockBLL.Quantity = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][3].ToString()), 2); stockBLL.Unit = PurchaseReturnDT.Rows[i][2].ToString(); bool y = PurchaseReturnDetailsDAL.insertPurchaseReturnDetails(prdBLL); if (y == true) { bool x = stockDAL.dereaseUpdate(stockBLL); } isSuccess = b && y; isSuccess = true; } isSuccess = b; if (isSuccess == true) { //scope.Complete(); MessageBox.Show("Transaction Completed"); //clear(); } else { MessageBox.Show("Transaction Failed"); } } else { MessageBox.Show("Please Select Retrun Reson"); } } else { MessageBox.Show("Please Add product Details"); } } else { MessageBox.Show("Please Select Customer Details"); } } else { MessageBox.Show("Please Select Purchase Type GST OR NOGST"); } }