Exemple #1
0
        private static bool VerifyField(WDBField field)
        {
            WDBFieldVerify fieldVerify = fieldVerifyDic[field];

            List <string> errors = (List <string>)context.Get(WDBContextIENames.CONTEXT_ERRORS_NAME);

            if (string.IsNullOrEmpty(field.Name))
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_FIELD_NAME_EMPTY_ERR, field.Col));
                return(false);
            }
            if (!Regex.IsMatch(field.Name, WDBVerifyConst.VERIFY_FIELD_NAME_REGEX))
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_FIELD_NAME_REGEX_ERR, field.Col));
                return(false);
            }
            if (fieldVerify.FieldType == WDBFieldType.None)
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_FIELD_TYPE_NONE_ERR, field.Col, field.Name));
                return(false);
            }
            bool result = true;

            if (fieldVerify.ValueValidations != null && fieldVerify.ValueValidations.Length > 0)
            {
                foreach (var validation in fieldVerify.ValueValidations)
                {
                    if (validation.GetType() == typeof(ErrorValidation))
                    {
                        errors.Add(string.Format(WDBVerifyConst.VERIFY_FIELD_VALIDATIONS_ERR, field.Col, field.Name, field.ValidationRule));
                        result = false;
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        private static bool VerifySheet(WDBSheet sheet)
        {
            List <string> errors = (List <string>)context.Get(WDBContextIENames.CONTEXT_ERRORS_NAME);

            if (string.IsNullOrEmpty(sheet.Name))
            {
                errors.Add(WDBVerifyConst.VERIFY_SHEET_NAME_EMPTY_ERR);
                return(false);
            }
            if (!Regex.IsMatch(sheet.Name, WDBVerifyConst.VERIFY_SHEET_NAME_REGEX))
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_SHEET_NAME_REGEX_ERR, sheet.Name));
                return(false);
            }

            if (sheet.FieldCount == 0)
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_SHEET_NO_FIELD_ERR, sheet.Name));
                return(false);
            }
            if (sheet.LineCount == 0)
            {
                errors.Add(string.Format(WDBVerifyConst.VERIFY_SHEET_NO_ROW_ERR, sheet.Name));
                return(false);
            }
            bool result = true;

            for (int i = 0; i < sheet.FieldCount; ++i)
            {
                WDBField       field       = sheet.GetFieldAtIndex(i);
                WDBFieldVerify fieldVerify = new WDBFieldVerify()
                {
                    FieldType        = field.FieldType,
                    FieldPlatform    = field.FieldPlatform,
                    ValueValidations = field.ValueValidations,
                };
                fieldVerifyDic.Add(field, fieldVerify);
                if (!VerifyField(field))
                {
                    result = false;
                }
            }
            if (!result)
            {
                return(false);
            }

            context.Add(WDBContextIENames.CONTEXT_SHEET_NAME, sheet);
            for (int i = 0; i < sheet.LineCount; ++i)
            {
                WDBLine line = sheet.GetLineAtIndex(i);
                if (line.CellCount != sheet.FieldCount)
                {
                    result = false;
                    errors.Add(string.Format(WDBVerifyConst.VERIFY_SHEET_FIELD_ROW_ERR, sheet.FieldCount, line.Row));
                }
            }
            if (result)
            {
                for (int i = 0; i < sheet.FieldCount; ++i)
                {
                    WDBField       field       = sheet.GetFieldAtIndex(i);
                    WDBFieldVerify fieldVerify = fieldVerifyDic[field];
                    context.Add(WDBContextIENames.CONTEXT_FIELD_NAME, field);
                    context.Add(WDBContextIENames.CONTEXT_FIELD_VERIFY_NAME, fieldVerify);

                    for (int j = 0; j < sheet.LineCount; ++j)
                    {
                        WDBLine line = sheet.GetLineAtIndex(j);
                        WDBCell cell = line.GetCellByIndex(i);
                        context.Add(WDBContextIENames.CONTEXT_LINE_NAME, line);
                        if (cell.Col != field.Col)
                        {
                            result = false;
                            errors.Add(string.Format(WDBVerifyConst.VERIFY_CELL_COL_NOTSAME_ERR, cell.Row, cell.Col));
                        }
                        else if (fieldVerify.ValueValidations != null && fieldVerify.ValueValidations.Length > 0)
                        {
                            context.Add(WDBContextIENames.CONTEXT_CELL_NAME, cell);

                            foreach (var cellValidation in fieldVerify.ValueValidations)
                            {
                                context.InjectTo(cellValidation);
                                if (!cellValidation.Verify())
                                {
                                    result = false;
                                }
                            }
                            context.Remove(WDBContextIENames.CONTEXT_CELL_NAME);
                        }
                        context.Remove(WDBContextIENames.CONTEXT_LINE_NAME);
                    }
                    context.Remove(WDBContextIENames.CONTEXT_FIELD_NAME);
                    context.Remove(WDBContextIENames.CONTEXT_FIELD_VERIFY_NAME);
                }
            }
            context.Remove(WDBContextIENames.CONTEXT_SHEET_NAME);

            return(result);
        }