Example #1
0
        public void ImportTransactionsfromdb()
        {
            ofDialog            = new OpenFileDialog();
            ofDialog.DefaultExt = "db";

            if (DialogResult.OK == ofDialog.ShowDialog())
            {
                invoices_table InvoiceTable = new invoices_table();
                string         query;
                DataTable      dds = new DataTable();

                using SQLiteConnection iconn = new SQLiteConnection("Data Source=" + ofDialog.FileName + ";Version=3;");
                {
                    query = "select * from invoices";
                    SQLiteDataAdapter dd = new SQLiteDataAdapter(query, iconn);
                    iconn.Open();
                    dd.Fill(dds);       // dds has no records from customertable
                }
                transactionsTable tBLL; // , tPrev = new transactionsTable();

                foreach (DataRow dr in dds.Rows)
                {
                    tBLL = new transactionsTable();
                    // create invoice and detail
                    tBLL.customer_id      = customers.GetDeaCustIDFromName(dr[0].ToString()).id;
                    tBLL.invoice_number   = Convert.ToInt32(dr[1].ToString());
                    tBLL.transaction_date = DateTime.Parse(dr[2].ToString()).Ticks;
                    tBLL.grandTotal       = Convert.ToDecimal(dr[3].ToString());
                    tBLL.tax      = Convert.ToDecimal(dr[4].ToString());
                    tBLL.amtPaid  = Convert.ToDecimal(dr[5].ToString());
                    tBLL.due_date = tBLL.transaction_date;
                    if (tBLL.amtPaid > 0)
                    {
                        tBLL.datePaid = tBLL.due_date;
                    }
                    else
                    {
                        tBLL.datePaid = DateTime.Today.Ticks;
                    }
                    tBLL.taxableSub    = Convert.ToDecimal(dr[9].ToString());
                    tBLL.nonTaxableSub = Convert.ToDecimal(dr[8].ToString());
                    if (dr[6].ToString() == "Paid")
                    {
                        tBLL.status = 3;
                    }
                    else
                    {
                        tBLL.status = 0;
                    }
                    tBLL.terms = "Due on Receipt";
                    transactions.Insert_Transaction(tBLL);
                }
                MessageBox.Show("All Set!");
            }
        }
        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 or Customer Here
            //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       = 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 Logged in user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            //Lets Create a Boolean Variable and set its value to false
            bool success = false;

            //Actual Code to Insert Transaction And Transaction Details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //Create aboolean 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][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;

                    //Here Increase or Decrease Product Quantity based on Purchase or sales
                    string transactionType = lblTop.Text;

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

                    //Insert Transaction Details 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 MEGA STORE PVT. LTD. \r\n\r\n";
                    printer.SubTitle            = "Kurunegala, Puttalam Rd \r\n Phone: 077-8513462 \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: " + txtGrandTotal.Text + "\r\n\r\n" + "Thank you for doing business with us.";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);

                    MessageBox.Show("Transaction Completed Sucessfully");
                    //Celar 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 = "";
                    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");
                }
            }
        }
Example #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Get the Values from PurchaseSales Form First
            transactionsTable transaction = new transactionsTable();

            //Get the ID of Customer Here
            //Lets get name of the customer first
            if (cbCustomer.SelectedIndex < 0)
            {
                MessageBox.Show("Must select a Customer!");
                return;
            }
            // string deaCustName = "Frank Shannon"; // FROM combobox
            // customersBLL dc = // dcDAL.GetDeaCustIDFromName(deaCustName);

            // DETAILS for transaction
            transaction.invoice_number   = Convert.ToInt32(txtInvNumber.Text);
            transaction.customer_id      = Convert.ToInt32(cbCustomer.SelectedValue.ToString()); // dc.id;
            transaction.transaction_date = dtpBillDate.Value.Date.Ticks;
            transaction.due_date         = dtpDueDate.Value.Date.Ticks;
            transaction.terms            = txtTerms.Text;
            transaction.nonTaxableSub    = decimal.Parse(txtNonTaxable.Text);
            transaction.taxableSub       = decimal.Parse(txtSubTotal.Text);
            transaction.tax        = decimal.Parse(txtSalesTax.Text);
            transaction.grandTotal = decimal.Parse(txtGrandTotal.Text);
            transaction.amtPaid    = 0;
            transaction.datePaid   = 0;
            transaction.status     = (int)status.notpaid;


            // transaction.added_by = u.id;
            transaction.transactionDetails = transactionDT;

            //Lets Create a Boolean Variable and set its value to false
            bool success = false;

            //Actual Code to Insert Transaction And Transaction Details
            //Create aboolean value and insert transaction
            bool w = tDAL.Insert_Transaction(transaction);

            //Use for loop to insert Transaction Details
            for (int i = 0; i < transactionDT.Rows.Count; i++)
            {
                //Get all the details of the product
                transactionItemsTable transactionDetail = new transactionItemsTable();

                transactionDetail.product_name = transactionDT.Rows[i][0].ToString();
                transactionDetail.description  = transactionDT.Rows[i][1].ToString();
                transactionDetail.price        = Math.Round(decimal.Parse(transactionDT.Rows[i][2].ToString()), 2);
                transactionDetail.qty          = decimal.Parse(transactionDT.Rows[i][3].ToString());
                transactionDetail.total        = Math.Round(decimal.Parse(transactionDT.Rows[i][4].ToString()), 2);
                // transactionDetail.description = txtDescription.Text;
                transactionDetail.invoice_id = Convert.ToInt32(txtInvNumber.Text);
                // MessageBox.Show(transactionDT.Rows[i]["Taxable"].ToString());
                transactionDetail.isTaxable = Convert.ToInt32(transactionDT.Rows[i]["Taxable"].ToString());

                //Insert Transaction Details inside the database
                bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                success = w && y;
            }

            if (success == true)
            {
                gParams.lastinvoice = Convert.ToInt32(txtInvNumber.Text);
                gParams.saveParams();
            }
            else
            {
                //Transaction Failed
                MessageBox.Show("Transaction Failed");
                this.Close();
            }
            if (MessageBox.Show("Print this invoice?", "Print", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // Print to PDF :)
                // Process.Start("JTS_Invoice_pdf.exe", gParams.lastinvoice.ToString());
                Invoices.CreateInvoice(gParams.lastinvoice);
            }
            this.Close();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Get the values from purchase sales from first
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

            //Get the id of Dealer and Customer
            //Lets get the name of the dealer and 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.ig             = decimal.Parse(txtig.Text);
            transaction.cg             = decimal.Parse(txtcg.Text);
            transaction.sg             = decimal.Parse(txtsg.Text);
            transaction.igamount       = decimal.Parse(textigstamount.Text);
            transaction.cgamount       = decimal.Parse(textcgstamount.Text);
            transaction.sgamount       = decimal.Parse(textsgstamount.Text);
            transaction.discount       = decimal.Parse(txtDiscount.Text);
            transaction.discountamount = decimal.Parse(textdiscoutamount.Text);

            //Get the username of logged in user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            //Create a Boolean Variable and set its value to false
            bool success = false;

            //Actual code to Insert Transaction and transactionDetails
            using (TransactionScope scope = new TransactionScope())
            {
                int tranactionID = -1;

                //Create a Boolean Value and Insert Transaction
                bool w = tDAL.Insert_Transaction(transaction, out tranactionID);

                //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][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;

                    //Increase or Decrease Product Quantity Based on Purchase or Sales
                    string transactionType = lblTop.Text;

                    //Check Whetehr we are on purchase or sales
                    bool x = false;
                    if (transactionType == "Purchase")
                    {
                        //Increase the Product
                        x = pDAL.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }
                    else if (transactionType == "Sales")
                    {
                        //Decrease Product Quantity
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }

                    //Insert TransactionDetails inside our database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }

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

                    label6.Text  = txtSubTotal.Text;
                    label7.Text  = txtDiscount.Text;
                    label8.Text  = txtcg.Text;
                    label9.Text  = txtig.Text;
                    label10.Text = txtsg.Text;
                    label11.Text = textcgstamount.Text;
                    label12.Text = textigstamount.Text;
                    label13.Text = textsgstamount.Text;
                    label14.Text = txtGrandTotal.Text;
                    label15.Text = textdiscoutamount.Text;

                    MessageBox.Show("Transaction Completed Successfully.");
                    comboBox1.Visible = true;


                    //Clear the data Grid View and all the TextBxs
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();

                    txtSearch.Text         = "";
                    txtName.Text           = "";
                    txtEmail.Text          = "";
                    txtAddress.Text        = "";
                    txtSearchProduct.Text  = "";
                    txtProductName.Text    = "";
                    txtInventory.Text      = "";
                    txtRate.Text           = "";
                    txtQty.Text            = "";
                    txtSubTotal.Text       = "0";
                    txtDiscount.Text       = "0";
                    txtig.Text             = "0";
                    txtcg.Text             = "0";
                    txtsg.Text             = "0";
                    textigstamount.Text    = "0";
                    textsgstamount.Text    = "0";
                    textcgstamount.Text    = "0";
                    textdiscoutamount.Text = "0";
                    txtGrandTotal.Text     = "0";
                    txtPaidAmount.Text     = "";
                }
                else
                {
                    MessageBox.Show("Transaction Failed.");
                }
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (cmbBoxTransactionType.Text == "Giao hàng" && txtBoxCustomerAddress.Text == "")
            {
                MessageBox.Show("Bạn chưa điền địa chỉ giao hàng của khách!");
            }
            else if (txtBoxCustomerName.Text == "")
            {
                MessageBox.Show("Bạn quên điền thông tin khách hàng");
            }
            else if (Convert.ToInt32(txtBoxSubTotal.Text.Replace(",", "")) == 0)
            {
                MessageBox.Show("Bạn chưa thêm món ăn vào đơn ");
            }
            else
            {
                int totalRows = dgvAddedProducts.Rows.Count;

                int verticalLength = (totalRows * 3 + 23) * 13;
                printPreviewDialog1.Document = printDocument1;
                printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("pprnm", 300, verticalLength);
                printPreviewDialog1.ShowDialog();
                //Get the value from Purchase sales
                transactionBLL transactionBLL = new transactionBLL();

                //Get customer details

                transactionBLL.customer_name    = txtBoxCustomerName.Text;
                transactionBLL.customer_contact = txtBoxCustomerContact.Text;
                transactionBLL.type             = cmbBoxTransactionType.Text;
                transactionBLL.grandTotal       = Convert.ToInt32(txtBoxGrandTotal.Text.Replace(",", ""));
                transactionBLL.transaction_date = DateTime.Now;
                transactionBLL.tax      = 0;
                transactionBLL.discount = Convert.ToInt32(txtBoxDiscount.Text);
                transactionBLL.billText = receipt;

                string username = fLogin.logged_in;

                transactionBLL.added_by           = username;
                transactionBLL.transactionDetails = transactionDT;
                //Lets create a boolean var and set its value to false
                bool success = false;


                int transactionID = -1;
                //Create a boolean value and insert transaction
                bool transactionInsert = transactionDAL.Insert_Transaction(transactionBLL);

                //Use for loop to insert transaction details
                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    //Get all the details of the product
                    transactionDetailBLL transactionDetailBLL = new transactionDetailBLL();
                    //Get the product name and convert it to ID
                    string     ProductName = transactionDT.Rows[i][0].ToString();
                    productBLL productBLL  = productDAl.GetIDFromProductName(ProductName);

                    transactionDetailBLL.product_id       = productBLL.id;
                    transactionDetailBLL.product_note     = transactionDT.Rows[i][1].ToString();
                    transactionDetailBLL.rate             = Convert.ToInt32(transactionDT.Rows[i][2].ToString().Replace(",", ""));
                    transactionDetailBLL.qty              = Convert.ToInt32(transactionDT.Rows[i][3].ToString());
                    transactionDetailBLL.total            = Convert.ToInt32(transactionDT.Rows[i][4].ToString().Replace(",", ""));
                    transactionDetailBLL.customer_name    = txtBoxCustomerName.Text;
                    transactionDetailBLL.customer_contact = txtBoxCustomerContact.Text;
                    transactionDetailBLL.added_date       = DateTime.Now;
                    transactionDetailBLL.added_by         = username;

                    //Insert transaction details inside the database
                    bool transactionDetailInsert = transactionDetailDAL.InsertTransactionDetail(transactionDetailBLL);
                    success = transactionInsert && transactionDetailInsert;
                }

                if (success = true)
                {
                    MessageBox.Show("Hóa đơn hoàn tất");
                    //Print bill
                    receipt = "-----------------------------------------------------------------------------" + Environment.NewLine;
                    clear();
                }
                else
                {
                    //transaction failed
                    MessageBox.Show("Hóa đơn thất bại");
                }
            }
        }
Example #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Get the values from Purchase and Sales form first
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

            // Get the ID of Dealer or Customer here
            // Get the 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 the loggedin user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            // boolean variable and set it to false
            bool success = false;

            // insert transaction and transaction Details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //create a boolean value and insert transaction
                bool w = tDAL.Insert_Transaction(transaction, out transactionID);

                // 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 product name and convert it to id
                    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;

                    // increase/decrease product Quantity based on purchase or sells
                    string transactionType = lblTop.Text;

                    // check if we are on purchase or sales page
                    bool x = false;
                    if (transactionType == "Purchase")
                    {
                        // increase the product qty
                        x = pDAL.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }
                    else if (transactionType == "Sales")
                    {
                        // decrease product quantity
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }

                    //insert transaction details in the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }

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

                    // print the bill
                    DGVPrinter printer = new DGVPrinter();

                    printer.Title               = "\r\n\r\n\r\n SOPHIE'S STORE PVT. LTD. \r\n\r\n";
                    printer.SubTitle            = "Bellevue, Washington \r\n Phone: 425-xxx-xxxx \r\n\r\n";
                    printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
                    printer.PageNumbers         = true;
                    printer.PageNumberInHeader  = false;
                    printer.PorportionalColumns = true;
                    printer.HeaderCellAlignment = StringAlignment.Near;

                    //limit grand total to 2 decimal values
                    decimal GTTwoDecimal = Math.Round(decimal.Parse(txtGrandTotal.Text), 2);
                    printer.Footer        = "Discount: " + txtDiscount.Text + "% \r\n" + "VAT: " + txtVat.Text + "%\r\n" + "Grand Total:  " + GTTwoDecimal.ToString() + "\r\n" + "Thank you for doing buisness with us!";
                    printer.FooterSpacing = 15;
                    printer.PrintDataGridView(dgvAddedProducts);



                    MessageBox.Show("Transaction completed Successfully.");
                    //clear the data grid view and text boxes
                    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           = "";
                    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.");
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            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();

                    //Code to Print Bill
                    DGVPrinter printer = new DGVPrinter();

                    printer.Title               = "\r\n\r\n\r\n TEAM ANTIVIRUS PVT. LTD. \r\n\r\n";
                    printer.SubTitle            = "Dhaka, Bangladesh \r\n Phone: 017xxxxxxxx \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:" + txtGrandTotal.Text + "\r\n\r\n" + "Thank You";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(pnldataGridView);

                    MessageBox.Show("Transaction Completed Successfully");

                    pnldataGridView.DataSource = null;
                    pnldataGridView.Rows.Clear();

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtProductSearch.Text = "";
                    txtProductName.Text   = "";
                    txtInventory.Text     = "0";
                    txtRate.Text          = "0";
                    txtVat.Text           = "0";
                    txtQty.Text           = "0";
                    txtSubTotal.Text      = "0";
                    txtGrandTotal.Text    = "0";
                    txtDiscount.Text      = "0";
                    txtPaidAmount.Text    = "0";
                    txtReturnAmount.Text  = "0";
                }
                else
                {
                    MessageBox.Show("Transaction Failed");
                }
            }
        }
        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.");
                }
            }
        }
Example #9
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 or Customer Here
            //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       = 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 Logged in user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            //Lets Create a Boolean Variable and set its value to false
            bool success = false;

            //Actual Code to Insert Transaction And Transaction Details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //Create aboolean 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][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;

                    //Here Increase or Decrease Product Quantity based on Purchase or sales
                    string transactionType = lblTop.Text;

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

                    //Insert Transaction Details inside the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }

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



                    MessageBox.Show("Transaction Completed Sucessfully");
                    //Celar 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 = "";
                    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");
                }
            }
        }
Example #10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //get the details from the Purchasesale form
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

            //get the id of dealer or customer
            //get the name of dealer or customer
            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 logged in user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            //create a Boolean variable and set its value to false
            bool success = false;

            //Actual code to insert Transaction and transaction details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //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][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;

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

                if (success == true)
                {
                    //transaction complete
                    scope.Complete();
                    MessageBox.Show("Transaction Complete Sucessfull.");
                    //clear data gridview and textbox
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtSearchProduct.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.");
                }
            }
        }
Example #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //validation
            if (decimal.Parse("0" + txtCheque.Text) > 0 && txtChequeNo.Text.Length < 2)
            {
                MessageBox.Show("Please enter a cheque no.");
            }

            //Get the Values from PurchaseSales Form First
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

            //Get the ID of Dealer or Customer Here
            //Lets get name of the dealer or customer first
            string     deaCustName = cmbCustomer.Text;
            DeaCustBLL dc          = dcDAL.GetDeaCustIDFromName(deaCustName);

            transaction.invoice_no = decimal.Parse(txtInvoiceNo.Text);
            //transaction.invoice_no = decimal.Parse(tDAL.GetNextInvoiceNo(transaction.type).ToString());
            transaction.dea_cust_id      = dc.id;
            transaction.grandTotal       = Math.Round(decimal.Parse("0" + txtGrandTotal.Text), 2);
            transaction.transaction_date = dtpBillDate.Value;
            transaction.tax       = decimal.Parse("0" + txtVat.Text);
            transaction.discount  = decimal.Parse("0" + txtDiscount.Text);
            transaction.cash      = decimal.Parse("0" + txtCash.Text);
            transaction.card      = decimal.Parse("0" + txtCard.Text);
            transaction.cheque    = decimal.Parse("0" + txtCheque.Text);
            transaction.cheque_no = decimal.Parse("0" + txtChequeNo.Text);

            //Get the Username of Logged in user
            string  username = frmLogin.loggedIn;
            userBLL u        = uDAL.GetIDFromUsername(username);

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

            //Lets Create a Boolean Variable and set its value to false
            bool success = false;

            //Actual Code to Insert Transaction And Transaction Details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //Create aboolean 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][0].ToString();
                    productsBLL p           = pDAL.GetProductIDFromName(ProductName);

                    transactionDetail.transastion_id = transactionID;
                    transactionDetail.product_id     = p.id;
                    transactionDetail.rate           = decimal.Parse(transactionDT.Rows[i][2].ToString());
                    transactionDetail.qty            = decimal.Parse(transactionDT.Rows[i][3].ToString());
                    transactionDetail.discount       = decimal.Parse(transactionDT.Rows[i][4].ToString());
                    transactionDetail.total          = Math.Round(decimal.Parse(transactionDT.Rows[i][5].ToString()), 2);
                    transactionDetail.dea_cust_id    = dc.id;
                    transactionDetail.added_date     = DateTime.Now;
                    transactionDetail.added_by       = u.id;

                    //Here Increase or Decrease Product Quantity based on Purchase or sales
                    string transactionType = lblTop.Text;

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

                    //Insert Transaction Details inside the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;

                    //tDAL.IncrementInvNo(decimal.Parse(tDAL.GetNextInvoiceNo().ToString()));
                    tDAL.UpdateInvNo(decimal.Parse(txtInvoiceNo.Text), transactionType);
                }
                //update grand total
                if (success == true)
                {
                    ////////////frmReport r = new frmReport();
                    ////////////r.DocId = 1;
                    ////////////r.TrID = transactionID;
                    ////////////r.ShowDialog();
                    //Transaction Complete
                    scope.Complete();

                    //Code to Print Bill

                    //to do print bills


                    //DGVPrinter printer = new DGVPrinter();

                    //printer.Title = "\r\n\r\n\r\n ANYSTORE PVT. LTD. \r\n\r\n";
                    //printer.SubTitle = "Kathmandu, Nepal \r\n Phone: 01-045XXXX \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: " + txtGrandTotal.Text + "\r\n\r\n" + "Thank you for doing business with us.";
                    //printer.FooterSpacing = 15;
                    //printer.PrintDataGridView(dgvAddedProducts);


                    //MessageBox.Show("Transaction Completed Sucessfully");
                    //Celar the Data Grid View and Clear all the TExtboxes
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();
                    transactionDT.Rows.Clear();



                    txtSearchProduct.Text = "";
                    cmbItemName.Text      = "";
                    TxtQty.Text           = "0";
                    txtSubTotal.Text      = "0";
                    txtDiscount.Text      = "0";
                    txtVat.Text           = "0";
                    txtGrandTotal.Text    = "0";
                    txtCash.Text          = "0";
                    txtCard.Text          = "0";
                    txtCheque.Text        = "0";
                    txtChequeNo.Text      = "0";
                    txtReturnAmount.Text  = "0";
                    txtInvoiceNo.Text     = (decimal.Parse(txtInvoiceNo.Text) + 1).ToString();
                }
                else
                {
                    //Transaction Failed
                    MessageBox.Show("Transaction Failed");
                }
            }
        }
Example #12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            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();
                    DGVPrinter printer = new DGVPrinter();
                    printer.Title               = "\r\n\r\n\r\n ANYSTORE PVT. LTD. \r\n\r\n";
                    printer.SubTitle            = "Kathmandu, Nepal \r\n Phone: 01-045XXXX \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: " + txtGrandTotal.Text + "\r\n\r\n" + "Thank you for doing business with us.";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);

                    MessageBox.Show("ทำการบันทึกข้อมูลการซือ ขาย เรียบร้อยแล้ว");
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtSearchProduct.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
                {
                    MessageBox.Show("ไม่สามารถทำการบันทึกการซื้อ ขายได้! กรุณาลองใหม่อีกครั้ง");
                }
            }
        }
Example #13
0
        private void BtnCalcSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Get the values from PurchaseSales Form
                transactionsBLL transaction = new transactionsBLL();
                transaction.type = lblPurchasesAndSales.Text;

                //Get the id and name of dealer or customer
                string    deaCustName = tbName.Text;
                DeaCusBLL dc          = dcDAL.GetDeaCusIdFromName(deaCustName);
                transaction.deal_cust_id    = dc.id;
                transaction.grandTotal      = Math.Round(decimal.Parse(tbGrandTotal.Text), 2);
                transaction.transactionDate = DateTime.Now;
                transaction.tax             = decimal.Parse(tbVat.Text);
                transaction.discount        = decimal.Parse(tbDiscount.Text);

                //get the username of logged in user
                string  username = Login.loggedIn;
                userBLL u        = uDAL.GetIDFromUsername(username);
                transaction.addedBy            = u.id;
                transaction.transactionDetails = transactionDT;

                //create a boolean and set value
                bool success = false;
                //Insert transaction in table
                using (TransactionScope scope = new TransactionScope())
                {
                    int transactionID = -1;

                    //create a bool value and insert transaction
                    bool w = tDAL.Insert_Transaction(transaction, out transactionID);
                    for (int i = 0; i < transactionDT.Rows.Count; i++)
                    {
                        //Get all the details of the subscription
                        transactionDetailBLL transactionDetail = new transactionDetailBLL();
                        //convert subscription Name to id
                        string           name = transactionDT.Rows[i][0].ToString();
                        subscriptionsBLL p    = pDAL.GetSubscriptionIDFromName(name);

                        transactionDetail.subscriptionid = p.id;
                        transactionDetail.price          = decimal.Parse(transactionDT.Rows[i][1].ToString());
                        transactionDetail.quantity       = decimal.Parse(transactionDT.Rows[i][2].ToString());
                        transactionDetail.total          = Math.Round(decimal.Parse(transactionDT.Rows[i][3].ToString()), 2);
                        transactionDetail.dealer_cust_id = dc.id;
                        transactionDetail.addedDate      = DateTime.Now;
                        transactionDetail.addedBy        = u.id;

                        //change quantity based on sales or purchases
                        string transactionType = lblPurchasesAndSales.Text;
                        //Create a bool and check for type of transaction
                        bool x = false;
                        if (transactionType == "Purchase")
                        {
                            x = pDAL.IncreaseProduct(transactionDetail.subscriptionid, transactionDetail.quantity);
                        }
                        else if (transactionType == "Sales")
                        {
                            //Decrease the Product Quantity
                            x = pDAL.DecreaseProduct(transactionDetail.subscriptionid, transactionDetail.quantity);
                        }
                        //Insert transaction Details
                        bool y = tdDAL.Insert_TransactionDetail(transactionDetail);
                        success = w && x && y;
                    }
                    if (success == true)
                    {
                        scope.Complete();

                        //Print Bill
                        DGVPrinter printer = new DGVPrinter();

                        printer.Title               = "\r\n\r\n\r\n Flava Solutions Gymn MGMT. LTD. \r\n\r\n";
                        printer.SubTitle            = "Angels, Spanish Town \r\n Phone: 876-619-1097 - 99 \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: " + tbDiscount.Text + "% \r\n" + "VAT: " + tbVat.Text + "% \r\n" + "Grand Total: " + tbGrandTotal.Text + "\r\n\r\n" + "Thank you for doing business with us.";
                        printer.FooterSpacing       = 15;
                        printer.PrintDataGridView(dgvPurchases);



                        MessageBox.Show("Transaction Completed Successfully");
                        //Clear datagrid view
                        dgvPurchases.DataSource = null;
                        dgvPurchases.Rows.Clear();
                        Clear1();
                    }
                    else
                    {
                        //transaction Failed
                        MessageBox.Show("Transaction Failed");
                    }
                }
            }
            finally
            {
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //get the details purchase from the for textboxes
                transactionsBLL transaction = new transactionsBLL();

                transaction.type = lblTop.Text;

                //get the id of dealer or customer
                //get the name of the dealer or customer
                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 logged in user
                string username = frmLogin.loggedIn;

                userBLL u = uDAL.GetIDFromUsername(username);

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

                //create a boolean variable and set its value to false
                bool success = false;

                //code to INSert TRansaction and Transaction details
                using (TransactionScope scope = new TransactionScope())
                {
                    int transactionID = -1;
                    //create a boolean value and insert transaction
                    bool w = tDAL.Insert_Transaction(transaction, out transactionID);

                    //use for loop to inser transaction details
                    for (int i = 0; i < transactionDT.Rows.Count; i++)
                    {
                        //get all the details of the roduct
                        transactionDetailBLL transactionDetail = new transactionDetailBLL();
                        //get the product name and convert it to ID
                        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;

                        //Increase or Decrease Product Qty based on purchase or sales
                        string transactionType = lblTop.Text;

                        //check whether its on purchase or sale
                        bool x = false;
                        if (transactionType == "Purchase")
                        {
                            //increse the product qty
                            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 Transaction details inside the database
                        bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                        success = w && x && y;
                    }

                    if (success == true)
                    {
                        //Transaction comlete
                        scope.Complete();
                        MessageBox.Show("Transaction Completed Successfully!");
                        //clear the data grid view and clear all he textboxes
                        dgvAddedProducts.DataSource = null;
                        dgvAddedProducts.Rows.Clear();

                        txtSearch.Text        = "";
                        txtName.Text          = "";
                        txtEmail.Text         = "";
                        txtAddress.Text       = "";
                        txtContact.Text       = "";
                        txtSearchProduct.Text = "";
                        txtProductName.Text   = "";
                        txtInventory.Text     = "0";
                        txtRate.Text          = "0";
                        txtQty.Text           = "0";
                        txtSubTotal.Text      = "0";
                        txtDiscount.Text      = "0"; //////////0
                        txtGrandTotal.Text    = "0";
                        txtVat.Text           = "0"; /////////0
                        txtPaidAmount.Text    = "0";
                        txtReturnAmount.Text  = "0";
                    }
                    else
                    {
                        //Transaction failed
                        MessageBox.Show("Transaction Failed!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        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 ");
                }
            }
        }