private void Update_Click(object sender, RoutedEventArgs e) //Method for the Update Button { Employee selectedEmployee = listBox.SelectedItem as Employee; //slected employee from list box if (selectedEmployee != null) //checks if slection is null { string fName = textBox.Text, lName = textBox1.Text; //Sets all the variables in boxs decimal Salary = decimal.Parse(Salarytxt.Text); //Converts all boxs from String to decimal or int decimal hourlyRate = decimal.Parse(hourlyRatetxt.Text); int hoursWorked = int.Parse(hoursWorkedtxt.Text); if (Salarytxt != null && FT.IsChecked == true) //checks if it is fulltime or part time { FullTime employee = new FullTime(fName, lName, Salary); //creates updated employee FTemploy.Add(employee); //adds the new updated employee to observableCollection Employees.Add(employee); FTemploy.Remove(selectedEmployee); //REmoves the old employee Employees.Remove(selectedEmployee); } else if (hourlyRatetxt != null && hoursWorkedtxt != null && PT.IsChecked == true) //checks if it is fulltime or part time { PartTime employee = new PartTime(fName, lName, hourlyRate, hoursWorked); //creates updated employee PTemploy.Add(employee); //adds the new updated employee to observableCollection Employees.Add(employee); PTemploy.Remove(selectedEmployee); //removes old employee Employees.Remove(selectedEmployee); } } }
private void button1_Click(object sender, RoutedEventArgs e) //This is the method for the Add button, to add a new employee { //read details from screen string firstName = textBox.Text; string lastName = textBox1.Text; if (PT.IsChecked == true) //Checks if PT is slected { decimal hourRate; double hourWorked; hourRate = decimal.Parse(hourlyRatetxt.Text); //Changes from string to Decimal hourWorked = double.Parse(hoursWorkedtxt.Text); //Changes from string to Double PartTime employee = new PartTime(firstName, lastName, hourRate, hourWorked); //create new PartTime employee PTemploy.Add(employee); //add to ObservableCollection Employees.Add(employee); //add to ObservableCollection } else if (FT.IsChecked == true) //checks if FT is selected { decimal salary; salary = decimal.Parse(Salarytxt.Text); //changed from string to decimal FullTime employee = new FullTime(firstName, lastName, salary); //create a new fulltime employee FTemploy.Add(employee); //add to ObservableCollection Employees.Add(employee); //add to ObservableCollection } }
private void Window_Loaded(object sender, RoutedEventArgs e) //when the window is loaded { //creating base employees FullTime employee = new FullTime("Jess", "WALSH", 200); FullTime employee1 = new FullTime("Joe", "MURPHY", 300); PartTime employee2 = new PartTime("Jane", "JONES", 15, 10); PartTime employee3 = new PartTime("John", "SMITH", 20, 7); //adding employees to ObservableCollection Employees.Add(employee); Employees.Add(employee1); Employees.Add(employee2); Employees.Add(employee3); //adding employees to ObservableCollection FTemploy.Add(employee); FTemploy.Add(employee1); PTemploy.Add(employee2); PTemploy.Add(employee3); //Used to filter the list box by FullTime or PartTime employees if (CheckFT.IsChecked == true && CheckPT.IsChecked == true) { listBox.ItemsSource = Employees; } else if (CheckFT.IsChecked == true) { listBox.ItemsSource = FTemploy; } else if (CheckPT.IsChecked == true) { listBox.ItemsSource = PTemploy; } else { listBox.ItemsSource = null; } }