套打根据单据体物料编码分组分文件导出二开示例

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

套打根据单据体物料编码分组分文件导出二开示例

以采购申请单为例,采购申请单详情如下:

按明细中的物料编码分组之后分文件导出。在BOS设计器中找到采购申请单,在菜单集合中添加一个按钮,挂上表单插件代码。代码示例如下:

using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kingdee.BOS.Printing.PlugIn.Test
{
    public class NoteExportGroup : AbstractBillPlugIn
    {
        private List<string> Groups;
        private string CurrentGroup ;
        public override void BarItemClick(Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.ToLower() == "tbprintentrys")
            {
                GetEntityData();
                try
                {
                    foreach (var group in Groups)
                    {
                        CurrentGroup = group;
                        string[] tempIds = { "fb91139e-4545-42b9-9a5f-257e947eecde" };
                        PrintExportInfo pExInfo = new PrintExportInfo();
                        pExInfo.PageId = this.View.PageId;
                        pExInfo.FormId = this.View.BillBusinessInfo.GetForm().Id;
                        pExInfo.BillIds = new List<string> { this.View.Model.GetPKValue().ToString() };//单据内码
                        pExInfo.TemplateIds = tempIds.ToList();//套打模板ID
                        pExInfo.FileType = ExportFileType.XLSX;//文件格式
                        Export(pExInfo);
                    }
                }
                finally
                {
                    Groups = null;
                    CurrentGroup = null;
                }
            }
        }
        private void Export(PrintExportInfo pExInfo)
        {
            string fileName = Guid.NewGuid().ToString() + ".xlsx";
            pExInfo.FilePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName);
            Kingdee.BOS.Web.Bill.BillView billView = (Kingdee.BOS.Web.Bill.BillView)this.View;
            billView.ExportNotePrint(pExInfo);
        }

        private void GetEntityData()
        {
            Groups = new List<string>();
           var entityObjs= this.Model.GetEntityDataObject(this.View.BillBusinessInfo.GetEntity("FEntity"));
           if (entityObjs != null)
           {
               foreach (var obj in entityObjs)
               {
                   DynamicObject dy = obj["MATERIALID"] as DynamicObject ;
                   if (dy != null && dy.DynamicObjectType.Properties.ContainsKey("Number"))
                   {
                       var name = ObjectUtils.Object2String(dy["Number"]);
                       if (!Groups.Contains(name))
                       {
                           Groups.Add(name);
                       }
                   }
                 
               }
           }
        }

        public override void OnPrepareNotePrintData(Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
        {
            base.OnPrepareNotePrintData(e);
            if (e.DataSourceId == "FEntity")
            {
                e.DataObjects = e.DataObjects.Where(p => p["FMATERIALID_FNUMBER"].ToString() == CurrentGroup).ToArray();
            }
        }
    }
}

在导出的路径中,可以看到导出的文件:

套打根据单据体物料编码分组分文件导出二开示例

以采购申请单为例,采购申请单详情如下:按明细中的物料编码分组之后分文件导出。在BOS设计器中找到采购申请单,在菜单集合中添加一个按钮...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息