} //Holds latest end valid public Link(DataTable[] dataTables, int row) { //Get the stn and wislr id from the link_link (first) table stnId = dataTables[0].Rows[row].ItemArray[0].ToString(); wislrId = dataTables[0].Rows[row].ItemArray[3].ToString(); //Find stn link in stn date table List <DataRow> stnRows = dataTables[1].Rows.Cast <DataRow>().ToList(); DataRow stnDateRow = stnRows.Find(index => index.ItemArray[0].ToString() == stnId); //Find wislr link in wislr date table List <DataRow> wislrRows = dataTables[2].Rows.Cast <DataRow>().ToList(); DataRow wislrDateRow = wislrRows.Find(index => index.ItemArray[0].ToString() == wislrId); //Compare wislr and stn dates then get larger date via datetools usedStartDate = DateTools.getLaterDate(stnDateRow.ItemArray[1].ToString(), wislrDateRow.ItemArray[1].ToString()); usedEndDate = DateTools.getLaterDate(stnDateRow.ItemArray[2].ToString(), wislrDateRow.ItemArray[2].ToString()); ////Find stn link in stn date table //DataRow stnDateRow = stnDates.Find(index => index.ItemArray[0].ToString() == stnId); ////Find wislr link in wislr date table //DataRow wislrDateRow = wislrDates.Find(index => index.ItemArray[0].ToString() == wislrId); ////Compare wislr and stn dates then get larger date via datetools //usedStartDate = DateTools.getLaterDate(stnDateRow.ItemArray[1].ToString(), wislrDateRow.ItemArray[1].ToString()); //usedEndDate = DateTools.getLaterDate(stnDateRow.ItemArray[2].ToString(), wislrDateRow.ItemArray[2].ToString()); }
//A method that returns an array that will later be written to a text file each element is a line of a text file private string[] getBadDates() { DataTable table; outTable = new DataTable(); List <string> errorTypeCount = new List <string>(); List <string> writeContents = new List <string>(); string[] columNames = { "STNID", "WISLRID", "END_VALID", "START_VALID" }; DataBaseTools dbTools = new DataBaseTools(); dbTools.progressUpdated += dbTools_ProgressUpdated; dbTools.didReceiveFatalError += dbTools_didReceiveFatalError; table = dbTools.getDataTable(filePath, tableName); string stnId; string wislrId; string recordCreated; string recordHistoric; string startValid; string endValid; int localErrorCount; //Local errorCount keeps up with errors per row while errorCount is total erros over the whole file the error count is displayed once date check is done int[] errors = { 0, 0, 0, 0 }; foreach (string name in columNames) { outTable.Columns.Add(name); } for (int i = 0; i < table.Rows.Count; i++) { stnId = table.Rows[i].ItemArray[0].ToString(); wislrId = table.Rows[i].ItemArray[3].ToString(); recordCreated = table.Rows[i].ItemArray[12].ToString(); recordHistoric = table.Rows[i].ItemArray[13].ToString(); startValid = table.Rows[i].ItemArray[14].ToString(); endValid = table.Rows[i].ItemArray[15].ToString(); localErrorCount = 0; writeContents.Add("STNID: " + stnId + " WISLRID: " + wislrId + " {"); //The rows aren't always the same in our datatables and the datatable in access so we give them the stnid and wislrid if (string.IsNullOrEmpty(recordHistoric) && !string.IsNullOrEmpty(endValid)) //No end valid date for record historic { writeContents.Add(Environment.NewLine + " There is no Record Historic for End Valid (" + endValid + ")" + Environment.NewLine); errors[0]++; localErrorCount++; } if (DateTools.getLaterDate(endValid, startValid) == startValid) { writeContents.Add(Environment.NewLine + " Start Valid is more recent than End Valid (" + endValid + ")" + Environment.NewLine); //End valid is earlier than the start valid errors[1]++; localErrorCount++; } if (DateTools.getLaterDate(recordHistoric, startValid) == startValid) //Start valid is more recent than record historic { writeContents.Add(Environment.NewLine + " Start Valid is more recent than Record Historic" + Environment.NewLine); errors[2]++; localErrorCount++; } if (DateTools.getLaterDate(recordCreated, startValid) == startValid) //Start valid is more recent than record created { writeContents.Add(Environment.NewLine + " Start Valid is more recent than Record Created" + Environment.NewLine); errors[3]++; localErrorCount++; } if (localErrorCount == 0) //If we don't have errors here remove the opening line and brace { writeContents.RemoveAt(writeContents.Count - 1); } else //If we have local errors close it off with a brace and a new line { errorCount += localErrorCount; //Keep track of all errors writeContents.Add("}\n"); DataRow currentRow = outTable.NewRow(); currentRow["STNID"] = stnId; currentRow["WISLRID"] = wislrId; currentRow["END_VALID"] = endValid; currentRow["START_VALID"] = startValid; outTable.Rows.Add(currentRow); } } errorTypeCount.Add("Error types:\nThere is no Record Historic for End Valid: " + errors[0] + "\n"); errorTypeCount.Add("Start Valid is more recent than End Valid: " + errors[1] + "\n"); errorTypeCount.Add("Start Valid is more recent than Record Historic: " + errors[2] + "\n"); errorTypeCount.Add("Start Valid is more recent than Record Created: " + errors[3] + "\n" + Environment.NewLine); return(errorTypeCount.ToArray().Concat(writeContents.ToArray()).ToArray()); //Return array of lines }