Example #1
0
        public void Execute(BasePage Context)
        {
            Int32 EventId = WebHelper.GetIntParam(Context.Request, "EventId", 0);

            if (EventId > 0)
            {
                var EventItem = Playngo_ClientZone_Event.FindByKeyForEdit(EventId);
                if (EventItem != null && EventItem.ID > 0)
                {
                    //拼凑文件名
                    String FileName = String.Format("Users_{0}_{1}.{2}", Context.ModuleId, DateTime.Now.ToString("yyyyMMddHHmmssffff"), "csv");
                    //文件路径
                    String FilePath = Context.Server.MapPath(String.Format("{0}ClientZone/Export/{1}", Context.PortalSettings.HomeDirectory, FileName));
                    //文件实体
                    var fileInfo = new FileInfo(FilePath);

                    //文件路径是否需要创建
                    if (!fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }


                    //创建导出类实体
                    ExportDotNet excel = new ExportDotNet();
                    //导出标题(Excel之类的才有)
                    excel.Title          = String.Format("User list of events {0}", EventItem.Title);
                    excel.ExportFileName = FilePath;


                    DataTable dt = new DataTable(excel.Title);
                    //获取表格数据
                    dt = GetDataTable(EventItem, dt, Context);
                    //导出表格数据到CSV
                    Boolean flag = excel.ExportToCSV(dt);

                    if (flag)
                    {
                        //下载文件
                        FileSystemUtils.DownloadFile(excel.ExportFileName, FileName);
                    }
                }
                else
                {
                    ResponseString = "没找到数据怎么搞";
                }
            }
            else
            {
                ResponseString = "传过来的文件编号都不对";
            }
        }
        /// <summary>
        /// 导出表格信息
        /// </summary>
        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            try
            {
                var UserList = GetUserList();
                if (UserList != null && UserList.Count > 0)
                {
                    DataTable UserTable = ConvertUserList(UserList);



                    //拼凑文件名
                    String FileName = String.Format("Users_{0}_{1}.{2}", ModuleId, DateTime.Now.ToString("yyyyMMddHHmmssffff"), "xls");
                    //文件路径
                    String FilePath = Context.Server.MapPath(String.Format("{0}ClientZone/Export/{1}", PortalSettings.HomeDirectory, FileName));
                    //文件实体
                    var fileInfo = new FileInfo(FilePath);

                    //文件路径是否需要创建
                    if (!fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }


                    //创建导出类实体
                    ExportDotNet excel = new ExportDotNet();
                    //导出标题(Excel之类的才有)
                    excel.Title          = "Users";
                    excel.ExportFileName = FilePath;

                    Boolean flag = excel.ExportToExcel(UserTable);

                    if (flag)
                    {
                        //下载文件
                        FileSystemUtils.DownloadFile(excel.ExportFileName, FileName);
                    }
                }
                else
                {
                    //没有用户
                }
            }
            catch (Exception ex)
            {
                ProcessModuleLoadException(ex);
            }
        }
        public void Execute(BasePage Context)
        {
            var FileList = new List <Playngo_ClientZone_DownloadFile>();


            //将文件列表取出
            String FileIds = WebHelper.GetStringParam(Context.Request, "FileIds", "");

            if (!String.IsNullOrEmpty(FileIds))
            {
                FileIds = FileIds.Trim(',');
                if (!String.IsNullOrEmpty(FileIds))
                {
                    FileList = Playngo_ClientZone_DownloadFile.FindAllByIds(FileIds);
                }
            }

            //待打包的文件路径
            var FilePathList = new List <String>();

            if (FileList != null && FileList.Count > 0)
            {
                //将文件的路径收集着
                foreach (var FileItem in FileList)
                {
                    if (FileItem != null && FileItem.ID > 0 && !String.IsNullOrEmpty(FileItem.Options))
                    {
                        if (Context.IsPreRoleView(FileItem.Per_AllUsers, FileItem.Per_Roles) && Context.IsPreJurisdictionView(FileItem.Per_AllJurisdictions, FileItem.Per_Jurisdictions))
                        {
                            var FileItemOptions = ConvertTo.Deserialize <List <KeyValueEntity> >(FileItem.Options);
                            if (FileItemOptions != null)
                            {
                                TemplateFormat xf         = new TemplateFormat(Context);
                                String         UploadFile = xf.GetFilePath(xf.ViewItemSettingT <String>(FileItem.Options, "UploadFile", ""), Context);
                                if (!String.IsNullOrEmpty(UploadFile))
                                {
                                    UploadFile = Context.Server.MapPath(UploadFile);
                                    if (File.Exists(UploadFile) && !FilePathList.Exists(r => r.ToLower() == UploadFile.ToLower()))
                                    {
                                        FilePathList.Add(UploadFile);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //没有权限下载
                        }
                    }
                }


                if (FilePathList != null && FilePathList.Count > 0)
                {
                    //整理压缩包文件路径等信息
                    String   ZipPath = Context.Server.MapPath(String.Format("{0}ClientZone/temporary/download-{1}files-{2}.zip", Context.PortalSettings.HomeDirectory, FilePathList.Count, DateTime.Now.ToString("yyyyMMdd-Hms")));
                    FileInfo ZipFile = new FileInfo(ZipPath);
                    if (!ZipFile.Directory.Exists)
                    {
                        ZipFile.Directory.Create();
                    }
                    else
                    {
                        //清楚很多天前的文件
                        FileSystemUtils.ClearFiles(ZipFile.Directory, 1);
                    }

                    //创建压缩包
                    FileSystemUtils.CreateZipFiles(FilePathList, ZipPath);


                    //将压缩好的文件列表下载
                    FileSystemUtils.DownloadFile(ZipPath, Path.GetFileName(ZipPath));
                }
                else
                {
                    IsResponseWrite = true;
                    ResponseString  = "No files found.";
                }
            }
        }