private void btnEdEdit_Click(object sender, EventArgs e) { if (btnEdEdit.Text.Trim() == "EDIT") { enableEditTxtboxes(); btnEdEdit.Text = "Save"; } else { MyStaff myStaff = new MyStaff(); bool ok = true; errP.Clear(); try { myStaff.StaffID = lblEdStaffID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblEdStaffID, MyEx.toString()); } try { myStaff.Email = txtEdEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdEmail, MyEx.toString()); } try { myStaff.Forename = txtEdForeN.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdForeN, MyEx.toString()); } try { myStaff.TelNo = txtEdTel.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdTel, MyEx.toString()); } try { myStaff.Job = txtEdJobR.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdJobR, MyEx.toString()); } try { myStaff.Surname = txtEdSurN.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdSurN, MyEx.toString()); } try { myStaff.JobDescription = txtEdJobDesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEdJobDesc, MyEx.toString()); } try { if (ok) { drStaff.BeginEdit(); drStaff["StaffID"] = myStaff.StaffID; drStaff["StaffFName"] = myStaff.Forename; drStaff["StaffSName"] = myStaff.Surname; drStaff["Job"] = myStaff.Job; drStaff["JobDesc"] = myStaff.JobDescription; drStaff["StaffEmail"] = myStaff.Email; drStaff["StaffTel"] = myStaff.TelNo; drStaff.EndEdit(); daStaff.Update(dsKaizen, "Staff"); btnEdEdit.Text = "EDIT"; MessageBox.Show("Employee Details Updated", "Staff"); tabStaff.SelectedIndex = 0; disableEditTxtboxes(); } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
private void btnAAStaff_Click(object sender, EventArgs e) { MyStaff myStaff = new MyStaff(); bool ok = true; errP.Clear(); try { myStaff.StaffID = lblAddStaffID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblAddStaffID, MyEx.toString()); } try { myStaff.Email = txtAEmail.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtAEmail, MyEx.toString()); } try { myStaff.Forename = txtAForeN.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtAForeN, MyEx.toString()); } try { myStaff.TelNo = txtATel.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtATel, MyEx.toString()); } try { myStaff.Job = cmbAJr.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbAJr, MyEx.toString()); } try { myStaff.Surname = txtASurN.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtASurN, MyEx.toString()); } try { myStaff.JobDescription = txtAJobDesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtAJobDesc, MyEx.toString()); } try { if (ok) { drStaff = dsKaizen.Tables["Staff"].NewRow(); drStaff["StaffID"] = myStaff.StaffID; drStaff["StaffFName"] = myStaff.Forename; drStaff["StaffSName"] = myStaff.Surname; drStaff["Job"] = myStaff.Job; drStaff["JobDesc"] = myStaff.JobDescription; drStaff["StaffEmail"] = myStaff.Email; drStaff["StaffTel"] = myStaff.TelNo; dsKaizen.Tables["Staff"].Rows.Add(drStaff); daStaff.Update(dsKaizen, "Staff"); MessageBox.Show("Employee Added"); if (MessageBox.Show("Do you wish to add another Employee?", "Add Employee", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { clearAddForm(); getStaffID(dsKaizen.Tables["Staff"].Rows.Count); } else { tabStaff.SelectedIndex = 0; } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }