public IEnumerable <LateTimesheet> GetLateTimesheets() { List <LateTimesheet> lateTimesheets = new List <LateTimesheet>(); if (File.Exists(_lateTimeSheetFilePath)) { using (var timesheetReader = new StreamReader(_lateTimeSheetFilePath)) { string headerLine = timesheetReader.ReadLine(); string line; while ((line = timesheetReader.ReadLine()) != null) { var lineColumns = line.Split('\t'); var currentTimesheet = new LateTimesheet(); currentTimesheet.FullName = lineColumns[0]; currentTimesheet.Rank = lineColumns[1]; currentTimesheet.EmployeeId = lineColumns[2]; currentTimesheet.CycleEndDate = Convert.ToDateTime(lineColumns[3]); currentTimesheet.Speciality = lineColumns[4]; currentTimesheet.TimeSheetStatus = lineColumns[5]; currentTimesheet.EmployeeEmail = lineColumns[6]; currentTimesheet.PeopleManager = lineColumns[7]; currentTimesheet.PeopleManagerEmail = lineColumns[8]; lateTimesheets.Add(currentTimesheet); } } } return(lateTimesheets); }
private void SendLateTimesheetEmail(IEnumerable <LateTimesheet> employeeLateTimesheets) { LateTimesheet employeeLatestTimesheet = employeeLateTimesheets.First(); var messageBuilder = new StringBuilder(); Console.WriteLine($" Emailing {employeeLatestTimesheet.FullName} for {employeeLatestTimesheet.TimeSheetStatus} timesheet for {employeeLatestTimesheet.CycleEndDate}"); // Console.WriteLine("------------------------------------------------"); _emailSender.SendLateTimesheetEmail(employeeLatestTimesheet.EmployeeEmail, employeeLatestTimesheet.PeopleManagerEmail, CreateEmailBodyWithTable(employeeLateTimesheets)); }
private void SendLateTimesheetMessage(IEnumerable <LateTimesheet> employeeLateTimesheets) { LateTimesheet employeeLatestTimesheet = employeeLateTimesheets.First(); Console.WriteLine($" Messaging {employeeLatestTimesheet.FullName} for {employeeLatestTimesheet.TimeSheetStatus} timesheet for {employeeLatestTimesheet.CycleEndDate}"); // Console.WriteLine("-----------------------Table--------------------"); // var messageBuilder = new StringBuilder(); // CreateEmployeeMissingTimesheetTable(messageBuilder, employeeLateTimesheets); // Console.WriteLine(messageBuilder.ToString()); // Console.WriteLine("------------------------------------------------"); }
public IEnumerable <LateTimesheet> GetLateTimesheets() { List <LateTimesheet> lateTimesheets = new List <LateTimesheet>(); if (File.Exists(_lateTimeSheetFilePath)) { Excel.Application excelApp = new Excel.Application(); Excel.Workbook timesheetsWorkbook = excelApp.Workbooks.Open(_lateTimeSheetFilePath); Excel.Worksheet timesheetsWorksheet = (Excel.Worksheet)timesheetsWorkbook.Sheets[1]; Excel.Range timesheetRange = timesheetsWorksheet.UsedRange; int numRows = timesheetRange.Rows.Count; for (int i = 2; i <= numRows; i++) { var currentTimesheet = new LateTimesheet(); currentTimesheet.FullName = (string)(timesheetRange.Cells[i, 1] as Excel.Range).Text; currentTimesheet.Rank = (string)(timesheetRange.Cells[i, 2] as Excel.Range).Text; currentTimesheet.EmployeeId = (string)(timesheetRange.Cells[i, 3] as Excel.Range).Text; currentTimesheet.CycleEndDate = Convert.ToDateTime((string)(timesheetRange.Cells[i, 4] as Excel.Range).Text); currentTimesheet.Speciality = (string)(timesheetRange.Cells[i, 5] as Excel.Range).Text; currentTimesheet.TimeSheetStatus = (string)(timesheetRange.Cells[i, 6] as Excel.Range).Text; currentTimesheet.EmployeeEmail = (string)(timesheetRange.Cells[i, 7] as Excel.Range).Text; currentTimesheet.PeopleManager = (string)(timesheetRange.Cells[i, 8] as Excel.Range).Text; currentTimesheet.PeopleManagerEmail = (string)(timesheetRange.Cells[i, 9] as Excel.Range).Text; currentTimesheet.CurrentMarketUnit = (string)(timesheetRange.Cells[i, 10] as Excel.Range).Text; currentTimesheet.Account = (string)(timesheetRange.Cells[i, 11] as Excel.Range).Text; lateTimesheets.Add(currentTimesheet); } Marshal.ReleaseComObject(timesheetRange); Marshal.ReleaseComObject(timesheetsWorksheet); timesheetsWorkbook.Close(); Marshal.ReleaseComObject(timesheetsWorkbook); excelApp.Quit(); Marshal.ReleaseComObject(excelApp); } return(lateTimesheets); }
private void CreateAndSaveTeamsMessages(IEnumerable <List <LateTimesheet> > teamsMessagesTimesheets) { StringBuilder teamsMessages = new StringBuilder(); foreach (var timesheetsGroup in teamsMessagesTimesheets) { LateTimesheet firstLateTimesheet = timesheetsGroup.First(); teamsMessages.Append($"Messaging {firstLateTimesheet.FullName}\n"); teamsMessages.Append($"Hello,\n\nAccording to a report generated with data pulled from {_reportCreationTimeString},"); teamsMessages.Append(" you are missing your timesheet(s) for the following week end dates. Please submit your timesheet ASAP and let me know when this is complete.\n\n"); foreach (var sheet in timesheetsGroup) { teamsMessages.Append($"Name: {sheet.FullName}\n"); teamsMessages.Append($"Missing Timesheet: {sheet.CycleEndDate}\n"); teamsMessages.Append($"Status of Timesheet: {sheet.TimeSheetStatus}\n\n"); } teamsMessages.Append("Please make sure to \"Submit\" the timesheet and not just \"Save\".\n\n"); teamsMessages.Append("Thank you\n"); teamsMessages.Append($"{_senderName}\n"); teamsMessages.Append("------------------------------------------------------------\n"); } System.IO.File.WriteAllText(_teamsMessagesSaveFile, teamsMessages.ToString()); }