예제 #1
0
        private void frmPurchaseAndSales_Load(object sender, EventArgs e)
        {
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(KeyEvent);

            //Get the transactionType value from frmUserDashboard
            string type = frmUserDashboard.transactionType;

            //Set the value on lblTop
            lblTop.Text = type;

            //Specify Columns for our TransactionDataTable
            transactionDT.Columns.Add("Code");
            transactionDT.Columns.Add("Product Name");
            transactionDT.Columns.Add("Rate");
            transactionDT.Columns.Add("Quantity");
            transactionDT.Columns.Add("Discount");
            transactionDT.Columns.Add("Total");

            //Get the keyword fro the text box
            //string keyword = txtSearch.Text;

            //if (keyword == "")
            //{
            //    //Clear all the textboxes
            //    txtName.Text = "";
            //    txtEmail.Text = "";
            //    txtContact.Text = "";
            //    txtAddress.Text = "";
            //    return;
            //}

            //Write the code to get the details and set the value on text boxes
            //DeaCustBLL dc = dcDAL.GetDealerCustomerForTransaction();

            txtInvoiceNo.Text = tDAL.GetNextInvoiceNo(type).ToString();

            DataSet ds = dcDAL.GetDealerCustomerForTransaction();

            //Now transfer or set the value from DeCustBLL to textboxes
            cmbCustomer.DataSource    = ds.Tables[0];
            cmbCustomer.ValueMember   = "name";
            cmbCustomer.DisplayMember = "name";
            this.ActiveControl        = txtSearchProduct;

            //Get Item list
            DataTable items = pDAL.Search("");

            cmbItemName.DataSource    = items;
            cmbItemName.ValueMember   = "name";
            cmbItemName.DisplayMember = "description";


            //foreach (DataGridViewRow row in dgvAddedProducts.Rows)
            //{
            //    transactionDT.Rows.Add(row.Cells[0].Value, row.Cells[1].Value, row.Cells[2].Value, row.Cells[3].Value, row.Cells[4].Value, row.Cells[5].Value);
            //    //foreach (DataGridViewCell cell in row.Cells)
            //    //{
            //    //    transactionDT.Rows[transactionDT.Rows.Count - 1][cell.ColumnIndex] = cell.Value.ToString();
            //    //}

            //}
        }
예제 #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //Update Quantity----------------------------------------------------
            transactionsBLL transaction = new transactionsBLL();


            //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.type             = "ADJ";
            transaction.invoice_no       = 0;
            transaction.dea_cust_id      = 0;
            transaction.grandTotal       = Math.Round(decimal.Parse("0" + txtQty.Text) - decimal.Parse("0" + txtNewQty.Text), 2) * decimal.Parse("0" + txtRate.Text);
            transaction.transaction_date = DateTime.Now;
            transaction.tax       = 0;
            transaction.discount  = 0;
            transaction.cash      = 0;
            transaction.card      = 0;
            transaction.cheque    = 0;
            transaction.cheque_no = 0;

            //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 = dgvProducts.SelectedRows[0].Cells[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");
                }
            }
            //-------------------------------------------------------------------

            //Get the Values from UI or Product Form
            p.id          = int.Parse(txtID.Text);
            p.name        = txtName.Text;
            p.category    = cmbCategory.Text;
            p.description = txtDescription.Text;
            p.rate        = decimal.Parse(txtRate.Text);
            p.qty         = decimal.Parse(txtNewQty.Text);
            p.added_date  = DateTime.Now;
            //Getting Username of logged in user for added by
            String  loggedUsr = frmLogin.loggedIn;
            userBLL usr       = udal.GetIDFromUsername(loggedUsr);

            p.added_by = usr.id;

            //Create a boolean variable to check if the product is updated or not
            bool success = pdal.Update(p);

            //If the prouct is updated successfully then the value of success will be true else it will be false
            if (success == true)
            {
                //Product updated Successfully
                MessageBox.Show("Product Successfully Updated");
                Clear();
                //REfresh the Data Grid View
                DataTable dt = pdal.Select();
                dgvProducts.DataSource = dt;
            }
            else
            {
                //Failed to Update Product
                MessageBox.Show("Failed to Update Product");
            }
        }