Exemple #1
0
        public bool Delete(transactionDetailBLL c)
        {
            bool          isSucces = false;
            SqlConnection conn     = new SqlConnection(myconnstring);

            try
            {
                string     sql = "DELETE FROM tbl_transaction_detail WHERE Id=@Id";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@Id", c.Id);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSucces = true;
                }
                else
                {
                    isSucces = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSucces);
        }
Exemple #2
0
        public bool UpdateTransactionDetail(transactionDetailBLL td)
        {
            //Create a boolean value and set its default value to false
            bool isSuccess = false;

            //Create a database connection here
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Sql Query to Insert Transaction detais
                string sql = "UPDATE tbl_transaction_detail set product_id = " + td.product_id + ", transaction_id = " + td.transastion_id + ", rate = " + td.rate + ", qty = " + td.qty + ", discount = " + td.discount + ", total = " + td.total + ", dea_cust_id = " + td.dea_cust_id + ", added_date = '" + td.added_date.ToString("MM/dd/yyyy HH:mm:ss.fff") + "', added_by = '" + td.added_by + "' WHERE id = " + 2 + "";

                //Passing the value to the SQL Query
                SqlCommand cmd = new SqlCommand(sql, conn);

                ////Passing the values using cmd
                //cmd.Parameters.AddWithValue("@product_id", );
                //cmd.Parameters.AddWithValue("@transaction_id", );
                //cmd.Parameters.AddWithValue("@rate", );
                //cmd.Parameters.AddWithValue("@qty", );
                //cmd.Parameters.AddWithValue("@discount", );
                //cmd.Parameters.AddWithValue("@total", );
                //cmd.Parameters.AddWithValue("@dea_cust_id", );
                //cmd.Parameters.AddWithValue("@added_date", );
                //cmd.Parameters.AddWithValue("@added_by", );

                //Open Database connection
                conn.Open();

                //declare the int variable and execute the query
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    //Query Executed Successfully
                    isSuccess = true;
                }
                else
                {
                    //FAiled to Execute Query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close Database Connection
                conn.Close();
            }
            return(isSuccess);
        }
Exemple #3
0
        public bool InsertTransactionDetail(transactionDetailBLL td)
        {
            //create Sql connection first
            SqlConnection conn = new SqlConnection(myconnstrng);

            //create a boolean Value and set it default Value to false
            bool isSuccess = false;

            try
            {
                //Create SQL quary to Insert Detail of Dea_Cust table in database
                string sql = "INSERT INTO tbl_transaction_detail (product_id, rate, qty, total, dea_cust_id, added_date, added_by) VALUES (@product_id, @rate, @qty, @total, @dea_cust_id, @added_date, @added_by)";

                //create SQL Command to Execute the Quary
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passing the value using parameter
                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);

                //opening datsbase connection
                conn.Open();

                //create Integer variable to check if the quary is executed  or not
                int rows = cmd.ExecuteNonQuery();

                //If the quary executed Successfully the value of rows will be greater 0 else it will less than 0.
                if (rows > 0)
                {
                    //Quary is Executed Successfully
                    isSuccess = true;
                }
                else
                {
                    //failed to execute the Quary
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }


            return(isSuccess);
        }
Exemple #4
0
        public bool InsertTransactionDetail(transactionDetailBLL td)
        {
            //Creating a bool value and setting its default value to false
            bool isSuccess = false;
            //Create SqlConnection
            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                //Query to insert transaction
                string sql = "INSERT INTO tbl_transaction_detail (product_id,rate,qty,total,dea_cust_id,added_date,added_by) VALUES(@product_id,@rate,@qty,@total,@dea_cust_id,@added_date,@added_by,@added_by)";

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

                //Passing Values through parameterd
                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);


                //Open Database Connection
                conn.Open();

                //Creating the int  Variable to execute query
                int rows = cmd.ExecuteNonQuery();

                //If the query  is executed successfully then its value will be greater than 0 else it will be less than 0
                if (rows > 0)
                {
                    //Query Executed Succesfully
                    isSuccess = true;
                }
                else
                {
                    //Failed to execute
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
        public bool InsertTransactionDetail(transactionDetailBLL transactionDetail)
        {
            //Create a boolean value and set its default value to false
            bool isSuccess = false;
            //Create a sqlConnection first
            SqlConnection connection = new SqlConnection(myconnectingstring);

            try
            {
                //SQL Query to insert transactions
                string sql = "INSERT INTO tbl_transaction_detail (product_id, rate, qty, total, customer_name, added_date, added_by)" +
                             "VALUES (@product_id, @rate, @qty, @total, @customer_name, @added_date, @added_by)";

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

                cmd.Parameters.AddWithValue("@product_id", transactionDetail.product_id);
                cmd.Parameters.AddWithValue("@rate", transactionDetail.rate);
                cmd.Parameters.AddWithValue("@qty", transactionDetail.qty);
                cmd.Parameters.AddWithValue("@total", transactionDetail.total);
                cmd.Parameters.AddWithValue("@customer_name", transactionDetail.customer_name);
                cmd.Parameters.AddWithValue("@added_date", transactionDetail.added_date);
                cmd.Parameters.AddWithValue("@added_by", transactionDetail.added_by);

                //Open database connection
                connection.Open();

                //Execute the query
                int rows = cmd.ExecuteNonQuery();


                //If the query is executed successfully then the value will not be null else it will be null
                if (rows > 0)
                {
                    // Query executed successfully;
                    isSuccess = true;
                }
                else
                {
                    // Failed to execute query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close the connection
                connection.Close();
            }
            return(isSuccess);
        }
Exemple #6
0
        public bool InsertTransactionDetail(transactionDetailBLL td)
        {
            //Create a boolean value and set its default value to false
            bool isSuccess = false;

            //Create a database connection here
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Sql Query to Insert Transaction detais
                string sql = "INSERT INTO tbl_transaction_detail (product_id, transaction_id, rate, qty, discount, total, dea_cust_id, added_date, added_by) VALUES (@product_id, @transaction_id, @rate, @qty, @discount, @total, @dea_cust_id, @added_date, @added_by)";

                //Passing the value to the SQL Query
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Passing the values using cmd
                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@transaction_id", td.transastion_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@discount", td.discount);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);

                //Open Database connection
                conn.Open();

                //declare the int variable and execute the query
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    //Query Executed Successfully
                    isSuccess = true;
                }
                else
                {
                    //FAiled to Execute Query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close Database Connection
                conn.Close();
            }
            return(isSuccess);
        }
        public bool InsertTransactionDetail(transactionDetailBLL td)
        {
            //create a boolean value and set its default value to false
            bool isSuccess = false;

            //create database connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //sql query to insert transaction details
                string sql = "INSERT INTO tbl_transaction_detail (product_id, rate, qty, total, dea_cust_id, added_by) VALUES (@product_id, @rate, @qty, @total, @dea_cust_id, @added_by)";

                //passing the value to sql query
                SqlCommand cmd = new SqlCommand(sql, conn);
                //passing the values using cmd
                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);

                //open database connection
                conn.Open();

                //declare the int variable and execute the query
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    //query executed successfully
                    isSuccess = true;
                }
                else
                {
                    //fILED to execute the query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //close database connection
                conn.Close();
            }

            return(isSuccess);
        }
        public bool Insert_TransactionDetail(transactionDetailBLL td)
        {
            //Create a bool and set the value to false
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "INSERT into dbo.transactionDetail(subscriptionid, price, quantity, total, dealer_cust_id, addedDate, addedBy) Values(@subscriptionid, @price, @quantity, @total, @dealer_cust_id, @addedDate, @addedBy)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@subscriptionid", td.subscriptionid);
                cmd.Parameters.AddWithValue("@price", td.price);
                cmd.Parameters.AddWithValue("@quantity", td.quantity);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dealer_cust_id", td.dealer_cust_id);
                cmd.Parameters.AddWithValue("@addedDate", td.addedDate);
                cmd.Parameters.AddWithValue("@addedBy", td.addedBy);
                //open database connection
                conn.Open();

                //execute the query
                int rows = cmd.ExecuteNonQuery();
                //id the query is execute successfully then the value will not be null, else it will be null
                if (rows > 0)

                {// Queryable executed successfully
                    isSuccess = true;
                }
                else
                {
                    //failed to execute query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemple #9
0
        public bool InsertTransactionDetail(transactionDetailBLL td)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string sql = "INSERT INTO tbl_transaction_detail (product_id, rate, qty, total, dea_cust_id, added_date, added_by) VALUES (@product_id, @rate, @qty, @total, @dea_cust_id, @added_date, @added_by)";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //get the values from 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 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();
            }
        }
Exemple #12
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.");
                }
            }
        }
Exemple #13
0
        private void BtnCalcSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Get the values from PurchaseSales Form
                transactionsBLL transaction = new transactionsBLL();
                transaction.type = lblPurchasesAndSales.Text;

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

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

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

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

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

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

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

                        printer.Title               = "\r\n\r\n\r\n Flava Solutions Gymn MGMT. LTD. \r\n\r\n";
                        printer.SubTitle            = "Angels, Spanish Town \r\n Phone: 876-619-1097 - 99 \r\n\r\n";
                        printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
                        printer.PageNumbers         = true;
                        printer.PageNumberInHeader  = false;
                        printer.PorportionalColumns = true;
                        printer.HeaderCellAlignment = StringAlignment.Near;
                        printer.Footer              = "Discount: " + tbDiscount.Text + "% \r\n" + "VAT: " + tbVat.Text + "% \r\n" + "Grand Total: " + tbGrandTotal.Text + "\r\n\r\n" + "Thank you for doing business with us.";
                        printer.FooterSpacing       = 15;
                        printer.PrintDataGridView(dgvPurchases);



                        MessageBox.Show("Transaction Completed Successfully");
                        //Clear datagrid view
                        dgvPurchases.DataSource = null;
                        dgvPurchases.Rows.Clear();
                        Clear1();
                    }
                    else
                    {
                        //transaction Failed
                        MessageBox.Show("Transaction Failed");
                    }
                }
            }
            finally
            {
            }
        }
Exemple #14
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 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)
        {
            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)
        {
            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("ไม่สามารถทำการบันทึกการซื้อ ขายได้! กรุณาลองใหม่อีกครั้ง");
                }
            }
        }
Exemple #18
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");
                }
            }
        }
Exemple #19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //get the value from purchase form first
            transactionBLL transaction = new transactionBLL();

            transaction.type = lblTop.Text;

            //get the ID of dealer or customer here.
            //let get the name of dealer first
            string     DeaCustName = txtName.Text;
            DeaCustBLL dc          = dcDAL.GetDeaCustIDFromName(DeaCustName);

            transaction.dea_cus_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 boolean variable and set it value to false/
            bool success = false;

            //Actual Code to insert transaction and transaction detail
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //create a boolean Value and insert transaction
                bool w = tDAL.InsertTransaction(transaction, out transactionID);

                //use for loop to insert transaction Detail
                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    //Get all the detail of products
                    transactionDetailBLL transactionDetail = new transactionDetailBLL();
                    //Get the products name and convert 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 Pyurchase or Sales
                    string transactionType = lblTop.Text;

                    //let check weather we are in purchase or sales
                    bool x = false;
                    if (transactionType == "PURCHASE")
                    {
                        x = pDAL.Increaseproduct(transactionDetail.product_id, transactionDetail.qty);
                        //Increase the product
                    }
                    else if (transactionType == "SALES")
                    {
                        //decrease the product
                        x = pDAL.DecreaseProduct(transactionDetail.product_id, transactionDetail.qty);
                    }
                    //Insert transaction Detail in to DataBase
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);
                    success = w && x && y;
                }
                if (success == true)
                {
                    //Transaction Completed
                    scope.Complete();

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

                    printer.Title               = "\r\n\r\n\r\n ANYSTORE PVT.LTD. \r\n\r\n";
                    printer.SubTitle            = "Highfrezh, Ajoke \r\n phone: 01-41XXXXX \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" + "Thanks for doing business with us";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);



                    MessageBox.Show("Transaction Complete successfully");
                    //Clear datagrid veiw and all the TextBoxs
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtProductSearch.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 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!");
                }
            }
        }
Exemple #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (cmbBoxTransactionType.Text == "Giao hàng" && txtBoxCustomerAddress.Text == "")
            {
                MessageBox.Show("Bạn chưa điền địa chỉ giao hàng của khách!");
            }
            else if (txtBoxCustomerName.Text == "")
            {
                MessageBox.Show("Bạn quên điền thông tin khách hàng");
            }
            else if (Convert.ToInt32(txtBoxSubTotal.Text.Replace(",", "")) == 0)
            {
                MessageBox.Show("Bạn chưa thêm món ăn vào đơn ");
            }
            else
            {
                int totalRows = dgvAddedProducts.Rows.Count;

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

                //Get customer details

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

                string username = fLogin.logged_in;

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


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

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

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

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

                if (success = true)
                {
                    MessageBox.Show("Hóa đơn hoàn tất");
                    //Print bill
                    receipt = "-----------------------------------------------------------------------------" + Environment.NewLine;
                    clear();
                }
                else
                {
                    //transaction failed
                    MessageBox.Show("Hóa đơn thất bại");
                }
            }
        }
        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.");
                }
            }
        }
        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.");
                }
            }
        }
Exemple #24
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Get the Values from PurchaseSales Form First
            transactionsBLL transaction = new transactionsBLL();

            transaction.type = lblTop.Text;

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

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

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

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

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

            //Actual Code to Insert Transaction And Transaction Details
            using (TransactionScope scope = new TransactionScope())
            {
                int transactionID = -1;
                //Create aboolean value and insert transaction
                bool w = tDAL.Insert_Transaction(transaction, out transactionID);

                //Use for loop to insert Transaction Details
                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    //Get all the details of the product
                    transactionDetailBLL transactionDetail = new transactionDetailBLL();
                    //Get the Product name and convert it to id
                    string      ProductName = transactionDT.Rows[i][0].ToString();
                    productsBLL p           = pDAL.GetProductIDFromName(ProductName);

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

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

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

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

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



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

                    txtSearch.Text        = "";
                    txtName.Text          = "";
                    txtEmail.Text         = "";
                    txtContact.Text       = "";
                    txtAddress.Text       = "";
                    txtSearchProduct.Text = "";
                    txtProductName.Text   = "";
                    txtInventory.Text     = "0";
                    txtRate.Text          = "0";
                    TxtQty.Text           = "0";
                    txtSubTotal.Text      = "0";
                    txtDiscount.Text      = "0";
                    txtVat.Text           = "0";
                    txtGrandTotal.Text    = "0";
                    txtPaidAmount.Text    = "0";
                    txtReturnAmount.Text  = "0";
                }
                else
                {
                    //Transaction Failed
                    MessageBox.Show("Transaction Failed");
                }
            }
        }
        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");
                }
            }
        }
Exemple #26
0
        // Here we will create and declare a bool variable.

        public bool InsertTranscationDetail(transactionDetailBLL td)

        {
            // Create a boolean Variable , create a boolean value and set its default value to false

            bool isSuccess = false;

            // 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);

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

                string sql = "INSERT INTO tbl_transaction_detail (product_id,rate,qty,total,dea_cust_id,added_date,added_by) VALUES (@product_id,@rate,@qty,@total,@dea_cust_id,@added_date,@added_by)";

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

                //passing values through parameters using cmd

                cmd.Parameters.AddWithValue("@product_id", td.product_id);
                cmd.Parameters.AddWithValue("@rate", td.rate);
                cmd.Parameters.AddWithValue("@qty", td.qty);
                cmd.Parameters.AddWithValue("@total", td.total);
                cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
                cmd.Parameters.AddWithValue("@added_date", td.added_date);
                cmd.Parameters.AddWithValue("@added_by", td.added_by);

                // Open Database connection

                conn.Open();

                //creating int variable to execute the query. Here we don't need first column or first row so we will use this old method
                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 (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    // Query Not Done successfully
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }