操作插件中的校验器里获取分录
金蝶云社区-李超身份
李超
0人赞赏了该文章 875次浏览 未经作者许可,禁止转载编辑于2016年11月14日 22:24:17

标红的两种写法都是错的,请问应该如何写呢?
另外单据的基础资料属性为什么我在OnPreparePropertys中加了,但是在 DataEntity里依然没有呢?请赐教:handshake
[code]


[/code]

[Description("物料清单保存校验")]
public class Save : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("MATERIALTYPE");
e.FieldKeys.Add("F_gg_IsConvertTo100");

}
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
CheckSonMatIsRight SonMatvalidator = new CheckSonMatIsRight();
SonMatvalidator.EntityKey = "FTreeEntity";
e.Validators.Add(SonMatvalidator);
}

}
internal class CheckSonMatIsRight : AbstractValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
if (dataEntities == null || dataEntities.Length == 0)
{
return;
}
bool isHavaeConvert100Mat =false ;
int MATERIALTYPE4=0;
int MATERIALTYPE5=0;
int MATERIALTYPE6=0;
//检查是否包含折百物料

foreach(ExtendedDataEntity entityObj in dataEntities)
{
// DynamicObjectCollection collection = (DynamicObjectCollection)entityObj["DataEntity"];
DynamicObjectCollection collection = (DynamicObjectCollection)entityObj["TreeEntity"];
foreach(var row in collection)
{
if (row["F_gg_IsConvertTo100"].ToString() == "1")
{
isHavaeConvert100Mat=true;
}
switch ((int)row["MATERIALTYPE"])
{
default:
break;
case 4:
MATERIALTYPE4++;
break;
case 5:
MATERIALTYPE5++;
break;
case 6:
MATERIALTYPE6++;
break;
}

}

}
//有折百物料的情况下,遍历分录,检查并记录子项物料类型为456的行的数量
if(isHavaeConvert100Mat)
{
}
if(MATERIALTYPE4<1||MATERIALTYPE5<1||MATERIALTYPE6!=1)
{
ValidationErrorInfo errorinfo= new ValidationErrorInfo(
"",
"", 0, 0,
"001",
"有折百含量物料的情况下,主料和助剂不能少与1种,并且填充料必须是1钟。",
"BOM配置不合规,请按要求调整"
);
validateContext.AddError(dataEntities, errorinfo);
}
}
}