コード例 #1
0
ファイル: FileIO.cs プロジェクト: brandond12/EMS
        /**
        * \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;
        }
コード例 #2
0
ファイル: UIMenu.cs プロジェクト: brandond12/EMS
        /**
        * \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;
        }