填充单据体的几各种方式原创
金蝶云社区-湖南客户成功吴双得
湖南客户成功吴双得
112人赞赏了该文章 802次浏览 未经作者许可,禁止转载编辑于2023年10月27日 11:25:47

目前用到的几中填充单据体的方式
一、表单插件 SetValue 方式

image.png

Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
            DynamicObjectCollection entityDataObject = this.Model.GetEntityDataObject(entity);
            this.Model.DeleteEntryData("FEntity");
            int i = this.Model.GetEntryRowCount("FEntity") - 1;
            foreach (DynamicObject dydata in docData)
            {
                // 单据体增加新行,并更新行索引
                this.Model.SetEntryCurrentRowIndex("FEntity", i);
                this.Model.SetValue("FSeq", i);
                this.Model.SetItemValueByID("FMaterialID2", dydata["FMaterialID"], i);
                this.View.InvokeFieldUpdateService("FMaterialID2", i);//触发字段值更新,单据头字段行号填0
                this.Model.SetItemValueByID("FLot", dydata["F_Lot"], i);
                this.View.InvokeFieldUpdateService("FLot", i);//触发字段值更新,单据头字段行号填0
                this.Model.SetValue("FNumerator", dydata["FQty"], i);
                this.View.InvokeFieldUpdateService("FNumerator", i);//触发字段值更新,单据头字段行号填0
                this.Model.CreateNewEntryRow("FEntity");

                i++;
            }
            this.View.UpdateView("FEntity");

二、实体填充 ,可用于表单插件(感觉性能好些)、服务插件

        private void FillEntityData(DynamicObjectCollection retDatas, string entityKey)
        {
            if (retDatas != null && retDatas.Count() > 0)
            {
                //回写计划用料清单
                Entity entity = this.Model.BusinessInfo.GetEntity(entityKey);
                DynamicObjectCollection entityData = this.Model.GetEntityDataObject(entity);
                entityData.Clear();
                int i = 0;
                foreach (DynamicObject dyData in retDatas)
                {   //每一行的值定义成 DynamicObject类型
                    DynamicObject row = new DynamicObject(entity.DynamicObjectType);
                    //通过 SeqDynamicProperty 设置序号
                    entity.SeqDynamicProperty.SetValue(row, i + 1);
                    //对实体赋值
                    row["F_paez_zxwlbm_Id"] = dyData["FSubMaterial_Id"];
                    row["F_paez_kcdw_Id"] = dyData["FUnitID_Id"];
                    row["F_paez_BaseUnitID_Id"] = dyData["F_paez_BaseUnitID_Id"];
                    row["F_paez_dwyl"] = dyData["FQty"];
                    entityData.Add(row);
                    i++;
                }
                //加载全部基础资料字段 的 DynamicObject对象,便于页面显示 
                DBServiceHelper.LoadReferenceObject(this.Context, entityData.ToArray<DynamicObject>(), entityData.DynamicCollectionItemPropertyType, false);
                this.View.UpdateView(entityKey);
            }
        }

特殊说明:
1、分录序号。  

 entity.SeqDynamicProperty.SetValue(row, i + 1);

2、通过 ID 加载基础资料字段  DynamicObject 数据包,用于表单插件显示 。 最后参考 用 false。或实际确认

DBServiceHelper.LoadReferenceObject(this.Context, entityData.ToArray<DynamicObject>(), entityData.DynamicCollectionItemPropertyType, false);


三、操作插件构建 单据视图 使用 SetValue

            foreach (var billDynObjEx in billDynObjExs)
            {
                string fromId = e.TargetBusinessInfo.GetForm().Id;
                if (!fromId.Equals("AR_RECEIVEBILL"))
                    return;
                //创建目标单据视图
                var tView = CreateView(fromId);
                //单个单据数据包
                var billDynObj = billDynObjEx.DataEntity;
                //给模型设置数据包
                tView.Model.DataObject = billDynObj;

                DynamicObjectCollection docSrcEntry = billDynObj["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection;
                int row = 0;
                foreach(DynamicObject dySrcEntry in docSrcEntry)
                {
                    tView.Model.CreateNewEntryRow("FRECEIVEBILLENTRY");
                    long SRCSETTLETYPEID_Id = System.Convert.ToInt64(dySrcEntry["SRCSETTLETYPEID_Id"]);
                    decimal REALRECAMOUNT = System.Convert.ToDecimal(dySrcEntry["REALRECAMOUNT"]);
                    string srcMyBankAcc = dySrcEntry["FSRCMyBankAcct"].ToString();
                    string srcOtherBankAcc = dySrcEntry["FSRCOtherBankAcct"].ToString();
                    tView.Model.SetValue("FPURPOSEID", SRCSETTLETYPEID_Id, row);
                    tView.Model.SetValue("FPURPOSEID", 20010, row);
                    row++;
                }
            }
        private Kingdee.BOS.Core.DynamicForm.IDynamicFormView CreateView(string formId)
        {
            FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId);
            var OpenParameter = CreateOpenParameter(this.Context, metadata);
            var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true);
            string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web";
            Type type = Type.GetType(importViewClass);
            Kingdee.BOS.Core.DynamicForm.IDynamicFormView view = (Kingdee.BOS.Core.DynamicForm.IDynamicFormView)Activator.CreateInstance(type);
            ((Kingdee.BOS.Core.DynamicForm.IDynamicFormViewService)view).Initialize(OpenParameter, Provider);
            return view;
        }


总结:总体来说就是 实体赋值或页面赋值,个人应用发现是 实体赋值 性能好些,页面赋值 可以有值更新等 方便些。


对于方便与性能,或不到之处,欢迎大家斧正!!

赞 112