private void btnLoadFile_Click(object sender, EventArgs e) { FileHandler txtload = new FileHandler(); SequenceID.setEmployee_id(1); // Initialize the Sequence Id employees.ReturnList().Clear(); employees = txtload.readFile(); // Clean the List Box listBoxEmployees.Items.Clear(); foreach (Employee emp in employees.ReturnList()) { listBoxEmployees.Items.Add(employees.ShowListInBox(emp)); } }
private void btnModify_Click(object sender, EventArgs e) { Employee emp = null; string ccode = ""; int temp_seq = 0; try { if (cmbCategory.Text == "FullTime") { ccode = "FT"; if (!DataValidator.verifyData(txtFTAnnualSalary.Text, new Regex(DataValidator.patternMoney))) { MessageBox.Show("Annual Salary must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new FullTime((EnumPosition)cmbFTPosition.SelectedItem, Convert.ToDouble(txtFTAnnualSalary.Text)); temp_seq = emp.getId(); //Store last sequence } else if (cmbCategory.Text == "PartTime") { ccode = "PT-"; if (cmbPTContractType.Text == "Consultant_Trainers") { ccode += "CON"; if (!DataValidator.verifyData(txtPTContractMonth.Text, new Regex(DataValidator.patternNumber))) { MessageBox.Show("Contract Month must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!DataValidator.verifyData(txtPTTCHourlySal.Text, new Regex(DataValidator.patternHours))) { MessageBox.Show("Week hours must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!DataValidator.verifyData(txtPTCTWeekHours.Text, new Regex(DataValidator.patternHours))) { MessageBox.Show("Hours must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new ConsultantTrainer((EnumContractType)cmbPTContractType.SelectedItem, Convert.ToInt16(txtPTContractMonth.Text), Convert.ToDouble(txtPTTCHourlySal.Text), Convert.ToDouble(txtPTCTWeekHours.Text)); temp_seq = emp.getId(); //Store last sequence } else if (cmbPTContractType.Text == "Internship_Student") { ccode += "INT"; if (!DataValidator.verifyData(txtPTInternSal.Text, new Regex(DataValidator.patternMoney))) { MessageBox.Show("Internship Salary must be a numeric value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } emp = new Internship(Convert.ToDouble(txtPTInternSal.Text), (EnumContractType)cmbPTContractType.SelectedItem, Convert.ToInt16(txtPTContractMonth.Text)); temp_seq = emp.getId(); //Store last sequence } else { MessageBox.Show("Must be selected a Contract Type...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Must be selected an Employee's Category...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { emp.setFname(txtFirstName.Text); emp.setLname(txtLastName.Text); if (!DataValidator.verifyData(txtSIN.Text, new Regex(DataValidator.patternSIN))) { MessageBox.Show("Social Security must be a code like this ###-###-###", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setDepartment((EnumDepartment)cmbDept.SelectedItem); emp.setCategory((EnumCategory)cmbCategory.SelectedItem); if (!DataValidator.verifyData(txtHDay.Text, new Regex(DataValidator.patternDay))) { MessageBox.Show("Wrong day...Must be between 1 and 31", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHMonth.Text, new Regex(DataValidator.patternMonth))) { MessageBox.Show("Wrong month...Must be between 1 and 12", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHYear.Text, new Regex(DataValidator.patternYear))) { MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setHire_date(new Date(txtHDay.Text, txtHMonth.Text, txtHYear.Text)); if (!DataValidator.verifyData(txtBDay.Text, new Regex(DataValidator.patternDay))) { MessageBox.Show("Wrong day...Must be between 1 and 31", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtBMonth.Text, new Regex(DataValidator.patternMonth))) { MessageBox.Show("Wrong month...Must be between 1 and 12", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtBYear.Text, new Regex(DataValidator.patternYear))) { MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setBirthday(new Date(txtBDay.Text, txtBMonth.Text, txtBYear.Text)); if (!DataValidator.verifyData(txtAddStrNo.Text, new Regex(DataValidator.patternNumber))) { MessageBox.Show("Wrong Street No... Must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtAddApt.Text, new Regex(DataValidator.patternApt))) { MessageBox.Show("Wrong Appartment/House No... Must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtAddApt.Text, new Regex(DataValidator.patternApt))) { MessageBox.Show("Wrong Zip Code... Must be like this X#X-#X#", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setAddress(new Address(txtAddStrNo.Text, txtAddStrName.Text, txtAddApt.Text, txtAddCity.Text, txtAddState.Text, txtAddCountry.Text, txtAddZipCode.Text)); if (!DataValidator.verifyData(txtHCountCode.Text, new Regex(DataValidator.patternCountcode))) { MessageBox.Show("Wrong Phone Country Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHCityCode.Text, new Regex(DataValidator.patternCitycode))) { MessageBox.Show("Wrong Phone City Code...Must be a 3 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtHLocalCode.Text, new Regex(DataValidator.patternLocalcode))) { MessageBox.Show("Wrong Phone Local...Must be a 7 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setHome_ph(new Phone(txtHCountCode.Text, txtHCityCode.Text, txtHLocalCode.Text)); if (!DataValidator.verifyData(txtCCountCode.Text, new Regex(DataValidator.patternCountcode))) { MessageBox.Show("Wrong Phone Country Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtCCityCode.Text, new Regex(DataValidator.patternCitycode))) { MessageBox.Show("Wrong Phone City Code...Must be a 3 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } if (!DataValidator.verifyData(txtCLocalCode.Text, new Regex(DataValidator.patternLocalcode))) { MessageBox.Show("Wrong Phone Local...Must be a 7 digits number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setCel_ph(new Phone(txtCCountCode.Text, txtCCityCode.Text, txtCLocalCode.Text)); if (!DataValidator.verifyData(txtEmail.Text, new Regex(DataValidator.patternEmail))) { MessageBox.Show("Wrong email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SequenceID.setEmployee_id(temp_seq); // Decrease the sequence return; } emp.setEmail(txtEmail.Text); emp.setSocial_security(tempsin); //Assign last displayed SIN txtTwoWeeksSal.Text = emp.getTwoWeeks_salary().ToString("#.##") + " $"; emp.setId(temp_id); emp.setContract(ccode); txtKey.Text = emp.getContract(); if (txtSIN.Text != emp.getSocial_security()) { MessageBox.Show("Can't to modify the SIN in the Modify option. It should use Add button", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (update_index > -1) { // Update list Box and list of employees //listBoxEmployees.Items.Insert(update_index, emp); employees.modify(emp, emp.getSocial_security()); listBoxEmployees.Items.Clear(); foreach (Employee temp in employees.ReturnList()) { this.listBoxEmployees.Items.Add(employees.ShowListInBox(temp)); } btnReset.PerformClick(); update_index = -1; save_flag = true; MessageBox.Show("Employee Mofified", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("It must to select an item and display it. Use Display Option", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Missing or incorrects values to enter...Check and Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("2222222222222Missing or incorrects values to enter...Check and Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }