private void btnEditSupplier_Click(object sender, EventArgs e) { try { if (!GetConfirmation("Are you sure to edit this Supplier?", "Confirm Edit!!")) { return; } Supplier supplier = new Supplier(txtSupplierName.Text.Trim(), txtSupplierAddress.Text.Trim(), txtSupplierPhoneNumber.Text.Trim(), checkBoxIsActive.Checked); if ((supplierBindingSource.Current as Supplier) == null) { throw new Exception("Couldn't get this Supplier to Edit"); } supplier.Id = (supplierBindingSource.Current as Supplier).Id; CustomResult customResult = bus.EditSupplier(supplier); if (customResult.Result == CustomResultType.Succeed) { supplierDataGridView.Refresh(); MessageBox.Show("Supplier Edited", "Inform", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearSupplierTextBoxes(); ReloadSuppliersProductsBindingSource_Grid(); ReloadAddSupplierProductBindingSource_Supplier(); ReloadRemoveSupplierProductBindingSource_Supplier(); ReloadRemoveSupplierProductBindingSource_Product(); txtSupplierName.Focus(); } else if (customResult.Result == CustomResultType.InvalidModelState) { validator.DisplayModelValidationErrorsAndFocus(supplier.GetType()); } else if (customResult.Result == CustomResultType.InvalidInput) { MessageBox.Show(customResult.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSupplierPhoneNumber.Focus(); } else { throw new Exception(customResult.ErrorMessage); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSupplierName.Focus(); } }