单据转换-单据体携带多选基础资料字段
上篇文章是携带单据头多选基础资料字段,下面介绍单据转换-单据体携带多选基础资料字段,代码如下:
```
/// <summary>
/// 单据从源单到目标单已经转换完毕,输出最后的目标单数据包之前触发,
/// 此时,目标单数据包已经构建完毕,不会再有变动了
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// 可以在此事件中,对目标单数据包进行最后的修订、补充
/// </remarks>
public override void AfterConvert(AfterConvertEventArgs e)
{
base.AfterConvert(e);
string TgtFieldKey = "FCESHI1";
string SrcFieldKey = "FCESHI2";
/*
* <0>数据准备
*/
MulBaseDataField tgtBaseDataField = e.TargetBusinessInfo.GetField(TgtFieldKey) as MulBaseDataField;
MulBaseDataField srcBaseDataField = e.SourceBusinessInfo.GetField(SrcFieldKey) as MulBaseDataField;
if (tgtBaseDataField == null || srcBaseDataField == null)
return;
Func<Kingdee.BOS.Orm.DataEntity.DynamicObject, Kingdee.BOS.Orm.DataEntity.DynamicObject> loadSrcRowObj = (srcRow) =>
{
long pkId = ObjectUtils.Object2Int64(srcRow[e.SourceBusinessInfo.GetForm().PkFieldName]);
Kingdee.BOS.Orm.DataEntity.DynamicObject srcObj = LoadSrcBills(e, pkId, SrcFieldKey);
if (srcObj == null)
return null;
string entryKey = string.Format("{0}_{1}", srcBaseDataField.EntityKey, srcBaseDataField.Entity.EntryPkFieldName);
int entryId = ObjectUtils.Object2Int(srcRow[entryKey]);
Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection entityObjs = srcObj[srcBaseDataField.Entity.EntryName] as Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection;
if (entityObjs == null)
return null;
foreach (var entityRow in entityObjs)
{
if (ObjectUtils.Object2Int(entityRow[0]) == entryId)
{
return entityRow;
}
}
return null;
};
Dictionary<object, Kingdee.BOS.Orm.DataEntity.DynamicObject> baseDataObjCache = new Dictionary<object, Kingdee.BOS.Orm.DataEntity.DynamicObject>();
/*
* <1>根据下游单据的数据包,和源单信息,填入多选基础资料
*/
Entity tgtEntity = tgtBaseDataField.Entity;
var targetEntityObjs = e.Result.FindByEntityKey(tgtEntity.Key);
for (int i = 0, sz = targetEntityObjs.Length; i < sz; ++i)
{
var tgtEntityRow = targetEntityObjs[i];
if (tgtEntityRow.DataEntity == null)
continue;
//获取当前目标行的源单数据集合
var sourceRows = tgtEntityRow["ConvertSource"] as List<Kingdee.BOS.Orm.DataEntity.DynamicObject>;
if (sourceRows == null)
continue;
foreach (var srcRow in sourceRows)
{
var srcRowObj = loadSrcRowObj(srcRow);
if (srcRowObj == null)
continue;
//获取源行的多选基础资料
var srcMulBaseData = srcRowObj[srcBaseDataField.PropertyName] as Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection;
if (srcMulBaseData == null || srcMulBaseData.Count <= 0)
continue;
//构造目标单的多选基础资料
Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection tgtMulBaseData = tgtEntityRow.DataEntity[tgtBaseDataField.RefEntityDynamicProperty] as Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection;
if (tgtMulBaseData == null)
{
tgtMulBaseData = new Kingdee.BOS.Orm.DataEntity.DynamicObjectCollection(tgtBaseDataField.RefEntityDynamicObjectType, tgtEntityRow.DataEntity);
tgtEntityRow.DataEntity[tgtBaseDataField.RefEntityDynamicProperty] = tgtMulBaseData;
}
foreach (var srcBaseData in srcMulBaseData)
{
if (srcBaseData == null)
continue;
/*
* 引用属性不一样,重新加载数据
*/
object srcBaseDataId = ((Kingdee.BOS.Orm.DataEntity.DynamicObject)srcBaseData[srcBaseDataField.PropertyName])[0];
if (!baseDataObjCache.ContainsKey(srcBaseDataId))
{
baseDataObjCache[srcBaseDataId] = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Load(this.Context, new object[] { srcBaseDataId }, tgtBaseDataField.RefFormDynamicObjectType)[0];
}
Kingdee.BOS.Orm.DataEntity.DynamicObject tgtBaseDataObjRow = new Kingdee.BOS.Orm.DataEntity.DynamicObject(tgtBaseDataField.RefEntityDynamicObjectType);
tgtBaseDataObjRow[tgtBaseDataField.RefIDDynamicProperty] = srcBaseDataId;
tgtBaseDataObjRow[tgtBaseDataField.DynamicProperty] = baseDataObjCache[srcBaseDataId];
tgtMulBaseData.Add(tgtBaseDataObjRow);
}
}
}
}
老师你好,我想获取单据类型对应的值 怎么操作?请大神指点一下
单据转换-单据体携带多选基础资料字段
上篇文章是携带单据头多选基础资料字段,下面介绍单据转换-单据体携带多选基础资料字段,代码如下:``` /// <summary> ...
点击下载文档
本文2024-09-16 17:13:20发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14316.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章