Exemplo n.º 1
0
        /**
        * \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;
        }
Exemplo n.º 2
0
 public void ToStringTestValid()
 {
     DateTime DOB = new DateTime(1954, 08, 20);
     DateTime DOH = new DateTime(1994, 09, 03);
     DateTime DOT = new DateTime(2014, 12, 23);
     ContractEmployee employee = new ContractEmployee("Brandon", "Davies", 543456789, DOB, DOH, DOT, 18);
     String toString = employee.ToString();
     Assert.IsTrue(toString == "|CT|Brandon|Davies|543456789|1954-08-20|1994-09-03|2014-12-23|18|");
 }