Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SysDataImportTemplate ent = null;

            switch (this.RequestAction)
            {
            case RequestActionEnum.Delete:
                ent = this.GetTargetData <SysDataImportTemplate>();
                ent.DoDelete();
                this.SetMessage("删除成功!");
                break;

            case RequestActionEnum.Custom:
                IList <object> idList = RequestData.GetList <object>("IdList");

                if (idList != null && idList.Count > 0)
                {
                    if (RequestActionString == "batchdelete")
                    {
                        SysDataImportTemplate.DoBatchDelete(idList.ToArray());
                    }
                }
                break;

            default:
                ents = SysDataImportTemplateRule.FindAll(SearchCriterion);
                this.PageState.Add("SysDataImportTemplateList", ents);
                break;
            }
        }
        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="tmplCode">模板编码</param>
        /// <param name="fileFullName"></param>
        public static void ImportDataByTemplateCode(string tmplCode, string fileFullName)
        {
            SysDataImportTemplate tmplEnt = SysDataImportTemplate.FindFirstByProperties("Code", tmplCode);

            ImportTemplateStructure its = ImportTemplateStructure.GetFromConfig(tmplEnt.Config);
            string filePath             = FileService.GetFilePathByFullID(fileFullName);

            ImportData(its, filePath);
        }
        /// <summary>
        /// 当模版文件变化时操作
        /// </summary>
        /// <param name="ent"></param>
        public static void DoImportTemplateFileChanged(SysDataImportTemplate ent)
        {
            // 当模版文件有变化是,同时更新下载文件与配置模版
            string filePath = FileService.GetFilePathByFullID(ent.TemplateFileID.TrimEnd(','));

            ImportTemplateParser    itp = new ImportTemplateParser(filePath);
            ImportTemplateStructure its = itp.GetStructure();

            ent.Config         = its.GetConfig();
            ent.DownloadFileID = ent.TemplateFileID;    // 这里下载文件与模版文件为同一文件
        }
        /// <summary>
        /// 获取EasyDictionary数据
        /// </summary>
        /// <param name="tmplCode">模版编码</param>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public static DataTable GetDataTableByTemplateCode(string tmplCode, string fileFullName)
        {
            SysDataImportTemplate tmplEnt = SysDataImportTemplate.FindFirstByProperties("Code", tmplCode);

            ImportTemplateStructure struc = ImportTemplateStructure.GetFromConfig(tmplEnt.Config);
            string filePath = FileService.GetFilePathByFullID(fileFullName);

            DataTable dt = GetDataTable(struc, filePath);

            return(dt);
        }
Пример #5
0
        string code = String.Empty; // 对象编码

        #endregion

        #region ASP.NET 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            op   = RequestData.Get <string>("op");
            code = RequestData.Get <string>("code");

            SysDataImportTemplate ent = null;

            switch (this.RequestAction)
            {
            case RequestActionEnum.Custom:
                if (RequestActionString == "import")
                {
                    code = FormData.Get <string>("Code");

                    if (!String.IsNullOrEmpty(code))
                    {
                        ent = SysDataImportTemplate.FindFirstByProperties("Code", code);

                        string fileFullName = FormData.Get <string>("DataFileID");
                        if (!String.IsNullOrEmpty(fileFullName))
                        {
                            DataImportService.ImportData(ent.Config, fileFullName);

                            // 导入完成后删除原文件
                            FileService.DeleteFileByFullID(fileFullName);
                        }
                    }
                }
                else if (RequestActionString == "gettmplid")
                {
                    // 下载文件模板时用于获取模板文件id(异步)
                    if (IsAsyncRequest && !String.IsNullOrEmpty(code))
                    {
                        ent = SysDataImportTemplate.FindFirstByProperties("Code", code);

                        // 返回模板文件ID
                        PageState.Add("id", FileService.GetFileIDByFullID(ent.TemplateFileID));
                    }
                }
                break;

            case RequestActionEnum.Default:
                if (!String.IsNullOrEmpty(code))
                {
                    ent = SysDataImportTemplate.FindFirstByProperties("Code", code);
                    this.SetFormData(ent);
                }
                break;
            }
        }
        string type = String.Empty; // 对象类型

        #endregion

        #region ASP.NET 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            op   = RequestData.Get <string>("op");
            id   = RequestData.Get <string>("id");
            type = RequestData.Get <string>("type");

            SysDataImportTemplate ent = null;

            switch (this.RequestAction)
            {
            case RequestActionEnum.Update:
                ent = this.GetTargetData <SysDataImportTemplate>();
                SysDataImportTemplate pent = this.GetPostedData <SysDataImportTemplate>();

                bool isTemplateFileChanged = false;
                if (ent.TemplateFileID != pent.TemplateFileID)
                {
                    isTemplateFileChanged = true;
                }

                DataHelper.MergeData(ent, pent);        // 手工合并源数据与提交数据

                if (isTemplateFileChanged)
                {
                    DataImportService.DoImportTemplateFileChanged(ent);     // 触发模版文件变化操作
                }

                ent.DoUpdate();
                this.SetMessage("修改成功!");
                break;

            case RequestActionEnum.Insert:
            case RequestActionEnum.Create:
                ent             = this.GetPostedData <SysDataImportTemplate>();
                ent.CreaterID   = UserInfo.UserID;
                ent.CreaterName = UserInfo.Name;

                DataImportService.DoImportTemplateFileChanged(ent);     // 触发模版文件变化操作

                ent.DoCreate();
                this.SetMessage("新建成功!");
                break;

            case RequestActionEnum.Delete:
                ent = this.GetTargetData <SysDataImportTemplate>();
                ent.DoDelete();
                this.SetMessage("删除成功!");
                return;
            }

            if (op != "c" && op != "cs")
            {
                if (!String.IsNullOrEmpty(id))
                {
                    ent = SysDataImportTemplate.Find(id);
                }

                this.SetFormData(ent);
            }
            else
            {
                PageState.Add("CreaterName", UserInfo.Name);
                PageState.Add("CreatedDate", DateTime.Now);
            }
        }