public SeasonalEmployee(SeasonalEmployee prev) : base(prev) { season = prev.GetSeason(); piecePay = prev.GetPiecePay(); SetType("SN"); }
/// <summary> /// Add a new employee type, given a set of information the method will decide which employee type is requested to be created and to provide the /// information in creating that specific employee type /// </summary> /// <param name="record">Contains a set of information regarding which employee type to create and what information it should contain</param> /// <returns></returns> public void Add(object record) { if (((string)record)[0] != ';') { try { string[] recordStr = ((string)record).Split('|'); Employee newEmployee = null; switch (recordStr[0].ToUpper()) { case "FT": newEmployee = new FulltimeEmployee(recordStr); break; case "PT": newEmployee = new ParttimeEmployee(recordStr); //PARAM Needs to be changed, temp fix break; case "CT": newEmployee = new ContractEmployee(recordStr); //PARAM Needs to be changed, temp fix break; case "SN": newEmployee = new SeasonalEmployee(recordStr); //PARAM Needs to be changed, temp fix break; default: break; } if (newEmployee != null) { if (newEmployee.IsValid) { //Exist by sin if (!employeeSinExist(newEmployee)) { employees.Add(newEmployee); } else { Logging.LogString("Tried adding employee but the SIN/BN matched another record."); throw new ArgumentException("That Sin Already Exists"); } } else { //Employee is not valid dont add Needs LOG } } } catch (MissingMemberException mME) { //throw mME; } catch (ArgumentException aE) { throw aE; } } }
/** * \brief Give employee write and file to write to * * \details <b>Details</b> * * \employeeList - <b>List<AllEmployees.Employee></b> - The employees records * \param fileName - <b>String</b> - The file path and name of file storing the records * * \return umOfRecordsSaved - <b>Int</b> - The number of employees that were sucessfully saved */ public static int WriteRecord(List<AllEmployees.Employee> employeeList, String fileName) { int numOfRecordsSaved = 0; if (wasRead == true) { File.WriteAllText(fileName, String.Empty); } foreach (Employee emp in employeeList) { string identifier = emp.GetEmployeeType(); string fileOutput = ""; if (identifier == "CT") { AllEmployees.ContractEmployee employeeData = new AllEmployees.ContractEmployee(); employeeData = (AllEmployees.ContractEmployee)emp; if (employeeData.Validate() == true) { fileOutput = employeeData.ToString();//test sample of gow to format StreamWriter sw = File.AppendText(fileName);//write data (Details Method) sw.WriteLine(fileOutput);//will append if file exists or create new if it does not already exist sw.Close(); Logging.Log("FileIO", "WriteAllRecords", "ContractEmployee written to file"); numOfRecordsSaved++; } else { Logging.Log("FileIO", "WriteAllRecords", "ContractEmployee was invalid and was not written to file"); } } else if (identifier == "FT") { AllEmployees.FulltimeEmployee employeeData = new AllEmployees.FulltimeEmployee(); employeeData = (AllEmployees.FulltimeEmployee)emp; if (employeeData.Validate() == true) { fileOutput = employeeData.ToString();//test sample of gow to format StreamWriter sw = File.AppendText(fileName);//write data (Details Method) sw.WriteLine(fileOutput);//will append if file exists or create new if it does not already exist sw.Close(); Logging.Log("FileIO", "WriteAllRecords", "FulltimeEmployee written to file"); numOfRecordsSaved++; } else { Logging.Log("FileIO", "WriteAllRecords", "FullTimeEmployee was invalid and was not written to file"); } } else if (identifier == "PT") { AllEmployees.ParttimeEmployee employeeData = new AllEmployees.ParttimeEmployee(); employeeData = (AllEmployees.ParttimeEmployee)emp; if (employeeData.Validate() == true) { fileOutput = employeeData.ToString();//test sample of gow to format StreamWriter sw = File.AppendText(fileName);//write data (Details Method) sw.WriteLine(fileOutput);//will append if file exists or create new if it does not already exist sw.Close(); Logging.Log("FileIO", "WriteAllRecords", "ParttimeEmployee written to file"); numOfRecordsSaved++; } else { Logging.Log("FileIO", "WriteAllRecords", "PartTimeEmployee was invalid and was not written to file"); } } else if (identifier == "SN") { AllEmployees.SeasonalEmployee employeeData = new AllEmployees.SeasonalEmployee(); employeeData = (AllEmployees.SeasonalEmployee)emp; if (employeeData.Validate() == true) { fileOutput = employeeData.ToString();//test sample of gow to format StreamWriter sw = File.AppendText(fileName);//write data (Details Method) sw.WriteLine(fileOutput);//will append if file exists or create new if it does not already exist sw.Close(); Logging.Log("FileIO", "WriteAllRecords", "SeasonalEmployee written to file"); numOfRecordsSaved++; } else { Logging.Log("FileIO", "WriteAllRecords", "SeasonalEmployee was invalid and was not written to file"); } } else { Logging.Log("FileIO", "WriteAllRecords", "invalid unknown employee type was not written to file: " + identifier); } } return numOfRecordsSaved; }
/// <summary> /// Method Name: SaveDatabase. /// The purpose of this method is to parse the database into an output string to save to a file. This method /// ensures that all of the database items it is outputting are valid, else it will not ouptut them. The format /// in which a database item is outputted is as such: /// (Employee Type)|(Last Name)|(First Name)|(SIN)|(SubField1)|(SubField2)|(SubField3)| /// </summary> /// <returns></returns> public bool SaveDatabase() { String fileOutput; FullTimeEmployee ft = new FullTimeEmployee(); PartTimeEmployee pt = new PartTimeEmployee(); ContractEmployee c = new ContractEmployee(); SeasonalEmployee s = new SeasonalEmployee(); //Clear the file. FileStream db = databaseFile.Openfile("dbase.dtb", 'W'); databaseFile.WriteToFile(db, ""); databaseFile.CloseFile(db); //Insert a default header comment. fileOutput = ";\r\n;EMS Database File\r\n;Save Date: " + DateTime.Now.ToString() + "\r\n;Comments:\r\n;\r\n"; //For each employee in the database. databaseContainer.ForEach(delegate(Employee entry) { //If the employee is valid. if (entry.Validate()) { //Parse each field for output. fileOutput = fileOutput + entry.GetEmployeeType(); fileOutput = fileOutput + "|" + entry.GetLastName(); fileOutput = fileOutput + "|" + entry.GetFirstName(); fileOutput = fileOutput + "|" + entry.GetSocialNumber(); //If the date is 0 if (entry.GetDateOfBirth() == new DateTime(0)) { //Output N/A fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + entry.GetDateOfBirth().Year + "-" + entry.GetDateOfBirth().Month + "-" + entry.GetDateOfBirth().Day; } //Get the employee type. switch (entry.GetEmployeeType()) { //If the employee is a Full Time employee. case "FT": ft = (FullTimeEmployee)entry; //If the date is 0. if (ft.GetDateOfHire() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + ft.GetDateOfHire().Year + "-" + ft.GetDateOfHire().Month + "-" + ft.GetDateOfHire().Day; } //If the date is 0. if (ft.GetDateOfTermination() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + ft.GetDateOfTermination().Year + "-" + ft.GetDateOfTermination().Month + "-" + ft.GetDateOfTermination().Day; } fileOutput = fileOutput + "|" + ft.GetSalary(); break; //If the employee is a Part Time employee. case "PT": pt = (PartTimeEmployee)entry; //If the date is 0. if (pt.GetDateOfHire() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + pt.GetDateOfHire().Year + "-" + pt.GetDateOfHire().Month + "-" + pt.GetDateOfHire().Day; } //If the date is 0. if (pt.GetDateOfTermination() == new DateTime(0)) { //Out N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + pt.GetDateOfTermination().Year + "-" + pt.GetDateOfTermination().Month + "-" + pt.GetDateOfTermination().Day; } fileOutput = fileOutput + "|" + pt.GetHourlyWage(); break; //If the employee is a Contract Employee. case "CT": c = (ContractEmployee)entry; //If the date is 0. if (c.GetContractStartDate() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + c.GetContractStartDate().Year + "-" + c.GetContractStartDate().Month + "-" + c.GetContractStartDate().Day; } //If the date is 0. if (c.GetContractStopDate() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + c.GetContractStopDate().Year + "-" + c.GetContractStartDate().Month + "-" + c.GetContractStartDate().Day; } fileOutput = fileOutput + "|" + c.GetFixedContractAmount(); break; //The the employee is a Seasonal Employee. case "SN": s = (SeasonalEmployee)entry; fileOutput = fileOutput + "|" + Enum.GetName(typeof(Season), (s.GetSeason())); fileOutput = fileOutput + "|" + s.GetPiecePay(); break; } fileOutput = fileOutput + "|\r\n"; } }); //Write the parsed output string to a file. db = databaseFile.Openfile("dbase.dtb", 'W'); databaseFile.WriteToFile(db, fileOutput); databaseFile.CloseFile(db); return true; }
/// <summary> /// Method Name: AddSeasonalEmployee. /// The purpose of this function is to get the user to enter the data pertaining to a full time employee and /// add that into the employee database. /// </summary> /// <returns>Returns True if succesfull and False otherwise.</returns> private bool AddSeasonalEmployee() { // create a seasonal employee object which will be placed in the database after entering the data SeasonalEmployee entry = new SeasonalEmployee(); //declare local variables bool result = false; float piecePay = 0; this.SetBaseAttributes(entry); // get the season in which the employee was employed Console.WriteLine("Please enter the season in which the employee was employed:"); result = entry.SetSeason(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid season in which the employee was employed:"); result = entry.SetSeason(Console.ReadLine()); } // get the pay in which the employee received Console.WriteLine("Please enter the piecpay which the employee received for their work:"); while (true) { try { piecePay = float.Parse(Console.ReadLine().Replace("$", "")); entry.SetPiecePay(piecePay); break; } catch { Console.WriteLine("Please re-enter a valid piece in which the employee received for their work:"); } } // validate all data entered for the current seasonal employee if (entry.Validate() == false) { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'F', "Seasonal Employee"); Console.WriteLine("There was an error with the employee entered. Please add the employee again."); return false; } // add the employee to the database try { databaseContainer.Add(entry); } catch { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'F', "Seasonal Employee"); // if there was an error indicate that the employee could not be added to the database. Console.WriteLine("The employee could not be added to the database."); return false; } Console.Clear(); Console.WriteLine("\nThe employee added was:\n"); logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'S', "Seasonal Employee"); entry.Details(); // return true on success return true; }
public void DisplayAllEmployees_ValidEmployeesInList_DisplaysAllEmployees() { // Add the full-time employee to the container employeeRepo.AddEmployeeToList(FTEmployee); // Instantiate a part-time employee and add it to the container DateTime dateOfBirth = new DateTime(1987, 06, 22); DateTime dateOfHire = new DateTime(2013, 04, 12); DateTime dateOfTermination = new DateTime(2014, 05, 13); ParttimeEmployee PTEmployee = new AllEmployees.ParttimeEmployee("Mark", "Smith", 872098933, dateOfBirth, dateOfHire, dateOfTermination, 30); employeeRepo.AddEmployeeToList(PTEmployee); // Instantiate a contract employee and add it to the container dateOfBirth = new DateTime(1989, 07, 02); DateTime contractStartDate = new DateTime(2014, 02, 08); DateTime contractStopDate = new DateTime(2014, 09, 12); ContractEmployee CTEmployee = new AllEmployees.ContractEmployee("Anna", "Miller", 892398402, dateOfBirth, contractStartDate, contractStopDate, 25000); employeeRepo.AddEmployeeToList(CTEmployee); // Instantiate a seasonal employee and add it to the container dateOfBirth = new DateTime(1991, 03, 18); SeasonalEmployee SNEmployee = new AllEmployees.SeasonalEmployee("Jake", "Williams", 912098933, dateOfBirth, "Summer", 20); employeeRepo.AddEmployeeToList(SNEmployee); // Initialize a string with input data and initalize other variables var privateObject = new PrivateObject(employeeRepo); String dataToPassIn = "\n\n\n\n"; // Set the console to read input from the input data string using (var input = new StringReader(dataToPassIn)) { Console.SetIn(input); // Execute the method that is being tested privateObject.Invoke("DisplayAllEmployees"); /* There is no assert, since the user has to view the * output to make sure the method is operating properly */ } }
public void TestingValidateSeason_SeasonalEmployee_Exception() { bool status = false; string[] testData = new string[6] { "qwer", "drfdgf", "246 454 284", "1997/3/14", "dfser", "45.34" }; SeasonalEmployee testEmployee = new SeasonalEmployee(); status = testEmployee.ValidateSeason("Wisdfnter"); Assert.AreEqual(false, status); }
public void TestingValidateContract_SeasonalEmployee_Exception() { string[] testData = new string[6] { "qwer", "drfdgf", "046 454 286", "1997/3/14", "black", "45.34" }; try { SeasonalEmployee testEmployee = new SeasonalEmployee(testData); bool status = testEmployee.Validate(); Assert.AreEqual(true, status); } catch (Exception e) { Assert.AreEqual(true, true); } }
public void ConstructorWithNamesTestValid3() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "LeRoy-Davies"); }
public void ConstructorWithNamesTestInvalidSpace() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Mc Davies"); }
public void ConstructorWithNamesTestInvalidNumber() { SeasonalEmployee employee = new SeasonalEmployee("Brandon2", "Davies"); }
public void ConstructorWithAllParamTestValid2() { DateTime DOB = new DateTime(1991, 12, 23); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Mc'Davies", 123456789, DOB, "Winter", 15); }
public void ConstructorWithAllParamTestValid1() { DateTime DOB = new DateTime(1993, 04, 24); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies", 123456789, DOB ,"Summer", 10); }
/*! * FUNCTION : private static void employeeDetailsMenu(string employee, string type) * * DESCRIPTION : This function displays the menu that allows the user to create new employees. * * PARAMETERS : \param string employee : The last/company name of the new employee * \param string type : The type of employee being created * * RETURN : None * */ private static void employeeDetailsMenu(string employee, string type) { try { bool done = false; string fname = ""; string lname = employee; string dob = ""; string sin = ""; string doh = ""; string dot = ""; string tmpSal = ""; double sal = 0; string tmpRate = ""; double rate = 0; string cStartD = ""; string cStopD = ""; string tmpAmount = ""; double amount = 0; string season = ""; string tmpPay = ""; double pay = 0; while (!done) { Console.WriteLine("\nEMPLOYEE DETAILS FOR {0}", lname); Console.WriteLine("1. Specify Base Employee Details"); switch(type) { case "FT": { Console.WriteLine("2. Specify Date of Hire"); Console.WriteLine("3. Specify Date of Termination"); Console.WriteLine("4. Specify Salary"); Console.WriteLine("9. Quit"); char input = Console.ReadKey().KeyChar; switch (input) { case '1': { Console.WriteLine("\nWhat is the new Employee's First Name?"); fname = Console.ReadLine(); Console.WriteLine("What is the new Employee's Date of Birth? (YYYY-MM-DD)"); dob = Console.ReadLine(); Console.WriteLine("What is the new Employee's Social Insurance Number? (XXX XXX XXX)"); sin = Console.ReadLine(); break; } case '2': { Console.WriteLine("\nWhat is the new Employee's Date of Hire? (YYYY-MM-DD)"); doh = Console.ReadLine(); break; } case '3': { Console.WriteLine("\nWhat is the new Employee's Date of Termination? (YYYY-MM-DD)"); dot = Console.ReadLine(); break; } case '4': { while (true) { Console.WriteLine("\nWhat is the new Employee's Salary? (Do not include the '$')"); tmpSal = Console.ReadLine(); try { sal = Double.Parse(tmpSal); break; } catch (Exception) { Console.WriteLine("Not a number"); } } break; } case '9': { done = true; break; } default: { break; } } break; } case "PT": { Console.WriteLine("2. Specify Date of Hire"); Console.WriteLine("3. Specify Date of Termination"); Console.WriteLine("4. Specify Hourly Rate"); Console.WriteLine("9. Quit"); char input = Console.ReadKey().KeyChar; switch (input) { case '1': { Console.WriteLine("\nWhat is the new Employee's First Name?"); fname = Console.ReadLine(); Console.WriteLine("What is the new Employee's Date of Birth? (YYYY-MM-DD)"); dob = Console.ReadLine(); Console.WriteLine("What is the new Employee's Social Insurance Number? (XXX XXX XXX)"); sin = Console.ReadLine(); break; } case '2': { Console.WriteLine("\nWhat is the new Employee's Date of Hire? (YYYY-MM-DD)"); doh = Console.ReadLine(); break; } case '3': { Console.WriteLine("\nWhat is the new Employee's Date of Termination? (YYYY-MM-DD)"); dot = Console.ReadLine(); break; } case '4': { while (true) { Console.WriteLine("\nWhat is the new Employee's Hourly Rate? (Do not include the '$')"); tmpRate = Console.ReadLine(); try { rate = Double.Parse(tmpRate); break; } catch (Exception) { Console.WriteLine("Not a number"); } } break; } case '9': { done = true; break; } default: { break; } } break; } case "CT": { Console.WriteLine("2. Specify Contract Start Date"); Console.WriteLine("3. Specify Contract End Date"); Console.WriteLine("4. Specify Fixed Contract Amount"); Console.WriteLine("9. Quit"); char input = Console.ReadKey().KeyChar; switch(input) { case '1': { Console.WriteLine("What is the new Company's Date of Incorporation? (YYYY-MM-DD)"); dob = Console.ReadLine(); Console.WriteLine("What is the new Company's Business Number? (XXXXX XXXX)"); sin = Console.ReadLine(); break; } case '2': { Console.WriteLine("What is the Contract's Start Date? (YYYY-MM-DD)"); cStartD = Console.ReadLine(); break; } case '3': { Console.WriteLine("What is the Contract's End Date? (YYYY-MM-DD)"); cStopD = Console.ReadLine(); break; } case '4': { while (true) { Console.WriteLine("What is the Contract's Fixed Amount? (Do not include the '$')"); tmpAmount = Console.ReadLine(); try { amount = Double.Parse(tmpAmount); break; } catch (Exception) { Console.WriteLine("Not a number"); } } break; } case '9': { done = true; break; } default: { break; } } break; } case "SN": { Console.WriteLine("2. Specify Season"); Console.WriteLine("3. Specify Piece Pay"); Console.WriteLine("9. Quit"); char input = Console.ReadKey().KeyChar; switch (input) { case '1': { Console.WriteLine("\nWhat is the new Employee's First Name?"); fname = Console.ReadLine(); Console.WriteLine("What is the new Employee's Date of Birth? (YYYY-MM-DD)"); dob = Console.ReadLine(); Console.WriteLine("What is the new Employee's Social Insurance Number? (XXX XXX XXX)"); sin = Console.ReadLine(); break; } case '2': { Console.WriteLine("\nWhat is the Season the new Employee's working in? (winter, spring, summer, fall)"); season = Console.ReadLine(); break; } case '3': { while (true) { Console.WriteLine("\nWhat is the new Employee's Piece Pay? (Do not include the '$')"); tmpPay = Console.ReadLine(); try { pay = Double.Parse(tmpPay); break; } catch (Exception) { Console.WriteLine("Not a number"); } } break; } case '9': { done = true; break; } default: { break; } } break; } } } /* Creating employees */ switch(type) { case "FT": { FulltimeEmployee tmpFTEmp = new FulltimeEmployee(fname, lname, dob, sin, doh, dot, sal); empList.Add(tmpFTEmp, tmpFTEmp.Validate()); break; } case "PT": { ParttimeEmployee tmpPTEmp = new ParttimeEmployee(fname, lname, dob, sin, doh, dot, rate); empList.Add(tmpPTEmp, tmpPTEmp.Validate()); break; } case "CT": { ContractEmployee tmpCTEmp = new ContractEmployee(fname, lname, dob, sin, cStartD, cStopD, amount); empList.Add(tmpCTEmp, tmpCTEmp.Validate()); break; } case "SN": { SeasonalEmployee tmpSNEmp = new SeasonalEmployee(fname, lname, dob, sin, season, pay); empList.Add(tmpSNEmp, tmpSNEmp.Validate()); break; } } } catch (Exception ex) { Logger.Log("UIMemu", "employeeDetailsMenu(string, string)", ex.Message); } }
/*! * FUNCTION : private static void fileManagementMenu() * * DESCRIPTION : This function displays the menu that allows the user to open, read, and write to the database file(s). * * PARAMETERS : None * * RETURN : None * */ private static void fileManagementMenu() { try { bool done = false; List<string> database = new List<string>(); while (!done) { Console.WriteLine("\nFILE MANAGEMENT MENU"); Console.WriteLine("1. Load EMS DBase from file"); Console.WriteLine("2. Save Employee Set to EMS DBase File"); Console.WriteLine("9. Return to Main Menu"); char input = Console.ReadKey().KeyChar; switch (input) { /*! * File Management Menu item 1 gets the data from the database file as returned from Database.LoadDatabase(). * It then parses the string and makes a temporary employee with those fields. * If the temporary employee is valid, it adds it to the list of employees. */ case '1': { Console.WriteLine("\nWhat file would you like to load the database from? (e.g. 'DBase.txt')"); string fileName = Console.ReadLine(); database = Database.LoadDatabase(fileName); if (database[0] == "ERROR") { Console.WriteLine("Failed to load the database."); } else { foreach (string s in database) { int index = 0; string fname = ""; string lname = ""; string dob = ""; string sin = ""; string empType = ""; while (s[index] != '|') { empType += s[index]; index++; } index++; while (s[index] != '|') { lname += s[index]; index++; } index++; while (s[index] != '|') { fname += s[index]; index++; } index++; while (s[index] != '|') { sin += s[index]; index++; } index++; while (s[index] != '|') { dob += s[index]; index++; } index++; switch (empType) { case "FT": { string doh = ""; string dot = ""; string tmpSal = ""; double sal = 0; while (s[index] != '|') { doh += s[index]; index++; } index++; while (s[index] != '|') { dot += s[index]; index++; } index++; while (s[index] != '|') { tmpSal += s[index]; sal = Double.Parse(tmpSal); index++; } index++; FulltimeEmployee tmpFTEmp = new FulltimeEmployee(fname, lname, dob, sin, doh, dot, sal); empList.Add(tmpFTEmp, tmpFTEmp.Validate()); break; } case "PT": { string doh = ""; string dot = ""; string tmpRate = ""; double rate = 0; while (s[index] != '|') { doh += s[index]; index++; } index++; while (s[index] != '|') { dot += s[index]; index++; } index++; while (s[index] != '|') { tmpRate += s[index]; rate = Double.Parse(tmpRate); index++; } index++; ParttimeEmployee tmpFTEmp = new ParttimeEmployee(fname, lname, dob, sin, doh, dot, rate); empList.Add(tmpFTEmp, tmpFTEmp.Validate()); break; } case "CT": { string cStartD = ""; string cStopD = ""; string tmpAmount = ""; double amount = 0; while (s[index] != '|') { cStartD += s[index]; index++; } index++; while (s[index] != '|') { cStopD += s[index]; index++; } index++; while (s[index] != '|') { tmpAmount += s[index]; amount = Double.Parse(tmpAmount); index++; } index++; ContractEmployee tmpFTEmp = new ContractEmployee(fname, lname, dob, sin, cStartD, cStopD, amount); empList.Add(tmpFTEmp, tmpFTEmp.Validate()); break; } case "SN": { string season = ""; string tmpPay = ""; double pay = 0; while (s[index] != '|') { season += s[index]; index++; } index++; while (s[index] != '|') { tmpPay += s[index]; pay = Double.Parse(tmpPay); index++; } index++; SeasonalEmployee tmpFTEmp = new SeasonalEmployee(fname, lname, dob, sin, season, pay); empList.Add(tmpFTEmp, tmpFTEmp.Validate()); break; } } } } database.Clear(); break; } /*! * File Management Menu item 2 creates a string with the employee data. * It passes that string to Database.SaveDatabase() for saving. */ case '2': { Console.WriteLine("\nWhat file would you like to load the database from? (e.g. 'DBase.txt')"); string fileName = Console.ReadLine(); string traStr = empList.GetDetailsToSave(); string tempStr = ""; for (int x = 0; x < traStr.Length; x++ ) { if(traStr[x] != '\n') { tempStr += traStr[x]; } else { database.Add(tempStr); tempStr = ""; } } Database.SaveDatabase(database, fileName); database.Clear(); break; } case '9': { done = true; break; } default: { break; } } } } catch (Exception ex) { Logger.Log("UIMemu", "fileManagementMenu", ex.Message); } }
public void TestingValidateContract_SeasonalEmployee_Normal() { bool status = false; string[] testData = new string[6] { "qwer", "drfdgf", "246 454 284", "1997/3/14", "Winter", "45.34" }; try { SeasonalEmployee testEmployee = new SeasonalEmployee(testData); status = testEmployee.Validate(); } catch (EmployeeException ee) { string errors = ee.GetError(); } Assert.AreEqual(true, status); }
public void DetailsTestValid() { DateTime DOB = new DateTime(1993, 04, 24); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Mc'Davies", 123456789, DOB, "Winter", 15); String details = employee.Details(); Assert.IsTrue(details == "Employee Type: Seasonal\nName: Brandon Mc'Davies\nSocial Insurance Number: 123 456 789\nDate of Birth: 1993-04-24\nSeason: Winter\nPrice per Piece: 15"); }
public void TestingValidateLongingString_SeasonalEmployee_Exception() { bool status = false; string[] testData = new string[6] { "qwer", "drfdgf", "246 454 284", "1997/3/14", "dfser", "45.34" }; try { SeasonalEmployee testEmployee = new SeasonalEmployee(testData); status = testEmployee.SuccessLogString(); } catch (EmployeeException ee) { string errors = ee.GetError(); } Assert.AreEqual(false, status); }
public void SetPiecePayInvalidNegitive() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies"); bool retVal = employee.SetPiecePay(-10); Assert.IsFalse(retVal); Assert.AreEqual(employee.GetPiecePay(), 0); }
/** * @fn public void Load() * * @brief Loads from database file. * * @return void. */ public void Load() { employees.Clear(); List<List<string>> records = file.ReadRecords("|"); foreach(List<string> record in records) { if(record.Count <= 1) { continue; } Employee newEmployee = null; switch(record[0]) { case "CE": newEmployee = new ContractEmployee(); break; case "SE": newEmployee = new SeasonalEmployee(); break; case "PE": newEmployee = new ParttimeEmployee(); break; case "FE": newEmployee = new FulltimeEmployee(); break; } newEmployee.InitFromRecord(record); employees.Add(newEmployee); } }
public void SetPiecePayValid() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies"); bool retVal = employee.SetPiecePay(10); Assert.IsTrue(retVal); Assert.AreEqual(employee.GetPiecePay(), 10); }
/// <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; }
public void SetSeasonInvalid() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies"); string currentSeason = employee.GetSeason(); bool retVal = employee.SetSeason("Summer3"); Assert.IsFalse(retVal); Assert.AreEqual(employee.GetSeason(), currentSeason); }
/// <summary> /// Method Name: LoadDatabase. /// The purpose of this method is to parse an input string from a file into objects to be added to the database. This method /// ensures that all of the database items it is creating are valid, else it will not create them. The format /// in which a database item is read in is as such: /// (Employee Type)|(Last Name)|(First Name)|(SIN)|(SubField1)|(SubField2)|(SubField3)| /// </summary> /// <returns>A boolean value of true upon completion.</returns> public bool LoadDatabase() { String fileInput = ""; FullTimeEmployee ft = new FullTimeEmployee(); PartTimeEmployee pt = new PartTimeEmployee(); ContractEmployee c = new ContractEmployee(); SeasonalEmployee s = new SeasonalEmployee(); String currentType = ""; String tempSin = ""; Boolean sinValid = true; String[] objects; //Read in the data from the database file. FileStream db = databaseFile.Openfile("dbase.dtb", 'R'); fileInput = databaseFile.ReadFromFile(db); databaseFile.CloseFile(db); //Remove null terminations and carrige returns. fileInput = fileInput.Replace("\0", ""); fileInput = fileInput.Replace("\r", ""); //Split up the fields for each new line. objects = fileInput.Split('\n'); //Initialize an multi-array for each attribute. String[][] attributes = new String[objects.Length][]; for (int k = 0; k < objects.Length; k++) { attributes[k] = new String[10]; } //For each object to be entered into the database. for (int i = 0; i < objects.Length; i++) { //Reset the valid SIN flag to true. sinValid = true; //Split up the object into attributes. attributes[i] = objects[i].Split('|'); //For each attribute in the current object. for (int j = 0; j < attributes[i].Length; j++) { //If the current attribute is the employee identifier. if (j == 0) { //Check what type of employee the object is. switch (attributes[i][0]) { //If the employee is a Full Time employee. case "FT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the full Time employee object to house the attributes. ft = new FullTimeEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Part Time employee. case "PT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Part Time employee object to house the attributes. pt = new PartTimeEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Contract Employee. case "CT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Contract employee object to house the attributes. c = new ContractEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Seasonal Employee. case "SN": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Seasonal Employee object to house the attributes. s = new SeasonalEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //Not a valid employee type. default: //Nullify the current employee type. currentType = ""; //Break the current object's cycle of the for loop. j = attributes.Length; break; } } //If the current attribute is not the employee identifier. else { //Check the current employee type. switch (currentType) { //If the current employee is a Full Time employee case "FT": //Switch based the the current attribute being read in. switch (j) { //Set the first name. case 1: //Make sure there are no spaces. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetLastName(attributes[i][j]); break; //Set the last name. case 2: //Make sure there are no spaces. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: if (ft.CheckSinNumber(attributes[i][j])) { //Make sure there are no spaces in the SIN number. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { ft.SetDateOfBirth(new DateTime(0)); } else { ft.SetDateOfBirth(attributes[i][j]); } break; //Set the Date of Hire. case 5: if (attributes[i][j] == "N/A") { ft.SetDateOfHire(new DateTime(0)); } else { ft.SetDateOfHire(attributes[i][j]); } break; //Set the Date of Termination. case 6: if (attributes[i][j] == "N/A") { ft.SetDateOfTermination(new DateTime(0)); } else { ft.SetDateOfTermination(attributes[i][j]); } break; //Set the current Salary. case 7: try { ft.SetSalary(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Part Time employee. case "PT": //Switch based on the current attribute. switch (j) { //Set the first name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetLastName(attributes[i][j]); break; //Set the last name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetFirstName(attributes[i][j]); break; //Set the sin number. case 3: if (pt.CheckSinNumber(attributes[i][j])) { attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { pt.SetDateOfBirth(new DateTime(0)); } else { pt.SetDateOfBirth(attributes[i][j]); } break; //Set the Date of Hire. case 5: if (attributes[i][j] == "N/A") { pt.SetDateOfHire(new DateTime(0)); } else { pt.SetDateOfHire(attributes[i][j]); } break; //Set the Date of Termination. case 6: if (attributes[i][j] == "N/A") { pt.SetDateOfTermination(new DateTime(0)); } else { pt.SetDateOfTermination(attributes[i][j]); } break; //Set the Hourly Rate. case 7: try { pt.SetHourlyRate(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Contract Employee. case "CT": switch (j) { //Set the last name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); c.SetLastName(attributes[i][j]); break; //Set the first name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); c.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: tempSin = attributes[i][j]; break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { c.SetDateOfBirth(new DateTime(0)); } else { c.SetDateOfBirth(attributes[i][j]); } if (c.CheckSinNumber(tempSin)) { tempSin = tempSin.Replace(" ", ""); c.SetSocialNumber(tempSin); } break; //Set the Contract Start Date. case 5: if (attributes[i][j] == "N/A") { c.SetContractStartDate(new DateTime(0)); } else { c.SetContractStartDate(attributes[i][j]); } break; //Set the Contract End Date. case 6: if (attributes[i][j] == "N/A") { c.SetContractStartDate(new DateTime(0)); } else { c.SetContractStopDate(attributes[i][j]); } break; case 7: try { c.SetFixedContractAmount(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Seasonal Employee. case "SN": //Switch based on the current attribute. switch (j) { //Set the last name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetLastName(attributes[i][j]); break; //Set the first name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: if (s.CheckSinNumber(attributes[i][j])) { attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { s.SetDateOfBirth(new DateTime(0)); } else { s.SetDateOfBirth(attributes[i][j]); } break; //Set the Season. case 5: s.SetSeason(attributes[i][j]); break; //Set the piece pay. case 6: try { s.SetPiecePay(float.Parse(attributes[i][j])); } catch { } break; } break; } } } //If the valid SIN flag was not invalidated. if (sinValid) { //Check the current employee type. switch (currentType) { //If the current employee is a Full Time Employee. case "FT": //Validate the full time employee. if (ft.Validate()) { //Add the employee to the database. databaseContainer.Add(ft); } break; //If the current employee is a Part Time employee. case "PT": //Validate the part tiem employee. if (pt.Validate()) { //Add the employee to the database. databaseContainer.Add(pt); } break; //If the current employee is a Contract employee. case "CT": //Validate the COntract employee. if (c.Validate()) { //Add the employee to the database. databaseContainer.Add(c); } break; //If the current employee is a Seasonal Employee. case "SN": //Validate the seasonal Employee. if (s.Validate()) { //Add the employee to the database. databaseContainer.Add(s); } break; } } } return true; }
public void ConstructorWithAllParamTestInvalidPiecePay() { DateTime DOB = new DateTime(1993, 04, 24); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies", 123456789, DOB, "Fall", -12); }
public void SetSeasonValid3() { SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies"); bool retVal = employee.SetSeason("Summer"); Assert.IsTrue(retVal); Assert.AreEqual(employee.GetSeason(), "Summer"); }
public void ToStringTestValid() { DateTime DOB = new DateTime(1993, 04, 24); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Mc'Davies", 123456789, DOB, "Winter", 15); String toString = employee.ToString(); Assert.IsTrue(toString == "|SN|Brandon|Mc'Davies|123456789|1993-04-24|Winter|15|"); }
/** * @fn private bool ModifySeasonalEmployee(SeasonalEmployee employee, string returnMessage) * * @brief allows user to modify this employee using the command line. * * @param SeasonalEmployee The employee to modify. * @param returnMessage message displayed to the user as the option to return from this method. * * @return whether the user canceled. */ private bool ModifySeasonalEmployee(SeasonalEmployee employee, string returnMessage) { bool done = false; bool isCanceled = false; //loop until user goes back do { Console.Clear(); Console.WriteLine(employee.Details()); Console.WriteLine("1. Change First Name(A-Z, a-z, ', -)"); Console.WriteLine("2. Change Last Name(A-Z, a-z, ', -)"); Console.WriteLine("3. Change Date of birth(yyyy-mm-dd)"); Console.WriteLine("4. Change Social insurance number"); Console.WriteLine("5. Change Piece Pay"); Console.WriteLine("6. Change Season"); Console.WriteLine("8. Cancel"); Console.WriteLine("9. " + returnMessage); //get user input until valid bool valid; do { valid = true; string input = Console.ReadLine(); switch (input) { case "1": Console.Write("Enter a new first name:"); while (employee.SetFirstName(Console.ReadLine()) == false) { Console.Write("Invalid name, Enter a new first name:"); } break; case "2": Console.Write("Enter a new last name:"); while (employee.SetLastName(Console.ReadLine()) == false) { Console.Write("Invalid name, Enter a new last name:"); } break; case "3": bool dateOfBirthDone = false; while (!dateOfBirthDone) { Console.Write("Enter a new date of birth:"); try { while (employee.SetDateofBirth(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) { Console.Write("Invalid date, Enter a new date of birth:"); } dateOfBirthDone = true; } catch (FormatException ex) { Console.WriteLine("Invalid date, Format: yyyy-mm-dd"); dateOfBirthDone = false; } } break; case "4": Console.Write("Enter a new social insurance number:"); while(employee.SetSocialInsuranceNumber(Console.ReadLine()) == false) { Console.Write("Invalid number, Enter a new social insurance number:"); } break; case "5": bool piecePayDone = false; while (!piecePayDone) { Console.Write("Enter a new piece pay:"); try { while (employee.SetPiecePay(decimal.Parse(Console.ReadLine())) == false) { Console.Write("Invalid pay, Enter a new piece pay:"); } piecePayDone = true; } catch (FormatException ex) { Console.WriteLine("Piece pay must be a number"); piecePayDone = false; } } break; case "6": Console.Write("Enter a new season:"); while(employee.SetSeason(Console.ReadLine()) == false) { Console.Write("Invalid season, Enter a new season:"); } break; case "8": done = true;//end isCanceled = true; break; case "9": done = true;//end isCanceled = false; break; default: Console.WriteLine("Invalid input, please enter number corrispoding to a menu option:"); valid = false; break; } } while (!valid); } while (!done); return isCanceled; }
public void ConstructorWithAllParamTestInvalidSeason() { DateTime DOB = new DateTime(1993, 04, 24); SeasonalEmployee employee = new SeasonalEmployee("Brandon", "Davies", 123456789, DOB, "October", 13); }
/** * \brief given string from file, pars all data into list, return list valid employees * * \details <b>Details</b> * * \param fileText - <b>string</b> - The string of data containing an employees records * * \return employeeRec - <b>List<AllEmployees.Employee></b> - The list of all the employee records in the strinng of data */ private static List<AllEmployees.Employee> ParsRecord(String fileText) { List<AllEmployees.Employee> employeeRec = new List<AllEmployees.Employee>(); //tostringbase string employeeString = firstName + "|" + lastName + "|" + SocialInsuranceNumber + "|" + DateOfBirth.Year + "-" + DateOfBirth.Month + "-" + DateOfBirth.Day + "|"; char[] delimiterChars = { '|', '\n'}; string[] words = fileText.Split(delimiterChars); int wordCounter = 0; while (wordCounter < words.Count() - 1) { if (words[wordCounter] == "CT") { bool isValid = true; if (words.Length > (wordCounter + 7)) { //AllEmployees.ContractEmployee contractEmp = new AllEmployees.ContractEmployee(words[wordCounter], words[wordCounter+1], Convert.ToInt32(words[wordCounter+2]), words[wordCounter+3], words[wordCounter+4], words[wordCounter+5], Convert.ToDouble(words[wordCounter+6])); try { AllEmployees.ContractEmployee contractEmp = new AllEmployees.ContractEmployee(); contractEmp.SetEmployeeType(words[wordCounter]); wordCounter++; contractEmp.SetLastName(words[wordCounter]); wordCounter++; wordCounter++; contractEmp.SetSocialInsuranceNumber(Convert.ToInt32(words[wordCounter]));//only take an int wordCounter++; contractEmp.SetDateOfBirth(words[wordCounter]); wordCounter++; contractEmp.SetContractStartDate(words[wordCounter]); wordCounter++; isValid = contractEmp.SetContractStopDate(words[wordCounter]); if (words[wordCounter] == "") { isValid = true; } wordCounter++; contractEmp.SetFixedContractAmount(Convert.ToDouble(words[wordCounter])); wordCounter++; if (contractEmp.Validate() == true && isValid == true) { employeeRec.Add(contractEmp); Logging.Log("FileIO", "ParsRecord", "contract employee added"); wordCounter++; } else { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a contract employee"); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } catch (Exception ex) { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a contract employee - Error Message: " + ex.Message); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } else { Logging.Log("FileIO", "ParsRecord", "Not enough employee data for a contract employee"); break; } } else if (words[wordCounter] == "FT") { bool isValid = true; if (words.Length > (wordCounter + 7)) { AllEmployees.FulltimeEmployee fullTimeEmp = new AllEmployees.FulltimeEmployee(); try { fullTimeEmp.SetEmployeeType(words[wordCounter]); wordCounter++; fullTimeEmp.SetLastName(words[wordCounter]); wordCounter++; fullTimeEmp.SetFirstName(words[wordCounter]); wordCounter++; fullTimeEmp.SetSocialInsuranceNumber(Convert.ToInt32(words[wordCounter]));//only takes an int wordCounter++; fullTimeEmp.SetDateOfBirth(words[wordCounter]); wordCounter++; fullTimeEmp.SetDateOfHire(words[wordCounter]); wordCounter++; isValid = fullTimeEmp.SetDateOfTermination(words[wordCounter]); if (words[wordCounter] == "") { isValid = true; } wordCounter++; fullTimeEmp.SetSalary(Convert.ToDouble(words[wordCounter]));//only takes a float wordCounter++; if (fullTimeEmp.Validate() == true && isValid == true) { wordCounter++; employeeRec.Add(fullTimeEmp); Logging.Log("FileIO", "ParsRecord", "full time employee added"); } else { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a full time employee"); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } catch (Exception ex) { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a full time employee - Error Message: " + ex.Message); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } else { Logging.Log("FileIO", "ParsRecord", "Not enough employee data for a full time employee"); break; } } else if (words[wordCounter] == "PT") { if (words.Length > (wordCounter + 7)) { bool isValid = true; AllEmployees.ParttimeEmployee partTimeEmp = new AllEmployees.ParttimeEmployee(); try { partTimeEmp.SetEmployeeType(words[wordCounter]); wordCounter++; partTimeEmp.SetLastName(words[wordCounter]); wordCounter++; partTimeEmp.SetFirstName(words[wordCounter]); wordCounter++; partTimeEmp.SetSocialInsuranceNumber(Convert.ToInt32(words[wordCounter]));//only takes an int wordCounter++; partTimeEmp.SetDateOfBirth(words[wordCounter]); wordCounter++; partTimeEmp.SetDateOfHire(words[wordCounter]); wordCounter++; isValid = partTimeEmp.SetDateOfTermination(words[wordCounter]); if (words[wordCounter] == "") { isValid = true; } wordCounter++; partTimeEmp.SetHourlyRate(Convert.ToDouble(words[wordCounter]));//only takes a float wordCounter++; if (partTimeEmp.Validate() == true && isValid == true) { wordCounter++; employeeRec.Add(partTimeEmp); Logging.Log("FileIO", "ParsRecord", "part time employee added"); } else { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a part time employee"); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } catch (Exception ex) { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a part time employee - Error Message: " + ex.Message); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } else { Logging.Log("FileIO", "ParsRecord", "Not enough employee data for a part time employee"); break; } } else if (words[wordCounter] == "SN") { if (words.Length > (wordCounter + 6)) { AllEmployees.SeasonalEmployee seasonalEmp = new AllEmployees.SeasonalEmployee(); try { seasonalEmp.SetEmployeeType(words[wordCounter]); wordCounter++; seasonalEmp.SetLastName(words[wordCounter]); wordCounter++; seasonalEmp.SetFirstName(words[wordCounter]); wordCounter++; seasonalEmp.SetSocialInsuranceNumber(Convert.ToInt32(words[wordCounter]));//only takes an int wordCounter++; Logging.Log("FileIO", "ParsRecord", "SN Birthday: " + words[wordCounter]); seasonalEmp.SetDateOfBirth(words[wordCounter]); wordCounter++; Logging.Log("FileIO", "ParsRecord", "SN Season: " + words[wordCounter]); seasonalEmp.SetSeason(words[wordCounter]); wordCounter++; Logging.Log("FileIO", "ParsRecord", "SN PiecePay: " + words[wordCounter]); seasonalEmp.SetPiecePay(Convert.ToDouble(words[wordCounter]));//only takes a float wordCounter++; if (seasonalEmp.Validate() == true) { wordCounter++; employeeRec.Add(seasonalEmp); Logging.Log("FileIO", "ParsRecord", "seasonal employee added"); } else { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a seasonal employee"); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } catch (Exception ex) { Logging.Log("FileIO", "ParsRecord", "invalid employee data for a seasonal employee - Error Message: " + ex.Message); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } else { Logging.Log("FileIO", "ParsRecord", "Not enough employee data for a seasonal employee"); break; } } else { //string className, string methodName, string eventDetails Logging.Log("FileIO", "ParsRecord", "invalid employee type in file"); while (words[wordCounter] != "FT" && words[wordCounter] != "PT" && words[wordCounter] != "SN" && words[wordCounter] != "CT" && wordCounter < words.Count() - 1) { wordCounter++; } } } return employeeRec; }
public void TestInitialize() { // Instantiate the container employeeRepo = new Container(); // Instantiate a full-time employee DateTime dateOfBirth = new DateTime(1990, 09, 10); DateTime dateOfHire = new DateTime(2010, 10, 11); DateTime dateOfTermination = new DateTime(2012, 02, 19); FTEmployee = new AllEmployees.FulltimeEmployee("Sam", "Jones", 902398402, dateOfBirth, dateOfHire, dateOfTermination, 50000); // Instantiate a part-time employee dateOfBirth = new DateTime(1987, 06, 22); dateOfHire = new DateTime(2013, 04, 12); dateOfTermination = new DateTime(2014, 05, 13); PTEmployee = new AllEmployees.ParttimeEmployee("Mark", "Smith", 872098933, dateOfBirth, dateOfHire, dateOfTermination, 30); // Instantiate a contract employee dateOfBirth = new DateTime(1989, 07, 02); DateTime contractStartDate = new DateTime(2014, 02, 08); DateTime contractStopDate = new DateTime(2014, 09, 12); CTEmployee = new AllEmployees.ContractEmployee("Anna", "Miller", 892398402, dateOfBirth, contractStartDate, contractStopDate, 25000); // Instantiate a seasonal employee dateOfBirth = new DateTime(1991, 03, 18); SNEmployee = new AllEmployees.SeasonalEmployee("Jake", "Williams", 912098933, dateOfBirth, "Summer", 20); }