1、由于在BOS设计器中配置校验不生效,目前该校验只能通过二开插件实现
2、具体步骤如下:
2.1、在保存操作上二开一个插件:获取子项物料的辅助属性,根据子项物料的辅助属性是否启用 + 工程变更单明细行上的辅助属性是否有值 + 行标识为新增或者修改后,判断物料启用辅助属性,辅助属性必录。如图所示:
2.2、保存插件具体二开实现:
(1) 二开插件继承:AbstractMfgOperationPlugIn,重写OnAddValidators:增加一个校验插件IsAuxPropMustInputValidator
(2)实现校验器IsAuxPropMustInputValidator:继承AbstractMfgServiceValidator,重写Validate
(3)组件引用:
3、具体的代码可见(供参考):
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.MFG.App.ServicePlugIn;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS;
using Kingdee.K3.MFG.App;
using Kingdee.BOS.Util;
using System.Data;
using Kingdee.BOS.App.Data;
using Kingdee.K3.MFG.App.ServiceValidator;
using Kingdee.BOS.Core;
namespace Kingdee.K3.MFG.ENG.EK.App.ServicePlugIn.ECN.Validator
{
/// <summary>
/// 校验:物料启用辅助属性,则辅助属性必录
/// </summary>
[Description("校验物料启用辅助属性,则辅助属性必录")]
public class IsAuxPropMustInputValidator : AbstractMfgServiceValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, BOS.Core.Validation.ValidateContext validateContext, Context ctx)
{
if (dataEntities.IsEmpty()) return;
base.Validate(dataEntities, validateContext, ctx);
foreach (ExtendedDataEntity item in dataEntities)
{
DynamicObject billData = item.DataEntity;
DynamicObjectCollection entryDatas = billData.GetDynamicValue<DynamicObjectCollection>("TreeEntity");
string msg = string.Empty;
bool isValidate = false;
StringBuilder sbErrMsg = new StringBuilder();
foreach (DynamicObject entryData in entryDatas)
{
//获取子项物料数据包
DynamicObject materilIdChild = entryData.GetDynamicValue<DynamicObject>("MATERIALIDCHILD");
if (materilIdChild.IsNullOrEmpty()) continue;
DynamicObjectCollection materialAuxPty = materilIdChild.GetDynamicValue<DynamicObjectCollection>("MaterialAuxPty");
if (materialAuxPty.IsEmpty()) continue;
long auxPropId = entryData.GetDynamicValue<long>("AuxPropId_Id");
string changeLabel = entryData.GetDynamicValue<string>("ChangeLabel");
if ((changeLabel =="1" || changeLabel =="2") && materialAuxPty.Any(f => f.GetDynamicValue<bool>("IsEnable1")) && auxPropId == 0)
{
int seq = entryData.GetDynamicValue<int>("Seq");
msg += seq + ",";
isValidate = true;
}
}
sbErrMsg.Append(string.Format("明细行{0}的子项物料启用了辅助属性,但辅助属性未录入值,无法进行保存操作", msg.TrimEnd(',')));
if (isValidate)
{
this.vContext.AddError(
billData,
item.DataEntityIndex,
sbErrMsg.ToString(),
this.OperationName);
}
}
}
}
}