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" }); } }
public void writeDictionary() { payrollDict = new Dictionary <string, EmployeePayrollEntry>(); for (int i = 0; i < payrollEntries.Length; i++) { EmployeePayrollEntry payrollEntry = payrollEntries[i]; payrollDict.Add(payrollEntry.Id, payrollEntry); } }
public EmployeePayrollEntry GetByEmployeeId(string employeeId) { EmployeePayrollEntry entry = null; if (payrollDict != null && payrollDict.Count > 0) { try { entry = payrollDict[employeeId]; } catch (Exception e) { //Console.WriteLine("No employee found by that id: " + e.Message); } } return(entry); }
public static void run(string delimiter, EmployeePayrollEntry[] sortedEntries) { paycheckStrings = new string[sortedEntries.Length]; for (int i = 0; i < sortedEntries.Length; i++) { EmployeePayrollEntry e = sortedEntries[i]; string text = e.Id; text += delimiter + " " + e.firstName; text += delimiter + " " + e.lastName; text += delimiter + " " + e.getPeriodGrossPay().ToString("F"); text += delimiter + " " + e.getFederalTax().ToString("F"); text += delimiter + " " + e.getStateTax().ToString("F"); text += delimiter + " " + e.getNetPay().ToString("F"); paycheckStrings[i] = text; } writePaychecksToFile(); }
public static List <TopEarnerModel> getSortedListGrossLastNameFirstName(EmployeePayrollEntry[] entries) { List <TopEarnerModel> topEarnerList = new List <TopEarnerModel>(); for (int i = 0; i < entries.Length; i++) { EmployeePayrollEntry entry = entries[i]; TopEarnerModel earner = new TopEarnerModel(); earner.lastName = entry.lastName; earner.firstName = entry.firstName; earner.numYearsWorked = getNumYearsWorked(entry.startDate); earner.grossPay = entry.getPeriodGrossPay(); topEarnerList.Add(earner); } var top = topEarnerList.OrderBy(e => e.grossPay). ThenBy(e => e.lastName). ThenBy(e => e.firstName). ToList(); return(top); }