private void createPayrollRecords() { try { payrollEntries = new EmployeePayrollEntry[rawLines.Length]; for (int i = 0; i < rawLines.Length; i++) { string[] fields = rawLines[i].Split(','); string payType = fields[3]; EmployeePayrollEntry emp = null; if (payType.ToUpper().Equals("H")) { emp = new HourlyEmployeeEntry(fields); } else if (payType.ToUpper().Equals("S")) { emp = new SalaryEmployeeEntry(fields); } else { Console.WriteLine("ERROR: Unknown PayType for Employee Id: " + fields[0] + " Name: " + fields[2] + ", " + fields[1]); } payrollEntries[i] = emp; } } catch { payrollEntries = new EmployeePayrollEntry[1]; payrollEntries[0] = new HourlyEmployeeEntry(new string[] { "NoValues", "NoValues", "NoValues", "H", "0.0", "1/1/2000", "NO", "0.0" }); } }
private static bool isFileOfEmployeeRecords(string path) { try { string line1 = File.ReadLines(path).First(); string[] fields = line1.Split(','); EmployeePayrollEntry testEntry = new HourlyEmployeeEntry(fields); } catch { Console.WriteLine("File entered is not in the valid payroll format."); Console.WriteLine("File must have: Id, firstName, lastName, payType, salary, startDate, residenceState, hoursWorked."); Console.WriteLine("Example:\n1,JANE,DOE,H,29.77,9/5/05,NM,70"); return(false); } return(true); }