コード例 #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
ファイル: FileIO.cs プロジェクト: brandond12/EMS
        /**
        * \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;
        }
コード例 #3
0
       public void TestingValidateContract_ParttimeEmployee_Exception()
       {
           string[] testData = new string[7] {
                "qwer",
                "drfdgf",
                "046 454 286",
                "1997/3/14",
                "2000/12/12",
                "2013/10/9",
                "a"
            };
           try
           {
               ParttimeEmployee testEmployee = new ParttimeEmployee(testData);
               bool status = testEmployee.Validate();
               Assert.AreEqual(false, status);
           }
           catch (Exception e)
           {
               Assert.AreEqual(true, true);

           }
       }
コード例 #4
0
 public void TestingValidateContract_ParttimeEmployee_Normal()
 {
     string[] testData = new string[7] {
         "qwer",
         "drfdgf",
         "246 454 284",
         "1997/3/14",
         "2000/12/12",
         "2013/10/9",
         "45.34"
     };
     ParttimeEmployee testEmployee = new ParttimeEmployee(testData);
     bool status = testEmployee.Validate();
     Assert.AreEqual(true, status);
 }
コード例 #5
0
ファイル: UIMenu.cs プロジェクト: bdiebold3924/SQ1-EMS-1
 /*!
  * 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);
     }
 }
コード例 #6
0
ファイル: UIMenu.cs プロジェクト: bdiebold3924/SQ1-EMS-1
 /*!
  * 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);
     }
 }