单据列表和编辑界面套打携带凭证号(以应收单为例)二开方案仅供参考

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

单据列表和编辑界面套打携带凭证号(以应收单为例)二开方案仅供参考

  1. 使用visual studio新建工程,并添加相关引用


  2. 新建类TestPrinter.cs,继承基类“AbstractBillPlugIn”,并重载OnPrepareNotePrintData方法。


  3. using Kingdee.BOS.App.Data;
    using Kingdee.BOS.Core.Bill.PlugIn;
    using Kingdee.BOS.Orm.DataEntity;
    using Kingdee.BOS.Orm.Metadata.DataEntity;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace TestPrintPlugIn
    {
        public class TestPrinter : AbstractBillPlugIn
        { 
            public override void OnPrepareNotePrintData(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
            {
                if (e.DataSourceId.Equals("FBillHead", StringComparison.OrdinalIgnoreCase))
                {
                    DynamicObject billObj = this.Model.DataObject;
                    // 读取单据内码                
                    long billId = Convert.ToInt64(billObj[0]);
                    // 查询vh表获取单据对应凭证号
                    string sql = string.Format("SELECT VH.FID,VH.FVOUCHERGROUPNO  FROM T_AR_RECEIVABLE_VH VH WHERE FID={0}", billId);
                    DataSet dataset = DBUtils.ExecuteDataSet(this.Context, sql);
                    Dictionary<string, string> myDictionary = new Dictionary<string, string>();
                    foreach (DataTable dtt in dataset.Tables)
                    {
                        for (int i = 0; i < dtt.Rows.Count; i++)
                        {
                            try
                            {
                                myDictionary.Add(dtt.Rows[i]["FID"].ToString(), dtt.Rows[i]["FVOUCHERGROUPNO"].ToString());
                            }
                            catch (Exception ex)
                            {
                                //log                        
                            }
                        }
                    }
                    //注册临时字段                
                    DynamicObjectType dot = e.DataObjects[0].DynamicObjectType;
                    dot.RegisterSimpleProperty("FVOUCHERGROUPNO", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FVOUCHERGROUPNO" });
                    DynamicObject obj = new DynamicObject(dot);
                    foreach (var p in e.DataObjects[0].DynamicObjectType.Properties)
                    {
                        obj[p] = e.DataObjects[0][p];
                    }
                    //动态字段赋值                
                    obj["FVOUCHERGROUPNO"] = myDictionary[billId.ToString()];
                    e.DataObjects[0] = obj;
                }
                base.OnPrepareNotePrintData(e);
            }
        }
    }
  4. 新建类TestPrinterList.cs,继承基类“ AbstractListPlugIn”,并重载OnPrepareNotePrintData方法。


  5. using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace TestPrintPlugIn
    {
        public class TestPrinterList : AbstractListPlugIn
        {
            public override void OnPrepareNotePrintData(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
            {
                base.OnPrepareNotePrintData(e);
                if (e.DataSourceId.Equals("FBillHead", StringComparison.OrdinalIgnoreCase))
                {
                    if (e.DataObjects != null)
                    {
                        List<long> lstId = new List<long>();
                        foreach (var data in e.DataObjects)
                        {
                            lstId.Add(Convert.ToInt32(data["FID"]));
                        }
                        //查询vh表获取单据对应凭证号
                        string sql = string.Format("SELECT VH.FID,VH.FVOUCHERGROUPNO  FROM T_AR_RECEIVABLE_VH VH WHERE FID IN ({0})", string.Join(",",lstId));
                        DataSet dataset = DBUtils.ExecuteDataSet(this.Context, sql);
                        Dictionary<string, string> myDictionary = new Dictionary<string, string>();
                        foreach (DataTable dtt in dataset.Tables)
                        {
                            for (int i = 0; i < dtt.Rows.Count; i++)
                            {
                                try
                                {
                                    myDictionary.Add(dtt.Rows[i]["FID"].ToString(), dtt.Rows[i]["FVOUCHERGROUPNO"].ToString());
                                }
                                catch (Exception ex)
                                {
                                    //log                        
                                }
                            }
                        }
                        //注册临时字段     
                        DynamicObjectType dot = e.DataObjects[0].DynamicObjectType;
                        dot.RegisterSimpleProperty("FVOUCHERGROUPNO", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FVOUCHERGROUPNO" });
                        for (int i = 0; i < e.DataObjects.Length; i++)
                        {
                            DynamicObject obj = new DynamicObject(dot);
                            foreach (var p in dot.Properties)
                            {
                                obj[p] = e.DataObjects[i][p];
                            }
                            //动态字段赋值                
                            obj["FVOUCHERGROUPNO"] = myDictionary[Convert.ToString(e.DataObjects[i]["FID"])];
                            e.DataObjects[i] = obj;
                        }
                    }
                }
                
            }
        }
    }


  6. 插件开发完毕后,编译工程生成成*.dll文件。

  7. 将步骤四里面编译生成的dll文件放到服务器Cloud站点的website/bin目录下面,并重启IIS。

  8. 在BOS IDE里面扩展应收单,给应收单注册套打插件。


  9. 套打设计器里面绑定动态字段“FVOUCHERGROUPNO”


  10. 登录 Cloud,打开应收单,打印预览

   

单据列表和编辑界面套打携带凭证号(以应收单为例)二开方案仅供参考

使用visual studio新建工程,并添加相关引用新建类TestPrinter.cs,继承基类“AbstractBillPlugIn”,并重载OnPrepareNotePrintData方法。u...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息