}//end of cmbEmployee //Methods //create employee based on what type of employee public void createEmployee() { //declare variables String name; //Dertermine type of employee if (rbtnHourly.Checked) { //create hourly employee name = txtEmpName.Text; int hours = int.Parse(txtEmpInfo2.Text); Double wage = double.Parse(txtEmpInfo3.Text); hEmp = new HourlyEmployee(hours, wage, name, Employee.EmployeeType.HourlyEmployee); //calculate wage txtGrossEanings.Text = hEmp.GrossEarnings().ToString("C"); txtLessTax.Text = hEmp.Tax.ToString("C"); txtNetEarnings.Text = hEmp.NetEarnings.ToString("C"); empList.Add(hEmp); //add employee to list cmbEmployee.Items.Add(hEmp.Name); //add employee to combo box } else if (rbtnCommission.Checked) { //create commissioned employee name = txtEmpName.Text; Double grossSale = double.Parse(txtEmpInfo2.Text); Double commissionRate = double.Parse(txtEmpInfo3.Text); cEmp = new CommissionEmployee(grossSale, commissionRate, name, Employee.EmployeeType.CommissionEmployee); //calculate wage txtGrossEanings.Text = cEmp.GrossEarnings().ToString("C"); txtLessTax.Text = cEmp.Tax.ToString("C"); txtNetEarnings.Text = cEmp.NetEarnings.ToString("C"); empList.Add(cEmp); //add employee to list cmbEmployee.Items.Add(cEmp.Name); } else if (rbtnWeekly.Checked) { //create salaried employee name = txtEmpName.Text; Double sales = double.Parse(txtEmpInfo2.Text); sEmp = new SalariedEmployee(sales, name, Employee.EmployeeType.SalariedEmployee); //calculate wage txtGrossEanings.Text = sEmp.GrossEarnings().ToString("C"); txtLessTax.Text = sEmp.Tax.ToString("C"); txtNetEarnings.Text = sEmp.NetEarnings.ToString("C"); empList.Add(sEmp); //add employee to list cmbEmployee.Items.Add(sEmp.Name); //display new employee to combobox } }//end of create employee
}//end of rbtnWeekly private void cmbEmployee_SelectedIndexChanged(object sender, EventArgs e) { if (cmbEmployee.SelectedIndex != 0) { int empIndex = (cmbEmployee.SelectedIndex - 1); if (empList[empIndex].TypeOfEmployee == Employee.EmployeeType.HourlyEmployee) { //update labels rbtnHourly.Checked = true; lblEmpInfo2.Text = "Hours Worked:"; lblEmpInfo3.Text = "Hourly Wage:"; txtEmpInfo2.Visible = true; txtEmpInfo3.Visible = true; hEmp = (HourlyEmployee)empList[empIndex]; //Display Calculated Wages txtEmpName.Text = hEmp.Name; txtEmpInfo2.Text = hEmp.HoursWorked.ToString(); txtEmpInfo3.Text = hEmp.HourlyWage.ToString(); txtGrossEanings.Text = hEmp.GrossEarnings().ToString("C"); txtLessTax.Text = hEmp.Tax.ToString("C"); txtNetEarnings.Text = hEmp.NetEarnings.ToString("C"); } else if (empList[empIndex].TypeOfEmployee == Employee.EmployeeType.CommissionEmployee) { //update labels rbtnCommission.Checked = true; lblEmpInfo2.Text = "Gross Sales: "; lblEmpInfo3.Text = "Commission Rate: "; txtEmpInfo2.Visible = true; txtEmpInfo3.Visible = true; cEmp = (CommissionEmployee)empList[empIndex]; //Display Calculated Wages txtEmpName.Text = cEmp.Name; txtEmpInfo2.Text = cEmp.GrossSales.ToString(); txtEmpInfo3.Text = (cEmp.CommissionRate * 100).ToString(); txtGrossEanings.Text = cEmp.GrossEarnings().ToString("C"); txtLessTax.Text = cEmp.Tax.ToString("C"); txtNetEarnings.Text = cEmp.NetEarnings.ToString("C"); } else if (empList[empIndex].TypeOfEmployee == Employee.EmployeeType.SalariedEmployee) { //update labels rbtnWeekly.Checked = true; lblEmpInfo2.Text = "Salary: "; lblEmpInfo3.Visible = false; txtEmpInfo3.Visible = false; sEmp = (SalariedEmployee)empList[empIndex]; //Display Calculated Wages txtEmpName.Text = sEmp.Name; txtEmpInfo2.Text = sEmp.WeeklySalary.ToString(); txtGrossEanings.Text = sEmp.GrossEarnings().ToString("C"); txtLessTax.Text = sEmp.Tax.ToString("C"); txtNetEarnings.Text = sEmp.NetEarnings.ToString("C"); } } }//end of cmbEmployee