private List <ExcelEntry> GetUpdateEntries(List <Range> changedRowsWithTimeID) { List <ExcelEntry> updateEntries = new List <ExcelEntry>(); // Loop trough each row with a Time-ID. foreach (Range row in changedRowsWithTimeID) { ExcelEntry buffer = ExcelEntry.FromRow(row.Row); // Check if the entry is ignorable. bool ignorable = IsIgnorableEntry(buffer); if (!ignorable) { // Check if the entry is valid. bool valid = ValidateExcelEntryWithTimeID(buffer); if (valid) { updateEntries.Add(buffer); } } } return(updateEntries); }
private List <ExcelEntry> GetAddEntries(List <Range> rowsWithoutTimeID) { List <ExcelEntry> addEntries = new List <ExcelEntry>(); // Loop through each row with no Time-ID. foreach (Range row in rowsWithoutTimeID) { ExcelEntry buffer = ExcelEntry.FromRow(row.Row); // Check if the entry is ignorable. bool ignorable = IsIgnorableEntry(buffer); if (!ignorable) { // Check if the entry is valid. bool valid = ValidateExcelEntry(buffer); if (valid) { addEntries.Add(buffer); } } } return(addEntries); }
private bool ValidateExcelEntryWithTimeID(ExcelEntry entry) { bool validated = true; validated = ValidateExcelEntry(entry); if (string.IsNullOrEmpty(entry.TimeID) || !Regex.IsMatch(entry.TimeID, @"^\d+$")) { validated = false; Globals.Breakdowns.TimeIDs.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } return(validated); }
private List <ExcelEntry> GetRemoveEntries(List <Range> changedRowsWithTimeID) { List <ExcelEntry> removeEntries = new List <ExcelEntry>(); // Loop trough each row with a Time-ID. foreach (Range row in changedRowsWithTimeID) { ExcelEntry buffer = ExcelEntry.FromRow(row.Row); // Check if the entry is ignorable. bool ignorable = IsIgnorableEntry(buffer); if (ignorable) { removeEntries.Add(buffer); } } return(removeEntries); }
private bool ValidateExcelEntry(ExcelEntry entry) { bool validated = true; if (string.IsNullOrEmpty(entry.ID)) { validated = false; Globals.Breakdowns.IDs.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (entry.Date == null || (DateTime.Now - entry.Date.Value).Days > (365 * 3)) { validated = false; Globals.Breakdowns.Dates.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (entry.TimeFrom == null) { validated = false; Globals.Breakdowns.TimeBegin.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (entry.TimeTo == null) { validated = false; Globals.Breakdowns.TimeEnd.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (string.IsNullOrEmpty(entry.EmployeeCode) || !Regex.IsMatch(entry.EmployeeCode, @"^[a-zA-Z]+$")) { validated = false; // Set the row to red, indicating failure or incomplete. Globals.Breakdowns.Cells[entry.Row, 5].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (string.IsNullOrEmpty(entry.Project)) { validated = false; Globals.Breakdowns.Projects.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (string.IsNullOrEmpty(entry.Phase)) { validated = false; Globals.Breakdowns.Phases.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } if (string.IsNullOrEmpty(entry.Code)) { validated = false; Globals.Breakdowns.Codes.Cells[entry.Row, 1].Interior.Color = ColorTranslator.FromHtml("#d32836"); } return(validated); }
/// <summary> /// /// </summary> /// <param name="entry"></param> /// <returns></returns> private bool IsIgnorableEntry(ExcelEntry entry) => entry.Date == null && entry.TimeFrom == null && entry.TimeTo == null && string.IsNullOrEmpty(entry.EmployeeCode);