/// <summary> /// Checks that all visible fields have data, parses the data and saves to array /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { Employee emp = null; if (!Regex.IsMatch(txtbxEmpID.Text, @"[0-9]{5}")) { errorMessage += "Enter a valid employee number"; MessageBox.Show(errorMessage); } else { if (rbSalary.Checked) { errorMessage = ""; if (cmbobxMaritalStatus.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment.Text == "") { txtboxDepartment.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName.Text == "") { txtbxEmpName.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1.Text == "") { txtbxVal1.BackColor = Color.Red; errorMessage += errorMnthSalary + "\r\n"; } if (txtbxVal1.Text != "" && double.Parse(txtbxVal1.Text) <= 1) { txtbxVal1.BackColor = Color.Red; errorMessage += errorLowSalary + "\r\n"; MessageBox.Show(errorMessage); } else if (txtbxEmpName.Text == "" || txtbxVal1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName.BackColor = Color.White; txtbxVal1.BackColor = Color.White; emp = new Salary(txtbxEmpID.Text, txtbxEmpName.Text, txtboxDepartment.Text, txtbxJobTitle.Text, false, false, cmbobxMaritalStatus.SelectedIndex, txtbxVal1.Text); BusinessRules.Instance[uint.Parse(txtbxEmpID.Text)] = emp; } } else if (rbHourly.Checked) { errorMessage = ""; if (cmbobxMaritalStatus.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment.Text == "") { txtboxDepartment.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName.Text == "") { txtbxEmpName.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1.Text == "") { txtbxVal1.BackColor = Color.Red; errorMessage += errorHrlyRt + "\r\n"; } if (txtbxVal2.Text == "") { txtbxVal2.BackColor = Color.Red; errorMessage += errorHrsWrkd; } if (txtbxEmpName.Text == "" || txtbxVal1.Text == "" || txtbxVal2.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName.BackColor = Color.White; txtbxVal1.BackColor = Color.White; txtbxVal2.BackColor = Color.White; emp = new Hourly(txtbxEmpID.Text, txtbxEmpName.Text, txtboxDepartment.Text, txtbxJobTitle.Text, false, false, cmbobxMaritalStatus.SelectedIndex, txtbxVal1.Text, txtbxVal2.Text); BusinessRules.Instance[uint.Parse(txtbxEmpID.Text)] = emp; } } else if (rbSales.Checked) { errorMessage = ""; if (cmbobxMaritalStatus.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment.Text == "") { txtboxDepartment.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName.Text == "") { txtbxEmpName.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1.Text == "") { txtbxVal1.BackColor = Color.Red; errorMessage += errorMnthSalary + "\r\n"; } if (txtbxVal2.Text == "") { txtbxVal2.BackColor = Color.Red; errorMessage += errorCmmsnSales + "\r\n"; } if (txtbxVal3.Text == "") { txtbxVal3.BackColor = Color.Red; errorMessage += errorGrssSales + "\r\n"; } if (txtbxVal1.Text != "" && double.Parse(txtbxVal1.Text) <= 1) { txtbxVal1.BackColor = Color.Red; errorMessage += errorLowSalary + "\r\n"; MessageBox.Show(errorMessage); } else if (txtbxEmpName.Text == "" || txtbxVal1.Text == "" || txtbxVal2.Text == "" || txtbxVal3.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName.BackColor = Color.White; txtbxVal1.BackColor = Color.White; txtbxVal2.BackColor = Color.White; txtbxVal3.BackColor = Color.White; emp = new Sales(txtbxEmpID.Text, txtbxEmpName.Text, txtboxDepartment.Text, txtbxJobTitle.Text, false, false, cmbobxMaritalStatus.SelectedIndex, txtbxVal1.Text, txtbxVal2.Text, txtbxVal3.Text); BusinessRules.Instance[uint.Parse(txtbxEmpID.Text)] = emp; } } else if (rbContract.Checked) { errorMessage = ""; if (cmbobxMaritalStatus.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment.Text == "") { txtboxDepartment.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName.Text == "") { txtbxEmpName.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1.Text == "") { txtbxVal1.BackColor = Color.Red; errorMessage += errorCntrctSls + "\r\n"; } if (txtbxEmpName.Text == "" || txtbxVal1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName.BackColor = Color.White; txtbxVal1.BackColor = Color.White; emp = new Contract(txtbxEmpID.Text, txtbxEmpName.Text, txtboxDepartment.Text, txtbxJobTitle.Text, false, false, cmbobxMaritalStatus.SelectedIndex, txtbxVal1.Text, txtbxVal2.Text); BusinessRules.Instance[uint.Parse(txtbxEmpID.Text)] = emp; //rTxtBxEmpData.AppendText(BusinessRules.Instance[empID].EmployeeID + "\r\n"); //rTxtBxEmpData.AppendText(BusinessRules.Instance[empID].EmployeeName + "\r\n"); //rTxtBxEmpData.AppendText(BusinessRules.Instance[empID].EmployeeType + "\r\n"); //rTxtBxEmpData.AppendText(BusinessRules.Instance[empID].ContractSalary + "\r\n"); } } } if (!rbContract.Checked && !rbHourly.Checked && !rbSalary.Checked && !rbSales.Checked) { MessageBox.Show(invalidEmpError); } resetValues(); }
private void btnUpdateEmp_Click(object sender, EventArgs e) { Employee emp = null; if (!Regex.IsMatch(txtbxEmpID_1.Text, @"[0-9]{5}")) { errorMessage += "Enter a valid employee number"; MessageBox.Show(errorMessage); } else { if (rbSalary_1.Checked) { errorMessage = ""; if (cmbobxMaritalStatus_1.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment_1.Text == "") { txtboxDepartment_1.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle_1.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName_1.Text == "") { txtbxEmpName_1.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1_1.Text == "") { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorMnthSalary + "\r\n"; } if (txtbxVal1_1.Text != "" && double.Parse(txtbxVal1_1.Text) <= 1) { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorLowSalary + "\r\n"; MessageBox.Show(errorMessage); } else if (txtbxEmpName_1.Text == "" || txtbxVal1_1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName_1.BackColor = Color.White; txtbxVal1_1.BackColor = Color.White; emp = new Salary(txtbxEmpID_1.Text, txtbxEmpName_1.Text, txtboxDepartment_1.Text, txtbxJobTitle_1.Text, false, false, cmbobxMaritalStatus_1.SelectedIndex, txtbxVal1_1.Text); BusinessRules.Instance.EditEmployee(emp); this.Close(); } } else if (rbHourly_1.Checked) { errorMessage = ""; if (cmbobxMaritalStatus_1.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment_1.Text == "") { txtboxDepartment_1.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle_1.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName_1.Text == "") { txtbxEmpName_1.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1_1.Text == "") { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorHrlyRt + "\r\n"; } if (txtbxVal2_1.Text == "") { txtbxVal2_1.BackColor = Color.Red; errorMessage += errorHrsWrkd; } if (txtbxEmpName_1.Text == "" || txtbxVal1_1.Text == "" || txtbxVal2_1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName_1.BackColor = Color.White; txtbxVal1_1.BackColor = Color.White; txtbxVal2_1.BackColor = Color.White; emp = new Hourly(txtbxEmpID_1.Text, txtbxEmpName_1.Text, txtboxDepartment_1.Text, txtbxJobTitle_1.Text, false, false, cmbobxMaritalStatus_1.SelectedIndex, txtbxVal1_1.Text, txtbxVal2_1.Text); BusinessRules.Instance.EditEmployee(emp); this.Close(); } } else if (rbSales_1.Checked) { errorMessage = ""; if (cmbobxMaritalStatus_1.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment_1.Text == "") { txtboxDepartment_1.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle_1.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName_1.Text == "") { txtbxEmpName_1.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1_1.Text == "") { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorMnthSalary + "\r\n"; } if (txtbxVal2_1.Text == "") { txtbxVal2_1.BackColor = Color.Red; errorMessage += errorCmmsnSales + "\r\n"; } if (txtbxVal3_1.Text == "") { txtbxVal3_1.BackColor = Color.Red; errorMessage += errorGrssSales + "\r\n"; } if (txtbxVal1_1.Text != "" && double.Parse(txtbxVal1_1.Text) <= 1) { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorLowSalary + "\r\n"; MessageBox.Show(errorMessage); } else if (txtbxEmpName_1.Text == "" || txtbxVal1_1.Text == "" || txtbxVal2_1.Text == "" || txtbxVal3_1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName_1.BackColor = Color.White; txtbxVal1_1.BackColor = Color.White; txtbxVal2_1.BackColor = Color.White; txtbxVal3_1.BackColor = Color.White; emp = new Sales(txtbxEmpID_1.Text, txtbxEmpName_1.Text, txtboxDepartment_1.Text, txtbxJobTitle_1.Text, false, false, cmbobxMaritalStatus_1.SelectedIndex, txtbxVal1_1.Text, txtbxVal2_1.Text, txtbxVal3_1.Text); BusinessRules.Instance.EditEmployee(emp); this.Close(); } } else if (rbContract_1.Checked) { errorMessage = ""; if (cmbobxMaritalStatus_1.SelectedIndex == 0) { errorMessage += errorMaritalStatus + "\r\n"; } if (txtboxDepartment_1.Text == "") { txtboxDepartment_1.BackColor = Color.Red; errorMessage += errorEnterDepartment + "\r\n"; } if (txtbxJobTitle_1.Text == "") { errorMessage += errorEnterJobTitle + "\r\n"; } if (txtbxEmpName_1.Text == "") { txtbxEmpName_1.BackColor = Color.Red; errorMessage += errorEnterName + "\r\n"; } if (txtbxVal1_1.Text == "") { txtbxVal1_1.BackColor = Color.Red; errorMessage += errorCntrctSls + "\r\n"; } if (txtbxEmpName_1.Text == "" || txtbxVal1_1.Text == "") { MessageBox.Show(errorMessage); } else { txtbxEmpName_1.BackColor = Color.White; txtbxVal1_1.BackColor = Color.White; emp = new Contract(txtbxEmpID_1.Text, txtbxEmpName_1.Text, txtboxDepartment_1.Text, txtbxJobTitle_1.Text, false, false, cmbobxMaritalStatus_1.SelectedIndex, txtbxVal1_1.Text, txtbxVal2_1.Text); BusinessRules.Instance.EditEmployee(emp); this.Close(); } } } if (!rbContract_1.Checked && !rbHourly_1.Checked && !rbSalary_1.Checked && !rbSales_1.Checked) { MessageBox.Show(invalidEmpError); } }
//this method collects the information for an Salary employee by accepting only a salary object as a parameter public static void CollectSalaryInformation(Salary theEmployee) { theEmployee.AnnualSalary = InputUtilities.getDoubleInputValue("annual salary"); theEmployee.ManagementLevel = InputUtilities.getIntegerInputValue("management level"); }
private void btnSalary_Click(object sender, EventArgs e) { Salary form = new Salary(); form.ShowDialog(); }