public static string VerifyFileIntact(ClassDataFile datFile, ClassAuditEntriesDataTable auditEntries = null) { string message = "Not successful. No Audit entry found for this file"; //• Audit Type depends on if the auditEntries table has been supplied or not if (auditEntries == null) { if (datFile.AmountOfLines == datFile.IntendedAmountOfLines) message = "Self Check Successful"; else message = "Self Check Not Successful. File is not complete:CDR MISMATCH"; } else { foreach (DataRow dr in auditEntries.entriesTable.Rows) { if (dr["FileName"].ToString() == datFile.FileName.Substring(0, 8)) { if (Convert.ToInt16(dr["CDR_Count"]) == datFile.AmountOfLines) { message = "AuditFile Check Successful"; break; } else { message = "AuditFile Check Not Successful. File is not complete:CDR MISMATCH"; break; } } } } return message; }
public static List<ClassDataFile> CompileFileList(string pickUpLocation, ref ClassImportInfoDataTable infoTable, bool useAuditFile) { List<ClassDataFile> fileList = new List<ClassDataFile>(); String[] filePaths = Directory.GetFiles(pickUpLocation); ClassDataFile[] datFiles = new ClassDataFile[filePaths.Count()]; int count = 0; if (useAuditFile) { string auditFileLocation = Properties.Settings.Default.AuditFileLocation; ClassAuditFile auditFile = new ClassAuditFile(auditFileLocation); DataTables.ClassAuditEntriesDataTable auditEntriesTable = new DataTables.ClassAuditEntriesDataTable(); auditEntriesTable = DataTables.ClassAuditEntriesDataTable.FillEntriesTable(auditFile); if (auditEntriesTable.entriesTable.Rows.Count >= 1) { foreach (String fileLoc in filePaths) { datFiles[count] = new ClassDataFile(filePaths[count]); infoTable.AddNewRow(datFiles[count], ref infoTable); string message = string.Empty; message = ClassAuditing.SelfCheck(datFiles[count]); infoTable.UpdateRow(datFiles[count], "Self_Check_Result", message, ref infoTable); message = ClassAuditing.AuditFileCheck(datFiles[count], auditEntriesTable); infoTable.UpdateRow(datFiles[count], "AuditFile_Check_Result", message, ref infoTable); //• ONLY ADD FILE TO LIST IF AUDIT PASSED if ((datFiles[count].PassedSelfCheck == true) && (datFiles[count].PassedAuditFileCheck == true)) fileList.Add(datFiles[count]); count++; } } } else { foreach (String fileLoc in filePaths) { datFiles[count] = new ClassDataFile(filePaths[count]); infoTable.AddNewRow(datFiles[count], ref infoTable); string message = string.Empty; message = ClassAuditing.SelfCheck(datFiles[count]); infoTable.UpdateRow(datFiles[count], "Self_Check_Result", message, ref infoTable); //• ONLY ADD FILE TO LIST IF AUDIT PASSED if (datFiles[count].PassedSelfCheck == true) fileList.Add(datFiles[count]); count++; } } return fileList; }
//This class sould contain the static methods for the two types of Auditing, als use static properties for the messages. public static DataTable CheckForInCompleteAudits(string connectionString, ClassAuditEntriesDataTable entriesTable, ref ClassImportInfoDataTable infoTable) { DataTable _resultTable = new DataTable(); _resultTable = ClassSQLAccess.SelectInCompletesAudits(connectionString, entriesTable); if (_resultTable.Rows.Count >= 1) UpdateInCompleteAudits(_resultTable, entriesTable, ref infoTable, connectionString); return _resultTable; }
//Private Methods //Public Methods private static void AddNewEntry(string line, ref ClassAuditEntriesDataTable entriesTable) { DataRow newEntry = entriesTable.entriesTable.NewRow(); newEntry["Billing_Month"] = line.Substring(0, 4); newEntry["Date"] = line.Substring(4, 8); newEntry["FileName"] = line.Substring(12, 8); newEntry["CDR_Count"] = line.Substring(20, 12); newEntry["Combined_Usage"] = line.Substring(32, line.Length - 32); entriesTable.entriesTable.Rows.Add(newEntry); entriesTable.entriesTable.AcceptChanges(); }
public static ClassAuditEntriesDataTable FillEntriesTable(Classes.ClassAuditFile auditFile) { ClassAuditEntriesDataTable result = new ClassAuditEntriesDataTable(); using (StreamReader sr = new StreamReader(auditFile.location)) { String line; while ((line = sr.ReadLine()) != null) { AddNewEntry(line, ref result); } sr.Close(); } return result; }
public static void UpdateInCompleteAudits(DataTable table, ClassAuditEntriesDataTable entriesTable, ref ClassImportInfoDataTable infoTable, string connectionString) { string message; foreach (DataRow dataRow in table.Rows) { ClassDataFile datFile = new ClassDataFile(dataRow); infoTable.AddNewRow(datFile, ref infoTable); message = ClassGatherInfo.VerifyFileIntact(datFile, entriesTable); message = AuditFileCheck(datFile, entriesTable); infoTable.UpdateRow(datFile, "AuditFile_Check_Result", message, ref infoTable); //• ONLY UPDATE THE ENTRY IF AUDIT PASSED if (datFile.PassedAuditFileCheck) ClassSQLAccess.UpdateIncompleteAudit(datFile, connectionString); } }
public static string AuditFileCheck(ClassDataFile datFile, ClassAuditEntriesDataTable auditEntries) { string message = "Not successful. No Audit entry found for this file"; foreach (DataRow dr in auditEntries.entriesTable.Rows) { if (dr["FileName"].ToString() == datFile.FileName.Substring(0, 8)) { if (Convert.ToInt16(dr["CDR_Count"]) == datFile.AmountOfLines) { message = "AuditFile Check Successful"; datFile.PassedAuditFileCheck = true; datFile.AuditFileEntryAmount = Convert.ToInt16(dr["CDR_Count"]); break; } else { message = "AuditFile Check Not Successful. File is not complete:CDR MISMATCH"; datFile.PassedAuditFileCheck = false; break; } } } return message; }