仓位插件赋值-学习笔记
仓位的使用方式 :【仓位数据查询-学习笔记】
值集组合方式
非组合值方式
插件
表单插件
单据转换插件
服务端插件
一、BOS配置实现
【仓库设置默认仓位】
物料设置默认仓库仓位,物料值更新配置服务"携带相关基础资料到指定列",对仓位进行赋值
局限性:只能指定默认值,无法运用复杂的判断逻辑,不同场景赋值不同的仓库仓位
二、二开插件
1、表单插件 + 值集组合方式
说明:需知道仓位的组合内码 SELECT * FROM T_BAS_FLEXVALUESDETAIL
RelatedFlexGroupField stockLocField = this.View.BusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; DynamicObject dyRow = this.View.Model.GetEntityDataObject(stockLocField.Entity)[e.Row]; // 清空仓位 stockLocField.DynamicProperty.SetValue(dyRow, null); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 0); var stockLoc = BusinessDataServiceHelper.LoadFromCache(this.View.Context, new object[] { "100009" }, stockLocField.RefFormDynamicObjectType); stockLocField.DynamicProperty.SetValue(dyRow, stockLoc[0]); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 100009); this.View.UpdateView("FStockLocId", e.Row);
2、表单插件 + 非值集组合方式
说明:
仓库的仓位值集下没有设置对应仓位值,可以选择任意的仓位值
此时并未生成仓位内码,需要构造仓位字段的数据包,给单据的数据包赋值,然后单据保存之后会自动生成内码
保存时,可以看到仓位的数据包包含两个FLEXVALUESY,即仓位值数据包,可以理解为模拟页面选择仓位值维度
RelatedFlexGroupField stockLocField = this.View.BusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; DyxnamicObject dyRow = this.View.Model.GetEntityDataObject(stockLocField.Entity)[e.Row]; // 清空仓位(标准单据单据体配置有实体服务规则,仓库改变会清空仓位,这里需要把这个设置取消,否则插件赋值后,又被实体服务规则清空,导致没有赋值效果) stockLocField.DynamicProperty.SetValue(dyRow, null); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 0); Dictionary<string, long> dctFlexItemIds = new Dictionary<string, long>(); dctFlexItemIds.Add("FF100001", 100002); // 仓位值集Key - 仓位值内码 dctFlexItemIds.Add("FF100002", 100023); // 仓位值集Key - 仓位值内码 // 新建仓位值属性数据包,用来存储各维度值 DynamicObject stockLocObj = new DynamicObject(stockLocField.RefFormDynamicObjectType); foreach (var flexItem in dctFlexItemIds) { Field fldFlex = stockLocField.RelateFlexBusinessInfo.GetField(flexItem.Key); BaseDataField fldBDTypeFlex = fldFlex as BaseDataField; IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); DynamicObject[] flexItemObjs = viewService.LoadFromCache(this.Context, new object[] { flexItem.Value }, fldBDTypeFlex.RefFormDynamicObjectType); fldBDTypeFlex.RefIDDynamicProperty.SetValue(stockLocObj, flexItem.Value); fldBDTypeFlex.DynamicProperty.SetValue(stockLocObj, flexItemObjs[0]); } stockLocField.DynamicProperty.SetValue(dyRow, stockLocObj); var obj = SaveFlexObject(this.Context, stockLocObj); long flexDataId = Convert.ToInt64(obj[0]); stockLocField.RefIDDynamicProperty.SetValue(dyRow, flexDataId); this.View.UpdateView("FStockLocId", e.Row); public static DynamicObject SaveFlexObject(Context ctx, DynamicObject flexData) { var seqReader = new SequenceReader(ctx); var businessDataService = new BusinessDataService(); seqReader.AutoSetPrimaryKey(new[] { flexData }, flexData.DynamicObjectType); return businessDataService.Save(ctx, new[] { flexData })[0]; }
3、单据转换插件 + 值集组合方式
单据转换中采用表达服务策略对仓位的赋值无效
说明:需知道仓位的组合内码 SELECT * FROM T_BAS_FLEXVALUESDETAIL
public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e) { IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); var dataObjs = e.Result.FindByEntityKey("FBillHead"); foreach (var obj in dataObjs) { DynamicObjectCollection entrys = obj.DataEntity["BillEntry"] as DynamicObjectCollection; RelatedFlexGroupField stockLocField = e.TargetBusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; foreach (DynamicObject entry in entrys) { var stockLoc = BusinessDataServiceHelper.LoadFromCache(this.Context, new object[] { "100009" }, stockLocField.RefFormDynamicObjectType); stockLocField.DynamicProperty.SetValue(entry, stockLoc[0]); stockLocField.RefIDDynamicProperty.SetValue(entry, 100009); } } }
4、单据转换插件 + 非值集组合方式
说明:类似于2中表单插件 + 非值集组合方式的处理方式
public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e) { IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); var dataObjs = e.Result.FindByEntityKey("FBillHead"); foreach (var obj in dataObjs) { DynamicObjectCollection entrys = obj.DataEntity["BillEntry"] as DynamicObjectCollection; RelatedFlexGroupField stockLocField = e.TargetBusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; foreach (DynamicObject entry in entrys) { Dictionary<string, long> dctFlexItemIds = new Dictionary<string, long>(); dctFlexItemIds.Add("FF100001", 100002); // 仓位值集Key - 仓位值内码 dctFlexItemIds.Add("FF100002", 100023); // 仓位值集Key - 仓位值内码 DynamicObject stockLocObj = new DynamicObject(stockLocField.RefFormDynamicObjectType); foreach (var flexItem in dctFlexItemIds) { Field fldFlex = stockLocField.RelateFlexBusinessInfo.GetField(flexItem.Key); BaseDataField fldBDTypeFlex = fldFlex as BaseDataField; IViewService viewService1 = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); DynamicObject[] flexItemObjs = viewService1.LoadFromCache(this.Context, new object[] { flexItem.Value }, fldBDTypeFlex.RefFormDynamicObjectType); fldBDTypeFlex.RefIDDynamicProperty.SetValue(stockLocObj, flexItem.Value); fldBDTypeFlex.DynamicProperty.SetValue(stockLocObj, flexItemObjs[0]); } stockLocField.DynamicProperty.SetValue(entry, stockLocObj); var obj = SaveFlexObject(this.Context, stockLocObj); long flexDataId = Convert.ToInt64(obj[0]); stockLocField.RefIDDynamicProperty.SetValue(entry, flexDataId); } } } public static DynamicObject SaveFlexObject(Context ctx, DynamicObject flexData) { var seqReader = new SequenceReader(ctx); var businessDataService = new BusinessDataService(); seqReader.AutoSetPrimaryKey(new[] { flexData }, flexData.DynamicObjectType); return businessDataService.Save(ctx, new[] { flexData })[0]; }
参考:
仓位这方面,可以当官方资料了
有用,Mark收藏
仓位插件赋值-学习笔记
仓位的使用方式 :【仓位数据查询-学习笔记】值集组合方式非组合值方式插件表单插件单据转换插件服务端插件一、BOS配置实现【仓库设置默认...
点击下载文档
上一篇:系统对接-数据库共享下一篇:【汇总】星空PLM二开指南(持续更新...)
本文2024-09-16 17:17:28发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14757.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章