private void picCustomerSave_Click(object sender, EventArgs e) { MyCustomer myCust = new MyCustomer(); bool ok = true; errP.Clear(); //Customer Number try { myCust.CustomerNumber = lblCustNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblCustNo, MyEx.toString()); } //Customer Title try { myCust.Title = cmbTitle.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbTitle, MyEx.toString()); } //Customer Forename try { myCust.Forename = txtForename.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtForename, MyEx.toString()); } //Customer Surname try { myCust.Surname = txtSurname.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtSurname, MyEx.toString()); } //Customer Street try { myCust.Street = txtStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtStreet, MyEx.toString()); } //Customer City try { myCust.City = txtCity.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCity, MyEx.toString()); } //Customer County try { myCust.County = txtCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCounty, MyEx.toString()); } //Customer PostCode try { myCust.Postcode = txtPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPostcode, MyEx.toString()); } //Customer TelNo try { myCust.TelNo = txtPhoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPhoneNo, MyEx.toString()); } //Try Adding try { if (ok) { drCustomer = dsBelfray.Tables["Customer"].NewRow(); drCustomer["customerNo"] = myCust.CustomerNumber; drCustomer["customerTitle"] = myCust.Title; drCustomer["customerForename"] = myCust.Forename; drCustomer["customerSurname"] = myCust.Surname; drCustomer["customerStreet"] = myCust.Street; drCustomer["customerCity"] = myCust.City; drCustomer["customerCounty"] = myCust.County; drCustomer["customerPostcode"] = myCust.Postcode; drCustomer["customerTel"] = myCust.TelNo; dsBelfray.Tables["Customer"].Rows.Add(drCustomer); daCustomer.Update(dsBelfray, "Customer"); MessageBox.Show("Customer Added"); clearCustomerPanel(); custPanelCont(); bookPanelCont(); int noRows = dsBelfray.Tables["Customer"].Rows.Count; //cb ProductType cmbCustomerNo.DataSource = dsBelfray.Tables["Customer"]; cmbCustomerNo.ValueMember = "customerNo"; cmbCustomerNo.DisplayMember = "customerNo"; cmbCustomerNo.SelectedIndex = noRows - 1; } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }
private void picCustomerSave_Click(object sender, EventArgs e) { MyCustomer myCust = new MyCustomer(); bool ok = true; errP.Clear(); //Customer Number try { myCust.CustomerNumber = lblCustNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblCustNo, MyEx.toString()); } //Customer Title try { myCust.Title = cmbTitle.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbTitle, MyEx.toString()); } //Customer Forename try { myCust.Forename = txtForename.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtForename, MyEx.toString()); } //Customer Surname try { myCust.Surname = txtSurname.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtSurname, MyEx.toString()); } //Customer Street try { myCust.Street = txtStreet.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtStreet, MyEx.toString()); } //Customer City try { myCust.City = txtCity.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCity, MyEx.toString()); } //Customer County try { myCust.County = txtCounty.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCounty, MyEx.toString()); } //Customer PostCode try { myCust.Postcode = txtPostcode.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPostcode, MyEx.toString()); } //Customer TelNo try { myCust.TelNo = txtPhoneNo.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPhoneNo, MyEx.toString()); } //Try Adding try { if (ok) { drCustomer.BeginEdit(); drCustomer["customerForename"] = myCust.Title; drCustomer["customerForename"] = myCust.Forename; drCustomer["customerSurname"] = myCust.Surname; drCustomer["customerStreet"] = myCust.Street; drCustomer["customerCity"] = myCust.City; drCustomer["customerCounty"] = myCust.County; drCustomer["customerPostcode"] = myCust.Postcode; drCustomer["customerTel"] = myCust.TelNo; drCustomer.EndEdit(); daCustomer.Update(dsBelfray, "Customer"); MessageBox.Show("Customer Updated"); disableCustomerEdit(); } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }