Example #1
0
        private void lbxEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //clears each tbx each time a new employee is selected
            tbxSalary.Clear();
            tbxHoursWorked.Clear();
            tbxHourlyRate.Clear();

            //check which employee is selected
            Employee selectedEmployee = lbxEmployees.SelectedItem as Employee;

            //check to see if there is an employee selected
            if (selectedEmployee != null)
            {
                //display employee's name
                tbxFirstName.Text = selectedEmployee.FirstName;
                tbxLastName.Text  = selectedEmployee.LastName;

                //check if selected employee is FullTimeEmployee or PartTimeEmployee
                if (selectedEmployee is FullTimeEmployee)
                {
                    //puts selected employee in new employee of correct derived class (FullTimeEmployee) so you can call the correct properties (Salary)
                    FullTimeEmployee selectedFTEmployee = selectedEmployee as FullTimeEmployee;
                    //checks fulltime radio button
                    rbFullTime.IsChecked = true;
                    //displays FullTimeEmployee's Salary
                    tbxSalary.Text = selectedFTEmployee.Salary.ToString();
                    //displays employees monthly pay by calling the class method
                    tblkCalcMonthlyPay.Text = ("€" + selectedFTEmployee.CalculateMonthlyPay().ToString("F"));
                }
                else if (selectedEmployee is PartTimeEmployee)
                {
                    //puts selected employee in new employee of correct derived class (PartTimeEmployee) so you can call the correct properties (HoursWorked, HourlyRate)
                    PartTimeEmployee selectedPTEmployee = selectedEmployee as PartTimeEmployee;
                    //checks part time radio button
                    rbPartTime.IsChecked = true;
                    //display PartTimeEmployee's HoursWorked and HourlyRate
                    tbxHoursWorked.Text = selectedPTEmployee.HoursWorked.ToString();
                    tbxHourlyRate.Text  = selectedPTEmployee.HourlyRate.ToString();
                    //displays employees monthly pay by calling the class method
                    tblkCalcMonthlyPay.Text = ("€" + selectedPTEmployee.CalculateMonthlyPay().ToString("F"));
                }
            }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();
            //makes both checkboxes checked upon initialization
            cboxFullTime.IsChecked = true;
            cboxPartTime.IsChecked = true;

            //create objects
            FullTimeEmployee em1 = new FullTimeEmployee("Jess", "Walsh", 50000);
            FullTimeEmployee em2 = new FullTimeEmployee("Joe", "Murphy", 100000);
            PartTimeEmployee em3 = new PartTimeEmployee("John", "Smith", 15, 10);
            PartTimeEmployee em4 = new PartTimeEmployee("Jane", "Jones", 13, 15);

            //add objects to list
            employees.Add(em1);
            employees.Add(em2);
            employees.Add(em3);
            employees.Add(em4);

            //sort employees by LastName(uses IComparible)
            employees.Sort();
        }