平台基于性能考虑目前暂未支持单据转换携带多语言字段的所有语言文本,后续版本会增加支持,不着急的童鞋可以等新版发布,着急的童鞋可参考本贴进行二开支持。
测试单据:【采购申请单下推采购订单】
操作步骤:
1.采购申请单添加多语言字段
2.采购订单单添加多语言字段
3.采购申请单到采购订单的单据转换规则设置中,增加多语言字段映射
4.注册单据转换插件
5.插件示例代码[code]using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
namespace V7.PlugInTest.Convert
{
public class SetMulLangConvertPlugIn : AbstractConvertPlugIn
{
///
/// 源单多语言字段Key
///
public const string SourceMlFieldKey = "F_PAEZ_MulLangTextSQD";
///
/// 源单数据包用于存储多语言字段数据的属性名
///
public const string SourceMlFieldPropertyName = SourceMlFieldKey + "_ML";
///
/// 目标单多语言字段Key
///
public const string TargetMlFieldfKey = "F_PAEZ_MulLangTextDD";
///
/// 取源单数据前事件
/// 可在此事件中向源单数据包注册需要携带的多语言字段
///
///
public override void OnBeforeGetSourceData(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.BeforeGetSourceDataEventArgs e)
{
base.OnBeforeGetSourceData(e);
var sourceMlField = e.BusinessInfo.GetField(SourceMlFieldKey);
if (!e.QueryObject.DynamicObjectType.Properties.Contains(SourceMlFieldPropertyName))
{
// 在源单数据包动态实体类型中注册需要携带的多语言字段
e.QueryObject.DynamicObjectType.RegisterLocaleProperty(SourceMlFieldPropertyName, sourceMlField.GetPropertyType(), null, sourceMlField.Entity.PkFieldType);
}
}
///
/// 读取源单数据
/// 可在此事件中填充源单数据包多语言字段
///
///
public override void OnGetSourceData(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.GetSourceDataEventArgs e)
{
base.OnGetSourceData(e);
// 构建查询参数,用于查询源单多语言字段的数据包
var sourceMlField = e.SourceBusinessInfo.GetField(SourceMlFieldKey);
var queryParameter = new OQLFilter();
var soruceIds = string.Empty;
if (e.SourceData.Count == 1)
{
// 源单只有一个
soruceIds = e.SourceData[0][0].ToString();
queryParameter.Add(new OQLFilterHeadEntityItem() { FilterString = "FID=" + soruceIds });
}
else
{
// 源单有多个
soruceIds = string.Join(",", e.SourceData.Select(o => o[0]));
queryParameter.Add(new OQLFilterHeadEntityItem() { FilterString = "FID IN (" + soruceIds + ")" });
}
var selector = new List
selector.Add(new SelectorItemInfo(SourceMlFieldKey));
// 读取源单的多语言字段的数据并填充到源单据数据包
var sourceMlData = BusinessDataServiceHelper.Load(this.Context, e.SourceBusinessInfo.GetForm().Id, selector, queryParameter);
foreach (var obj in sourceMlData)
{
var sourceObj = e.SourceData.FirstOrDefault(o => o[0].Equals(obj[0]));
if (sourceObj != null)
{
sourceObj[SourceMlFieldPropertyName] = obj[sourceMlField.PropertyName];
}
}
}
///
/// 根据字段映射,向目标字段填充值
/// 可在此事件中填充目标单的多语言字段
///
///
public override void OnFieldMapping(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.FieldMappingEventArgs e)
{
base.OnFieldMapping(e);
if (e.TargetField.Key.Equals(TargetMlFieldfKey, StringComparison.OrdinalIgnoreCase))
{
var sourceData = (List
// 如果是单据头字段,直接从源单行集合的首行取值
// 如果是单据体字段,先按分组策略从源单行集合中查找匹配的行,然后再取值
var mlMapValue = sourceData[0][SourceMlFieldPropertyName];
e.ExtendedDataEntity.DataEntity[TargetMlFieldfKey] = mlMapValue;
// 上面已经完成目标单的数据填充,平台内部不再需要填充
e.Cancel = true;
}
}
}
}
[/code]
推荐阅读