private void btnSave_Click(object sender, EventArgs e) { // int ProductId = int.Parse(txtId.Text.Trim()); string error = ""; if (txtName.Text.Trim().Length == 0) { error += "Name cannot be null \n"; } if (txtQuantity.Text.Trim().Length == 0) { error += "Quantity cannot be null \n"; } if (txtUnit.Text.Trim().Length == 0) { error += "Unit cannot be null \n"; } if (error != null && !error.Equals("")) { MessageBox.Show(error, "ERROR"); // MessageBox.Show() } else { string ProductName = txtName.Text.Trim(); double UnitPrice = double.Parse(txtUnit.Text.Trim()); int Quantity = int.Parse(txtQuantity.Text.Trim()); product.ProductName = ProductName; product.UnitPrice = UnitPrice; product.Quantity = Quantity; if (product.ProductId == 0) { if (manage.AddNew(product)) { MessageBox.Show("Added Successfully!!!"); ViewOrSearch(); } } else { if (manage.AddNew(product)) { MessageBox.Show("Updated Successfully!!!"); ViewOrSearch(); } } Clear(); } }