工作流收信箱批量下载附件二开示例

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

工作流收信箱批量下载附件二开示例

第一步:在BOS设计器找到收信箱元数据WF_MessageBill,拓展之后,添加批量下载菜单:

第二步:在拓展的元数据的表单插件中,挂上插件,插件代码示例如下:


using ICSharpCode.SharpZipLib.Zip;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Util;


private string _temppath;
        public override void BarItemClick(Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.EqualsIgnoreCase("FBatchDownload"))
            {
                Download();
            }
        }

        private void Download()
        {
            var attachment = this.Model.GetValue("FFileUpdate");

            var array = SerializatonUtil.DeserializeFromBase64<JSON.JSONArray>(attachment.ToString());
            //待压缩临时文件夹路径。
            _temppath = HttpContext.Current.Server.MapPath(KeyConst.TEMPFILEPATH);
            string tempZipDirPath = Path.Combine(_temppath, Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempZipDirPath);
            foreach (var ar in array)
            {
                string serverFileName = Convert.ToString(((JSON.JSONObject)ar)["ServerFileName"]);
                var fileContenObject = ((JSON.JSONObject)ar)["FileContent"];
                string tempZipFilePath = Path.Combine(tempZipDirPath, serverFileName);
                DownloadFileFromDatabase(tempZipFilePath, (Byte[])fileContenObject);
            }

            CheckAndCompresseFile(tempZipDirPath);
        }
        private void DownloadFileFromDatabase(string tempZipFilePath, Byte[] fileContenObject)
        {
            using (FileStream fs = new FileStream(tempZipFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
            using (BinaryWriter bw = new BinaryWriter(fs))
            {
                bw.Write(fileContenObject);
            }
        }

        private void CheckAndCompresseFile(string tempZipDirPath)
        {

            DirectoryInfo dirInfo = new DirectoryInfo(tempZipDirPath);
            if (dirInfo.GetFiles().Length <= 0)
            {
                return;
            }

           var _zipfilename = string.Format("Attachment_{0}.zip", Guid.NewGuid());

            string zipfilepath = Path.Combine(_temppath, _zipfilename);
            CreateZipFile(tempZipDirPath, zipfilepath);
            ShowZipDownLoadForm(zipfilepath);
        }
        private void CreateZipFile(string sourceDirectory, string zipFilePath)
        {
            if (!Directory.Exists(sourceDirectory))
            {
                return;
            }
            ZipOutputStream stream = null;
            try
            {
                stream = new ZipOutputStream(File.Create(zipFilePath));
                stream.SetLevel(0); // 压缩级别 0-9
                byte[] buffer = new byte[4096]; //缓冲区大小
                string[] filenames = Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories);
                foreach (string file in filenames)
                {
                    ZipEntry entry = new ZipEntry(file.Replace(sourceDirectory, "").TrimStart('\\'));
                    entry.DateTime = DateTime.Now;
                    stream.PutNextEntry(entry);
                    using (FileStream fs = File.OpenRead(file))
                    {
                        int sourceBytes;
                        do
                        {
                            sourceBytes = fs.Read(buffer, 0, buffer.Length);
                            stream.Write(buffer, 0, sourceBytes);
                        } while (sourceBytes > 0);
                    }
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Finish();
                    stream.Close();
                }
            }
        }
        private void ShowZipDownLoadForm(string zipfilepath)
        {
            string downloadUrl = PathUtils.ConvertPhysicalPathToDownloadUrl(this.Context, zipfilepath);
            ViewCommonAction.ShowWebURL(this.View, downloadUrl);
            this.View.SendDynamicFormAction(this.View);
        }


工作流收信箱批量下载附件二开示例

第一步:在BOS设计器找到收信箱元数据WF_MessageBill,拓展之后,添加批量下载菜单:第二步:在拓展的元数据的表单插件中,挂上插件,插件...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息