/// <summary> /// Get required colour for the cell /// </summary> /// <param name="state">COBieAttributeState</param> /// <returns>string</returns> private string GetCellColour(COBieAttributeState state) { switch (state) { case COBieAttributeState.Required_PrimaryKey: case COBieAttributeState.Required_CompoundKeyPart: case COBieAttributeState.Required_Information: return("Yellow"); case COBieAttributeState.Required_Multi_PrimaryKey: case COBieAttributeState.Required_Reference_PrimaryKey: case COBieAttributeState.Required_Reference_ForeignKey: case COBieAttributeState.Required_Reference_PickList: return("Puce"); case COBieAttributeState.Required_PrimaryKey_IfSpecified: case COBieAttributeState.Required_System: case COBieAttributeState.Required_System_IfSpecified: return("Purple"); case COBieAttributeState.Required_IfSpecified: return("Green"); default: return("White"); } }
/// <summary> /// Validate the row columns against the attributes set for each column /// </summary> public void ValidateFields(ICOBieSheetValidationTemplate SheetValidator) { int r = 0; foreach (T row in Rows) { r++; for (int col = 0; col < row.RowCount; col++) { var cell = row[col]; COBieAttributeState state = cell.COBieColumn.AttributeState; var errorLevel = COBieError.ErrorLevels.Warning; if (SheetValidator != null && SheetValidator.IsRequired.ContainsKey(col) && SheetValidator.IsRequired[col]) { // Override required state based on validation template if ((SheetValidator.IsRequired.ContainsKey(col) && SheetValidator.IsRequired[col])) { errorLevel = COBieError.ErrorLevels.Error; switch (state) { case COBieAttributeState.Required_IfSpecified: state = COBieAttributeState.Required_Information; break; case COBieAttributeState.Required_System_IfSpecified: state = COBieAttributeState.Required_System; break; case COBieAttributeState.Required_PrimaryKey_IfSpecified: state = COBieAttributeState.Required_PrimaryKey; break; default: break; } } } COBieError errNull = GetCobieFieldNullError(row[col], state, errorLevel, SheetName, r, col, row.InitialRowHashValue); if (errNull != null) { _errors.Add(errNull); } else //passed null check so check format { errNull = GetCOBieFieldOutOfBoundsError(row[col], state, errorLevel, SheetName, r, col, row.InitialRowHashValue); if (errNull != null) { _errors.Add(errNull); } errNull = GetCOBieFieldFormatError(row[col], state, errorLevel, SheetName, r, col, row.InitialRowHashValue); if (errNull != null) { _errors.Add(errNull); } } } } }
public COBieAttributes(int order, COBieKeyType keyType, string referenceColumnName, COBieAttributeState state, string columnName, int maxLength, COBieAllowedType allowedType, COBieCardinality cardinality = COBieCardinality.OneToMany) { _state = state; _maxLength = maxLength; _allowedType = allowedType; _order = order; _columnName = columnName; _keyType = keyType; _referenceColumnName = referenceColumnName; _cardinality = cardinality; }
public COBieAttributes(int order, COBieKeyType keyType, string referenceColumnName, COBieAttributeState state, string columnName, int maxLength, COBieAllowedType allowedType, COBieCardinality cardinality = COBieCardinality.OneToMany) { _state = state; _maxLength = maxLength; _allowedType = allowedType; _order = order; _columnName = columnName; _keyType = keyType; _referenceColumnName = referenceColumnName; _cardinality = cardinality; }
/// <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> /// Get ErrorLevel base on the COBieAttributeState Attribute /// </summary> /// <param name="state">COBieAttributeState</param> /// <returns>COBieError.ErrorLevels enumeration</returns> public COBieError.ErrorLevels GetErrorLevel(COBieAttributeState state) { switch (state) { case COBieAttributeState.Required_PrimaryKey: case COBieAttributeState.Required_CompoundKeyPart: case COBieAttributeState.Required_Reference_ForeignKey: case COBieAttributeState.Required_Reference_PrimaryKey: case COBieAttributeState.Required_Reference_PickList: case COBieAttributeState.Required_Information: return(COBieError.ErrorLevels.Error); case COBieAttributeState.Required_System: case COBieAttributeState.Required_IfSpecified: case COBieAttributeState.Required_System_IfSpecified: case COBieAttributeState.Required_PrimaryKey_IfSpecified: return(COBieError.ErrorLevels.Warning); default: break; } return(COBieError.ErrorLevels.None); }
/// <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> /// 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); }
/// <summary> /// Get required colour for the cell /// </summary> /// <param name="state">COBieAttributeState</param> /// <returns>string</returns> private string GetCellColour(COBieAttributeState state) { switch (state) { case COBieAttributeState.Required_PrimaryKey: case COBieAttributeState.Required_CompoundKeyPart: case COBieAttributeState.Required_Information: return "Yellow"; case COBieAttributeState.Required_Multi_PrimaryKey: case COBieAttributeState.Required_Reference_PrimaryKey: case COBieAttributeState.Required_Reference_ForeignKey: case COBieAttributeState.Required_Reference_PickList: return "Puce"; case COBieAttributeState.Required_PrimaryKey_IfSpecified: case COBieAttributeState.Required_System: case COBieAttributeState.Required_System_IfSpecified: return "Purple"; case COBieAttributeState.Required_IfSpecified: return "Green"; default: return "White"; } }
public COBieAttributes(COBieAttributeState state) { _state = state; }
public COBieAttributes(COBieAttributeState state) { _state = state; }