需要引入的dll
Kingdee.BOS.Core.dll
Kingdee.BOS.ServiceHelper.dll
注意:BusinessInfo,在Kingdee.BOS.Core.Metadata.FormElement; 在验证类AbstractValidator是不存在相应方法的
这里贴出自己的代码备忘:
using System;
using System.Collections.Generic;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Validation;
using System.ComponentModel;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Log;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.ServiceHelper;
namespace Kingdee.BOS.WillFillInNetWeight
{
[Description("检验单净重字段必填校验插件")]
public class InspectionSheet: AbstractOperationServicePlugIn
{
/// <summary>
/// 优先加载字段
/// </summary>
/// <param name="e"></param>
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("FSupplierId");
e.FieldKeys.Add("FNetWeight");
}
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
InspectionSheetValidators inspectionSheetValidators = new InspectionSheetValidators(this.BusinessInfo.GetForm());
inspectionSheetValidators.AlwaysValidate = true;
inspectionSheetValidators.EntityKey = "FEntity";
e.Validators.Add(inspectionSheetValidators);
}
private class InspectionSheetValidators : AbstractValidator
{
private Form form;
public InspectionSheetValidators(Form form)
{
this.form = form;
}
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
if (dataEntities!=null)
{
List<LogObject> logs = new List<LogObject>();
foreach(ExtendedDataEntity obj in dataEntities)
{
if (Convert.ToInt32(obj.DataEntity["SupplierId_Id"]) !=0) {
string sql = string.Format(@"/*dialect*/SELECT *FROM T_BD_SUPPLIER WHERE FSUPPLIERID={0}", Convert.ToInt32(obj.DataEntity["SupplierId_Id"]));
DynamicObjectCollection doc = DBUtils.ExecuteDynamicObject(this.Context, sql);
DynamicObject dyo = doc[0];
if (Convert.ToInt32(dyo["F_AI_JHJJJGYS"])==1)
{
if (Convert.ToDouble(obj.DataEntity["FNetWeight"])==0)
{
validateContext.AddError(
obj.DataEntity,
new ValidationErrorInfo(
"FNetWeight",
obj.DataEntity["Id"].ToString(),
obj.DataEntityIndex,
obj.RowIndex,
"ALAOK00002000",
"单据" + obj.BillNo + "第" + (obj.RowIndex + 1) + "行,净重字段必填",
"审核:" + obj.BillNo,
ErrorLevel.Error
)
);
}
else
{
//为机加供应商,净重字段不为0,看物料净重字段是否为0,为0更新
string selectSql = string.Format(@"/*dialect*/SELECT *FROM t_BD_MaterialBase WHERE FMATERIALID={0}", Convert.ToInt32(obj.DataEntity["MaterialId_Id"]));
DynamicObjectCollection docs = DBUtils.ExecuteDynamicObject(this.Context, selectSql);
DynamicObject dyos = docs[0];
if (Convert.ToInt32(dyos["FNETWEIGHT"])==0)
{
string updateSql=string.Format(@"/*dialect*/UPDATE T_BD_MATERIALBASE SET FNETWEIGHT={0} FROM T_BD_MATERIALBASE A INNER JOIN (SELECT *FROM T_BD_MATERIAL WHERE FNUMBER=(SELECT FNUMBER FROM T_BD_MATERIAL WHERE FMATERIALID={1}))B ON(A.FMATERIALID=B.FMATERIALID)", Convert.ToDouble(obj.DataEntity["FNetWeight"]), Convert.ToInt32(obj.DataEntity["MaterialId_Id"]));
int updateNum=DBUtils.Execute(this.Context, updateSql);
if (updateNum>0)
{
LogObject log = new LogObject();
log.pkValue = dyos.ToString();
var Material = obj.DataEntity["MaterialId"] as DynamicObject;
log.Description = obj.BillNo + "审核,更新物料" + Material["Number"] + "净重成功";
log.OperateName = "更新物料净重";
log.ObjectTypeId = this.form.Id;
log.SubSystemId = this.form.SubsysId;
log.Environment = OperatingEnvironment.BizOperate;
logs.Add(log);
}
}
}
}
}
}
LogServiceHelper.BatchWriteLog(this.Context, logs);
}
}
}
}
}
推荐阅读