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(); } } } } } }