文章目录
- 金蝶云星空自定义校验器和使用
金蝶云星空自定义校验器和使用
1、创建类,并继承抽象接口
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Validation;
using System;namespace mm.K3.SCM.App.Service.PlugIn.SC.Validator
{public class AfterOrderCheckOtherBillValidator : AbstractValidator{}
}
2、重写抽象方法,对指定的数据进行校验
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Kingdee.BOS.Context ctx){throw new NotImplementedException();foreach (ExtendedDataEntity dyn in dataEntities){string billNo = dyn["BillNo"] + "";long fid = Convert.ToInt64(dyn["Id"]);//单FID//异常信息string _errorMsg = string.Empty;#region//逻辑处理,不符合条件就把异常信息汇总到 _errorMsg#endregionerrorLable:if (!string.IsNullOrEmpty(_errorMsg)){string titleInfo = string.Format("售后单-反审核");ValidationErrorInfo errorInfo = new ValidationErrorInfo(string.Empty, fid.ToString(), dyn.DataEntityIndex, dyn.RowIndex, fid.ToString(),_errorMsg, titleInfo, ErrorLevel.Error);validateContext.AddError(dyn, errorInfo);}}}
3、服务端操作插件注册校验器
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;
using mm.K3.SCM.App.Service.PlugIn.SC.Validator;
using System.ComponentModel;namespace mm.K3.SCM.App.Service.PlugIn.SC
{[Description("售后单-反审核"), HotUpdate]public class AfterOrderUnAudit : AbstractOperationServicePlugIn{public override void OnAddValidators(AddValidatorsEventArgs e){AfterOrderCheckOtherBillValidator validator = new AfterOrderCheckOtherBillValidator(){AlwaysValidate = true,EntityKey = "FBillHead"};e.Validators.Add(validator);}}
}
4、验证校验器