Ejemplo n.º 1
0
        public virtual void Import()
        {
            //根据视图名读取ExcelConfig信息。

            MDataRow excelInfo = null;
            int      index = 0, headCrossRowNum = 0;
            string   sheetName = null;

            try
            {
                excelInfo = ExcelConfig.GetExcelRow(ObjName);
                if (excelInfo != null)
                {
                    index           = excelInfo.Get <int>(Config_Excel.StartIndex, 0);
                    headCrossRowNum = excelInfo.Get <int>(Config_Excel.HeadCrossRowNum, 0);
                    sheetName       = excelInfo.Get <string>(Config_Excel.Description);
                }
            }
            catch (Exception err)
            {
                Log.WriteLogToTxt(err);//避免其它地方没有升级数据库表脚本。
            }
            MDataTable dt = ExcelHelper.ReadExcel(null, sheetName, index, headCrossRowNum, excelInfo != null);

            if (!dt.Columns.Contains(LangConst.ErrorInfo))
            {
                dt.Columns.Add(LangConst.ErrorInfo, System.Data.SqlDbType.NVarChar);
            }
            dt.TableName = excelInfo != null ? ObjName : TableName;
            bool         result  = false;
            string       msg     = string.Empty;
            ImportResult iResult = BeforeImport(dt, excelInfo, out msg);

            if (iResult == ImportResult.Continue)
            {
                result = FormatExcel(dt, excelInfo);
                if (result)
                {
                    dt.Columns.Remove(LangConst.ErrorInfo);
                    result = ExcelConfig.AcceptChanges(dt, excelInfo, ObjName);// dt.AcceptChanges(AcceptOp.Auto);
                }
            }
            else
            {
                result = iResult == ImportResult.True;
            }
            if (!result)
            {
                if (dt.DynamicData != null && dt.DynamicData is Exception)
                {
                    msg  = ((Exception)dt.DynamicData).Message;
                    msg += LangConst.ImportTemplateNotMatch;
                }
                if (excelStream == null)
                {
                    excelStream = ExcelHelper.SetError(dt);
                }
                if (string.IsNullOrEmpty(msg))
                {
                    msg = LangConst.ImportError + (excelStream != null ? LangConst.ImportCheckErrorInfo : LangConst.ImportCheckTemplateIsRight);
                }
            }
            else if (string.IsNullOrEmpty(msg))
            {
                msg = LangConst.ImportSuccess;
            }
            dt.DynamicData = null;
            dt             = null;
            GC.Collect();

            jsonResult = JsonHelper.OutResult(result, msg);
        }
Ejemplo n.º 2
0
        public void Import()
        {
            //根据视图名读取ExcelConfig信息。

            MDataRow excelInfo = null;
            int      index = 0, headCrossRowNum = 0;
            string   sheetName = null;

            try
            {
                excelInfo = ExcelConfig.GetExcelRow(ObjName);
                if (excelInfo != null)
                {
                    index           = excelInfo.Get <int>(Config_Excel.StartIndex, 0);
                    headCrossRowNum = excelInfo.Get <int>(Config_Excel.HeadCrossRowNum, 0);
                    sheetName       = excelInfo.Get <string>(Config_Excel.Description);
                }
            }
            catch (Exception err)
            {
                Log.WriteLogToTxt(err);//避免其它地方没有升级数据库表脚本。
            }
            MDataTable dt = ExcelHelper.ReadExcel(null, sheetName, index, headCrossRowNum, excelInfo != null);

            if (!dt.Columns.Contains("错误信息"))
            {
                dt.Columns.Add("错误信息", System.Data.SqlDbType.NVarChar);
            }
            dt.TableName = excelInfo != null ? ObjName : TableName;
            bool         result  = false;
            string       msg     = string.Empty;
            ImportResult iResult = BeforeImport(dt, excelInfo, out msg);

            if (iResult == ImportResult.Continue)
            {
                result = FormatExcel(dt, excelInfo);
                if (result)
                {
                    result = ExcelConfig.AcceptChanges(dt, excelInfo, ObjName);// dt.AcceptChanges(AcceptOp.Auto);
                }
            }
            else
            {
                result = iResult == ImportResult.True;
            }
            if (!result)
            {
                if (dt.DynamicData != null && dt.DynamicData is Exception)
                {
                    msg  = ((Exception)dt.DynamicData).Message;
                    msg += "(PS:可能模板不匹配)";
                }
                if (excelStream == null)
                {
                    excelStream = ExcelHelper.SetError(dt);
                }
                if (string.IsNullOrEmpty(msg))
                {
                    msg = "导入失败" + (excelStream != null ? "(请查看输出的Excel错误信息)" : "(请检测是否模板错误)");
                }
            }
            else if (string.IsNullOrEmpty(msg))
            {
                msg = "导入成功";
            }
            dt.DynamicData = null;
            dt             = null;
            GC.Collect();

            jsonResult = JsonHelper.OutResult(result, msg);
        }
Ejemplo n.º 3
0
        public virtual void Export()
        {
            MDataTable dt = Select(GridConfig.SelectType.Export);

            dt.TableName   = ObjName;
            dt.DynamicData = GridConfig.GetList(ObjName, GridConfig.SelectType.Export);
            Dictionary <string, string> formatParas = GridConfig.GetFormatter(dt); //格式化列头(描述)(需要修改列头的数据格式)

            KeyValueConfig.FormatNameValue(dt, formatParas, true);                 //格式化配置项
            string fix = ExcelHelper.BookType == ExcelHelper.WorkBookType.High ? ".xlsx" : ".xls";

            WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + "_" + DateTime.Now.ToString("yyyyMMdd") + fix, ExcelHelper.CreateExcel(dt));//ExcelHelper.CreateExcel(dt)
        }
Ejemplo n.º 4
0
        public void Export()
        {
            MDataTable dt = Select(GridConfig.SelectType.Export);

            dt.TableName   = ObjName;
            dt.DynamicData = GridConfig.GetList(ObjName, GridConfig.SelectType.All);
            Dictionary <string, string> formatParas = GridConfig.SetHeaderDescription(dt);                                                                              //格式化列头(描述)(需要修改列头的数据格式)

            KeyValueConfig.FormatNameValue(dt, formatParas, true);                                                                                                      //格式化配置项
            WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xls", ExcelHelper.CreateExcel(dt)); //ExcelHelper.CreateExcel(dt)
        }