Ejemplo n.º 1
0
        public static CheckResult Check(this CellData cell)
        {
            CheckResult result = new CheckResult(true);

            if (cell.rowIndex < 2)// id type
            {
                if (string.IsNullOrEmpty(cell.value))
                {
                    result.Set(false, string.Format(" 数据不能为空!==> {0}行,{1}({2})列 "
                                                    , cell.rowIndex + 1, cell.columnIndex + 1, IntToNumberSystem26(cell.columnIndex + 1)));
                }
            }
            else if (cell.rowIndex >= 3)// data
            {
                if (string.IsNullOrEmpty(cell.value) &&
                    cell.type != "string"    // can be none type
                    )
                {
                    result.Set(false, string.Format(" 数据不能为空!==> {0}行,{1}({2})列 "
                                                    , cell.rowIndex + 1, cell.columnIndex + 1, IntToNumberSystem26(cell.columnIndex + 1)));
                }
                else if (!CheckDataType(cell.value, cell.type))
                {
                    result.Set(false, string.Format(" 数据类型不匹配!==> {0}行,{1}({2})列 , 数据类型:{3}, 数据:{4}"
                                                    , cell.rowIndex + 1, cell.columnIndex + 1, IntToNumberSystem26(cell.columnIndex + 1)
                                                    , cell.type, cell.value));
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static CheckResult Check(this SheetData sheet)
        {
            Console.WriteLine("├─" + sheet.name);

            CheckResult result = new CheckResult(true);

            int cellCount = sheet.rows[0].cells.Count;

            for (int i = 0; i < sheet.rows.Count; i++)
            {
                var row = sheet.rows[i];

                if (row.cells.Count != cellCount)
                {
                    result.Set(false, string.Format("第{0}行长度({1})不正确,正确长度{2}"
                                                    , i + 1, row.cells.Count, cellCount));
                    return(result);
                }
            }

            if (!result.isSucceed)
            {
                return(result);
            }

            foreach (var row in sheet.rows)
            {
                result = row.Check();
                if (!result.isSucceed)
                {
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static CheckResult Check(this TableData table)
        {
            Console.WriteLine(table.name);

            CheckResult result = new CheckResult(true);

            //raw_name, raw_type
            List <CellData> rawNames = table.sheets[0].rows[0].cells;
            List <CellData> rawTypes = table.sheets[0].rows[1].cells;

            //check repeated
            foreach (var rawName in rawNames)
            {
                var group = rawNames.FindAll(a => a.value == rawName.value);
                if (group.Count >= 2)
                {
                    result.Set(false, string.Format("Sheet({0}) 存在重复的属性名(第一行是属性名)" +
                                                    ", 属性名{1}, {2}行,{3}({4})列 与 {5}行,{6}({7})列 "
                                                    , table.sheets[0].name, rawName.value
                                                    , group[0].rowIndex + 1, group[0].columnIndex + 1, CellExtend.IntToNumberSystem26(group[0].columnIndex + 1)
                                                    , group[1].rowIndex + 1, group[1].columnIndex + 1, CellExtend.IntToNumberSystem26(group[1].columnIndex + 1)));
                    return(result);
                }
            }

            for (int i = 1; i < table.sheets.Count; i++)
            {
                for (int j = 0; j < rawNames.Count; j++)
                {
                    var rawNameCell = rawNames[j];
                    var nameCell    = table.sheets[i].rows[0].cells[j];
                    if (rawNameCell.value != nameCell.value)
                    {
                        result.Set(false, string.Format("Sheet({0}) 存在不一致的属性名(第一行是属性名)" +
                                                        ", 属性名{1}, 原始属性名{2}, {3}行,{4}({5})列 "
                                                        , table.sheets[i].name, nameCell.value, rawNameCell.value
                                                        , nameCell.rowIndex + 1, nameCell.columnIndex + 1, CellExtend.IntToNumberSystem26(nameCell.columnIndex + 1)));
                        return(result);
                    }


                    var rawTypeCell = rawTypes[j];
                    var typeCell    = table.sheets[i].rows[1].cells[j];
                    if (rawTypeCell.value != typeCell.value)
                    {
                        result.Set(false, string.Format("Sheet({0}) 存在不一致的类型(第二行是类型)" +
                                                        ", 类型{1}, 原始类型{2}, {3}行,{4}({5})列 "
                                                        , table.sheets[i].name, typeCell.value, rawTypeCell.value
                                                        , typeCell.rowIndex + 1, typeCell.columnIndex + 1, CellExtend.IntToNumberSystem26(typeCell.columnIndex + 1)));
                        return(result);
                    }
                }
            }

            HashSet <string> ids = new HashSet <string>();

            foreach (var sheet in table.sheets)
            {
                int ignoreRow = 3;
                foreach (var row in sheet.rows)
                {
                    if (row.cells.Count < 0 || ignoreRow-- > 0)
                    {
                        continue;
                    }
                    string id = row.cells[0].value;
                    if (ids.Contains(id))
                    {
                        result.Set(false,
                                   string.Format("Sheet({0}) 存在重复的ID:{1}",
                                                 sheet.name, id));
                        return(result);
                    }
                    else
                    {
                        ids.Add(id);
                    }
                }
            }


            if (!result.isSucceed)
            {
                return(result);
            }

            foreach (var sheet in table.sheets)
            {
                result = sheet.Check();
                if (!result.isSucceed)
                {
                    break;
                }
            }
            Console.WriteLine();
            return(result);
        }