} //Update button to update employee details private void btnDelete_Click(object sender, RoutedEventArgs e) { Employee selectedEmployee = lbxNames.SelectedItem as Employee; FullTimeEmployee selectedEmployeeFT = lbxNames.SelectedItem as FullTimeEmployee; PartTimeEmployee selectedEmployeePT = lbxNames.SelectedItem as PartTimeEmployee; employees.Remove(selectedEmployee); fullTimeEmployees.Remove(selectedEmployeeFT); partTimeEmployees.Remove(selectedEmployeePT); } //Delete button to delete employees
private void UpdateBtn_Click(object sender, RoutedEventArgs e) { //changing employee info //select from list FullTimeEmployee changeFullTimeEmp = EmployeeLB.SelectedItem as FullTimeEmployee; PartTimeEmployee changePartTimeEmp = EmployeeLB.SelectedItem as PartTimeEmployee; //looping through all fulltime employees for (int x = 0; x < fullTimeEmployees.Count; x++) { //if employee selected to change is in fulltime employee list if (changeFullTimeEmp == fullTimeEmployees[x]) { //takes in first name , surname and salary string changedFullTime = FirstNameTBox.Text; string changedPartTime = SurnameTBox.Text; decimal changedSalary = decimal.Parse(SalaryTBox.Text); //sets the new figures to the slected full employee fullTimeEmployees[x].FirstName = changedFullTime; fullTimeEmployees[x].LastName = changedPartTime; fullTimeEmployees[x].Salary = changedSalary; //refresh listbox EmployeeLB.ItemsSource = null; EmployeeLB.ItemsSource = fullTimeEmployees; } } //loops through part employee for (int z = 0; z < partTimeEmployees.Count; z++) { //if selected employee is part time if (changePartTimeEmp == partTimeEmployees[z]) { //takes in new first name , surname, hours rate , hours worked string changedFullTime = FirstNameTBox.Text; string changedPartTime = SurnameTBox.Text; decimal changedHourlyRate = decimal.Parse(HourlyRateTBox.Text); decimal changedHoursWorked = decimal.Parse(HoursWorkedTBox.Text); //sets new details partTimeEmployees[z].FirstName = changedFullTime; partTimeEmployees[z].LastName = changedPartTime; partTimeEmployees[z].HourlyRate = changedHourlyRate; partTimeEmployees[z].HoursWorked = changedHoursWorked; //refresh list box EmployeeLB.ItemsSource = null; EmployeeLB.ItemsSource = partTimeEmployees; } } }
private void DeleteBtn_Click(object sender, RoutedEventArgs e) { //select from list Employee delSelecetEmpl = EmployeeLB.SelectedItem as Employee; FullTimeEmployee delSelecetFullTimeEmpl = EmployeeLB.SelectedItem as FullTimeEmployee; PartTimeEmployee delSelecetPartTimeEmpl = EmployeeLB.SelectedItem as PartTimeEmployee; //loops through full time employee for (int z = 0; z < fullTimeEmployees.Count; z++) { //if selected employee is fulltime if (delSelecetFullTimeEmpl == fullTimeEmployees[z]) { //delete it fullTimeEmployees.RemoveAt(z); } //refresh list EmployeeLB.ItemsSource = null; EmployeeLB.ItemsSource = fullTimeEmployees; } //loop thorugh parttime employees for (int x = 0; x < partTimeEmployees.Count; x++) { // selected employee if (delSelecetPartTimeEmpl == partTimeEmployees[x]) { //delete it partTimeEmployees.RemoveAt(x); //refresh listbox EmployeeLB.ItemsSource = null; EmployeeLB.ItemsSource = partTimeEmployees; } } //loop through employee for (int Q = 0; Q < employees.Count; Q++) { if (delSelecetEmpl == employees[Q]) { //delete employee employees.RemoveAt(Q); //refresh page EmployeeLB.ItemsSource = null; EmployeeLB.ItemsSource = employees; } } }
private void Window_Loaded_1(object sender, RoutedEventArgs e) { FullTimeEmployee e1 = new FullTimeEmployee("John", "Munnelly", 15000); FullTimeEmployee e2 = new FullTimeEmployee("Robert", "Butler", 22250); PartTimeEmployee e3 = new PartTimeEmployee("Lenny", "Mcgourthy", 2000, 1000); PartTimeEmployee e4 = new PartTimeEmployee("Brian", "Hagan", 2000, 1200); //adds to observable collection fullTimeEmployees.Add(e1); fullTimeEmployees.Add(e2); //Add to Listbox lbxNames.ItemsSource = fullTimeEmployees; //adds to observable collection partTimeEmployees.Add(e3); partTimeEmployees.Add(e4); //Add to listbox lbxNames.ItemsSource = partTimeEmployees; }
//Window Loads private void Window_Loaded(object sender, RoutedEventArgs e) { Employee e1 = new PartTimeEmployee("Jane", "Jones", "Part Time", 10, 25); PartTimeEmployee pt1 = new PartTimeEmployee("Jane", "Jones", "Part Time", 10, 25); Employee e2 = new FullTimeEmployee("Joe", "Murphy", "Full Time", 52000); FullTimeEmployee ft1 = new FullTimeEmployee("Joe", "Murphy", "Full Time", 52000); Employee e3 = new PartTimeEmployee("John", "Smith", "Part Time", 12, 18); PartTimeEmployee pt2 = new PartTimeEmployee("John", "Smith", "Part Time", 12, 18); Employee e4 = new FullTimeEmployee("Jess", "Walsh", "Full Time", 78000); FullTimeEmployee ft2 = new FullTimeEmployee("Jess", "Walsh", "Full Time", 78000); employees.Add(e1); partTimeEmployees.Add(pt1); employees.Add(e2); fullTimeEmployees.Add(ft1); employees.Add(e3); partTimeEmployees.Add(pt2); employees.Add(e4); fullTimeEmployees.Add(ft2); lbxNames.ItemsSource = employees; } //Adds employees to list when the window loads
} //Clear button to clear all text boxes private void btnUpdate_Click(object sender, RoutedEventArgs e) { Employee Employee = lbxNames.SelectedItem as Employee; FullTimeEmployee FullTimeEmployee = lbxNames.SelectedItem as FullTimeEmployee; PartTimeEmployee PartTimeEmployee = lbxNames.SelectedItem as PartTimeEmployee; string FirstName = tbxFirstName.Text; string Surname = tbxSurname.Text; string WorkType; if (rbtnFT.IsChecked == true) { decimal Salary = Convert.ToDecimal(tbxSalary.Text); WorkType = "FullTime"; } else if (rbtnPT.IsChecked == true) { string HoursWorked = tbxHoursWorked.Text; string HourlyRate = tbxHourlyRate.Text; WorkType = "PartTime"; } } //Update button to update employee details
//seleted employee will display their information right private void EmployeeLB_SelectionChanged(object sender, SelectionChangedEventArgs e) { //take list to display from employee , full time and part time to be slected Employee selecetedEmployee = EmployeeLB.SelectedItem as Employee; PartTimeEmployee selecetedPartTime = EmployeeLB.SelectedItem as PartTimeEmployee; FullTimeEmployee selecetedFullTime = EmployeeLB.SelectedItem as FullTimeEmployee; //if a employee is selected if (selecetedEmployee != null) { //takes in first & last names FirstNameTBox.Text = selecetedEmployee.FirstName; SurnameTBox.Text = selecetedEmployee.LastName; if (selecetedEmployee.Shift == "Full Time") { // if full time needs to dispaly salary //clear hours worked and hour rate to not display anything HoursWorkedTBox.Clear(); HourlyRateTBox.Clear(); //dispaly salary in salaryTBox SalaryTBox.Text = selecetedFullTime.Salary.ToString(); } else { // else they will be part time //dont need salary so clear SalaryTBox.Clear(); HoursWorkedTBox.Text = selecetedPartTime.HourlyRate.ToString(); //display hours worked HourlyRateTBox.Text = selecetedPartTime.HoursWorked.ToString(); //display hours rate } // display Monthly Pay in textblock rounded up monthlyPayTxtBlock.Text = Decimal.Round(selecetedEmployee.CalculateMonthlyPay()).ToString(); } }