/// <summary> /// Adds the employee when the Ok button is clicked. /// </summary> /// <param name="sender">The button that is clicked.</param> /// <param name="e">Additional event information.</param> private void btnOK_Click(object sender, EventArgs e) { try { if (IsValidData()) { Employee employee = employeeDA.GetEmployeeByEmployeeId(txtEmployeeId.Text); if (employee == null) { employee = new Employee(txtEmployeeId.Text, txtFullName.Text, (Department)cboDepartment.SelectedItem, dtpWeekStartDate.Value, updSalary.Value); employeeDA.AddEmployee(employee); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Employee is already on list.", "Add Employee", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmployeeId.SelectAll(); txtEmployeeId.Focus(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.GetType().ToString() + "\n" + ex.StackTrace, "Exception Caught", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Removes a employee when the Remove button is clicked. /// It then updates the user interface. /// </summary> /// <param name="sender">The button that is clicked.</param> /// <param name="e">Additional event information.</param> private void btnRemove_Click(object sender, EventArgs e) { if (lvwEmployees.SelectedIndices.Count == 0) { MessageBox.Show("No employee was selected.", "Remove Employee", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int index = lvwEmployees.SelectedIndices[0]; DialogResult answer = MessageBox.Show("Are you sure you want to remove?", "Remove Employee", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (answer == DialogResult.Yes) { string employeeId = lvwEmployees.Items[index].SubItems[0].Text; Employee employee = employeeDA.GetEmployeeByEmployeeId(employeeId); employeeDA.RemoveEmployee(employee); this.FillEmployeeListView(); } else { lvwEmployees.Items[index].Selected = false; } } lvwEmployees.Focus(); }
/// <summary> /// Creates a Modify Employee form and displays the data of the employee with /// the given employeeId. /// </summary> /// <param name="employeeDA">Provides data access for a employee.</param> /// <param name="employeeId">The employeeId of the employee being modified.</param> public ModifyEmployeeForm(IEmployeeDA employeeDA, string employeeId) { InitializeComponent(); this.employeeDA = employeeDA; employee = employeeDA.GetEmployeeByEmployeeId(employeeId); txtEmployeeId.Text = employee.EmployeeId; txtFullName.Text = employee.FullName; cboDepartment.Text = employee.Department.ToString(); dtpWeekStartDate.Value = employee.WeekStart; updSalary.Value = employee.Salary; }
/// <summary> /// Creates a View Employee form and displays the data of the employee with /// the given employeeId. /// </summary> /// <param name="employeeDA">Provides data access for a employee.</param> /// <param name="employeeId">The employeeId of the employee being modified.</param> public ViewEmployeeForm(IEmployeeDA employeeDA, String employeeId) { InitializeComponent(); this.employeeDA = employeeDA; employee = employeeDA.GetEmployeeByEmployeeId(employeeId); txtEmployeeId.Text = employee.EmployeeId; txtFullName.Text = employee.FullName; txtDepartment.Text = employee.Department.ToString(); txtWeekStart.Text = employee.WeekStart.ToString("d"); txtSalary.Text = employee.Salary.ToString("c"); }