/// <summary> /// check for Field format Error in passed cell /// </summary> /// <param name="cell">COBieCell</param> /// <param name="sheetName">Sheet name</param> /// <param name="row">Row index</param> /// <param name="col">Column index</param> /// <param name="initialRowHash">Initial row hash value</param> /// <returns>COBieError or null</returns> public COBieError GetCOBieFieldFormatError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash) { COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row); int maxLength = cell.COBieColumn.ColumnLength; COBieAllowedType allowedType = cell.COBieColumn.AllowedType; if ((state == COBieAttributeState.Required_IfSpecified) || (state == COBieAttributeState.Required_System) || (state == COBieAttributeState.Required_System_IfSpecified) ) //if a required value but marked as n/a then do not class as error { if (cell.CellValue == Constants.DEFAULT_STRING) { return(null); } } //check cell.COBieColumn.AllowedType for format errors switch (allowedType) { case COBieAllowedType.AlphaNumeric: if (!cell.IsAlphaNumeric()) { err.ErrorDescription = ErrorDescription.AlphaNumeric_Value_Expected; err.ErrorType = COBieError.ErrorTypes.AlphaNumeric_Value_Expected; } break; case COBieAllowedType.Email: if (!cell.IsEmailAddress()) { err.ErrorDescription = ErrorDescription.ISODate_Value_Expected; err.ErrorType = COBieError.ErrorTypes.ISODate_Value_Expected; } break; case COBieAllowedType.ISODate: case COBieAllowedType.ISODateTime: if (!cell.IsDateTime()) { err.ErrorDescription = ErrorDescription.ISODate_Value_Expected; err.ErrorType = COBieError.ErrorTypes.ISODate_Value_Expected; } break; case COBieAllowedType.Numeric: if (!cell.IsNumeric()) { err.ErrorDescription = ErrorDescription.Numeric_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Numeric_Value_Expected; } break; case COBieAllowedType.AnyType: case COBieAllowedType.Text: if (!cell.IsText()) { err.ErrorDescription = ErrorDescription.Text_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Text_Value_Expected; } break; default: break; } if (err.ErrorType != COBieError.ErrorTypes.None) { err.FieldValue = cell.CellValue; if (err.ErrorLevel == COBieError.ErrorLevels.None) //if set above, just in case we do set above { err.ErrorLevel = errorLevel; } return(err); } return(null); }
/// <summary> /// Check for Field format length /// </summary> /// <param name="cell">COBieCell</param> /// <param name="sheetName">Sheet name</param> /// <param name="row">Row index</param> /// <param name="col">Column index</param> /// <param name="initialRowHash">Initial row hash value</param> /// <returns>COBieError or null</returns> public COBieError GetCOBieFieldOutOfBoundsError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash) { COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row); int maxLength = cell.COBieColumn.ColumnLength; if (cell.CellValue.Length > maxLength) { err.ErrorDescription = String.Format(ErrorDescription.Value_Out_of_Bounds, maxLength); err.ErrorType = COBieError.ErrorTypes.Value_Out_of_Bounds; err.ErrorLevel = errorLevel; // GetErroLevel(cell.COBieColumn.AttributeState); err.FieldValue = cell.CellValue; return(err); } return(null); }
/// <summary> /// Validating of the column COBieAttributeState attributes for null or n/a values /// </summary> /// <param name="cell">COBieCell</param> /// <param name="sheetName">Sheet name</param> /// <param name="row">Row index</param> /// <param name="col">Column index</param> /// <param name="initialRowHash">Initial row hash value</param> /// <returns>COBieError or null</returns> private COBieError GetCobieFieldNullError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash) { COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row); if ((string.IsNullOrEmpty(cell.CellValue)) || (cell.CellValue == Constants.DEFAULT_STRING) ) { switch (state) { case COBieAttributeState.Required_PrimaryKey: case COBieAttributeState.Required_CompoundKeyPart: err.ErrorDescription = ErrorDescription.PrimaryKey_Violation; err.ErrorType = COBieError.ErrorTypes.PrimaryKey_Violation; err.ErrorLevel = errorLevel; break; case COBieAttributeState.Required_Information: case COBieAttributeState.Required_System: switch (cell.COBieColumn.AllowedType) { case COBieAllowedType.AlphaNumeric: err.ErrorDescription = ErrorDescription.AlphaNumeric_Value_Expected; err.ErrorType = COBieError.ErrorTypes.AlphaNumeric_Value_Expected; break; case COBieAllowedType.Email: err.ErrorDescription = ErrorDescription.Email_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Email_Value_Expected; break; case COBieAllowedType.ISODateTime: case COBieAllowedType.ISODate: err.ErrorDescription = ErrorDescription.ISODate_Value_Expected; err.ErrorType = COBieError.ErrorTypes.ISODate_Value_Expected; break; case COBieAllowedType.Numeric: err.ErrorDescription = ErrorDescription.Numeric_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Numeric_Value_Expected; break; case COBieAllowedType.AnyType: case COBieAllowedType.Text: err.ErrorDescription = ErrorDescription.Text_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Text_Value_Expected; break; default: err.ErrorDescription = ErrorDescription.Text_Value_Expected; err.ErrorType = COBieError.ErrorTypes.Text_Value_Expected; break; } err.ErrorLevel = errorLevel; //err.ErrorLevel = COBieError.ErrorLevels.Warning; //set as a warning break; case COBieAttributeState.Required_Reference_PrimaryKey: case COBieAttributeState.Required_Reference_PickList: case COBieAttributeState.Required_Reference_ForeignKey: err.ErrorDescription = ErrorDescription.Null_ForeignKey_Value; err.ErrorType = COBieError.ErrorTypes.Null_ForeignKey_Value; err.ErrorLevel = errorLevel; break; case COBieAttributeState.Required_IfSpecified: case COBieAttributeState.Required_System_IfSpecified: case COBieAttributeState.Required_PrimaryKey_IfSpecified: if (cell.CellValue == Constants.DEFAULT_STRING) { return(null); //if a required value but not required in validation template then do not class as error } break; default: return(null); } if (err.ErrorType != COBieError.ErrorTypes.None) { err.FieldValue = cell.CellValue; return(err); } } return(null); }