自定义下推插件开发,调用转换规则实现自定义下推
本人之前遇到了一个要开发自定义下推插件的需求,苦于无师,只得在社区里面寻找关于下推插件开发的知识,但是搜到的大多年代久远,或没有详细说明,过程甚是艰难,我在此分享出我本次开发的方法,希望可以帮助第一次开发的小白,话不多说上源码!
添加引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.Const;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.Core.Metadata.ConvertElement;
using Kingdee.BOS.Core.DynamicForm.Operation;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Report.PlugIn;
using Kingdee.BOS.Contracts;
我用的是表单插件,继承:AbstractSysReportPlugIn
在此之前
我们要先配置本次下推所用到的 !!!转换规则!!!(划重点)
如果需要调用系统现有的转换规则,并实现上下查的功能,请移步自定义下推插件(调用系统现有的转换规则) (kingdee.com)
回到我们的插件,
1、首先我们要构建下推所用到的数据包
利用:DBUtils.ExecuteDynamicObject
2、根据转换规则标识获取相应的转换规则
利用:string convertRuleld = "SCP_InStockTOPayableMap";//SCP_InStockTOPayableMap为标识
var rule = ConvertServiceHelper.GetConvertRule(this.Context, convertRuleld).Rule;//rule 为转换规则
3、构建下推参数
List<ListSelectedRow> selectedRows = new List<ListSelectedRow>();(下附有源码)
PushArgs PushArgs = new PushArgs(rule, selectedRows.ToArray())
4、调用下推方法
ConvertOperationResult result = ConvertServiceHelper.Push(this.Context, PushArgs, option);
源码附上:
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("WOIN_tbButton1"))
{
string FormTitle = this.View.Model.DataObject["Id"].ToString();
var rows = DBUtils.ExecuteDynamicObject(this.Context, string.Format("select * from CAiGou where FID={0}", FormTitle));
foreach (var row in rows)
{
IConvertService service = Kingdee.BOS.App.ServiceHelper.GetService<IConvertService>();
string convertRuleld = "SCP_InStockTOPayableMap";
var rule = ConvertServiceHelper.GetConvertRule(this.Context, convertRuleld).Rule;
List<ListSelectedRow> selectedRows = new List<ListSelectedRow>();
string sourceFormId = "SCP_InStock";//发起下推的单据标识
string primaryKeyValue = row["FID"].ToString();//单据头内码
string entryPrimaryKeyValue = row["FENTRYID"].ToString();//下推的单据体内码
int rowKey = 0;//暂时没用上,给个0
ListSelectedRow sr = new ListSelectedRow(primaryKeyValue, entryPrimaryKeyValue, rowKey,
sourceFormId);
selectedRows.Add(sr);
PushArgs PushArgs = new PushArgs(rule, selectedRows.ToArray());//下推入口参数
OperateOption option = OperateOption.Create();//选项参数
option.SetVariableValue("customizeParam", "1");//注册自定义参数键值对
ConvertOperationResult result = ConvertServiceHelper.Push(this.Context, PushArgs, option);
// 获取生成的目标单据数据包,此处获取是为了拿到内码,做到像标准下推那样的弹出下游单据的功能
DynamicObject[] objs = (from p in result.TargetDataEntities select p.DataEntity).ToArray();
// 读取目标单据元数据
var targetBillMeta = MetaDataServiceHelper.Load(this.Context, "AP_PAYABLE") as FormMetadata;
OperateOption saveOption = OperateOption.Create();//AP_PAYABLE目标单据标识
// 忽略全部需要交互性质的提示,直接保存;
saveOption.SetIgnoreWarning(true); // 提交数据库保存,并获取暂存结果
var saveResult = BusinessDataServiceHelper.Draft(this.Context, targetBillMeta.BusinessInfo, objs, saveOption);
var dy = saveResult.SuccessDataEnity.ToList();
var FID = dy[0]["Id"].ToString();
if (result.IsSuccess == true)
{
//弹出下游单据
string pageId = Guid.NewGuid().ToString();
BillShowParameter showParameter = new BillShowParameter();
showParameter.FormId = "AP_PAYABLE";
showParameter.OpenStyle.ShowType = ShowType.Floating;
showParameter.PageId = pageId;
showParameter.Status = OperationStatus.EDIT;
showParameter.PKey = FID;
this.View.ShowForm(showParameter);
}
else
{
string msg = $"失败信息{result.IsShowMessage},失败内容{result.ValidationErrors}";
throw new Exception(msg);
}
}
}
}
在此感谢金蝶社区各位大佬的帮助,让我乘其阴凉!
弹出下游单据有问题可以参考这位大佬的帖子,插件内打开某一张单据 (kingdee.com),这篇文章的作者帮助过我很多,特此感谢!!!
小白第一次分享,如有错误还请指正,虚心求教中
自定义下推插件开发,调用转换规则实现自定义下推
本文2024-09-16 18:31:24发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22688.html