private void btnEditSupp_Click(object sender, EventArgs e) { if (btnEditSupp.Text == "EDIT SUPPLIER") { enableEditTxtboxes(); btnEditSupp.Text = "Save"; } else { MySupplier mySupplier = new MySupplier(); bool ok = true; errP.Clear(); try { mySupplier.Address = txtEdSuppAddress.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdSuppAddress, MyEx.toString()); } try { mySupplier.CompanyContact = txtEdContact.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdContact, MyEx.toString()); } try { mySupplier.TelNo = txtEDSuppTel.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEDSuppTel, MyEx.toString()); } try { mySupplier.Email = txtEdSuppEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdSuppEmail, MyEx.toString()); } try { mySupplier.CompanyName = txtEdCompName.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdCompName, MyEx.toString()); } try { if (ok) { drSupplier.BeginEdit(); //drSupplier = dsKaizen.Tables["Supplier"].NewRow(); drSupplier["SuppName"] = mySupplier.CompanyName; drSupplier["SuppCont"] = mySupplier.CompanyContact; drSupplier["SuppAddress"] = mySupplier.Address; drSupplier["SuppTel"] = mySupplier.TelNo; drSupplier["SuppEmail"] = mySupplier.Email; drSupplier.EndEdit(); daSupplier.Update(dsKaizen, "Supplier"); MessageBox.Show("Supplier Details Updated", "Supplier"); btnEditSupp.Text = "EDIT CUSTOMER"; tabSupplier.SelectedIndex = 0; } //disableEditTxtboxes(); } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
private void BtnSaveSup_Click(object sender, EventArgs e) { MySupplier mySupplier = new MySupplier(); bool ok = true; errP.Clear(); try { mySupplier.SuppID = lblSuppID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblSuppID, MyEx.toString()); } try { mySupplier.Address = txtSupAddress.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtSupAddress, MyEx.toString()); } try { mySupplier.CompanyContact = txtContact.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtContact, MyEx.toString()); } try { mySupplier.TelNo = txtSupTel.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtSupTel, MyEx.toString()); } try { mySupplier.Email = txtSupEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtSupEmail, MyEx.toString()); } try { mySupplier.CompanyName = txtCompName.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCompName, MyEx.toString()); } try { if (ok) { drSupplier = dsKaizen.Tables["Supplier"].NewRow(); drSupplier["SuppID"] = mySupplier.SuppID; drSupplier["SuppName"] = mySupplier.CompanyName; drSupplier["SuppCont"] = mySupplier.CompanyContact; drSupplier["SuppAddress"] = mySupplier.Address; drSupplier["SuppTel"] = mySupplier.TelNo; drSupplier["SuppEmail"] = mySupplier.Email; dsKaizen.Tables["Supplier"].Rows.Add(drSupplier); daSupplier.Update(dsKaizen, "Supplier"); MessageBox.Show("Supplier Added"); if (MessageBox.Show("Do you wish to add another Supplier?", "Add Supplier", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { clearAddForm(); getSuppID(dsKaizen.Tables["Supplier"].Rows.Count); } else { tabSupplier.SelectedIndex = 0; } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }