Ejemplo n.º 1
0
        /**
         * @fn  private bool ModifyContractEmployee(ContractEmployee employee, string returnMessage)
         *
         * @brief  allows user to modify this employee using the command line.
         *
         * @param   ContractEmployee    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 ModifyContractEmployee(ContractEmployee 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 Business number");
                Console.WriteLine("5.   Change Contract Start Date(yyyy-mm-dd)");
                Console.WriteLine("6.   Change Contract Stop Date(yyyy-mm-dd)");
                Console.WriteLine("7.   Change Fixed Contract Amount");
                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 contractStartDateDone = false;
                            while (!contractStartDateDone){
                                Console.Write("Enter a new contract start date:");
                                try  {
                                    while (employee.SetContractStartDate(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) {
                                        Console.Write("Invalid date, Enter a new contract start date:");
                                    }
                                    contractStartDateDone = true;
                                }
                                catch (FormatException ex){
                                    Console.WriteLine("Invalid date, Format: yyyy-mm-dd");
                                    contractStartDateDone = false;
                                }
                            }
                            break;
                        case "6":
                            bool contractStopDateDone = false;
                            while (!contractStopDateDone) {
                                Console.Write("Enter a new contract stop date:");
                                try {
                                    while (employee.SetContractStopDate(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) {
                                        Console.Write("Invalid date, Enter a new contract stop date:");
                                    }
                                    contractStopDateDone = true;
                                }
                                catch (FormatException ex) {
                                    Console.WriteLine("Invalid date, Format: yyyy-mm-dd");
                                    contractStopDateDone = false;
                                }
                            }
                            break;
                        case "7":
                            bool contractAmountDone = false;
                            while (!contractAmountDone) {
                                Console.Write("Enter a new fixed contract amount:");
                                try{
                                    while (employee.SetFixedContractAmount(decimal.Parse(Console.ReadLine())) == false) {
                                        Console.Write("Invalid amount, Enter a new fixed contract amount:");
                                    }

                                    contractAmountDone = true;
                                }
                                catch (FormatException ex) {
                                    Console.WriteLine("Fixed contract amount must be a number");
                                    contractAmountDone = false;
                                }
                            }
                            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;
        }
Ejemplo n.º 2
0
        /**
        * \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;
        }
Ejemplo n.º 3
0
        public void SetSocialInsuranceNumberTest()
        {
            SeasonalEmployee se = new SeasonalEmployee();
            bool retSe = se.SetSocialInsuranceNumber("111111111");

            ParttimeEmployee pe = new ParttimeEmployee();
            bool retPe = pe.SetSocialInsuranceNumber("111111111");

            FulltimeEmployee fe = new FulltimeEmployee();
            bool retFe = fe.SetSocialInsuranceNumber("111111111");

            ContractEmployee ce = new ContractEmployee();
            bool retCe = ce.SetSocialInsuranceNumber("111111111");

            Assert.AreEqual(retSe, true);
            Assert.AreEqual(retPe, true);
            Assert.AreEqual(retFe, true);
            Assert.AreEqual(retCe, true);
        }