private void btn_Calculate_Click(object sender, EventArgs e) { string _EmployeeName = txtName.Text; // before you run the code below, add an if statement here to check if the name already lists in the generic list if (!cmbEmpList.Items.Contains(_EmployeeName) && _EmployeeName != "") { /* check the employee type from the button at the top. * setup some sort of if then else to create the appropriate Object based on the type, and then fill in the proper data. * Drop the thing into the list */ // IMPORTANT - ADD A SAFETY CHECK IN HERE TO ENSURE THAT AN INVALID VALUE SUCH AS TEXT IN A NUMERIC FIELD IS CAUGHT!! int ii; double dd; bool _CheckHours = int.TryParse(txtHours.Text, out ii); bool _CheckWage = double.TryParse(txtWage.Text, out dd); if (rbtnSalary.Checked && int.TryParse(txtHours.Text, out ii)) { Console.WriteLine("User selected calculate, Salaryselected"); if (ii < 0) { // put a message here that hours are out of range MessageBox.Show("The value entered for salary is not valid."); } else { // for this next bunch of variables, consider whether or not there is duplication and where to put the code; Employee employee = new SalariedEmployee(_EmployeeName, EmployeeType.Salaried, Double.Parse(txtHours.Text)); cmbEmpList.Items.Add(employee.Name); // now add the object to the generic list employeesList.Add(employee); Display(employee); } } else if (rbtnCommission.Checked && int.TryParse(txtHours.Text, out ii) && double.TryParse(txtWage.Text, out dd)) { Console.WriteLine("User selected calculate, Commission selected"); double _CommissionRate = 0; _CommissionRate = Double.Parse(txtWage.Text); if (ii < 0 || _CommissionRate < 0) { // put a message here that hours are out of range MessageBox.Show("The number of hours/commission rate is out of range."); } else { Employee employee = new CommissionEmployee(_EmployeeName, EmployeeType.Commission, Double.Parse(txtHours.Text), _CommissionRate); cmbEmpList.Items.Add(employee.Name); // now add the object to the generic list employeesList.Add(employee); Display(employee); } } else if (rbtnHourly.Checked && int.TryParse(txtHours.Text, out ii) && double.TryParse(txtWage.Text, out dd)) { Console.WriteLine("User selected calculate, hourly selected"); if (ii < 0 || ii > 80 || dd < 0) { // put a message here that hours are out of range MessageBox.Show("The number of hours / wage is out of range."); } else { Employee employee = new HourlyEmployee(_EmployeeName, EmployeeType.Hourly, int.Parse(txtHours.Text), double.Parse(txtWage.Text)); cmbEmpList.Items.Add(employee.Name); // now add the object to the generic list employeesList.Add(employee); Display(employee); } } else { MessageBox.Show("Text was entered but a number was expected."); } } // end contains check else { MessageBox.Show("The name cannot be left blank, or already exists!"); } }