二开干预套打取数示例(动态字段使用)
金蝶云社区-天冥异
天冥异
3人赞赏了该文章 847次浏览 未经作者许可,禁止转载编辑于2018年08月02日 20:19:15

目前套打是不会对数据做干预的,也就是说单据上面一个字段的值是什么,那么打印出来就是什么。如果需要对打印出来的数据做变更,可以通过二次开发来实现。

目前套打是不会对数据做干预的,也就是说单据上面一个字段的值是什么,那么打印出来就是什么。如果需要对打印出来的数据做变更,可以通过二次开发来实现。
    比如有一个打印需求:需要将采购订单上面“供应商名称”“大写金额”“金额” 连接起来进行打印输出。那么可以在套打插件里面将三个字段的连接起来配合动态字段进行打印。

操作步骤:
一.使用visual studio新建工程,并添加相关引用:

二.新建类,并继承基类“AbstractBillPlugIn”。

三.重载OnPrepareNotePrintData方法。

四.OnPrepareNotePrintData实现干预套打取数的逻辑, 本贴示例逻辑为:
     1.获取采购订单上面“供应商名称”“大写金额”“金额”三个字段值,并作连接处理。
     2.定义名字为“FMyself”的动态字并注册。
     3.给动态字段赋值。
    本帖最后会附上示例插件的完整代码。
五.插件开发完毕后,编译工程生成成*.dll文件。

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

七.在BOS IDE里面扩展采购订单,给采购订单注册套打插件。


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


九.登录 Cloud,打开采购订单,打印预览。



注:本帖示例为单据打印,如果需要列表打印生效,则需要继承AbstractListPlugIn基类,在OnPrepareNotePrintData实现干预套打取数的逻辑。


附:本案例所用的套打插件代码:
  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using System.Threading.Tasks;


  6. using Kingdee.BOS.Core.Bill.PlugIn;

  7. using Kingdee.BOS.Core.Metadata.FieldElement;

  8. using Kingdee.BOS.Orm.DataEntity;

  9. using Kingdee.BOS.Orm.Metadata.DataEntity;


  10. namespace TestPrintPlugin

  11. {

  12.     public class TestPrintPlugin : AbstractBillPlugIn

  13.     {

  14.        

  15.         public override void OnPrepareNotePrintData(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)

  16.         {


  17.             if (e.DataSourceId.Equals("FBillHead", StringComparison.OrdinalIgnoreCase))

  18.             {

  19.                 DynamicObject billObj = this.Model.DataObject;

  20.                 // 首先获取各种元素的元数据

  21.                 Field fldBillNo = this.View.BillBusinessInfo.GetField("FBillNo");

  22.                 Field amount = this.View.BillBusinessInfo.GetField("FBillAmount");

  23.                 BaseDataField fldSupplier = this.View.BillBusinessInfo.GetField("FSupplierId") as BaseDataField;

  24.            

  25.                 // 读取单据内码

  26.                 long billId = Convert.ToInt64(billObj[0]);

  27.                 //单据编号

  28.                 string billNo = Convert.ToString(fldBillNo.DynamicProperty.GetValue(billObj));

  29.                 //供应商

  30.                 DynamicObject fldSupplierValue = fldSupplier.DynamicProperty.GetValue(billObj) as DynamicObject;


  31.                 // 基础资料属性值(供应商)

  32.                 string supplierName = "";

  33.                 if (fldSupplierValue != null)

  34.                 {

  35.                     long supplierId = Convert.ToInt64(fldSupplierValue[0]);

  36.                     string supplierNumber = fldSupplier.GetRefPropertyValue(fldSupplierValue, "FNumber").ToString();

  37.                     supplierName = fldSupplier.GetRefPropertyValue(fldSupplierValue, "FName").ToString();

  38.                 }


  39.                 // 财务子单据体

  40.                 DynamicObjectCollection FPOOrderFinanceList = billObj["POOrderFinance"] as DynamicObjectCollection;

  41.                 DynamicObject FPOOrderFinance = FPOOrderFinanceList[0];

  42.                 //金额字段

  43.                 double amountDisplayValue = Convert.ToDouble(amount.DynamicProperty.GetValue(FPOOrderFinance));

  44.                 //获取金额大写

  45.                 Kingdee.BOS.NumFormatTran.FormatTranslate formatTran = new Kingdee.BOS.NumFormatTran.FormatTranslate();

  46.                 formatTran.Resource = amountDisplayValue.ToString();

  47.                 //如需要支持英文大写格式,需要将下面代码替换成为:formatTran.Type =  Kingdee.BOS.Util.UpperStyle.EnglishDollarStyle.ToString();

  48.                 formatTran.Type = Kingdee.BOS.Util.UpperStyle.ChineseRmbStyle.ToString();

  49.                 string chineseAmount = Kingdee.BOS.Util.FormatTranslateUtil.Translate(formatTran);


  50.                 //动态字段注册赋值

  51.                 DynamicObjectType dot = e.DataObjects[0].DynamicObjectType;

  52.                 dot.RegisterSimpleProperty(

  53.                         "FMyself",

  54.                         typeof(object),

  55.                         attributes: new SimplePropertyAttribute() { Alias = "FMyself" }

  56.                         );

  57.      

  58.                 DynamicObject obj = new DynamicObject(dot);

  59.                 foreach (var p in e.DataObjects[0].DynamicObjectType.Properties)

  60.                 {

  61.                     obj[p] = e.DataObjects[0][p];

  62.                 }

  63.                 //动态字段赋值

  64.                 obj["FMyself"] =supplierName + chineseAmount + amountDisplayValue.ToString();

  65.         

  66.                 e.DataObjects[0] = obj;


  67.             }

  68.             

  69.             base.OnPrepareNotePrintData(e);


  70.         }


  71.           

  72.     }


  73. }


复制代码


赞 3