示例#1
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            //Create a boolean value and set its default value to false
            bool isSuccess = false;

            //Set the out transactionID value to negative 1 i.e. -1
            transactionID = -1;
            //Create a SqlConnection first
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //SQL Query to Insert Transactions
                string sql = "INSERT INTO tbl_transactions (type, dea_cust_id, grandTotal, transaction_date, tax, discount, added_by) VALUES (@type, @dea_cust_id, @grandTotal, @transaction_date, @tax, @discount, @added_by); SELECT @@IDENTITY;";

                //Sql Commandto pass the value in sql query
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passing the value to sql query using cmd
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);

                //Open Database Connection
                conn.Open();

                //Execute the Query
                object o = cmd.ExecuteScalar();

                //If the query is executed successfully then the value will not be null else it will be null
                if (o != null)
                {
                    //Query Executed Successfully
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    //failed to execute query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close the connection
                conn.Close();
            }

            return(isSuccess);
        }
示例#2
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            //create a boolean value and set its default to false
            bool isSuccess = false;

            // set the out transactionID value to negative one.
            transactionID = -1;
            // create sql connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                // SQL query to insert transaction
                string sql = "insert into tbl_transactions (type, dea_cust_id, grandTotal, transaction_date, tax, discount, added_by) values(@type, @dea_cust_id, @grandTotal, @transaction_date, @tax, @discount, @added_by); select @@IDENTITY;";

                //sql command to pass the value in sql query
                SqlCommand cmd = new SqlCommand(sql, conn);

                //passing the value to sql query using cmd
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);

                // Open database connection
                conn.Open();

                // excute the query
                object o = cmd.ExecuteScalar();

                // if query is excuted successfully then the value will not be null , else it will be null
                if (o != null)
                {
                    // Query executed successfully
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
        public bool Insert_transaction(transactionsBLL t, out int transactionID)
        {
            //create a bool value and seet its default value to false
            bool isSuccess = false;

            //set the transaction id value to -1
            transactionID = -1;
            //create a sql connection
            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                //sql query to insert transactions
                string sql = "INSERT INTO tbl_transactions (type, dea_cust_id, grandTotal, transaction_date, gst, discount, added_by) VALUES(@type, @dea_cust_id, @grandTotal, @transaction_date, @gst, @discount, @added_by); SELECT @@IDENTITY ";
                //SQL COMMAND TO PASS THE VALUE
                SqlCommand cmd = new SqlCommand(sql, conn);
                //passing the value using cmd
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@gst", t.gst);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);

                //open database connection
                conn.Open();
                //Execute the query
                object o = cmd.ExecuteScalar();

                //IF THE QUERY IS EXECUTED SUCCESSFULLY THEN THE VALUE WILL NOT BE MULL ELSE IT WILL BE NULL
                if (o != null)
                {
                    //Query Executed Successfully
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    //failed to execute
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
示例#4
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            bool isSuccess = false;


            transactionID = -1;
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                string sql = "INSERT INTO tbl_transactions(type, dea_cust_id, grandTotal, transaction_date, tax, discount, added_by) VALUES (@type, @dea_cust_id, @grandTotal, @transaction_date, @tax, @discount, @added_by)";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);


                conn.Open();

                object o = cmd.ExecuteScalar();

                if (o != null)
                {
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally {
                conn.Close();
            }

            return(isSuccess);
        }
示例#5
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            //create a boolean variable and set its default value false
            bool isSuccess = false;

            //set the out transaction
            transactionID = -1;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "INSERT into dbo.transactions (type, dealer_cust_id, grandTotal, transactionDate, tax, discount, addedBy) VALUES (@type, @dealer_cust_id, @grandTotal, @transactionDate, @tax, @discount, @addedBy); SELECT @@IDENTITY;";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dealer_cust_id", t.deal_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transactionDate", t.transactionDate);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@addedBy", t.addedBy);
                //open database connection
                conn.Open();

                //execute the query
                object o = cmd.ExecuteScalar();
                //id the query is execute successfully then the value will not be null, or else it will be null
                if (o != null)
                {// Query executed successfully
                    transactionID = int.Parse(o.ToString());
                }
                else
                {
                    //failed to execute query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
示例#6
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            bool isSuccess = false;

            //set the out transactionID value to -1
            transactionID = -1;
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                string sql = "INSERT INTO tbl_transactions (type, dea_cust_id, grandTotal, transaction_date, tax, discount, added_by) VALUES (@type, @dea_cust_id, @grandTotal, @transaction_date, @tax, @discount, @added_by); SELECT @@IDENTITY";
                //creating sql command to pass values in our query
                SqlCommand cmd = new SqlCommand(sql, conn);
                //passing values through parameters
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);
                //open database connection
                conn.Open();
                // execute  the query
                object o = cmd.ExecuteScalar();
                if (o != null)
                {
                    transactionID = int.Parse(o.ToString());
                    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 details from the form purchase sales form first
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

            //get the id of dealer or customer
            //lets get name of the delar or customer first
            string     deaCustName = txtDandCName.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.gst      = decimal.Parse(txtGST.Text);
            transaction.discount = decimal.Parse(txtDiscount.Text);

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

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

            //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 bool 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 converse into id
                    string      ProductName = transactiondt.Rows[i][0].ToString();
                    productsBLL p           = pDAL.GetProductsIDFromName(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 we r 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
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }

                    //Insert transactionsDetails inside the db
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }
                if (success == true)
                {
                    //transaction is Compelete
                    scope.Complete();

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

                    printer.Title               = "\r\n\r\n\r\nRISHI SOFTWARE PVT.LTD\r\n\r\n";
                    printer.SubTitle            = "Kenduadihi, Bankura \r\n Phone:-89720635\r\n\r\n";
                    printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
                    printer.PageNumbers         = true;
                    printer.PageNumberInHeader  = false;
                    printer.PorportionalColumns = true;
                    printer.HeaderCellAlignment = StringAlignment.Near;
                    //footer for our bill
                    printer.Footer        = "Discount:- " + txtDiscount.Text + "% \r\n" + "GST:- " + txtGST.Text + "%\r\n" + "Grand Total:- " + txtGrandTotal.Text + "\r\n\r\n" + "Thank You For Shopping 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();

                    txtDandCSearch.Text  = "";
                    txtDandCName.Text    = "";
                    txtDandCEmail.Text   = "";
                    txtDandCContact.Text = "";
                    txtDandCAddress.Text = "";

                    txtPDSearch.Text    = "";
                    txtPDName.Text      = "";
                    txtPDInventory.Text = "0";
                    txtPDRate.Text      = "0";
                    txtPDQty.Text       = "0";

                    txtSubTotal.Text     = "0";
                    txtDiscount.Text     = "0";
                    txtGST.Text          = "0";
                    txtGrandTotal.Text   = "0";
                    txtPaidAmount.Text   = "0";
                    txtReturnAmount.Text = "0";
                }
                else
                {
                    //Transaction Failed
                    MessageBox.Show("Transaction Failed!");
                }
            }
        }
示例#8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Get the values from form purchase Sales form First
            // we will create an objetct of Transactions Class

            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;

            // here we have first written method in DeaCustDAL and now forwarding as

            DeaCustBLL dc = dcDAL.GetDeaCustIDFromName(deaCustName);

            //Now we will refer the transaction

            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 user name,for added by, get the user name

            string username = frmLogin.loggedIn;

            userBLL u = uDAL.GetIDFromUsername(username);

            // we need to passthistransaction
            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 a Boolean value and Insert Transaction
                bool w = tDAL.Insert_Transcation(transaction, out transactionID);

                //Use for loop to insert transaction details

                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    // create all details of products

                    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 we will increase or decrease the quantity based on purchase or sales
                    // we have created Methods to Increase and decrease Qty.
                    // Here Increase or Decrease Product Qty based on Purchase or Sales
                    // we wil lspecify it is Sales or Purchase. we wil lcreate a string variable

                    string transactionType = lblTop.Text;

                    //Lets Check 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 Qty
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }


                    //Insert Transaction Details Inside the Database
                    bool y = tdDAL.InsertTranscationDetail(transactionDetail);
                    success = w && y && x;
                }
                if (success == true)
                {
                    // transaction complete
                    scope.Complete();

                    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     = "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("This Transaction Has Not Been Completed and Failed");
                }
            }
        }
        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();
            }
        }
示例#10
0
        // Here we will create and declare a bool variable.

        public bool Insert_Transcation(transactionsBLL t, out int transactionID)
        {
            //create a boolean value and set its default value to false

            bool isSuccess = false;

            // we need to assign the value to transaction iD. Set the out Transaction ID Value to minus one

            transactionID = -1;

            // creating sql connection to database. This will be in between bool variable isSuccess and we have returned it as well.

            SqlConnection conn = new SqlConnection(myconnstring);


            // here we will use our try catch block

            try
            {
                // writing SQL Query to get all data from database

                string sql = "INSERT INTO tbl_transactions (type,dea_cust_id,grandTotal,transaction_date,tax,discount,added_by) VALUES (@type,@dea_cust_id,@grandTotal,@transaction_date,@tax,@discount,@added_by); SELECT @@IDENTITY;";

                // create sql command to pass values
                SqlCommand cmd = new SqlCommand(sql, conn);

                //passing values through parameters using cmd

                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);

                // Open Database connection

                conn.Open();

                //creating int variable to execute the query

                // int rows = cmd.ExecuteNonQuery();
                object o = cmd.ExecuteScalar();

                //if the query is executed successfully then its value will be greater than zero else less than zero

                if (o != null)
                {
                    // Query executed Successfully
                    //

                    transactionID = int.Parse(o.ToString());

                    isSuccess = true;
                }
                else
                {
                    // Query Not Done successfully
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
示例#11
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.");
                }
            }
        }
        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 or details from the PurchaseForm 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 the 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 it's value to False
            bool success = false;

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

                //Create a boolean Value and Insert Transaction
                bool w = tDAL.Insert_Transction(transaction, out tranasctionID);

                //use for  loop to Insert Transaction Details
                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    //Get all the details of the product
                    transcationDetailsBLL transcationDetails = new transcationDetailsBLL();

                    //Get the product Name and convert it to id
                    string ProductName = transactionDT.Rows[i][0].ToString(); // Here was Errror before<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                    productsBLL p = pDAL.GetDeaProductIDFromName(ProductName);
                    transcationDetails.product_id  = p.id;
                    transcationDetails.rate        = decimal.Parse(transactionDT.Rows[i][1].ToString());
                    transcationDetails.qty         = decimal.Parse(transactionDT.Rows[i][2].ToString());
                    transcationDetails.total       = Math.Round(decimal.Parse(transactionDT.Rows[i][3].ToString()), 2);
                    transcationDetails.dea_cust_id = dc.id;
                    transcationDetails.added_date  = DateTime.Now;
                    transcationDetails.added_by    = u.id;

                    /*------------------------------------------------------------------------------------------------------------------
                     * ------------ PRODUCT INCREASE OR DECREASE OR UPDATE ---------------------------------------------------------------
                     * -------------------------------------------------------------------------------------------------------------------*/


                    //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(transcationDetails.product_id, transcationDetails.qty);
                    }
                    else if (transactionType == "Sales")
                    {
                        //Decrease the Product Quantity
                        x = pDAL.DecreaseProduct(transcationDetails.product_id, transcationDetails.qty);
                    }

                    /*---------------------------------------------------------------------------------------------------------------------------
                     * ------------------------PRODUCT INCREASE OR DECREASE OR UPDATE--------------------------------------------------------------
                     * ----------------------------------------------------------------------------------------------------------------------------*/

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

                if (success == true)
                {
                    //Transaction Complete
                    scope.Complete();
                    MessageBox.Show("Transaction Completed Sucessfully");

                    //Clear Data Grid View and all of the Textboxes
                    dgvAddedProoducts.DataSource = null;
                    dgvAddedProoducts.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");
                }
            }
        }
示例#16
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            //validation
            if (decimal.Parse("0" + txtCheque.Text) > 0 && txtChequeNo.Text.Length < 2)
            {
                MessageBox.Show("Please enter a cheque no.");
            }

            //to do cancell bills

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


            if (lblTop.Text == "Sales")
            {
                transaction.type = "CRN";
            }
            else if (lblTop.Text == "Purchase")
            {
                transaction.type = "RTS";
            }

            //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")
                    {
                        //Decrease the Product coz RTS
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }
                    else if (transactionType == "Sales")
                    {
                        //Increase the Product Quntiyt coz CRN
                        x = pDAL.IncreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }

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

                tDAL.UpdateInvNo(decimal.Parse(tDAL.GetNextInvoiceNo(transaction.type).ToString()), transaction.type);
                //tDAL.UpdateInvNo(decimal.Parse(txtInvoiceNo.Text), transaction.type);
                //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");
                }
            }
        }
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            //Create a Boolean Value and set its default value to false
            bool isSuccess = false;

            //Set the out transactionID value to negative 1 i.e. -1
            transactionID = -1;

            //Create a sql connection
            SqlConnection conn = new SqlConnection(myconnectstring);


            try
            {
                //SQL Query to INSERT Transactions
                string sql = "INSERT INTO tbl_transactions (type, dea_cust_id, grandTotal, transaction_date, ig, cg, sg, igamount, cgamount, sgamount, discount, discountamount, added_by) VALUES (@type, @dea_cust_id, @grandTotal, @transaction_date, @ig, @cg, @sg, @igamount, @cgamount, @sgamount, @discount, @discountamount, @added_by); SELECT @@IDENTITY";

                //SQL Command to pass the value in sql query
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passing the value using sql query using cmd
                cmd.Parameters.AddWithValue("@type", t.type);
                cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@ig", t.ig);
                cmd.Parameters.AddWithValue("@cg", t.cg);
                cmd.Parameters.AddWithValue("@sg", t.sg);
                cmd.Parameters.AddWithValue("@igamount", t.igamount);
                cmd.Parameters.AddWithValue("@cgamount", t.cgamount);
                cmd.Parameters.AddWithValue("@sgamount", t.sgamount);
                cmd.Parameters.AddWithValue("@discount", t.discount);
                cmd.Parameters.AddWithValue("@discountamount", t.discountamount);
                cmd.Parameters.AddWithValue("@added_by", t.added_by);

                conn.Open();

                //Execute the query
                object o = cmd.ExecuteScalar();

                if (o != null)
                {
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error", ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
示例#18
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("ไม่สามารถทำการบันทึกการซื้อ ขายได้! กรุณาลองใหม่อีกครั้ง");
                }
            }
        }
示例#19
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 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.");
                }
            }
        }
        public bool Update_Transaction(transactionsBLL t, out int transactionID)
        {
            //Create a boolean value and set its default value to false
            bool isSuccess = false;

            //Set the out transactionID value to negative 1 i.e. -1
            transactionID = t.id;
            //Create a SqlConnection first
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //SQL Query to Insert Transactions
                string sql = "UPDATE tbl_transactions  SET invoice_no = '" + t.invoice_no + "', type = 'Sales', dea_cust_id = " + t.dea_cust_id + ", grandTotal = " + t.grandTotal + ", transaction_date = '" + t.transaction_date.ToString("MM/dd/yyyy HH:mm:ss.fff") + "', tax = " + t.tax + ", discount =" + t.discount + ", added_by =  '" + t.added_by + "', cash = " + t.cash + ", card =  " + t.card + ", cheque = " + t.cheque + ", cheque_no = '" + t.cheque_no + "' WHERE id = " + t.id + "";



                //Sql Commandto pass the value in sql query
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passing the value to sql query using cmd
                //cmd.Parameters.AddWithValue("@invoice_no", t.invoice_no);
                //cmd.Parameters.AddWithValue("@type", t.type);
                //cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
                //cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                //cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                //cmd.Parameters.AddWithValue("@tax", t.tax);
                //cmd.Parameters.AddWithValue("@discount", t.discount);
                //cmd.Parameters.AddWithValue("@added_by", t.added_by);
                //cmd.Parameters.AddWithValue("@cash", t.cash);
                //cmd.Parameters.AddWithValue("@card", t.card);
                //cmd.Parameters.AddWithValue("@cheque", t.cheque);
                //cmd.Parameters.AddWithValue("@cheque_no", t.cheque_no);

                //Open Database Connection
                conn.Open();

                //Execute the Query
                object o = cmd.ExecuteNonQuery();

                //If the query is executed successfully then the value will not be null else it will be null
                if (o != null)
                {
                    //Query Executed Successfully
                    //transactionID = int.Parse(o.ToString());
                    isSuccess = true;
                }
                else
                {
                    //failed to execute query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close the connection
                conn.Close();
            }

            return(isSuccess);
        }
        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");
                }
            }
        }
示例#23
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.");
                }
            }
        }