public bool InsertTransactionDetail(transaction_detailBLL td) { //Create of boolean value set to default value t false bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "Insert into tbl_transaction_detail (product_id,rate,qty,total,dea_cust_id,added_date,added_by)values(@product_id,@rate,@qty,@total,@dea_cust_id,@added_date,@added_by)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@product_id", td.id); cmd.Parameters.AddWithValue("@rate", td.rate); cmd.Parameters.AddWithValue("@qty", td.qty); cmd.Parameters.AddWithValue("@total", td.total); cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id); cmd.Parameters.AddWithValue("@added_date", td.added_date); cmd.Parameters.AddWithValue("@added_by", td.added_by); 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 BtnSave_Click(object sender, EventArgs e) { //Get the values from Purchase from frst transactionBLL transaction = new transactionBLL(); transaction.type = lblTop.Text; //Get the ID of dealer or customer her //lets get name of the dealer or customer first string deaCustName = txtName.Text; DeaCustBLL dc = dcDAL.GetDeaCustIDFromName(deaCustName); transaction.dea_cust_id = dc.id; transaction.grandTotal = decimal.Parse(txtGrandTotal.Text); transaction.transaction_date = DateTime.Now; transaction.tax = decimal.Parse(txtVAT.Text); transaction.discount = decimal.Parse(txtDiscount.Text); //Get the username logged in user string username = frmLogin.loggedIn; userBLL u = uDal.GetIDFromUsername(username); transaction.added_by = u.id; transaction.transactionDetails = transactionDT; bool success = false; //Actual code to insert transaction and transaction details using (TransactionScope scope = new TransactionScope()) { int transactionID = -1; ///create boolean value and insert transaction bool w = tDAL.Insert_Transaction(transaction, out transactionID); //User for lopping transaction detaio for (int i = 0; i < transactionDT.Rows.Count; i++) { //Get all the details of the product transaction_detailBLL transactionDetail = new transaction_detailBLL(); //Get the Product name and convert it to id string Productname = txtProductName.Text; productsBLL p = pDAL.GetProductIDFromName(ProductName); transactionDetail.product_id = p.id; transactionDetail.rate = decimal.Parse(transactionDT.Rows[i][1].ToString()); transactionDetail.qty = decimal.Parse(transactionDT.Rows[i][2].ToString()); transactionDetail.total = Math.Round(decimal.Parse(transactionDT.Rows[i][3].ToString()), 3); transactionDetail.dea_cust_id = dc.id; transactionDetail.added_date = DateTime.Now; transactionDetail.added_by = u.id; //Here increase or Decrease Product Quantitiy based on Purchase or sales string transactionType = lblTop.Text; //Lets check wheather we are on purchase or sales bool x = false; if (transactionType == "Purchase") { x = pDAL.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty); } else if (transactionType == "Sales") { //Decrease the Product Quantitiy x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty); } //Insert Transaction Detail inside the Databsae bool y = tdDAL.InsertTransactionDetail(transactionDetail); success = w && y; } if (success == true) { //Transaction Completed scope.Complete(); //Code to print bill DGVPrinter printer = new DGVPrinter(); printer.Title = "\r\n\r\n ANYSTORE PVT. LTD."; printer.SubTitle = "Jepara, Suwawal \r\n Phone: 0895386989706"; printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = "Discount :" + txtDiscount.Text + "% \r\n " + "VAT:" + txtVAT.Text + "% \r\n" + "Grand Total:" + "r\n" + "Thank you for doing buisness with us "; printer.FooterSpacing = 15; printer.PrintDataGridView(dgvAddedProducts); MessageBox.Show("Transaction Completed Successfully"); dgvAddedProducts.DataSource = null; dgvAddedProducts.Rows.Clear(); txtSearch.Text = ""; txtName.Text = ""; txtEmail.Text = ""; txtContact.Text = ""; txtAddress.Text = ""; txtSearchProduct.Text = ""; txtProductName.Text = ""; txtInventory.Text = ""; txtRate.Text = ""; txtQty.Text = "0"; txtSubTotal.Text = "0"; txtDiscount.Text = "0"; txtVAT.Text = "0"; txtGrandTotal.Text = "0"; txtPaidAmount.Text = "0"; txtReturnAmount.Text = "0"; } else { MessageBox.Show("Transaction Failed "); } } }