private void btnConfirmEditSupplier_Click(object sender, EventArgs e) { if (btnConfirmEditSupplier.Text == "Edit") { txtAddSupplierName.Enabled = true; txtEditSupplierStreet.Enabled = true; txtEditSupplierTown.Enabled = true; txtEditSupplierCounty.Enabled = true; txtEditSupplierPostcode.Enabled = true; txtEditSupplierEmail.Enabled = true; txtEditSupplierTelephoneNo.Enabled = true; btnConfirmEditSupplier.Text = "Save"; } else { MySupplier mySupplier = new MySupplier(); bool ok = true; errorProvider1.Clear(); try { mySupplier.SupplierNo = lblEditActualSupplierNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(lblEditActualSupplierNo, MyEx.toString()); } try { mySupplier.Name = txtEditSupplierName.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierName, MyEx.toString()); } try { mySupplier.Street = txtEditSupplierStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierStreet, MyEx.toString()); } try { mySupplier.Town = txtEditSupplierTown.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierTown, MyEx.toString()); } try { mySupplier.County = txtEditSupplierCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierCounty, MyEx.toString()); } try { mySupplier.Postcode = txtEditSupplierPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierPostcode, MyEx.toString()); } try { mySupplier.TelephoneNo = txtEditSupplierTelephoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierTelephoneNo, MyEx.toString()); } try { mySupplier.Email = txtEditSupplierEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditSupplierEmail, MyEx.toString()); } try { if (ok) { drSupplier.BeginEdit(); drSupplier["SupplierNo"] = mySupplier.SupplierNo; drSupplier["Name"] = mySupplier.Name; drSupplier["Street"] = mySupplier.Street; drSupplier["Town"] = mySupplier.Town; drSupplier["County"] = mySupplier.County; drSupplier["Postcode"] = mySupplier.Postcode; drSupplier["Email"] = mySupplier.Email; drSupplier["TelephoneNo"] = mySupplier.TelephoneNo; drSupplier.EndEdit(); daSupplier.Update(dsSurefill, "Supplier"); MessageBox.Show("Supplier details updated", "Supplier"); txtEditSupplierName.Enabled = false; txtEditSupplierStreet.Enabled = false; txtEditSupplierTown.Enabled = false; txtEditSupplierCounty.Enabled = false; txtEditSupplierPostcode.Enabled = false; txtEditSupplierEmail.Enabled = false; txtEditSupplierTelephoneNo.Enabled = false; btnConfirmEditSupplier.Text = "Edit"; } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
private void btnConfirmAddSupplier_Click(object sender, EventArgs e) { MySupplier mySupplier = new MySupplier(); bool ok = true; errorProvider1.Clear(); try { mySupplier.SupplierNo = lblAddActualSupplierNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(lblAddActualSupplierNo, MyEx.toString()); } try { mySupplier.Name = txtAddSupplierName.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierName, MyEx.toString()); } try { mySupplier.Street = txtAddSupplierStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierStreet, MyEx.toString()); } try { mySupplier.Town = txtAddSupplierTown.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierTown, MyEx.toString()); } try { mySupplier.County = txtAddSupplierCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierCounty, MyEx.toString()); } try { mySupplier.Postcode = txtAddSupplierPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierPostcode, MyEx.toString()); } try { mySupplier.TelephoneNo = txtAddSupplierTelephoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierTelephoneNo, MyEx.toString()); } try { mySupplier.Email = txtAddSupplierEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddSupplierEmail, MyEx.toString()); } try { if (ok) { drSupplier = dsSurefill.Tables["Supplier"].NewRow(); drSupplier["SupplierNo"] = mySupplier.SupplierNo; drSupplier["Name"] = mySupplier.Name; drSupplier["Street"] = mySupplier.Street; drSupplier["Town"] = mySupplier.Town; drSupplier["County"] = mySupplier.County; drSupplier["Postcode"] = mySupplier.Postcode; drSupplier["Email"] = mySupplier.Email; drSupplier["TelephoneNo"] = mySupplier.TelephoneNo; dsSurefill.Tables["Supplier"].Rows.Add(drSupplier); daSupplier.Update(dsSurefill, "Supplier"); MessageBox.Show("Supplier Added"); if (MessageBox.Show("Do you want to add another Supplier?", "Add Supplier", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { clearAddForm(); getNumber(dsSurefill.Tables["Supplier"].Rows.Count); } else { } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }