private void ClrBtn_Click(object sender, RoutedEventArgs e) // event to clear text boxes { TxtBoxFN.Clear(); // clear the First Name Text Box TxtBoxSn.Clear(); // clear the Surname Text Box TxtBoxHR.Clear(); // clear the Hourly Rate Text Box TxtBoxHW.Clear(); // clear the Hours Worked Text Box TxtBoxSalary.Clear(); // clear the Salary Text Box TxtBlockMP2.Text = "$0"; // clear monhtlypay text block RBtnFT.IsChecked = false; // clear the Full Time radial button RBtnPT.IsChecked = false; // clear the Part Time radial button }
private void DeleteBtn_Click(object sender, RoutedEventArgs e) { Employee selectedEmployee = ListBox.SelectedItem as Employee; if (selectedEmployee != null) // ensure selected item isnt null { employees.Remove(selectedEmployee); // remove selected employee } TxtBoxFN.Clear(); // clear the First Name Text Box TxtBoxSn.Clear(); // clear the Surname Text Box TxtBoxHR.Clear(); // clear the Hourly Rate Text Box TxtBoxHW.Clear(); // clear the Hours Worked Text Box TxtBoxSalary.Clear(); // clear the Salary Text Box TxtBlockMP2.Text = "$0"; // clear monhtlypay text block RBtnFT.IsChecked = false; // clear the Full Time radial button RBtnPT.IsChecked = false; // clear the Part Time radial button }
private void AddBtn_Click(object sender, RoutedEventArgs e) { string firstName = TxtBoxFN.Text; string surname = TxtBoxSn.Text; if (RBtnFT.IsChecked == true && RBtnPT.IsChecked == false) // if statement to check if emp is part time or full time { decimal salary = Convert.ToDecimal(TxtBoxSalary.Text); // converts int to decimal for salary FullTimeEmployee emp = new FullTimeEmployee(); // fulltime employee object emp.FirstName = firstName; emp.Surname = surname; emp.Salary = salary; employees.Add(emp); } else if (RBtnFT.IsChecked == false && RBtnPT.IsChecked == true) { double hoursWorked = Convert.ToDouble(TxtBoxHW.Text); // converts int to double for hoursWorked decimal hourlyRate = Convert.ToDecimal(TxtBoxHR.Text); // converts int to decimal for hourlyRate PartTimeEmployee emp = new PartTimeEmployee(); // parttime employee object emp.FirstName = firstName; emp.Surname = surname; emp.HourlyRate = hourlyRate; emp.HoursWorked = hoursWorked; employees.Add(emp); } TxtBoxFN.Clear(); // clear the First Name Text Box TxtBoxSn.Clear(); // clear the Surname Text Box TxtBoxHR.Clear(); // clear the Hourly Rate Text Box TxtBoxHW.Clear(); // clear the Hours Worked Text Box TxtBoxSalary.Clear(); // clear the Salary Text Box TxtBlockMP2.Text = "$0"; // clear monhtlypay text block RBtnFT.IsChecked = false; // clear the Full Time radial button RBtnPT.IsChecked = false; // clear the Part Time radial button }
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { TxtBoxFN.Clear(); // clear the First Name Text Box TxtBoxSn.Clear(); // clear the Surname Text Box TxtBoxHR.Clear(); // clear the Hourly Rate Text Box TxtBoxHW.Clear(); // clear the Hours Worked Text Box TxtBoxSalary.Clear(); // clear the Salary Text Box TxtBlockMP2.Text = "$0"; // clear monhtlypay text block RBtnFT.IsChecked = false; // clear the Full Time radial button RBtnPT.IsChecked = false; // clear the Part Time radial button Employee selectedEmployee = ListBox.SelectedItem as Employee; if (selectedEmployee != null) // ensure selected item isnt null { TxtBoxFN.Text = selectedEmployee.FirstName; TxtBoxSn.Text = selectedEmployee.Surname; if (selectedEmployee is FullTimeEmployee) { FullTimeEmployee emp = selectedEmployee as FullTimeEmployee; TxtBoxSalary.Text = emp.Salary.ToString(); TxtBlockMP2.Text = "$" + emp.CalculateMonthlyPay().ToString(); RBtnFT.IsChecked = true; RBtnPT.IsChecked = false; } else if (selectedEmployee is PartTimeEmployee) { PartTimeEmployee emp = selectedEmployee as PartTimeEmployee; TxtBoxHR.Text = emp.HourlyRate.ToString(); TxtBoxHW.Text = emp.HoursWorked.ToString(); TxtBlockMP2.Text = "$" + emp.CalculateMonthlyPay().ToString(); RBtnPT.IsChecked = true; RBtnFT.IsChecked = false; } } }