实现效果图:
开发精华代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Validation;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.App.Data;
namespace YaTi.K3.SCM.Sal.App.ServicePlugIn.Lskd
{
[Description("控制抵用金额")]
public class KdconAmouofoffset : AbstractOperationServicePlugIn
{
/// <summary>
/// 加载字段,在校验器中使用到的字段都应加载,防止列表与单据内操作异常发生;
/// </summary>
/// <param name="e"></param>
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("FTHEAMOUNTOF");
e.FieldKeys.Add("FBillTypeID");
e.FieldKeys.Add("F_PBKA_Phone");
}
/// <summary>
/// 添加校验器
/// </summary>
/// <param name="e"></param>
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
var operValidator = new OperValidator();//实例化类;
operValidator.AlwaysValidate = true;
operValidator.EntityKey = "FBillHead";
e.Validators.Add(operValidator);
}
/// <summary>
/// 当前操作的校验器
/// </summary>
private class OperValidator : AbstractValidator
{
public override void Validate(Kingdee.BOS.Core.ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Kingdee.BOS.Context ctx)
{
if ((dataEntities != null) && (dataEntities.Length > 0))
{
foreach (Kingdee.BOS.Core.ExtendedDataEntity entity in dataEntities)
{
DynamicObject dataEntity = entity.DataEntity;
decimal Amount = Convert.ToDecimal(dataEntity["FTHEAMOUNTOF"]);//单据积分抵用金额;
string Fbilltypeid = dataEntity["FBillTypeID_Id"].ToString();//单据类型id;
string Ftelphone = dataEntity["F_PBKA_Phone"]==null?"" : dataEntity["F_PBKA_Phone"].ToString();
if (Amount > 0)
{
if (Fbilltypeid == "57faf492b10d31" && Ftelphone != ""&& dataEntity["BillNo"].ToString().IndexOf("LSD") > -1 )//57faf492b10d31标识单据是标准零售单,顾客电话不为空;
{
if (Getdnyn(Ftelphone).Count() <= 0)
{
ValidationErrorInfo info = new ValidationErrorInfo("F_PBKA_Phone", dataEntity["Id"].ToString(), entity.DataEntityIndex, entity.RowIndex, "OperatorPolicy", "顾客手机号不存在会员档案中,请修改正确!", "手机号", Kingdee.BOS.Core.Validation.ErrorLevel.Error);
validateContext.AddError(dataEntity, info);
}
else
if (Amount > Getkdhamount(Ftelphone))
{
ValidationErrorInfo info = new ValidationErrorInfo("FTHEAMOUNTOF", dataEntity["Id"].ToString(), entity.DataEntityIndex, entity.RowIndex, "OperatorPolicy", "输入的抵用金额过大,请修改正确!", "抵用金额", Kingdee.BOS.Core.Validation.ErrorLevel.Error);
validateContext.AddError(dataEntity, info);
}
}
}
}
}
}