public SupplierMasterBLL getSuplierIdFromName(string Name) { SupplierMasterBLL s = new SupplierMasterBLL(); SqlConnection con = new SqlConnection(myconnstrng); DataTable dt = new DataTable(); try { string sql = "SELECT SupplierID FROM Supplier_Master WHERE CompanyName='" + Name + "'"; SqlDataAdapter adapter = new SqlDataAdapter(sql, con); con.Open(); adapter.Fill(dt); if (dt.Rows.Count > 0) { s.SupplierID = int.Parse(dt.Rows[0]["SupplierID"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(s); }
public bool Update(SupplierMasterBLL sm) { // Creating Sql Connection First SqlConnection conn = new SqlConnection(myconnstrng); //Creating Default value for isSccuess bool isSuccess = false; try { string sql = "UPDATE Supplier_Master set CompanyName=@CompanyName,Address=@Address,City=@City,State=@State,Pincode=@Pincode,Country=@Country,Email=@Email,Phone_No=@Phone_No,Contact_Person=@Contact_Person,Contact_No=@Contact_No where SupplierID=@id"; //Passing values to query and execute SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@CompanyName", sm.CompanyName); cmd.Parameters.AddWithValue("@Address", sm.Address); cmd.Parameters.AddWithValue("@City", sm.City); cmd.Parameters.AddWithValue("@State", sm.State); cmd.Parameters.AddWithValue("@Pincode", sm.Pincode); cmd.Parameters.AddWithValue("@Country", sm.Country); cmd.Parameters.AddWithValue("@Email", sm.Email); cmd.Parameters.AddWithValue("@Phone_No", sm.Phone_No); cmd.Parameters.AddWithValue("@Contact_Person", sm.Contact_Person); cmd.Parameters.AddWithValue("@Contact_No", sm.Contact_No); cmd.Parameters.AddWithValue("@id", sm.SupplierID); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void textSearch_TextChanged(object sender, EventArgs e) { //get search keyword from search text box string keyword = textSearch.Text; if (keyword == "")//clear all textboex { textSupplierName.Text = ""; textAddress.Text = ""; textContact.Text = ""; textEmail.Text = ""; return; } SupplierMasterBLL smBLL = smDAL.SearchSupplier(keyword); textSupplierName.Text = smBLL.CompanyName; textContact.Text = smBLL.Phone_No; textEmail.Text = smBLL.Email; textAddress.Text = smBLL.Address; }
public SupplierMasterBLL SearchSupplier(String keyword) { // creat aobject fo supplierMaster BLLL SupplierMasterBLL sm = new SupplierMasterBLL(); //creating new Connection SqlConnection conn = new SqlConnection(myconnstrng); //create a data table to hold value DataTable dt = new DataTable(); try { string sql = "Select CompanyName,Phone_No,Email,Address from Supplier_Master where SupplierID like'%" + keyword + "%' OR CompanyName Like'%" + keyword + "%'"; //Sql data adapter to execute query SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); //open connecton to databaase conn.Open(); //transfer data from sql Data Adaptor to datatable adapter.Fill(dt); if (dt.Rows.Count > 0) { sm.CompanyName = dt.Rows[0]["CompanyName"].ToString(); sm.Email = dt.Rows[0]["Email"].ToString(); sm.Address = dt.Rows[0]["Address"].ToString(); sm.Phone_No = dt.Rows[0]["Phone_No"].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(sm); }
public bool Delete(SupplierMasterBLL sm) { // Creating Sql connection First SqlConnection conn = new SqlConnection(myconnstrng); //Seeting Default for isSuccess bool isSuccess = false; try { string sql = "Delete from Supplier_Master where SupplierID=@SupplierID"; //passing query sqlcommand SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@SupplierID", sm.SupplierID); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } 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"); } }
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"); } }