单据转换插件,无关联关联关系字段赋值,源单单据头字段到目标单单据体
using Kingdee.BOS.App;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
namespace 我的模板
{
[Description("【->】单据转换插件"), HotUpdate]
public class 单据转换插件 : AbstractConvertPlugIn
{
private long srcBillId;//源单 内码
private string srcFormId;//源单 表单唯一标识
/// <summary>
/// 获取 源单数据 时 调用
/// </summary>
public override void OnGetSourceData(GetSourceDataEventArgs e)
{
this.srcBillId = Convert.ToInt64(e.SourceData[0]["FID"]);
this.srcFormId = e.SourceBusinessInfo.GetForm().Id;
}
/// <summary>
/// 关联 数据实体类 创建完成 之后 调用
/// </summary>
public override void OnAfterCreateLink(CreateLinkEventArgs e)
{
DynamicObject 源单 = GetFullDataEntity(this.srcFormId, this.srcBillId);//第一张 源单
DynamicObject 目标单 = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead")[0].DataEntity;//第一张 目标单
Set(源单, 目标单);
}
/// <summary>
/// 设置
/// </summary>
private void Set(DynamicObject 源单, DynamicObject 目标单)
{
if (源单 == null || 目标单 == null) return;
}
/// <summary>
/// 获取 指定字段 的 动态对象
/// </summary>
/// <param name="fieldKey">基础资料 字段 唯一标识</param>
/// <param name="baseDataId">基础资料 内码</param>
/// <returns></returns>
private DynamicObject GetDynamicObject(string formId, string baseDataFieldKey, long baseDataId)
{
if (baseDataFieldKey.IsNullOrEmptyOrWhiteSpace() || baseDataId == 0) return null;
BaseDataField baseDataField = GetBusinessInfo(formId).GetField(baseDataFieldKey) as BaseDataField;
return ServiceHelper.GetService<IViewService>().LoadSingle(Context, baseDataId, baseDataField.RefFormDynamicObjectType);
}
/// <summary>
/// 获取 业务对象 信息
/// </summary>
/// <param name="formId">表单 唯一标识</param>
private BusinessInfo GetBusinessInfo(string formId)
{
if (formId.IsNullOrEmptyOrWhiteSpace()) return null;
return (MetaDataServiceHelper.Load(Context, formId) as FormMetadata).BusinessInfo;
}
/// <summary>
/// 获取 全部属性 的 数据实体类 对象
/// </summary>
/// <param name="formId">业务对象</param>
/// <param name="id">内码</param>
private DynamicObject GetFullDataEntity(string formId, long id)
{
if (formId.IsNullOrEmptyOrWhiteSpace() || id == 0) return null;
var metadata = MetaDataServiceHelper.Load(Context, formId) as FormMetadata;
return BusinessDataServiceHelper.LoadSingle(Context, id, metadata.BusinessInfo, null);
}
}
}
单据转换通用模板,直接复制过去就能用
单据转换插件,无关联关联关系字段赋值,源单单据头字段到目标单单据体
本文2024-09-16 17:41:19发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17322.html