Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (detail.ProductID == 0)
            {
                MessageBox.Show("Please select a product from product table");
            }
            else if (detail.CustomerID == 0)
            {
                MessageBox.Show("Please select a customer");
            }
            else if (detail.StockAmount < Convert.ToInt32(txtProductSalesAmount.Text))
            {
                MessageBox.Show("You have not enough product for sale");
            }
            else
            {
                detail.SalesAmount = Convert.ToInt32(txtProductSalesAmount.Text);
                detail.SalesDate   = DateTime.Today;

                if (bll.Insert(detail))
                {
                    MessageBox.Show("Sales was Added");
                    bll = new SalesBLL();
                    dto = bll.Select();
                    gridProduct.DataSource  = dto.Products;
                    gridCustomer.DataSource = dto.Customers;
                    comboFull             = false;
                    cbCategory.DataSource = dto.Categories;
                    if (dto.Products.Count > 0)
                    {
                        comboFull = true;
                    }
                    txtProductSalesAmount.Clear();
                }
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (detail.ProductID == 0)
            {
                MessageBox.Show("Please select a product");
            }
            else
            {
                if (!isUpdate)
                {
                    if (detail.CustomerID == 0)
                    {
                        MessageBox.Show("Please select a customer ID");
                    }
                    else if (detail.CustomerID == 0)
                    {
                        MessageBox.Show("Select a customer from the table");
                    }
                    else if (detail.StockAmount < Convert.ToInt32(txtProductStock.Text))
                    {
                        MessageBox.Show("Stock is not enough");
                    }
                    else
                    {
                        detail.SalesAmount = Convert.ToInt32(txtSalesAmount.Text);
                        detail.SalesDate   = DateTime.Today;

                        if (bll.Insert(detail))
                        {
                            MessageBox.Show("Sles was added");
                            bll = new SalesBLL();
                            dto = bll.Select();
                            GridProduct.DataSource = dto.Products;
                            combofull = false;
                            cmbCategory.DataSource = dto.Categories;
                            if (dto.Products.Count > 0)
                            {
                                combofull = true;
                            }
                            txtSalesAmount.Clear();
                        }
                    }
                }
                else
                {
                    if (detail.SalesAmount == Convert.ToInt32(txtSalesAmount.Text))
                    {
                        MessageBox.Show("There is not changes");
                    }
                    else
                    {
                        int temp = detail.StockAmount + detail.SalesAmount;
                        if (temp < Convert.ToInt32(txtSalesAmount.Text))
                        {
                            MessageBox.Show("You don have enoigh stock");
                        }
                        else
                        {
                            detail.SalesAmount = Convert.ToInt32(txtSalesAmount.Text);
                            detail.StockAmount = temp - detail.SalesAmount;
                            if (bll.Update(detail))
                            {
                                MessageBox.Show("Sales was updated");
                                this.Close();
                            }
                        }
                    }
                }
            }
        }