电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

单据上批量下载物料图片二开示例

来源:金蝶云社区作者:金蝶2024-09-237

单据上批量下载物料图片二开示例

比如在采购申请单中下载明细的物料对应的图片。物料图片分为数据库图片和文件服务器图片截图如下:

在采购申请单的表单插件中挂上插件,插件代码示例如下:

using ICSharpCode.SharpZipLib.Zip;

using Kingdee.BOS.Core;

using Kingdee.BOS.Core.Bill.PlugIn;

using Kingdee.BOS.Core.DynamicForm;

using Kingdee.BOS.FileServer.Core.Object;

using Kingdee.BOS.FileServer.ProxyService;

using Kingdee.BOS.Orm.DataEntity;

using Kingdee.BOS.ServiceHelper;

using Kingdee.BOS.Util;

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Web;


namespace Kingdee.BOS.Printing.PlugIn.Test

{

    public class DownloadPic : AbstractBillPlugIn

    {

        public DownloadPic()

        { }

        public override void BarItemClick(Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)

        {

            base.BarItemClick(e);

            if (e.BarItemKey == "ff_tbButton")

            {

                GetFMaterialIdPic();

            }

        }


private void GetFMaterialIdPic()

        {

            int count = this.View.Model.GetEntryRowCount("FEntity");

            for (int i = 0; i < count; i++)

            {

                DynamicObject materialId = this.View.Model.GetValue("FMaterialId", i) as DynamicObject;

                if (materialId != null)

                    GetPic(materialId["Id"]);

            }

        }


        private void GetPic(object materialId)

        {

            string _temppath = HttpContext.Current.Server.MapPath(KeyConst.TEMPFILEPATH);

            string tempZipDirPath = Path.Combine(_temppath, Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempZipDirPath);

            string sql = string.Format("select FIMAGE,FIMAGEFILESERVER from T_BD_MATERIAL where  FMaterialId={0}", materialId);

            DynamicObjectCollection obj = DBServiceHelper.ExecuteDynamicObject(this.View.Context, sql, null);

            if (obj != null)

            {

                var Image1 = obj[0]["FIMAGE"];

                var ImageFileServer = obj[0]["FIMAGEFILESERVER"];

                if (Image1 != null)

                {

                    DownloadFileFromDatabase(tempZipDirPath,(Byte[])Image1);

                }

                if (ImageFileServer != null)

                {

                    DownloadFileFromFileServer(tempZipDirPath, ImageFileServer.ToString());

                }

            }

            CheckAndCompresseFile(tempZipDirPath);

        }


private void DownloadFileFromDatabase(string tempZipFilePath, Byte[] image)

        {

            tempZipFilePath = Path.Combine(tempZipFilePath, Guid.NewGuid().ToString()+".webp");

            using (FileStream fs = new FileStream(tempZipFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite))

            using (BinaryWriter bw = new BinaryWriter(fs))

            {

                bw.Write(image);

            }

        }


        private void DownloadFileFromFileServer(string tempZipFilePath, string fileId)

        {

            tempZipFilePath = Path.Combine(tempZipFilePath, Guid.NewGuid().ToString() + ".webp");

            UpDownloadService upDownloadService = new UpDownloadService();

            TFileInfo tFile = new TFileInfo()

            {

                FileId = fileId,

                StartIndex = 0,

                CTX = this.Context,

                FilePath = tempZipFilePath

            };

            FileDownloadResult downloadResult = upDownloadService.DownloadSaveLocal(tFile);

        }


private void CheckAndCompresseFile(string tempZipDirPath)

        {

            DirectoryInfo dirInfo = new DirectoryInfo(tempZipDirPath);

           var _

单据上批量下载物料图片二开示例

比如在采购申请单中下载明细的物料对应的图片。物料图片分为数据库图片和文件服务器图片截图如下:在采购申请单的表单插件中挂上插件,插件...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信