Пример #1
0
        public static ConvertExceptionInfo Error(string info)
        {
            ConvertExceptionInfo exceptionInfo = new ConvertExceptionInfo();

            exceptionInfo.Abend    = true;
            exceptionInfo.Info     = info;
            exceptionInfo.InfoType = ExceptionInfoType.Error;
            return(exceptionInfo);
        }
Пример #2
0
        public static ConvertExceptionInfo Warn(string info)
        {
            ConvertExceptionInfo exceptionInfo = new ConvertExceptionInfo();

            exceptionInfo.Abend    = false;
            exceptionInfo.Info     = info;
            exceptionInfo.InfoType = ExceptionInfoType.Warn;
            return(exceptionInfo);
        }
Пример #3
0
 public static void Print(ConvertExceptionInfo info)
 {
     Console.ForegroundColor = GetColor(info.InfoType);
     WriteLine(info.Info, 0);
     Console.ForegroundColor = ConsoleColor.White;
     if (info.InfoType == ExceptionInfoType.Error)
     {
         KillApp(info.Info);
     }
 }
Пример #4
0
        public static ConvertExceptionInfo Create(bool abend, ExceptionInfoType infoType, string info = "")
        {
            ConvertExceptionInfo exceptionInfo = new ConvertExceptionInfo();

            exceptionInfo.Abend = abend;
            exceptionInfo.Info  = info;
            if (exceptionInfo.Abend)
            {
                exceptionInfo.InfoType = ExceptionInfoType.Error;
            }
            else
            {
                exceptionInfo.InfoType = infoType;
            }

            return(exceptionInfo);
        }
Пример #5
0
        public ConvertExceptionInfo Load(string filePath)
        {
            _filePath = filePath;

            if (string.IsNullOrEmpty(_filePath))
            {
                return(null);
            }

            if (_excelPackage != null)
            {
                _excelPackage.Dispose();
                _excelPackage = null;
                _sheetRef.Clear();
            }

            try
            {
                _excelPackage = new ExcelPackage(new FileStream(_filePath,
                                                                FileMode.Open,
                                                                FileAccess.Read,
                                                                FileShare.ReadWrite));

                for (int i = 0; i < _excelPackage.Workbook.Worksheets.Count; i++)
                {
                    var sheet = _excelPackage.Workbook.Worksheets[i];
                    if (sheet.Dimension != null)
                    {
                        _sheetRef.Add(sheet);
                    }
                }

                _sheetIndex = -1;
            }
            catch (System.Exception e)
            {
                return(ConvertExceptionInfo.Create(true, ExceptionInfoType.Error, e.ToString()));
            }

            return(null);
        }
Пример #6
0
        public ConvertExceptionInfo DetectionFourLine(string[] comments, string[] types, string[] clientFields)
        {
            if (comments.Length < 2 || types.Length < 2 || clientFields.Length < 2)
            {
                return(ConvertExceptionInfo.Warn(string.Format("{0}-({1}),格式不正确,忽略该分页!", _excelName, _sheetName)));
            }

            if (!IsType("TYPE", types))
            {
                return(ConvertExceptionInfo.Warn(ContentInfo("第二行第一列应为TYPE,忽略该分页! " + _defLength)));
            }

            if (!IsType("CLIENT", clientFields))
            {
                return(ConvertExceptionInfo.Warn(ContentInfo("第三行第一列应为CLIENT,忽略该分页!")));
            }


            //  客户端类型
            _sheetClientDefs.Clear();
            int defLength = 0;

            for (int i = 0; i < clientFields.Length; i++)
            {
                var field = clientFields[i];
                // var str = field == null ? "" : field.ToString();
                if (i == 0 || string.IsNullOrEmpty(field))
                {
                    continue;
                }


                string typeStr = string.Empty;
                if (i < types.Length)
                {
                    typeStr = types[i];
                }
                else
                {
                    SystemUtil.Abend(string.Format("{0}-({1})-({2},{3}), [{4}]字段,没有填写类型!",
                                                   _excelName,
                                                   _sheetName,
                                                   3,
                                                   i + 1,
                                                   field));
                }

                var valueType = ValueTypeUtil.String2ValueType(typeStr);
                if (valueType == ValueType.None)
                {
                    SystemUtil.Abend(string.Format("{0}-({1})-({2},{3}), 类型不存在! {4}",
                                                   _excelName,
                                                   _sheetName,
                                                   2,
                                                   i + 1,
                                                   valueType));
                }

                ClientDef def = new ClientDef();
                def.Field     = field;
                def.ValueType = valueType;

                //  主键类型缓存
                if (i == 1)
                {
                    _mainKeyDef.Field     = def.Field;
                    _mainKeyDef.ValueType = def.ValueType;
                }

                _sheetClientDefs.Add(i, def);
                ++defLength;
            }

            if (defLength < 1)
            {
                return(ConvertExceptionInfo.Warn(ContentInfo("该分页没有定义客户端字段,忽略该分页!")));
            }
            // else if (_defLength != -1 && _defLength != defLength)
            // {
            //     SystemUtil.Abend (ContentInfo (string.Format("分页之间,客户端字段数量不匹配! {0} : {1}", _defLength, defLength)));
            // }

            if (_defLength == -1)
            {
                _defLength = defLength;
            }
            return(null);
        }