/** * @fn void InsertEmployee(Employee employee); * * @brief inserts new employee into database * * @return void */ void InsertEmployee(Employee employee) { conn.Open(); SqlCommand cmd = null; switch (employee.GetEmployeeType()) { case "fulltime": cmd = new SqlCommand("INSERT INTO Employee (firstName, lastName, socialInsuranceNumber, dateOfBirth, isValid, isActive)" + "VALUES (" + employee.GetFirstName() + ", " + employee.GetLastName() + ", " + employee.GetSin() + ", " + employee.GetDateOfBirth() + "0, 0"); int employeeID = GetEmployeeID(); SqlCommand getId = new SqlCommand(); cmd = new SqlCommand("INSERT INTO FullTimeEmployee (employeeID, dateOfHire, dateOfTermination, salary)" + "VALUES (" + employeeID + ((FulltimeEmployee)employee).GetDateOfHire() + ", " + ((FulltimeEmployee)employee).GetDateOfTermination() + ", " + ((FulltimeEmployee)employee).GetSalary() + ")"); break; case "parttime": break; case "seasonal": break; case "contract": break; } cmd.Connection = conn; cmd.ExecuteNonQuery(); conn.Close(); }
/// <summary> /// Function Name: AddEmployee. /// The purpose of this function is to replicate the adding of an employee to the database. /// It can be expanded on in the future to use widespread but is currently only used for testing purposes. /// While testing this functional will ensure that the adding to list is succesfful and that validation is /// properly being conducted of the data being added to the database. /// </summary> /// <param name="entry">This parameter is an object passed in that can be any 1 of the 4 types of employees.</param> /// <returns></returns> public bool AddEmployee(Employee entry) { // declare local variables bool result; Employee genericClass = new Employee(); // switch on the type of employee passed in // and properly cast it switch (entry.GetEmployeeType()) { case "CT": genericClass = (ContractEmployee)entry; break; case "SN": genericClass = (SeasonalEmployee)entry; break; case "FT": genericClass = (FullTimeEmployee)entry; break; case "PT": genericClass = (PartTimeEmployee)entry; break; } // attempt to add the entry to the database // if the result is false from the validation return false // otherwise attempt to add it to the database if there is an // error return false try { result = genericClass.Validate(); if (result != false) { databaseContainer.Add(genericClass); return true; } } catch { return false; } return false; }
/// <summary> /// This method is used to set the first name, last name, date of birth, and SIN attributes, which /// is found in every employee class. This eliminates repeating the code 4 times in the above functions. /// </summary> /// <param name="entry">An object of type Employee used to set the attributes</param> private void SetBaseAttributes(Employee entry) { // initialize local variables bool result = false; String businessName = ""; String lastName = ""; String firstName = ""; String temp = ""; Console.WriteLine("***Employee Management System***\n"); if (entry.GetEmployeeType() == "CT") { // get the employee's last name Console.WriteLine("Please enter the contractor's business name:"); businessName = Console.ReadLine(); temp = businessName; temp = temp.Replace(" ", ""); if (temp == "") { result = false; } else { result = entry.SetLastName(businessName); } while (result == false) { Console.WriteLine("Please re-enter a valid contractor's business name:"); businessName = Console.ReadLine(); temp = businessName; temp = temp.Replace(" ", ""); if (temp == "") { result = false; } else { result = entry.SetLastName(businessName); } } // get the employee's date of birth Console.WriteLine("Please enter the date of the company's incorporation <YYYY-MM-DD>:"); result = entry.SetDateOfBirth(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter the date of the company's incorporation <YYYY-MM-DD>:"); result = entry.SetDateOfBirth(Console.ReadLine()); } // get the employee's social insurance number Console.WriteLine("Please enter the Business Number:"); result = entry.SetSocialNumber(Console.ReadLine().Replace(" ", "")); while (result == false) { Console.WriteLine("Please re-enter the contractor's Business Number:"); result = entry.SetSocialNumber(Console.ReadLine().Replace(" ", "")); } } else { // get the employee's first name Console.WriteLine("Please enter the employee's first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = entry.SetFirstName(firstName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = entry.SetFirstName(firstName); } } // get the employee's last name Console.WriteLine("Please enter the employee's last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = entry.SetLastName(lastName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = entry.SetLastName(lastName); } } // get the employee's date of birth Console.WriteLine("Please enter the employee's date of birth <YYYY-MM-DD>:"); result = entry.SetDateOfBirth(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid employee's date of birth <YYYY-MM-DD>:"); result = entry.SetDateOfBirth(Console.ReadLine()); } // get the employee's social insurance number Console.WriteLine("Please enter the employee's Social Insurance Number:"); result = entry.SetSocialNumber(Console.ReadLine().Replace(" ", "")); while (result == false) { Console.WriteLine("Please re-enter a valid employee's Social Insurance Number:"); result = entry.SetSocialNumber(Console.ReadLine().Replace(" ", "")); } } }
/// <summary> /// Method Name: UpdateEmployeeData. /// The purpose of this method is to allow a user to enter a SIN corresponding to an employee that they wish to update. /// A menu will then be presented in the console that will allow the user to update specific attributes found in any /// of the four employee types. The user also has the option of changing all attributes. /// </summary> /// <returns></returns> public bool UpdateEmployeeData() { // initialize local variables int foundElement = 0; String SIN = ""; int returnedResult = 0; bool result = false; float salary = 0, hourlyRate = 0, piecePay = 0, contractorsFixedAmount = 0; int i = 0; String input = ""; String firstName = ""; String lastName = ""; String temp = ""; // create objects of each type of employee to be used depending on what type of employee // the user is updating Employee baseEmployee = new Employee(); FullTimeEmployee ftEmployee = new FullTimeEmployee(); PartTimeEmployee ptEmployee = new PartTimeEmployee(); ContractEmployee cEmployee = new ContractEmployee(); SeasonalEmployee sEmployee = new SeasonalEmployee(); // get the user to enter a SIN number of the employee they would like to update Console.WriteLine("Please enter the SIN number of the employee you would like to update:"); // get the user to enter the sin until SIN = Console.ReadLine().Replace(" ", "") ; // reset the returnedResult returnedResult = 0; // find the element based on the employee's SIN number for (i = 0; i < databaseContainer.Count; i++) { // if the sin number is found in the database set the // found element to be that index if (databaseContainer[i].GetSocialNumber() == SIN) { foundElement = i; returnedResult++; } } // if the result was 0 then the Employee with the SIN entered from the user // was not found in the database - return false if (returnedResult == 0) { Console.WriteLine("Could not find employee with the specified SIN"); logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'F', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); return false; } // until the user presses 9 allow them to update the employee with the SIN they // previously entered while (input != "9") { // clear the console and display the menu Console.Clear(); // set the baseEmployee to be the employee found in the database baseEmployee = databaseContainer[foundElement]; Console.WriteLine("Currently Updating : {0} {1}", databaseContainer[foundElement].GetFirstName(), databaseContainer[foundElement].GetLastName()); Console.WriteLine("Updates Available:"); Console.WriteLine("\t1. First Name."); Console.WriteLine("\t2. Last Name/Business."); Console.WriteLine("\t3. SIN."); Console.WriteLine("\t4. Date Of Birth."); Console.WriteLine("\t5. Date Of Hire, Contract Start Date, Season"); Console.WriteLine("\t6. Salary, PiecePay, Fixed Contract Amount, Hourly Wage"); Console.WriteLine("\t7. Date of Termination, Contract End Date"); Console.WriteLine("\t8. Update All Information"); Console.WriteLine("\t9. Exit"); // read the user's menu choice input = Console.ReadLine(); // if the option is 1 to 4 then no casting needs to be done to find out which // type of employee it is because those attributes are found in all employees if (input == "1" || input == "2" || input == "3" || input == "4") { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'S', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); // switch on the input switch (input) { // modify the first name case "1": if (baseEmployee.GetEmployeeType() != "CT") { // display the current employee's firstname Console.WriteLine("Current employee's first name: {0} \n", baseEmployee.GetFirstName()); // get the employee's first name, make the user enter it until // it is valid Console.WriteLine("Please enter a new first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = baseEmployee.SetFirstName(firstName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = baseEmployee.SetFirstName(firstName); } } } break; // modify the last name case "2": if (baseEmployee.GetEmployeeType() != "CT") { // display the current employee's last name Console.WriteLine("Current employee's last name: {0}\n", baseEmployee.GetLastName()); // get the employee's last name, make the user enter a last name // until it is a valid string Console.WriteLine("Please enter a new last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } } } else { Console.WriteLine("Please enter a bussiness name:"); lastName = Console.ReadLine(); temp = lastName.Replace(" ", ""); if (temp == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } while (result == false) { Console.WriteLine("Please re-enter a valid business name:"); lastName = Console.ReadLine(); temp = lastName.Replace(" ", ""); if (temp == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } } } break; // modify the employee's social insurance number case "3": // display the current employee's social insurance number Console.WriteLine("Current employee's social insurance number : {0}\n", baseEmployee.GetSocialNumber()); // get the employee's social insurance number, make user re-enter the SIN until // it is valid Console.WriteLine("Please enter the employee's Social Insurance Number:"); while (result == false) { Console.WriteLine("Please re-enter a valid employee's Social Insurance Number:"); result = baseEmployee.SetSocialNumber(Console.ReadLine()); } break; // modify the employee's date of birth case "4": // display the current employee's date of birth Console.WriteLine("Current employee's date of birth : {0}\n", baseEmployee.GetDateOfBirth().ToShortDateString()); // get the employee's date of birth, make the user re-enter the birth date until // it is valid Console.WriteLine("Please enter the employee's date of birth <YYYY-MM-DD>:"); result = baseEmployee.SetDateOfBirth(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid employee's date of birth <YYYY-MM-DD>:"); result = baseEmployee.SetDateOfBirth(Console.ReadLine()); } break; } } // if were modifying attributes under the menu options 5 - 8 // then the attributes change accordingly to which type of employee being modified else { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'F', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); // switch on the employee type switch (databaseContainer[foundElement].GetEmployeeType()) { // if it's a full time employee being modified then: // // date of hire is being modifited when option 5 is pressed // yearly salary is being modified when option 6 is pressed // date of termination is being modified when option 7 is pressed case "FT": // cast the base employee as a full time employee ftEmployee = (FullTimeEmployee)baseEmployee; switch (input) { // update date of hire case "5": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Date of Hire : {0}", ftEmployee.GetDateOfHire().ToShortDateString()); // get the date the employee was hired Console.WriteLine("Please enter the date the employee was hired"); // get teh new date until it is valid result = ftEmployee.SetDateOfHire(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired"); result = ftEmployee.SetDateOfHire(Console.ReadLine()); } break; // update yearly salary case "6": // display the current salary and get the user to enter a new salary Console.WriteLine("Current Salary is : {0}", ftEmployee.GetSalary()); // get the employee's yearly salary Console.WriteLine("Please enter the employee's yearly salary (example 45000.54):"); while (true) { try { salary = float.Parse(Console.ReadLine()); ftEmployee.SetSalary(salary); break; } catch { Console.WriteLine("Please re-enter a valid employee's salary (example 45000.54):"); } } break; // update the date of termination case "7": // display the current salary and get the user to enter a new salary Console.WriteLine("Current date of Termination is : {0}", ftEmployee.GetDateOfTermination().ToShortDateString()); // get the date of termination if the employee was fired Console.WriteLine("Please enter a date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ftEmployee.SetDateOfTermination(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ftEmployee.SetDateOfTermination(Console.ReadLine()); } break; // update all employee information case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); ftEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddFullTimeEmployee(); break; } break; // if the employee type is a part time employee then: // // option 5 updates the employee's date of hire // option 6 updates the employee's hourly wage // option 7 updates the employee's date of termination // option 8 updates all fields case "PT": // cast the base employee as a part time employee ptEmployee = (PartTimeEmployee)baseEmployee; // switch on the input number switch (input) { // update the employee's hire date case "5": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Date of Hire : {0}", ptEmployee.GetDateOfHire().ToShortDateString()); // get the new date from the user Console.WriteLine("Please enter the date the employee was hired <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfHire(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfHire(Console.ReadLine()); } break; // update the employee's hourly wages case "6": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current employee's hourly wages : {0}", ptEmployee.GetHourlyWage()); // get the employee's hourly wages Console.WriteLine("Please enter the employee's hourly wage(ie. 15.00):"); while (true) { try { // attempt to parse if it does not succeed then it will throw an exception hourlyRate = float.Parse(Console.ReadLine()); ptEmployee.SetHourlyRate(hourlyRate); break; } catch { // display the error message to the user Console.WriteLine("Please re-enter a valid employee's hourly wage(ie. 15.00):"); } } break; // update the employee's date of termination case "7": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Employee's date of termination : {0}", ftEmployee.GetDateOfTermination().ToShortDateString()); // get the new date of termination Console.WriteLine("Please enter a date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfTermination(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfTermination(Console.ReadLine()); } break; case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); ptEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddPartTimeEmployee(); break; } break; // if were modifying a Contract Employee then // // option 5 is modifying the date in which the contract employee started // option 6 is the fixed contract amount // option 7 is modifying the date in which the contract employee ended their work case "CT": // cast the base employee as a contract employee cEmployee = (ContractEmployee)baseEmployee; switch (input) { // modify the date which the contract employee started case "5": // display the current date the empployee began Console.WriteLine("Current contract employee's start date : {0}", cEmployee.GetContractStartDate().ToShortDateString()); // get the start date in which the contractor began work Console.WriteLine("Please enter the start date for the contracted employee <YYYY-MM-DD>:"); result = cEmployee.SetContractStartDate(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); } break; // modify the fixed amount pay the contractor received case "6": // display the current fixed amount pay the contractor received Console.WriteLine("Current contractor's fixed pay amount : {0}", cEmployee.GetFixedContractAmount()); // get the contractor's fixed amount of pay Console.WriteLine("Please enter the contractor's fixed amount of pay (e.g. 4570.80):"); while (true) { try { contractorsFixedAmount = float.Parse(Console.ReadLine()); cEmployee.SetFixedContractAmount(contractorsFixedAmount); break; } catch { Console.WriteLine("Please re-enter a valid contractor's fixed amount of pay (e.g. 4570.80):"); } } break; // modify the date in which the contractor ended work case "7": // display the current date the empployee began Console.WriteLine("Current contract employee's stop date : {0}", cEmployee.GetContractStopDate().ToShortDateString()); // get the date in which the contractor ended the work Console.WriteLine("Please enter the date the contractor ended \nworking for your company <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter the date the contractor \nended working for your company <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); } break; // modify all the data in the current contract employee case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); cEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddContractEmployee(); break; } break; // if we are modifying a seasonal employee // // option 5 modifies the season in which the employee was employed // option 6 modifies the piece pay in which the employee received while employed // option 8 modifies all the attributes case "SN": sEmployee = (SeasonalEmployee)baseEmployee; switch (input) { // modify the season case "5": // display the season in which the employee was employed Console.WriteLine("Current employee's season of employment : {0}", sEmployee.GetSeason()); // get the season in which the employee was employed Console.WriteLine("Please enter the season in which the employee was employed:"); result = sEmployee.SetSeason(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid season in which the employee was employed:"); result = sEmployee.SetSeason(Console.ReadLine()); } break; // modify the piece pay case "6": // display the season in which the employee was employed Console.WriteLine("Current employee's piece pay : {0}", sEmployee.GetPiecePay()); // get the pay in which the employee received Console.WriteLine("Please enter the piece pay which the employee received for their work:"); while (true) { try { piecePay = float.Parse(Console.ReadLine()); sEmployee.SetPiecePay(piecePay); break; } catch { Console.WriteLine("Please re-enter a valid piece in which the employee received for their work:"); } } break; // modify all attributes case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); sEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddSeasonalEmployee(); break; } break; }/* End Switch */ }/* End Else Statement*/ }/* End While Loop*/ return true; }
/** * @fn void UpadateEmployee(Employee employee); * * @brief updates existing employee in database * * @return void */ void UpdateEmployee(Employee employee) { conn.Open(); SqlCommand cmd = null; switch (employee.GetEmployeeType()) { case "fulltime": break; case "parttime": break; case "seasonal": break; case "contract": break; } }
public void SetEmployeeTypeTestValidPartTime() { Employee employee = new Employee(); bool retVal = employee.SetEmployeeType("PT"); Assert.IsTrue(retVal); Assert.AreEqual(employee.GetEmployeeType(), "PT"); }
public void SetEmployeeTypeTestValidSeasonal() { Employee employee = new Employee(); bool retVal = employee.SetEmployeeType("SN"); Assert.IsTrue(retVal); Assert.AreEqual(employee.GetEmployeeType(), "SN"); }
public void SetEmployeeTypeTestValidContract() { Employee employee = new Employee(); bool retVal = employee.SetEmployeeType("CT"); Assert.IsTrue(retVal); Assert.AreEqual(employee.GetEmployeeType(), "CT"); }
public void SetEmployeeTypeTestInvalid() { Employee employee = new Employee(); bool retVal = employee.SetEmployeeType("AB"); Assert.IsFalse(retVal); Assert.AreEqual(employee.GetEmployeeType(), ""); }
/** * \brief The ShowEmployeeManagementMenu method will display to the user, a UI menu.This * menu allows the user to choose either to display an employee set, create a new employee, * modify and exisiting employee, remove an existing employee, or return to the main menu. * * \details <b>Details</b> * * \param args - n/a * * \throw <EndOfProgramException> - If the user wants the program to end * * \return n/a */ private void ShowEmployeeManagementMenu() { string str; do { // Employee object Employee employee = new Employee(); Console.WriteLine("Menu 3 : EMPLOYEE MANAGEMENT MENU"); Console.WriteLine("---------------------------------"); Console.WriteLine("1. Display Employee Set"); Console.WriteLine("2. Create a NEW Employee"); Console.WriteLine("3. Modify an EXISTING Employee"); Console.WriteLine("4. Remove an EXISTING Employee"); Console.WriteLine("9. Return to Main Menu"); str = Console.ReadLine(); Console.Clear(); string input; switch (str) { case "1": // Display the employees company.DisplayAllEmployees(); Console.Clear(); break; case "2": // Go to menu 4 menuOptionFlag = 1; employee = ShowEmployeeDetailsMenu(); if (cancel == false) { company.AddEmployeeToList(employee); Console.WriteLine("Employee was successfully added"); Console.WriteLine("Press enter to continue"); input = Console.ReadLine(); Console.Clear(); } break; case "3": // Go to menu 4 menuOptionFlag = 2; employee = ShowEmployeeDetailsMenu(); if (cancel == false) { employee = company.SelectEmployee(employee); if (employee.GetEmployeeType() != "") { company.ModifyEmployee(employee); Console.WriteLine("Employee was successfully modified."); Console.WriteLine("Press enter to continue"); input = Console.ReadLine(); Console.Clear(); } else { Console.WriteLine("Employee was not successfully modified."); Console.WriteLine("Press enter to continue"); input = Console.ReadLine(); Console.Clear(); } } cancel = false; break; case "4": cancel = false; menuOptionFlag = 3; // Give the employee details to the container class, and remove the applicable employee employee = ShowEmployeeDetailsMenu(); if (cancel == false) { employee = company.SelectEmployee(employee); if (employee.GetEmployeeType() != "") { company.RemoveEmployee(employee); Console.WriteLine("Employee was successfully removed."); Console.WriteLine("Press enter to continue"); input = Console.ReadLine(); Console.Clear(); } else { Console.WriteLine("Employee was not successfully removed."); Console.WriteLine("Press enter to continue"); input = Console.ReadLine(); Console.Clear(); } } break; case "9": break; default: Console.WriteLine("Invalid menu choice."); break; } } while (str != "9"); }
/** * \brief The ShowEmployeeDetailsMenu method will display to the user, a UI menu.This * menu allows the user to choose either to specify base employee details, to specify * values for any employee type, or return to the employee management menu. * * \details <b>Details</b> * * \param args - n/a * * \throw <EndOfProgramException> - If the user wants the program to end * * \return n/a */ private Employee ShowEmployeeDetailsMenu() { // Variables Employee employee = new Employee(); string menuOption = ""; while ((menuOption != "9") && (menuOption != "8")) { Console.WriteLine("Menu 4 : EMPLOYEE DETAILS MENU"); Console.WriteLine("---------------------------------"); if (employee.GetEmployeeType() == "") { Console.WriteLine("1. Specify Base Employee Details."); Console.WriteLine("8. Go Back"); menuOption = Console.ReadLine(); Console.Clear(); switch (menuOption) { case "1": employee = GetBaseEmployeeDetails(); break; case "8": cancel = true; break; default: Console.WriteLine("Invalid menu choice."); break; } } else if (employee.GetEmployeeType() == "FT") { Console.WriteLine("1. Specify Base Employee Details."); Console.WriteLine("2. Specify Date of Hire."); Console.WriteLine("3. Specify Date of Termination."); Console.WriteLine("4. Specify Employees Salary."); Console.WriteLine("8. Go back."); Console.WriteLine("9. Proceed."); menuOption = Console.ReadLine(); Console.Clear(); switch (menuOption) { case "1": employee = GetBaseEmployeeDetails(); break; case "2": Console.WriteLine("Specify the date of hire YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((FulltimeEmployee)employee).SetDateOfHire(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "3": Console.WriteLine("Specify the date of termination YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((FulltimeEmployee)employee).SetDateOfTermination(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "4": Console.WriteLine("Specify the salary"); string salaryInput = Console.ReadLine(); Console.Clear(); double salaryAmount; double.TryParse(salaryInput, out salaryAmount); // Sets the employee details to the users input and checks if it is in the proper format if (((FulltimeEmployee)employee).SetSalary(salaryAmount) == false) { Console.WriteLine("The salary must be greater than 0"); } break; case "8": cancel = true; break; case "9": break; default: Console.WriteLine("Invalid menu choice."); break; } } else if (employee.GetEmployeeType() == "PT") { Console.WriteLine("1. Specify Base Employee Details."); Console.WriteLine("2. Specify Date of Hire."); Console.WriteLine("3. Specify Date of Termination."); Console.WriteLine("4. Specify Hourly Rate."); Console.WriteLine("8. Go back."); Console.WriteLine("9. Proceed."); menuOption = Console.ReadLine(); Console.Clear(); switch (menuOption) { case "1": employee = GetBaseEmployeeDetails(); break; case "2": Console.WriteLine("Specify the date of hire YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((ParttimeEmployee)employee).SetDateOfHire(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "3": Console.WriteLine("Specify the date of termination YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((ParttimeEmployee)employee).SetDateOfTermination(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "4": Console.WriteLine("Specify the hourly rate"); // Sets the employee details to the users input and checks if it is in the proper format if (((ParttimeEmployee)employee).SetHourlyRate(double.Parse(Console.ReadLine())) == false) { Console.Clear(); Console.WriteLine("The hourly rate must be greater than 0"); } else { Console.Clear(); } break; case "8": cancel = true; break; case "9": break; default: Console.WriteLine("Invalid menu choice."); break; } } else if (employee.GetEmployeeType() == "CT") { Console.WriteLine("1. Specify Base Employee Details."); Console.WriteLine("2. Specify Contract Start Date."); Console.WriteLine("3. Specify Contract Stop Date."); Console.WriteLine("4. Specify Fixed Contract Amount."); Console.WriteLine("8. Go back."); Console.WriteLine("9. Proceed."); menuOption = Console.ReadLine(); Console.Clear(); switch (menuOption) { case "1": employee = GetBaseEmployeeDetails(); break; case "2": Console.WriteLine("Specify the contract's start date YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((ContractEmployee)employee).SetContractStartDate(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "3": Console.WriteLine("Specify the contract's stop date YYYY-MM-DD"); // Sets the employee details to the users input and checks if it is in the proper format if (((ContractEmployee)employee).SetContractStopDate(Console.ReadLine()) == false) { Console.Clear(); Console.WriteLine("The date was not valid"); } else { Console.Clear(); } break; case "4": Console.WriteLine("Specify the fixed contract amount"); // Sets the employee details to the users input and checks if it is in the proper format string contractInput = Console.ReadLine(); double contractAmount; double.TryParse(contractInput, out contractAmount); if (((ContractEmployee)employee).SetFixedContractAmount(contractAmount) == false) // first line get users input instead of try parse, just have the users input, second in if statement use the users input { Console.Clear(); Console.WriteLine("The fixed contract amount must be greater than 0"); } else { Console.Clear(); } break; case "8": cancel = true; break; case "9": break; default: Console.WriteLine("Invalid menu choice."); break; } } else if (employee.GetEmployeeType() == "SN") { Console.WriteLine("1. Specify Base Employee Details."); Console.WriteLine("2. Specify the Season."); Console.WriteLine("3. Specify the amount the employee receives per item produced."); Console.WriteLine("8. Go back."); Console.WriteLine("9. Proceed."); menuOption = Console.ReadLine(); Console.Clear(); switch (menuOption) { case "1": employee = GetBaseEmployeeDetails(); break; case "2": Console.WriteLine("Specify which season the employee is working in. The seaons can be: Summer, Winter, Fall, or Spring."); // Sets the employee details to the users input and checks if it is in the proper format string userInput = Console.ReadLine(); Console.Clear(); userInput = userInput.Substring(0, 1).ToUpper() + userInput.Substring(1).ToLower(); if (((SeasonalEmployee)employee).SetSeason(userInput) == false) { Console.WriteLine("The season must only be Summer, Winter, Fall, or Spring."); } break; case "3": Console.WriteLine("Specify the piece pay of the employee"); string pieceInput = Console.ReadLine(); Console.Clear(); double pieceAmount; double.TryParse(pieceInput, out pieceAmount); // Sets the employee details to the users input and checks if it is in the proper format if (((SeasonalEmployee)employee).SetPiecePay(pieceAmount) == false) { Console.WriteLine("The piece pay must be greater than 0"); } break; case "8": cancel = true; break; case "9": break; default: Console.WriteLine("Invalid menu choice."); break; } } else { Console.WriteLine("The employee type was invalid. Valid employee types are: FT, PT, CT, SN"); } } return employee; }
/** * \brief The GetBaseEmployeeDetails method will get the users input, set it in an employee object and return the employee object * to further process it. * * \details <b>Details</b> * * \param args - n/a * * \throw <EndOfProgramException> - If the user wants the program to end * * \return - <b> Employee emp </b>- returns the employee with information */ private static Employee GetBaseEmployeeDetails() { // Variables int employeeSIN; Employee tempEmp = new Employee(); string empType; string empLName; string empFName; string empSIN; string empDOB; FulltimeEmployee FTemp = new FulltimeEmployee(); ParttimeEmployee PTemp = new ParttimeEmployee(); ContractEmployee CTemp = new ContractEmployee(); SeasonalEmployee SNemp = new SeasonalEmployee(); if (menuOptionFlag == 1) { Console.WriteLine("Employee Creation"); Console.WriteLine("__________________"); Console.WriteLine("Press enter to skip entry."); } else if (menuOptionFlag == 2) { Console.WriteLine("Employee Modification"); Console.WriteLine("______________________"); Console.WriteLine("Press enter to skip entry."); } else if (menuOptionFlag == 3) { Console.WriteLine("Employee Deletion"); Console.WriteLine("__________________"); Console.WriteLine("Press enter to skip entry."); } // Prompt for details bool error = false; do{ if(error) { Console.WriteLine("Invalid data was put in. Acceptable employee types are 'FT' 'PT' 'CT' or 'SN'"); } error = true; Console.WriteLine("Enter the employee type \n 'FT' for FullTime \n 'PT' for PartTime \n 'CT' for Contract \n 'SN' for Seasonal:"); empType = Console.ReadLine(); Console.Clear(); empType = empType.ToUpper(); } while (!tempEmp.SetEmployeeType(empType)); error = false; if (tempEmp.GetEmployeeType() == "FT") { do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's last name:"); empLName = Console.ReadLine(); Console.Clear(); } while (!((Employee)FTemp).SetLastName(empLName)); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's first name:"); empFName = Console.ReadLine(); Console.Clear(); } while (!((Employee)FTemp).SetFirstName(empFName)); error = false; bool valid; do { if (error) { Console.WriteLine("Invalid data was put in. A SIN number should be in the format of ### ### ###"); } error = true; Console.WriteLine("Enter the employee's SIN number:"); empSIN = Console.ReadLine(); Console.Clear(); empSIN = empSIN.Replace(" ", ""); valid = int.TryParse(empSIN, out employeeSIN); } while (!((Employee)FTemp).SetSocialInsuranceNumber(employeeSIN) || (!valid && empSIN != "")); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. The date must be in the format of YYYY-MM-DD"); } error = true; Console.WriteLine("Enter the employee's date of birth in the format: YYYY-MM-DD"); empDOB = Console.ReadLine(); Console.Clear(); } while (!FTemp.SetDateOfBirth(empDOB)); error = false; } else if (tempEmp.GetEmployeeType() == "PT") { do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's last name:"); empLName = Console.ReadLine(); Console.Clear(); } while (!((Employee)PTemp).SetLastName(empLName)); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's first name:"); empFName = Console.ReadLine(); Console.Clear(); } while (!((Employee)PTemp).SetFirstName(empFName)); error = false; bool valid; do { if (error) { Console.WriteLine("Invalid data was put in. A SIN number should be in the format of ### ### ###"); } error = true; Console.WriteLine("Enter the employee's SIN number:"); empSIN = Console.ReadLine(); Console.Clear(); empSIN.Replace(" ", ""); valid = int.TryParse(empSIN, out employeeSIN); } while (!((Employee)PTemp).SetSocialInsuranceNumber(employeeSIN) || (!valid && empSIN != "")); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. The date must be in the format of YYYY-MM-DD"); } error = true; Console.WriteLine("Enter the employee's date of birth in the format: YYYY-MM-DD"); empDOB = Console.ReadLine(); Console.Clear(); } while (!PTemp.SetDateOfBirth(empDOB)); error = false; } else if (tempEmp.GetEmployeeType() == "CT") { do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's coorporation name:"); empLName = Console.ReadLine(); Console.Clear(); } while (!((Employee)CTemp).SetLastName(empLName)); error = false; bool valid; do { if (error) { Console.WriteLine("Invalid data was put in. A Business Number number should be in the format of #### #####"); } error = true; Console.WriteLine("Enter the employee's Business Number number:"); empSIN = Console.ReadLine(); Console.Clear(); empSIN.Replace(" ", ""); valid = int.TryParse(empSIN, out employeeSIN); } while (!((Employee)CTemp).SetSocialInsuranceNumber(employeeSIN) || (!valid && empSIN != "")); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. The date must be in the format of YYYY-MM-DD."); if(CTemp.GetSocialInsuranceNumber() != 0) { Console.WriteLine("The last 2 digits of the year \nshould match the first 2 digits of the Buisness Number: " + CTemp.GetSocialInsuranceNumber().ToString().Substring(0, 2)); } } error = true; Console.WriteLine("Enter the employee's date of incorporation in the format: YYYY-MM-DD"); empDOB = Console.ReadLine(); Console.Clear(); } while (!CTemp.SetDateOfBirth(empDOB)); error = false; } else if (tempEmp.GetEmployeeType() == "SN") { do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's last name:"); empLName = Console.ReadLine(); Console.Clear(); } while (!((Employee)SNemp).SetLastName(empLName)); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. There must only be letters, dashes, and/or apostrophes"); } error = true; Console.WriteLine("Enter the employee's first name:"); empFName = Console.ReadLine(); Console.Clear(); } while (!((Employee)SNemp).SetFirstName(empFName)); error = false; bool valid; do { if (error) { Console.WriteLine("Invalid data was put in. A SIN number should be in the format of ### ### ###"); } error = true; Console.WriteLine("Enter the employee's SIN number:"); empSIN = Console.ReadLine(); Console.Clear(); empSIN.Replace(" ", ""); valid = int.TryParse(empSIN, out employeeSIN); } while (!((Employee)SNemp).SetSocialInsuranceNumber(employeeSIN) || (!valid && empSIN != "")); error = false; do { if (error) { Console.WriteLine("Invalid data was put in. The date must be in the format of YYYY-MM-DD"); } error = true; Console.WriteLine("Enter the employee's date of birth in the format: YYYY-MM-DD"); empDOB = Console.ReadLine(); Console.Clear(); } while (!SNemp.SetDateOfBirth(empDOB)); error = false; } if (tempEmp.GetEmployeeType() == "FT") { return FTemp; } else if (tempEmp.GetEmployeeType() == "PT") { return PTemp; } else if (tempEmp.GetEmployeeType() == "CT") { return CTemp; } else if (tempEmp.GetEmployeeType() == "SN") { return SNemp; } return tempEmp; }