Beispiel #1
0
        // Delete employee button
        private void BtnDeleteEmployee_Click(object sender, EventArgs e)
        {
            // Locating the selected employee in the list box and deleting it
            ClsEmployeeDetails lcEmplyeeDetails = (ClsEmployeeDetails)LstEmployees.SelectedItem;

            // If the list is empty display message box saying there are no employees to delete
            if (lcEmplyeeDetails == null)
            {
                DialogResult NoEmployeeToDelete = MessageBox.Show("There are no employees to delete", "No Employees",
                                                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (NoEmployeeToDelete == DialogResult.OK)
                {
                    return;
                }
            }
            else
            {
                // Display message box asking if user wants to delete an employee first
                DialogResult DeletingEmployeeMessage = MessageBox.Show("You are about to delete an employee, are you sure you want to do this?", "Deleting Employee",
                                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                // If user selects yes
                if (DeletingEmployeeMessage == DialogResult.Yes)
                {
                    // Call delete employee method
                    DeleteEmployee();
                }
                else
                {
                    // Else close the message box and dont delete because the user clicked no
                    return;
                }
            }
        }
Beispiel #2
0
        // Delete employee details
        private void DeleteEmployee()
        {
            // Find the selected employee in the list
            ClsEmployeeDetails lcEmployeeDetails = (ClsEmployeeDetails)LstEmployees.SelectedItem;

            // Remove the selected employee
            ClsEmployeeList.EmployeeList.Remove(lcEmployeeDetails.ID);
            // Update the list box to show that the employee has been removed
            UpdateDisplay();
        }
 // Execute when we want this form to display itself, we now have show dialog to return a boolean rather than a dialog result due to the classes now call show dialog,
 // If we continue to use dialog result in our classes then we would need a refernce to window forms which is called talking to strangers and is poor style
 public bool ShowDialog(ClsEmployeeDetails prEmployeeDetails)
 {
     // Storing the parameter value in our member variable _EmployeeDetails
     _EmployeeDetails = prEmployeeDetails;
     // Calling the update display method
     UpdateDisplay();
     // Default method, this will return OK or cancel depends on what the user clicks on
     // This now returns a bool true/false
     return(ShowDialog() == DialogResult.OK);
 }
Beispiel #4
0
        // Edit employee details, now accepts an employee parameter
        private void EditEmployeeDetails()
        {
            // Locating the selected employee in the list box and editing it
            ClsEmployeeDetails lcEmplyeeDetails = (ClsEmployeeDetails)LstEmployees.SelectedItem;

            // If employee is not empty we edit it
            if (lcEmplyeeDetails != null && lcEmplyeeDetails.ViewEdit())
            {
                // Call update display method
                UpdateDisplay();
            }
        }
Beispiel #5
0
        // Create employee method
        private void CreateEmployee()
        {
            // We create a new employee by calling the factory method NewEmployee in ClsEmployeeDetails and stroing it in the local variable lcEmployeeDetails
            ClsEmployeeDetails lcEmployeeDetails = ClsEmployeeDetails.NewEmployee(CboEmployeeType.SelectedIndex);

            // If the user didn't cancel
            if (lcEmployeeDetails != null && lcEmployeeDetails.ViewEdit())
            {
                // Add the new employee details to the list box, as we are adding to a dictionary we need to put the key in
                ClsEmployeeList.EmployeeList.Add(lcEmployeeDetails.ID, lcEmployeeDetails);
                // Then we update the display to show the new employee in teh list box
                UpdateDisplay();
            }
        }
Beispiel #6
0
        // Modify employee button
        private void BtnModifyEmployee_Click(object sender, EventArgs e)
        {
            // Locating the selected employee in the list box and editing it
            ClsEmployeeDetails lcEmplyeeDetails = (ClsEmployeeDetails)LstEmployees.SelectedItem;

            // If no employees exist
            if (lcEmplyeeDetails == null)
            {
                // Call the message box method and display it
                NoEmployeeToEdit();
            }
            else
            {
                // Else edit the employe details
                EditEmployeeDetails();
            }
        }