// button for accepting the form private void btnAccept_Click(object sender, EventArgs e) { if (txtCName.IsPresent()) { //for add if (add) { this.createSupplierObjects(); try { SupplierDB.AddSupp(supplier); SupplierContactsDB.AddSupp(supplierContact); foreach (Products_Suppliers ps in productSuppliers) { ps.supplierid = supplier.SupplierId; Products_SuppliersDB.AddProdSupp(ps); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } // for modify else { SupplierContacts newSupplierinfo = new SupplierContacts(); newSupplierinfo.SupplierContactId = Convert.ToInt32(txtSCID.Text); newSupplierinfo.SupConFirstName = txtFirst.Text.ToString(); newSupplierinfo.SupConLastName = txtLast.Text.ToString(); newSupplierinfo.SupConCompany = txtCName.Text.ToString(); newSupplierinfo.SupConAddress = txtAddress.Text.ToString(); newSupplierinfo.SupConCity = txtCity.Text.ToString(); newSupplierinfo.SupConProv = txtProv.Text.ToString(); newSupplierinfo.SupConPostal = txtPO.Text.ToString(); newSupplierinfo.SupConCountry = txtCountry.Text.ToString(); newSupplierinfo.SupConBusPhone = txtPhone.Text.ToString(); newSupplierinfo.SupConFax = txtFax.Text.ToString(); newSupplierinfo.SupConEmail = txtEmail.Text.ToString(); newSupplierinfo.SupConURL = txtURL.Text.ToString(); newSupplierinfo.AffiliationId = ""; newSupplierinfo.SupplierId = Convert.ToInt32(txtSCID.Text); try { if (!SupplierContactsDB.UpdateSupplier(supplierContact, newSupplierinfo)) { MessageBox.Show("That Supplier has been updated or deleted already.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { supplierContact = newSupplierinfo; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }