コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                transactionsBLL transaction = new transactionsBLL();
                transaction.type = lblTop.Text;
                string deaCustName = txtName.Text;

                DeaCustBLL dc = dcDAL.GetDeaCustIdFromName(deaCustName);
                transaction.dea_cust_id      = dc.Id;
                transaction.grandTotal       = Math.Round(decimal.Parse(txtGrandTotal.Text), 2);
                transaction.transaction_date = DateTime.Now;
                transaction.tax      = decimal.Parse(txtVat.Text);
                transaction.discount = decimal.Parse(txtDiscount.Text);

                string  username = frmLogin.loggedIn;
                userBLL u        = uDAL.GetIdFromUsername(username);

                transaction.added_by           = u.Id;
                transaction.transactionDetails = transactionDT;

                bool success = false;
                using (TransactionScope scope = new TransactionScope())
                {
                    int  transactionId = -1;
                    bool w             = tDAL.Insert_Transaction(transaction, out transactionId);

                    for (int i = 0; i < transactionDT.Rows.Count; i++)
                    {
                        transactionDetailBLL transactionDetail = new transactionDetailBLL();
                        string      productName = transactionDT.Rows[i][0].ToString();
                        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()), 2);
                        transactionDetail.dea_cust_id = dc.Id;
                        transactionDetail.added_date  = DateTime.Now;
                        transactionDetail.added_by    = u.Id;


                        string transactionType = lblTop.Text;
                        bool   x = false;
                        if (transactionType == "PURCHASE")
                        {
                            x = pdal.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                        }
                        else if (transactionType == "SALES")
                        {
                            x = pdal.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                        }

                        bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                        success = w && x && y;
                    }

                    if (success == true)
                    {
                        scope.Complete();
                        MassageBox mb = new MassageBox("Transaction Success", MsgType.success);
                        mb.Show();
                        //MessageBox.Show("Transaction Completed Successfully...");
                        dgvAddedProducts.DataSource = null;
                        dgvAddedProducts.Rows.Clear();

                        txtSearch.Text        = "";
                        txtName.Text          = "";
                        txtEmail.Text         = "";
                        txtContact.Text       = "";
                        txtAddress.Text       = "";
                        txtSearchProduct.Text = "";
                        txtNamePro.Text       = "";
                        txtInventory.Text     = "0";
                        txtRate.Text          = "0";
                        txtQty.Text           = "0";
                        txtSubTotal.Text      = "0";
                        txtDiscount.Text      = "0";
                        txtVat.Text           = "0";
                        txtGrandTotal.Text    = "0";
                        txtPaidAmount.Text    = "0";
                        txtReturnAmount.Text  = "0";
                    }
                    else
                    {
                        MassageBox mb = new MassageBox("Transaction Failed", MsgType.retry);
                        mb.Show();
                        //MessageBox.Show("Transaction Failed...!!! Try again");
                    }
                }
            }catch (Exception)
            {
                MassageBox mb = new MassageBox("ERROR", MsgType.clear);
                mb.BackColor = Color.Crimson;
                mb.Show();
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //get the values from purchaseSales form first
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;
            //get the id of dealer and customer here
            //lets get name of dealer or customer first
            string     deaCustName = txtName.Text;
            DeaCustBLL dc          = dcDAL.GetDeaCustIdFromName(deaCustName);

            transaction.dea_cust_id      = dc.id;
            transaction.grandTotal       = Math.Round(decimal.Parse(txtGrandTotal.Text), 2);
            transaction.transaction_date = DateTime.Now;
            transaction.tax      = decimal.Parse(txtVat.Text);
            transaction.discount = decimal.Parse(txtDiscount.Text);
            //get the username of looged 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 detail
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //create boolean value and insert transaction
                bool w = tDAL.Insert_Transaction(transaction, out transactionID);

                //use for loop to insert transaction details
                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    // get all the details of the product
                    transactionDetailBLL transactionDetail = new transactionDetailBLL();
                    //get the product name and convert it to id
                    string      ProductName = transactionDT.Rows[i][1].ToString();
                    productsBLL p           = pDAL.GetProductIDFromName(ProductName);
                    transactionDetail.product_id  = p.id;
                    transactionDetail.rate        = decimal.Parse(transactionDT.Rows[i][2].ToString());
                    transactionDetail.qty         = decimal.Parse(transactionDT.Rows[i][3].ToString());
                    transactionDetail.total       = Math.Round(decimal.Parse(transactionDT.Rows[i][4].ToString()), 2);
                    transactionDetail.dea_cust_id = dc.id;
                    transactionDetail.added_date  = DateTime.Now;
                    transactionDetail.added_by    = u.id;

                    //here increse or decrease product qty based on purchase or sale
                    string transactionType = lblTop.Text;

                    //lets check whether we are on purchase or sale form
                    bool x = false;
                    if (transactionType == "Purchase")
                    {
                        //Increase the product
                        x = pDAL.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }
                    else if (transactionType == "Sales")
                    {
                        //Decrease the product qty
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }


                    //insert transactiondetail inside the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }

                if (success == true)
                {
                    //Transaction complete
                    scope.Complete();

                    //code to print bill
                    DGVPrinter printer = new DGVPrinter();
                    printer.Title               = "\r\n\r\n\r\n GKN INVENTORY PVT.LTD.\r\n\r\n";
                    printer.SubTitle            = "Kolkata, WestBengal \r\n Phone:+91-9765XXXXXX\r\n\r\n";
                    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: Rs. " + txtGrandTotal.Text + "\r\n\r\n" + "Thank you For doing business with us.";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);

                    MessageBox.Show("Transaction Completed Successfully.");
                    //clear the data grid view and clear all the textboxes
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtSearchProduct.Text = "";
                    txtproductid.Text     = "";
                    txtProductName.Text   = "";
                    txtInventory.Text     = "0";
                    txtRate.Text          = "0";
                    txtQty.Text           = "0";
                    txtSubTotal.Text      = "0";
                    txtDiscount.Text      = "0";
                    txtVat.Text           = "0";
                    txtGrandTotal.Text    = "0";
                    txtPaidAmount.Text    = "0";
                    txtReturnAmount.Text  = "0";
                }
                else
                {
                    //Transaction failed
                    MessageBox.Show("Transaction Failed.");
                }
            }
        }