Пример #1
0
        private void lstbxEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Creates a variable of type employee that contains the selected employee from the list box
            Employee selectedEmployee = lstbxEmployees.SelectedItem as Employee;

            //if the selected employee has contents, the code will be executed
            if (selectedEmployee != null)
            {
                //if the selected employee is a full time employee, the code is executed
                if (selectedEmployee is FullTimeEmployee)
                {
                    //Creates a variable of type FullTimeEmployee that contains the selected employee casted to FullTimeEmployee
                    FullTimeEmployee fullTime = (FullTimeEmployee)selectedEmployee;

                    //Adds the name of the employee to the first name text box
                    tbxFirstName.Text = fullTime.FirstName;
                    //Adds the surname of the employee to the surname text box
                    tbxSurname.Text = fullTime.Surname;
                    //Adds the salary of the employee to the salary text box
                    tbxSalary.Text = fullTime.Salary.ToString();
                    //Adds the monthly pay of the employee to the monthly pay text block
                    tblkMonthlyPay.Text = fullTime.CalculateMonthlyPay().ToString();
                    //Unchecks the full time radio button
                    rdobtnFullTime.IsChecked = true;
                    //Checks the part time radio button
                    rdobtnPartTime.IsChecked = false;

                    //Removes the text from the hourly rate and hours worked text boxes
                    tbxHourlyRate.Text  = "";
                    tbxHoursWorked.Text = "";
                }
                //if the selected employee is a part time employee, the code is executed
                else
                {
                    //creates a variable of type PartTimeEmployee that contains the selected employe casted to PartTimeEmployee
                    PartTimeEmployee partTime = (PartTimeEmployee)selectedEmployee;

                    //Adds the name of the employee to the first name text box
                    tbxFirstName.Text = partTime.FirstName;
                    //Adds the surname of the employee to the surname text box
                    tbxSurname.Text = partTime.Surname;
                    //Adds the hourly rate of the employee to the hourly rate text box
                    tbxHourlyRate.Text = partTime.HourlyRate.ToString();
                    //Adds the hours worked of the employee to the hours worked text box
                    tbxHoursWorked.Text = partTime.HoursWorked.ToString();
                    //Adds the monthly pay of the employee to the monthly pay text block
                    tblkMonthlyPay.Text = partTime.CalculateMonthlyPay().ToString();
                    //Unchecks the full time radio button
                    rdobtnFullTime.IsChecked = false;
                    //Checks the part time radio button
                    rdobtnPartTime.IsChecked = true;

                    //Removes the text from the hourly rate nd hours workedd text boxes
                    tbxSalary.Text = "";
                }
            }
        }