二开干预套打取数

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

二开干预套打取数

需求:取子单据体上字段,拼接进行打印输出

开发步骤:

  1. 在套打上定义名字为“FMODELNO”的动态字

  2. 插件代码进行取数赋值

(列表打印和单据打印是分开的。如果需要单据打印生效,则需要继承AbstractBilPlugIn基类,在OnPrepareNotePrintData实现干预套打取数的逻辑。列表同理。)


列表插件

 public override void OnPrepareNotePrintData(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"]));
                    }
                    Dictionary<long, string> myDictionary = new Dictionary<long, string>();
                    foreach (long billId in lstId)
                    {
                        FormMetadata meta = MetaDataServiceHelper.Load(this.Context, "BAS_PreBaseDataOne") as FormMetadata;
                        DynamicObject pgd = BusinessDataServiceHelper.LoadSingle(this.Context, billId, meta.BusinessInfo.GetDynamicObjectType());
                        if (pgd != null)
                        {
                            DynamicObject entity = (pgd["F_JDSL_Entity"] as DynamicObjectCollection).FirstOrDefault();
                            var names = (entity["F_JDSL_SubEntity"] as DynamicObjectCollection).Select(P => (P["F_JDSL_SubOperator"] as DynamicObject)["Name"]);
                            myDictionary[billId] = string.Join("、", names);
                        }

                    }
                    //注册临时字段     
                    DynamicObjectType dot = e.DataObjects[0].DynamicObjectType;
                    dot.RegisterSimpleProperty("FMyself", 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["FMODELNO"] = myDictionary[Convert.ToInt64(e.DataObjects[i]["FID"])];
                        e.DataObjects[i] = obj;
                    }



                }
            }



        }

表单插件

public class DeliverNoticePrintList :AbstractListPlugIn
    {
        public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
        {
            base.OnPrepareNotePrintData(e);
            if (e.NotePrintTplId == "8c80e77b-fdcf-4a41-bb87-cb1588b04eaa")
            {
                if (e.DataSourceId.Equals("FEntity", StringComparison.OrdinalIgnoreCase))
                {
                    if (e.DataObjects != null)
                    {
                        DynamicObjectType dataType = e.DataObjects[0].DynamicObjectType;
                        dataType.RegisterSimpleProperty("FMODELNO", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FMODELNO" });
                        for (int i = 0; i < e.DataObjects.Length; i++)
                        {
                            DynamicObject obj = new DynamicObject(dataType);
                            foreach (var p in dataType.Properties)
                            {
                                obj[p] = e.DataObjects[i][p];
                            }
                            obj["FMODELNO"] = getModelName((obj["F_NEST_BGDL_FName1"] as List<LocaleValue>)[0].ToString(), i+1);
                            e.DataObjects[i] = obj;
                        }
                    }
                }
            }
                    
        }
    }


参考链接:二开干预套打取数示例(动态字段使用)


能否讲讲如何动态注册字段,即实现 动态的行转列

二开干预套打取数

需求:取子单据体上字段,拼接进行打印输出开发步骤:在套打上定义名字为“FMODELNO”的动态字插件代码进行取数赋值(列表打印和单据打印是...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息