public bool insertTransactionDetail(TransactionDetailBLL t) { bool isSuccess = false; try { SqlCommand cmd = new SqlCommand("USP_InsertTransactionDetail", AppManager.ConnectionManager); cmd.CommandType = CommandType.StoredProcedure; //cmd.Parameters.Add("id", SqlDbType.Int).Value = t.id; cmd.Parameters.Add("product_id", SqlDbType.Int).Value = t.product_id; cmd.Parameters.Add("rate", SqlDbType.Decimal).Value = t.rate; cmd.Parameters.Add("qty", SqlDbType.Decimal).Value = t.qty; cmd.Parameters.Add("total", SqlDbType.Decimal).Value = t.total; cmd.Parameters.Add("dealer_customer_id", SqlDbType.Int).Value = t.dealer_customer_id; cmd.Parameters.Add("added_date", SqlDbType.DateTime).Value = t.added_date; cmd.Parameters.Add("added_by", SqlDbType.Int).Value = t.added_by; cmd.Parameters.Add("tranId", SqlDbType.Int).Value = t.tranId; int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(isSuccess); }
public bool InsertTransaction(TransactionDetailBLL t, int transactionsId) { bool isSuccess = false; transactionsId = -1; SqlConnection con = new SqlConnection(this.connect.connection); try { string sql = "INSERT INTO [dbo].[tbltransactions]" + "([type]" + ",[deacustid]" + ",[grandtotal]" + ",[transactiondate]" + ",[tax]" + ",[discount]" + ",[addedby])" + "VALUES" + "(@type," + "@deacustid," + "@grandtotal," + "@transactiondate," + "@tax," + "@discount," + "@addedby)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@type", t.Type); cmd.Parameters.AddWithValue("@deacustid", t.DeaCustID); cmd.Parameters.AddWithValue("@grandtotal", t.GrandTotal); cmd.Parameters.AddWithValue("@transactiondate", t.TransactionDate); cmd.Parameters.AddWithValue("@tax", t.Tax); cmd.Parameters.AddWithValue("@discount", t.Discount); cmd.Parameters.AddWithValue("@addedby", t.AddedBy); con.Open(); object o = cmd.ExecuteScalar(); if (o == null) { transactionsId = Convert.ToInt32(o.ToString()); isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { con.Close(); } return(isSuccess); }
public bool InsertTransactionDetail(TransactionDetailBLL td) { bool isSuccess = false; SqlConnection con = new SqlConnection(this.connect.connection); try { string sql = "INSERT INTO [dbo].[tbltransactiondetail]" + "([productid]" + ",[rate]" + ",[qty]" + ",[total]" + ",[deacustid]" + ",[addeddate]" + ",[addedby])" + "VALUES" + "(@productid," + "@rate," + "@qty," + "@total," + "@deacustid," + "@addeddate," + "@addedby)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@productid", td.ID); cmd.Parameters.AddWithValue("@rate", td.Rate); cmd.Parameters.AddWithValue("@qty", td.Qty); cmd.Parameters.AddWithValue("@total", td.GrandTotal); cmd.Parameters.AddWithValue("@deacustid", td.DeaCustID); cmd.Parameters.AddWithValue("@addeddate", td.AddedDate); cmd.Parameters.AddWithValue("@addedby", td.AddedBy); con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { con.Close(); } return(isSuccess); }
public bool InsertTransaction(TransactionDetailBLL u) { bool isSuccess = false; //Static Method to Connect Database SqlConnection con = new SqlConnection(myConnection); try { String sql = "INSERT INTO tbl_trasaction_detail (product_id,rate,qty,total,customer_id,added_date,added_by) VALUES(@product_id,@rate,@qty,@total,@customer_id,@added_date,@added_by)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@product_id", u.product_id); cmd.Parameters.AddWithValue("@rate", u.rate); cmd.Parameters.AddWithValue("@qty", u.qty); cmd.Parameters.AddWithValue("@total", u.total); cmd.Parameters.AddWithValue("@customer_id", u.customer_id); cmd.Parameters.AddWithValue("@added_date", u.added_date); cmd.Parameters.AddWithValue("@added_by", u.added_by); con.Open(); int rows = cmd.ExecuteNonQuery(); // if the Query is Excuted then the value of the rows will be greater thean zero if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } return(isSuccess); }
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"); } } }
private void btnSave_Click(object sender, EventArgs e) { TransactionsBLL transaction = new TransactionsBLL(); transaction.type = lblPurchaseAndSalesTop.Text; string dealerOrCustomerName = Common.ConvertToString(txtDealerAndCustomerName.Text.Trim()); //if (!String.IsNullOrEmpty(dealerOrCustomerName)) //{ DealerAndCustomerBLL dc = dcDAL.getDealerOrCustomerIdFromName(dealerOrCustomerName); transaction.dealer_customer_id = dc.id; //} //else //{ // transaction.dealer_customer_id = 0; //} transaction.grandTotal = Common.ConvertToDouble(txtGrandTotal.Text.Trim()); //transaction.transaction_date = DateTime.Now; transaction.transaction_date = dtpBillDate.Value; transaction.tax = Common.ConvertToDouble(txtGstPercentage.Text.Trim()); transaction.discount = Common.ConvertToDouble(txtDiscountPercentage.Text.Trim()); string loggedInUser = frmLogin.loggedInUser; UserBLL usr = uDAL.getUserIdFromUserName(loggedInUser); transaction.added_by = usr.id; transaction.transactionDetails = dtTransaction; bool isSuccess = false; //insert transaction details using (TransactionScope scope = new TransactionScope()) { int transactionId = -1; string transactionType = lblPurchaseAndSalesTop.Text; bool x = tDAL.insertTransactions(transaction, out transactionId); for (int i = 0; i < grdAddedProducts.Rows.Count; i++) { TransactionDetailBLL transactionDetails = new TransactionDetailBLL(); string productName = Common.ConvertToString(grdAddedProducts.Rows[i].Cells["ProductName"].Value); ProductsBLL p = pDAL.getProductIdFromName(productName); transactionDetails.product_id = p.id; transactionDetails.rate = Common.ConvertToDouble(grdAddedProducts.Rows[i].Cells["Rate"].Value); transactionDetails.qty = Common.ConvertToDouble(grdAddedProducts.Rows[i].Cells["Quantity"].Value); transactionDetails.total = Common.ConvertToDouble(grdAddedProducts.Rows[i].Cells["Total"].Value); transactionDetails.dealer_customer_id = dc.id; transactionDetails.added_date = dtpBillDate.Value; transactionDetails.added_by = usr.id; transactionDetails.tranId = transactionId; //increase or decrease the product quantity based on purchase and sales bool isPSIncreaseDecrease = false; if (transactionType == "PURCHASE") { //increase the product quantity isPSIncreaseDecrease = pDAL.increaseProductQuantity(transactionDetails.product_id, transactionDetails.qty); } else if (transactionType == "SALES") { //decrease the product quantity isPSIncreaseDecrease = pDAL.decreaseProductQuantity(transactionDetails.product_id, transactionDetails.qty); } bool y = tdDAL.insertTransactionDetail(transactionDetails); isSuccess = x && y && isPSIncreaseDecrease; } if (isSuccess) { scope.Complete(); printTransactionFromGrid(grdAddedProducts); if (transactionType == "PURCHASE") { MessageBox.Show("Purchase successfull"); } else if (transactionType == "SALES") { MessageBox.Show("Sales successfull"); } dtTransaction.Clear(); grdAddedProducts.DataSource = null; clearDealerAndCustomerDetails(); clearProductDetails(); clearCalculationDetails(); } else { MessageBox.Show("Transaction failed"); } } }