示例#1
0
        public bool Insert_Transaction(transactionsBLL t, out int transactionID)
        {
            bool isSuccess = false;

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

            try
            {
                string     sql = "INSERT INTO tbl_transactions(grandTotal, transaction_date, tax, discount) VALUES (@grandTotal, @transaction_date, @tax, @discount); SELECT @@IDENTITY";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
                cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
                cmd.Parameters.AddWithValue("@tax", t.tax);
                cmd.Parameters.AddWithValue("@discount", t.discount);

                conn.Open();
                object o = cmd.ExecuteScalar();
                if (o != null)
                {
                    transactionID = int.Parse(o.ToString());
                    isSuccess     = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            transactionsBLL transaction = new transactionsBLL();

            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);
            transaction.transactionDetails = transactionDT;

            bool success = false;

            //Actual code to insert transaction and transaction details in database
            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++)
                {
                    //get all details of products
                    transactionDetailBLL1 transactionDetail = new transactionDetailBLL1();

                    /*   string barcode = txtbarcode.Text;
                     * //=--------------------------------------------------
                     * ProductsBLL p = pDAL.GetProductIdFromBarcode(barcode);
                     * transactionDetail.id = p.P_Id;
                     * //=--------------------------------------------------
                     */
                    transactionDetail.barcode    = 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.added_date = DateTime.Now;

                    //Insert transaction details inside the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);


                    success = w && y;
                }     //w is the value after insertion. y is the value after inserting transaction details.
                if (success == true)
                {
                    scope.Complete();

                    //Code to print the bill
                    DGVPrinter printer = new DGVPrinter();
                    printer.Title               = "\r\n\r\n\r\n SMART SHOPPING CART BILLING SYSTEM \r\n "; // \n creates a new line \r carries the return
                    printer.SubTitle            = "The next level of shopping \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\r\n" + "THANK YOU AND COME AGAIN!";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);

                    MessageBox.Show("Transaction completed");
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();
                    txtbarcode.Text      = "";
                    txtDiscount.Text     = "";
                    txtgrandTotal.Text   = "0";
                    txtname.Text         = "";
                    txtPaidAmount.Text   = "0";
                    txtqty.Value         = 0;
                    txtReturnAmount.Text = "0";
                    txtSubTotal.Text     = "0";
                    txtTotalPrice.Text   = "0";
                    txtvat.Text          = "0";
                }
                else
                {
                    MessageBox.Show("Transaction failed");
                }
            }


            //Sending the message

            /* String CardName = "";
             * if (visaBtn.Checked)
             * {
             *   CardName = "Visa Card";
             * }
             * if (masterBtn.Checked)
             * {
             *   CardName = "Master Card";
             * }
             * if (paypal.Checked)
             * {
             *   CardName = "Paypal Account";
             * }
             *
             * String Msg = "/r/nDear Customer, Rs." + txtgrandTotal.Text + " have been succesfully transferred from your "+CardName+"-" + txtCardNo.Text + "Thank you and come again!/r/n"+ DateTime.Now;
             *
             *   const string accountSid = "AC548da52ee5513d71fe1dc352c465d38a";
             *   const string authToken = "91285ebd1030267cefce32d60374670d";
             *
             *   TwilioClient.Init(accountSid, authToken);
             *
             *   MessageResource.Create(
             *       from: new PhoneNumber("+1 857 407 3751"),
             *
             *       to: new PhoneNumber("+94" + txtphoneNo.Text),
             *       body: Msg);
             *   MessageBox.Show("Message sent");
             */
        }
示例#3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            transactionsBLL transaction = new transactionsBLL();

            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);
            transaction.transactionDetails = transactionDT;

            bool success = false;

            //Actual code to insert transaction and transaction details in database
            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++)
                {
                    //get all details of products
                    transactionDetailBLL1 transactionDetail = new transactionDetailBLL1();

                    /*   string barcode = txtbarcode.Text;
                     * //=--------------------------------------------------
                     * ProductsBLL p = pDAL.GetProductIdFromBarcode(barcode);
                     * transactionDetail.id = p.P_Id;
                     * //=--------------------------------------------------
                     */
                    transactionDetail.barcode    = 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.added_date = DateTime.Now;

                    //Insert transaction details inside the database
                    bool y = tdDAL.InsertTransactionDetail(transactionDetail);


                    success = w && y;
                }     //w is the value after insertion. y is the value after inserting transaction details.
                if (success == true)
                {
                    scope.Complete();

                    //Code to print the bill
                    DGVPrinter printer = new DGVPrinter();
                    printer.Title               = "\r\n\r\n\r\n SMART SHOPPING CART BILLING SYSTEM \r\n "; // \n creates a new line \r carries the return
                    printer.SubTitle            = "The next level of shopping \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\r\n" + "THANK YOU AND COME AGAIN!";
                    printer.FooterSpacing       = 15;
                    printer.PrintDataGridView(dgvAddedProducts);

                    MessageBox.Show("Transaction completed");
                    dgvAddedProducts.DataSource = null;
                    dgvAddedProducts.Rows.Clear();
                    txtbarcode.Text      = "";
                    txtDiscount.Text     = "";
                    txtgrandTotal.Text   = "0";
                    txtname.Text         = "";
                    txtPaidAmount.Text   = "0";
                    txtqty.Value         = 0;
                    txtReturnAmount.Text = "0";
                    txtSubTotal.Text     = "0";
                    txtTotalPrice.Text   = "0";
                    txtvat.Text          = "0";
                }
                else
                {
                    MessageBox.Show("Transaction failed");
                }
            }
        }