private void btnUpdate_Click(object sender, RoutedEventArgs e) //When Update button is clicked { Employee selectedEmployee = lbxEmployees.SelectedItem as Employee; //Saving the Data of selected Employee in another employee object if (selectedEmployee != null) //Making sure an employee is selected { //Checking if there is valid data inputted if (tbxFirstName.Text != "First Name..." && tbxFirstName.Text != "" && tbxLastName.Text != "Last Name..." && tbxLastName.Text != "" && (rbtnFullTime.IsChecked != false || rbtnPartTime.IsChecked != false)) { FullTimeEmployee tempFT = null; PartTimeEmployee tempPT = null; if (selectedEmployee is FullTimeEmployee) { UpdateFTEmployee(tempFT, tempPT, selectedEmployee);//Updating FT Employee } else { UpdatePTEmployee(tempFT, tempPT, selectedEmployee);//Updating PT Employee } } else//Show error message { MessageBox.Show("To Update an Employee, You Must Enter:\nFirst Name,\nLast Name,\nIf FT or PT," + "\n& All Relevant Data!"); ResetData(selectedEmployee);//Reset back to old data } } else//Show Error message { MessageBox.Show("To Update an Employee, You Must Select an Employee from the Employees' List!"); } }
private void lbxEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e) //Change of selection in listbox { Employee selectedEmployee = lbxEmployees.SelectedItem as Employee; //Saving the Data of selected Employee in another employee object if (selectedEmployee != null) //Making sure an employee is selected { //Setting the fields on the right of the display to the selected employee's data tbxFirstName.Text = selectedEmployee.FirstName; tbxLastName.Text = selectedEmployee.LastName; //Reseting Backgrounds to White, in case they are not tbxFirstName.Background = Brushes.White; tbxLastName.Background = Brushes.White; rbtnFullTime.Background = Brushes.White; rbtnPartTime.Background = Brushes.White; if (selectedEmployee is FullTimeEmployee) { FullTimeEmployee temp = (FullTimeEmployee)selectedEmployee; rbtnFullTime.IsChecked = true; tbxSalary.Text = temp.Salary.ToString(); tbxHoursWorked.Text = ""; tbxHourlyRate.Text = ""; tblkMonthlyPay.Text = temp.CalculateMonthlyPay().ToString("€0.00"); } else { PartTimeEmployee temp = (PartTimeEmployee)selectedEmployee; rbtnPartTime.IsChecked = true; tbxSalary.Text = ""; tbxHoursWorked.Text = temp.HoursWorked.ToString(); tbxHourlyRate.Text = temp.HourlyRate.ToString(); tblkMonthlyPay.Text = temp.CalculateMonthlyPay().ToString("€0.00"); } } }
private void CreateInitialEmployees() { //Create New Employees FullTimeEmployee fEmp1 = new FullTimeEmployee("Leopold", "Fitz", 32000); FullTimeEmployee fEmp2 = new FullTimeEmployee("Gemma", "Simmons", 35000); PartTimeEmployee pEmp1 = new PartTimeEmployee("Grant", "Ward", 8.5m, 10); PartTimeEmployee pEmp2 = new PartTimeEmployee("Daisy", "Johnson", 9.5m, 10); //Add Employees To List employees.Add(fEmp1); employees.Add(fEmp2); employees.Add(pEmp1); employees.Add(pEmp2); }
private void UpdateFTEmployee(FullTimeEmployee tempFT, PartTimeEmployee tempPT, Employee selectedEmployee)//Updating FT Employee { //Updating employee with inputted data tempFT = (FullTimeEmployee)selectedEmployee; if (tbxSalary.Text != "Salary..." && tbxSalary.Text != "") { tempFT.FirstName = tbxFirstName.Text; tempFT.LastName = tbxLastName.Text; tempFT.Salary = Convert.ToDecimal(tbxSalary.Text); UpdateEmployees(tempFT, tempPT, selectedEmployee); } else//Display error message { MessageBox.Show("To Update an Employee, You Must Enter All Relevant Data!"); tbxSalary.Text = tempFT.Salary.ToString(); tblkMonthlyPay.Text = tempFT.CalculateMonthlyPay().ToString("€0.00"); } }
private void AddNewEmployee() { FullTimeEmployee newFTEmp; PartTimeEmployee newPTEmp; //Setting inputted data, the data for new employee string firstName = tbxFirstName.Text; string lastName = tbxLastName.Text; if (rbtnFullTime.IsChecked == true) { if (tbxSalary.Text != "Salary..." && tbxSalary.Text != "") { decimal salary = Convert.ToDecimal(tbxSalary.Text); newFTEmp = new FullTimeEmployee(firstName, lastName, salary);//Creating new employee object } else { newFTEmp = new FullTimeEmployee(firstName, lastName); //Creating new employee object } employees.Add(newFTEmp); //Adding the new employee to the list of employees lbxEmployees.ItemsSource = null; //Refreshing the display in the listbox CkBxIsChecked(); //Check Filtering lbxEmployees.SelectedItem = newFTEmp; //Selecting the new employee } else if (rbtnPartTime.IsChecked == true) { if (tbxHoursWorked.Text != "Hours Worked..." && tbxHoursWorked.Text != "" && tbxHourlyRate.Text != "Hourly Rate..." && tbxHourlyRate.Text != "") { double hoursWorked = Convert.ToDouble(tbxHoursWorked.Text); decimal hourlyRate = Convert.ToDecimal(tbxHourlyRate.Text); newPTEmp = new PartTimeEmployee(firstName, lastName, hourlyRate, hoursWorked);//Creating new employee object } else { newPTEmp = new PartTimeEmployee(firstName, lastName); //Creating new employee object } employees.Add(newPTEmp); //Adding the new employee to the list of employees lbxEmployees.ItemsSource = null; //Refreshing the display in the listbox CkBxIsChecked(); //Check Filtering lbxEmployees.SelectedItem = newPTEmp; //Selecting the new employee } }
private void UpdateEmployees(FullTimeEmployee tempFT, PartTimeEmployee tempPT, Employee selectedEmployee)//Updating Employees' List/Refreshing Data { if (tempFT != null) { employees.Remove(selectedEmployee); //Remove the old employee object from the list employees.Add(tempFT); //Add the new updated version of the employee to the list lbxEmployees.ItemsSource = null; //Refreshing the display in the listbox CkBxIsChecked(); //Check Filtering lbxEmployees.SelectedItem = tempFT; //Setting the selected item to the new updated employee } else { employees.Remove(selectedEmployee); //Remove the old employee object from the list employees.Add(tempPT); //Add the new updated version of the employee to the list lbxEmployees.ItemsSource = null; //Refreshing the display in the listbox CkBxIsChecked(); //Check Filtering lbxEmployees.SelectedItem = tempPT; //Setting the selected item to the new updated employee } }
private void ResetData(Employee selectedEmployee)//Resetting back to old Data { tbxFirstName.Text = selectedEmployee.FirstName; tbxLastName.Text = selectedEmployee.LastName; if (selectedEmployee is FullTimeEmployee) { FullTimeEmployee temp = (FullTimeEmployee)selectedEmployee; rbtnFullTime.IsChecked = true; tbxSalary.Text = temp.Salary.ToString(); tblkMonthlyPay.Text = temp.CalculateMonthlyPay().ToString("€0.00"); } else { PartTimeEmployee temp = (PartTimeEmployee)selectedEmployee; rbtnPartTime.IsChecked = true; tbxHoursWorked.Text = temp.HoursWorked.ToString(); tbxHourlyRate.Text = temp.HourlyRate.ToString(); tblkMonthlyPay.Text = temp.CalculateMonthlyPay().ToString("€0.00"); } }