Esempio n. 1
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //addButton.Text = "Update";
            showGridView.Visible      = true;
            salesDataGridView.Visible = false;
            deleteButton.Visible      = false;

            int totRows = dataTable.Rows.Count;

            if (totRows == 0)
            {
                MessageBox.Show("Please, before submit Click to add product Item");
                return;
            }
            foreach (DataRow dr in dataTable.Rows)
            {
                if (i == 0)
                {
                    countRecord = _salesManager.CountRecord();
                    i++;
                }
                string rowCount = "2019-000" + ++countRecord;

                salesDetails.CustomerId        = Convert.ToInt32(customerComboBox.SelectedValue.ToString());
                salesDetails.Date              = dateTimePicker.Value.ToString("mm/dd/yyyy");
                salesDetails.LoyalityPoint     = Convert.ToDouble(loyaltyPointTextBox.Text);
                salesDetails.CategoryId        = Convert.ToInt32(categoryComboBox.SelectedValue.ToString());
                salesDetails.ProductId         = Convert.ToInt32(productComboBox.SelectedValue.ToString());
                salesDetails.SalesCode         = rowCount;
                salesDetails.Product           = dr["Product"].ToString();
                salesDetails.AvailableQuantity = Convert.ToDouble(aQuantityTextBox.Text);
                salesDetails.Quantity          = Convert.ToDouble(dr["Quantity"].ToString());
                salesDetails.MRP      = Convert.ToDouble(dr["MRP(TK)"].ToString());
                salesDetails.TotalMRP = Convert.ToDouble(dr["TotalMRP(TK)"].ToString());


                double soldPrice = salesDetails.MRP + salesDetails.MRP * 25 / 100;
                double profit    = soldPrice - salesDetails.MRP;

                //bool isAddPurchaseItem = _salesManager.AddSalesItem(salesDetails, soldPrice, profit);
                if (!_salesManager.IsStockProductName(salesDetails.Product))
                {
                    _salesManager.AddSalesItem(salesDetails, soldPrice, profit);
                }
                else
                {
                    _salesManager.UpdateSalesQty(salesDetails.Product, salesDetails.Quantity);
                }

                _salesManager.UpdateStockQty(salesDetails);
            }

            sales_Amount.CategoryId     = Convert.ToInt32(categoryComboBox.SelectedValue.ToString());
            sales_Amount.ProductId      = Convert.ToInt32(productComboBox.SelectedValue.ToString());
            sales_Amount.GrandTotal     = Convert.ToDouble(grandTotalTextBox.Text);
            sales_Amount.Discount       = Convert.ToDouble(discountTextBox.Text);
            sales_Amount.DiscountAmount = Convert.ToDouble(discountAmountTextBox.Text);
            sales_Amount.PayableAmount  = Convert.ToDouble(payableAmountTextBox.Text);

            bool isAddSalesAmount = _salesManager.AddSalesAmount(sales_Amount);

            grandTotalTextBox.Text     = "";
            discountTextBox.Text       = "";
            discountAmountTextBox.Text = "";
            payableAmountTextBox.Text  = "";

            showGridView.Visible      = true;
            salesDataGridView.Visible = false;
            List <Sales_Details> sales_Details = _salesManager.DisplaySalesItem();

            showGridView.DataSource = sales_Details;
            SL();
            addButton.Text = "Add";
            //Clear();

            dataTable.Clear();
            salesDataGridView.DataSource = dataTable;
            total = 0;
            MessageBox.Show("Iserted Successfully..");
        }