二开--实现单据转换配置携带多选基础资料

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

二开--实现单据转换配置携带多选基础资料

 /// <summary>
        /// 单据从源单到目标单已经转换完毕,输出最后的目标单数据包之前触发,
        /// 此时,目标单数据包已经构建完毕,不会再有变动了
        /// </summary>
        /// <param name="e"></param>
        /// <remarks>
        /// 可以在此事件中,对目标单数据包进行最后的修订、补充
        /// </remarks>
        public override void AfterConvert(AfterConvertEventArgs e)
        {
            base.AfterConvert(e);
                string tgtFieldKey = "Ftest1";
                string srcFieleKey = "Ftest2";
                if (e.Result == null)
                    return;
                /*
                 * <0>仅支持单据头到单据头,其他自行处理
                 */

                MulBaseDataField tgtBaseDataField = e.TargetBusinessInfo.GetField(tgtFieldKey) as MulBaseDataField;
                MulBaseDataField srcBaseDataField = e.SourceBusinessInfo.GetField(srcFieleKey) as MulBaseDataField;

                if (tgtBaseDataField == null || srcBaseDataField == null)
                    return;
                if (tgtBaseDataField.Entity.ElementType != Kingdee.BOS.Core.Metadata.ElementMetadata.ElementType.ELEMENTTYPE_BILLHEAD)
                    return;
                if (srcBaseDataField.Entity.ElementType != Kingdee.BOS.Core.Metadata.ElementMetadata.ElementType.ELEMENTTYPE_BILLHEAD)
                    return;
                /*
                 * <1>收集源单内码批量获取
                 */
                Entity tgtEntity = tgtBaseDataField.Entity;
                var targetEntityObjs = e.Result.FindByEntityKey(tgtEntity.Key);
                HashSet<object> srcPkIds = new HashSet<object>();
                for (int i = 0, sz = targetEntityObjs.Length; i < sz; ++i)
                {
                    var targetEntityRow = targetEntityObjs[i];
                    if (targetEntityRow.DataEntity == null)
                        continue;
                    //获取当前目标行的源单数据集合
                    var sourceEntityObjs = targetEntityRow["ConvertSource"] as List<Kingdee.BOS.Orm.DataEntity.DynamicObject>;
                    if (sourceEntityObjs == null)
                        continue;
                    foreach (var sourceObj in sourceEntityObjs)
                    {
                        if (sourceObj == null)
                            continue;
                        srcPkIds.Add(sourceObj[0]);
                    }
                }
                //<2>加载源单多选基础资料,这个地方由于是单据头可以直接取数
                List<string> loadFields = new List<string>() { srcFieleKey };
                Kingdee.BOS.Core.Metadata.BusinessInfo subBusinessInfo = e.SourceBusinessInfo.GetSubBusinessInfo(loadFields);
                var srcBillObjs = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Load(this.Context, srcPkIds.ToArray(), subBusinessInfo.GetDynamicObjectType());
                var srcBillObjsMap = srcBillObjs.ToDictionary((x) => { return x[0]; });
                Dictionary<object, Kingdee.BOS.Orm.DataEntity.DynamicObject> baseDataObjCache = new Dictionary<object, Kingdee.BOS.Orm.DataEntity.DynamicObject>();
                /*
                 * <3>将源单数据写到下游单据
                 */
                for (int i = 0, sz = targetEntityObjs.Length; i < sz; ++i)
                {
                    var tgtEntityRow = targetEntityObjs[i];
                    if (tgtEntityRow.DataEntity == null)
                        continue;
                    //获取当前目标行的源单数据集合
                    var sourceEntityObjs = tgtEntityRow["ConvertSource"] as List<Kingdee.BOS.Orm.DataEntity.DynamicObject>;
                    if (sourceEntityObjs == null)
                        continue;
                    //获取多选基础资料的数据
                    object srcPk = sourceEntityObjs[0][0];
                    var srcBillObj = srcBillObjsMap[srcPk];
                    var srcMulBaseData = srcBillObj[srcBaseDataField.Key] 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.Key])[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> /// 单据从源单到目标单已经转换完毕,输出最后的目标单数据包之前触发, /// 此时,目标单数据包已经构建完...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息