private void btnConfirmEditCust_Click(object sender, EventArgs e) { if (btnConfirmEditCust.Text == "Edit") { txtAddCustForename.Enabled = true; txtEditCustSurname.Enabled = true; txtEditCustStreet.Enabled = true; txtEditCustTown.Enabled = true; txtEditCustCounty.Enabled = true; txtEditCustPostcode.Enabled = true; txtEditCustTelephoneNo.Enabled = true; txtEditCustEmail.Enabled = true; btnConfirmEditCust.Text = "Save"; } else { //pnlEdit.Visible = false; MyCustomer myCustomer = new MyCustomer(); bool ok = true; errorProvider1.Clear(); try { myCustomer.CustomerNo = lblEditActaulCustNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(lblEditActaulCustNo, MyEx.toString()); } try { myCustomer.Forename = txtEditCustForename.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustForename, MyEx.toString()); } try { myCustomer.Surname = txtEditCustSurname.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustSurname, MyEx.toString()); } try { myCustomer.Street = txtEditCustStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustStreet, MyEx.toString()); } try { myCustomer.Town = txtEditCustTown.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustTown, MyEx.toString()); } try { myCustomer.County = txtEditCustCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustCounty, MyEx.toString()); } try { myCustomer.Postcode = txtEditCustPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustPostcode, MyEx.toString()); } try { myCustomer.TelephoneNo = txtEditCustTelephoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustTelephoneNo, MyEx.toString()); } try { myCustomer.Email = txtEditCustEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtEditCustEmail, MyEx.toString()); } try { if (ok) { drCustomer.BeginEdit(); drCustomer["CustomerNo"] = myCustomer.CustomerNo; drCustomer["Forename"] = myCustomer.Forename; drCustomer["Surname"] = myCustomer.Surname; drCustomer["Street"] = myCustomer.Street; drCustomer["Town"] = myCustomer.Town; drCustomer["County"] = myCustomer.County; drCustomer["Postcode"] = myCustomer.Postcode; drCustomer["TelephoneNo"] = myCustomer.TelephoneNo; drCustomer["Email"] = myCustomer.Email; drCustomer.EndEdit(); daCustomer.Update(dsSurefill, "Customer"); MessageBox.Show("Customer details updated", "Customer"); txtAddCustForename.Enabled = false; txtEditCustSurname.Enabled = false; txtEditCustStreet.Enabled = false; txtEditCustTown.Enabled = false; txtEditCustCounty.Enabled = false; txtEditCustPostcode.Enabled = false; txtEditCustTelephoneNo.Enabled = false; txtEditCustEmail.Enabled = false; btnConfirmEditCust.Text = "Edit"; } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
private void btnConfirmAddCust_Click(object sender, EventArgs e) { MyCustomer myCustomer = new MyCustomer(); bool ok = true; errorProvider1.Clear(); try { myCustomer.CustomerNo = lblAddActualCustomerNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(lblAddActualCustomerNo, MyEx.toString()); } try { myCustomer.Forename = txtAddCustForename.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustForename, MyEx.toString()); } try { myCustomer.Surname = txtAddCustSurname.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustSurname, MyEx.toString()); } try { myCustomer.Street = txtAddCustStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustStreet, MyEx.toString()); } try { myCustomer.Town = txtAddCustTown.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustTown, MyEx.toString()); } try { myCustomer.County = txtAddCustCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustCounty, MyEx.toString()); } try { myCustomer.Postcode = txtAddCustPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustPostcode, MyEx.toString()); } try { myCustomer.TelephoneNo = txtAddCustTelephoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustTelephoneNo, MyEx.toString()); } try { myCustomer.Email = txtAddCustEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errorProvider1.SetError(txtAddCustEmail, MyEx.toString()); } try { if (ok) { drCustomer = dsSurefill.Tables["Customer"].NewRow(); drCustomer["CustomerNo"] = myCustomer.CustomerNo; drCustomer["Forename"] = myCustomer.Forename; drCustomer["Surname"] = myCustomer.Surname; drCustomer["Street"] = myCustomer.Street; drCustomer["Town"] = myCustomer.Town; drCustomer["County"] = myCustomer.County; drCustomer["Postcode"] = myCustomer.Postcode; drCustomer["TelephoneNo"] = myCustomer.TelephoneNo; drCustomer["Email"] = myCustomer.Email; dsSurefill.Tables["Customer"].Rows.Add(drCustomer); daCustomer.Update(dsSurefill, "Customer"); MessageBox.Show("Customer Added"); if (MessageBox.Show("Do you want to add another customer?", "Add Customer", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { clearAddForm(); getNumber(dsSurefill.Tables["Customer"].Rows.Count); } else { } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } //pnlAdd.Visible = false; }