private void btn_edit_Click(object sender, EventArgs e) { int deptId = getDepartment(); if (validateFields()) { try { foreach (Employee emp in employee) { foreach (User u in user) { if (empId == emp.EmployeeID && emp.UserID == u.UserID) { SysAdmin_Rules.EditEmployee(empId, txt_firstName.Text, txt_lastName.Text, txt_phoneNum.Text, deptId); SysAdmin_Rules.EditUser(u.UserID, txt_username.Text, txt_password.Text); MessageBox.Show("The details for employee " + txt_firstName.Text + " has been successfully updated!"); this.Close(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btn_Create_Click(object sender, EventArgs e) { int dept = getDepartment(); if (validateFields()) { IUser duplicateUser = model.UserList.FirstOrDefault(user => user.Username == txt_username.Text.Trim()); if (duplicateUser == null) { try { SysAdmin_Rules.AddUser(Convert.ToInt32(txt_userId.Text), txt_username.Text, txt_password.Text); SysAdmin_Rules.AddEmployee(Convert.ToInt32(txt_employeeId.Text), txt_firstName.Text, txt_lastName.Text, txt_phoneNum.Text, dept, Convert.ToInt32(txt_userId.Text)); MessageBox.Show("The employee " + txt_firstName.Text + " was successfully added! An user account was created with username " + txt_username.Text); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("The username " + txt_username.Text + " already exists please try another username!"); } } }
private void btn_delete_Click(object sender, EventArgs e) { if (empId != 0) { if (MessageBox.Show("Are you sure you want to delete the employee " + txt_firstName.Text + " ?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { SysAdmin_Rules.DeleteEmployee(empId); MessageBox.Show("The employee " + txt_firstName.Text + " was successfully deleted!"); this.Close(); } } }