Ejemplo n.º 1
0
        /// <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);
        }