二开样例:BOM子项唯一性校验原创
3人赞赏了该文章
519次浏览
编辑于2021年08月09日 14:59:29
物料清单保存时,校验子项物料是否重复,插件代码样例如下:
using Kingdee.BOS.Orm.DataEntity; using Kingdee.K3.Core.MFG.EntityHelper; using Kingdee.K3.MFG.App.ServiceValidator; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Kd.Test.validator { public class BomChildUniqueVdt : AbstractMfgServiceValidator { public override void Validate(Kingdee.BOS.Core.ExtendedDataEntity[] dataEntities, Kingdee.BOS.Core.Validation.ValidateContext validateContext, Kingdee.BOS.Context ctx) { base.Validate(dataEntities, validateContext, ctx); foreach (var exDataEntity in dataEntities) { DynamicObjectCollection dataEntity = exDataEntity.DataEntity.GetDynamicValue<DynamicObjectCollection>("TreeEntity"); //BOM子项明细按物料编码分组 var childMtrlId = dataEntity.Where(w => w.GetDynamicValue<string>("MATERIALTYPE") == "1") .GroupBy(g => g.GetDynamicValue<long>("MATERIALIDCHILD_ID")).ToList(); StringBuilder errMsg = new StringBuilder(); foreach (var mtrlGroup in childMtrlId) { //分组数量大于1即子项不唯一 if (mtrlGroup.Count() > 1) { string mtrlName = mtrlGroup.First().GetDynamicValue<DynamicObject>("MATERIALIDCHILD").GetDynamicValue<string>("Name"); string seq = string.Empty; foreach (var item in mtrlGroup) { seq += item.GetDynamicValue<int>("Seq") + ","; } errMsg.AppendLine(string.Format("第{0}行物料{1}重复", seq, mtrlName)); } } if (errMsg.Length > 0) { this.vContext.AddError(exDataEntity.DataEntity, exDataEntity.DataEntityIndex, errMsg.ToString(), this.OperationName); } } } } public class BomSaveExt : AbstractOperationServicePlugIn { public override void OnAddValidators(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.AddValidatorsEventArgs e) { base.OnAddValidators(e); e.Validators.Add(new BomChildUniqueVdt() { EntityKey = "FBillHead", TimingPointString = ",Save," }); } } }
推荐阅读