// ---------------------------------------------------------------------------------------- /// <!-- AddTwoValuesTo --> /// <summary> /// Adds two column values (and perhaps two columns if needed) to the table /// </summary> /// <param name="errorTable"></param> /// <param name="col1"></param> /// <param name="col2"></param> /// <param name="data"></param> /// <param name="value1"></param> /// <param name="value2"></param> /// <returns></returns> public static bool AddTwoValuesTo(DataTable errorTable, DataRow data , DataColumn col1, DataColumn col2, string value1, string value2, bool isRowInsertedIntoErrorTable, int level) { InfoAspect.Measuring("AddTwoValuesTo(7)"); col1.AllowDBNull = true; col2.AllowDBNull = true; if ((!errorTable.Columns.Contains(col1.ToString())) && (!errorTable.Columns.Contains(col2.ToString()))) { errorTable.Columns.Add(col1); errorTable.Columns.Add(col2); } if (isRowInsertedIntoErrorTable == false) { errorTable.ImportRow(data); isRowInsertedIntoErrorTable = true; } else { // isrowinserted = true; } foreach (DataRow dtRow in errorTable.Rows) { if (dtRow["FileLineNumber"].ToString() == data["FileLineNumber"].ToString()) { AddErrorCell(value1, level + 1); dtRow[col1.ToString()] = value1; dtRow[col2.ToString()] = value2; } } InfoAspect.Measured("AddTwoValuesTo(7)"); return(isRowInsertedIntoErrorTable); }
// ---------------------------------------------------------------------------------------- /// <!-- AddTwoValuesTo --> /// <summary> /// Adds two values and possibly two columns to an error table /// </summary> /// <param name="errorTable"></param> /// <param name="data"></param> /// <param name="column1"></param> /// <param name="column2"></param> /// <param name="value1"></param> /// <param name="value2"></param> /// <returns></returns> public static bool AddTwoValuesTo(DataTable errorTable, DataRow data , string column1, string column2, string value1, string value2, bool isRowInsertedIntoErrorTable, int level) { InfoAspect.Measuring("AddTwoValuesTo"); DataColumn col1 = new DataColumn(column1, typeof(string)); DataColumn col2 = new DataColumn(column2, typeof(string)); isRowInsertedIntoErrorTable = AddTwoValuesTo(errorTable, data, col1, col2, value1, value2, isRowInsertedIntoErrorTable, level + 1); InfoAspect.Measured("AddTwoValuesTo"); return(isRowInsertedIntoErrorTable); }
// ---------------------------------------------------------------------------------------- /// <!-- InitializeTable --> /// <summary> /// Initializes the error log table /// </summary> /// <param name="importData"></param> /// <returns></returns> public static DataTable InitializeStatusErrorStorage(DataTable importData, string tableName, int level) { InfoAspect.Measuring("InitializeStatusErrorStorage"); DataTable statusErrorLog = importData.Clone(); statusErrorLog.TableName = "ErrorLog"; statusErrorLog.Columns.Add("Status_Error_Code", typeof(string)); statusErrorLog.Columns.Add("Error_Message", typeof(string)); statusErrorLog.TableName = "StatusErrorLog"; importData.TableName = tableName; importData.Columns.Add(new DataColumn("IsValid", typeof(bool))); importData.Columns.Add(new DataColumn("IsUpdate", typeof(bool))); InfoAspect.Measured("InitializeStatusErrorStorage"); return(statusErrorLog); }
// ---------------------------------------------------------------------------------------- /// <!-- CheckForError --> /// <summary> /// Checks for an error in a numeric code field and returns an error code /// if there is an error detected, otherwise returns blank /// </summary> /// <param name="required"></param> /// <param name="field"></param> /// <param name="fieldName"></param> /// <param name="options"></param> /// <param name="columnErrorCode"></param> /// <param name="nullErrorCode">null or blank but required</param> /// <param name="typeErrorCode">not a number</param> /// <param name="optionErrorCode">not in list</param> /// <returns></returns> public static string CheckForError(int required, DataRow field, string fieldName, Dictionary <int, int> options , string columnErrorCode, string nullErrorCode, string typeErrorCode, string optionErrorCode) { InfoAspect.Measuring("CheckForError(8a)"); string errorCode = string.Empty; if (field.Table.Columns.Contains(fieldName)) // Check column name existence { SqlInt32 num = InData.GetSqlInt32(field, fieldName); if (num.IsNull) // Check numeric type validity { string strScore = field[fieldName].ToString(); if (string.IsNullOrEmpty(strScore)) { if (required >= 2) { errorCode = nullErrorCode; } // Check required data existence } else { errorCode = typeErrorCode; } } else { if (!options.ContainsKey((int)num)) { errorCode = optionErrorCode; } } // Check data range validity } else { errorCode = columnErrorCode; } InfoAspect.Measured("CheckForError(8a)"); return(errorCode); }
// ---------------------------------------------------------------------------------------- /// <!-- CheckForError --> /// <summary> /// Checks for an error in a numeric value field and returns an error code /// if an error is found /// </summary> /// <param name="required"></param> /// <param name="field"></param> /// <param name="fieldName"></param> /// <param name="lo"></param> /// <param name="hi"></param> /// <param name="columnErrorCode"></param> /// <param name="nullErrorCode">null or blank but required</param> /// <param name="typeErrorCode">not a number</param> /// <param name="rangeErrorCode">out of range</param> /// <returns></returns> public static string CheckForError(int required, DataRow field, string fieldName, long lo, long hi , string columnErrorCode, string nullErrorCode, string typeErrorCode, string rangeErrorCode) { InfoAspect.Measuring("CheckForError(9)"); string errorCode = string.Empty; if (field.Table.Columns.Contains(fieldName)) // Check column name existence { SqlInt64 num = InData.GetSqlInt64(field, fieldName); if (num.IsNull) // Check numeric type validity { string strScore = field[fieldName].ToString(); if (string.IsNullOrEmpty(strScore)) { if (required >= 2) { errorCode = nullErrorCode; } // Check required data existence } else { errorCode = typeErrorCode; } } else { if (num < lo || num > hi) { errorCode = rangeErrorCode; } } // Check data range validity } else { errorCode = columnErrorCode; } InfoAspect.Measured("CheckForError(9)"); return(errorCode); }
// ---------------------------------------------------------------------------------------- /// <!-- CheckForError --> /// <summary> /// Check in database /// </summary> /// <param name="required"></param> /// <param name="field"></param> /// <param name="fieldName"></param> /// <param name="dataTable"></param> /// <param name="column"></param> /// <param name="columnErrorCode"></param> /// <param name="nullErrorCode"></param> /// <param name="formatErrorCode"></param> /// <param name="optionErrorCode"></param> /// <returns></returns> public static string CheckForError(int required, DataRow field, string fieldName, DataTable dataTable, string column , string columnErrorCode, string nullErrorCode, string formatErrorCode, string optionErrorCode) { InfoAspect.Measuring("CheckForError(10)"); string errorCode = string.Empty; if (field.Table.Columns.Contains(fieldName)) // Check column name existence { SqlString code = InData.GetSqlString(field, fieldName); if (code.IsNull || string.IsNullOrEmpty(code.ToString().Trim())) { if (required >= 2) { errorCode = nullErrorCode; } // Check required data existence } else { if (Regex.IsMatch(code.ToString(), "^'?[V0-9][0-9][0-9][.]?[0-9]*$", RegexOptions.IgnoreCase)) // Check data format validity { if (!InData.ContainsValue(dataTable, column, code)) { errorCode = optionErrorCode; } } else { errorCode = formatErrorCode; } } } else { errorCode = columnErrorCode; } InfoAspect.Measured("CheckForError(10)"); return(errorCode); }
// ---------------------------------------------------------------------------------------- /// <!-- CheckForError --> /// <summary> /// Checks for error on a string field and returns an error code /// if there is an error detected, otherwise returns blank /// </summary> /// <param name="required"></param> /// <param name="field"></param> /// <param name="fieldName"></param> /// <param name="pattern"></param> /// <param name="columnErrorCode"></param> /// <param name="nullErrorCode">null or blank but required</param> /// <param name="typeErrorCode">not matching pattern</param> /// <param name="optionErrorCode">unused</param> /// <returns></returns> public static string CheckForError(int required, DataRow field, string fieldName, string pattern , string columnErrorCode, string nullErrorCode, string typeErrorCode, string optionErrorCode) { InfoAspect.Measuring("CheckForError(8)"); string errorCode = string.Empty; if (field.Table.Columns.Contains(fieldName)) // Check column name existence { string str = field[fieldName].ToString(); // ---------------------------------------------------------------------- // Check for data existence and format validity // ---------------------------------------------------------------------- if (!string.IsNullOrEmpty(str.Trim())) { if (!Regex.IsMatch(str, pattern)) { errorCode = typeErrorCode; } } else { if (required >= 2) { errorCode = nullErrorCode; } } } else { errorCode = columnErrorCode; } InfoAspect.Measured("CheckForError(8)"); return(errorCode); }
// ---------------------------------------------------------------------------------------- /// <!-- RecordStatusError --> /// <summary> /// Adds an error row to the status-error log /// </summary> /// <param name="errorCode"></param> /// <param name="importRow">The row to be imported</param> /// <param name="statusErrorLog"></param> public static void RecordStatusError(string errorCode, DataRow importRow, DataTable statusErrorLog) { InfoAspect.Measuring("RecordStatusError"); int row = statusErrorLog.Rows.Count; if (Regex.IsMatch(errorCode, "03")) { Pause(); } statusErrorLog.ImportRow(importRow); statusErrorLog.Rows[row]["Status_Error_Code"] = errorCode; if (StatusError.ErrorCodeList.ContainsKey(errorCode)) { statusErrorLog.Rows[row]["Error_Message"] = StatusError.ErrorCodeList[errorCode]; } else { Pause(); } InfoAspect.Measured("RecordStatusError"); }