操作插件--单据体字段校验
1,103次浏览
编辑于2018年04月03日 14:16:48
[password]123456[/password]
namespace YEA.K3.MFG.ENG.Business.PlugIn.Base
{
[Description("操作插件:物料清单--子项物料+工位唯一")]
public class BomUniqueVerifyOperationPlugin : AbstractOperationServicePlugIn
{
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
AddTreeEntityValidator validator = new AddTreeEntityValidator();
validator.AlwaysValidate = true;
validator.EntityKey = "FTreeEntity";
e.Validators.Add(validator);
}
}
internal class AddTreeEntityValidator : AbstractValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
if (dataEntities == null || dataEntities.Length == 0)
{
return;
}
Dictionary dict = new Dictionary(); //存储比较行
foreach (ExtendedDataEntity entityObj in dataEntities)
{
string station = Convert.ToString(entityObj["F_YEA_STATION"]).Trim(); //工位
if (!string.IsNullOrWhiteSpace(station))
{
string material = Convert.ToString(entityObj["MATERIALIDCHILD_ID"]).Trim(); //子项物料
string value = material + "-" + station;
int key = Convert.ToInt32(entityObj["Seq"]); //序号
dict.Add(key, value);
}
}
var duplicateValues = dict.GroupBy(x => x.Value).Where(x => x.Count() > 1);
foreach (var item in duplicateValues)
{
List keyList = (from q in dict where q.Value == item.Key select q.Key).ToList();
string str = string.Join(",", keyList.ToArray());
foreach (var key in keyList)
{
ValidationErrorInfo errorinfo = new ValidationErrorInfo(
"", "", 0, 0, key.ToString(),
"BOM版本为\"" + dataEntities[0].BillNo + "\"的物料清单,子项明细的" + str + "行工位重复,请检查。",
"工位"
);
validateContext.AddError(dataEntities, errorinfo);
}
}
}
}
}
namespace YEA.K3.MFG.ENG.Business.PlugIn.Base
{
[Description("操作插件:物料清单--子项物料+工位唯一")]
public class BomUniqueVerifyOperationPlugin : AbstractOperationServicePlugIn
{
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
AddTreeEntityValidator validator = new AddTreeEntityValidator();
validator.AlwaysValidate = true;
validator.EntityKey = "FTreeEntity";
e.Validators.Add(validator);
}
}
internal class AddTreeEntityValidator : AbstractValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
if (dataEntities == null || dataEntities.Length == 0)
{
return;
}
Dictionary
foreach (ExtendedDataEntity entityObj in dataEntities)
{
string station = Convert.ToString(entityObj["F_YEA_STATION"]).Trim(); //工位
if (!string.IsNullOrWhiteSpace(station))
{
string material = Convert.ToString(entityObj["MATERIALIDCHILD_ID"]).Trim(); //子项物料
string value = material + "-" + station;
int key = Convert.ToInt32(entityObj["Seq"]); //序号
dict.Add(key, value);
}
}
var duplicateValues = dict.GroupBy(x => x.Value).Where(x => x.Count() > 1);
foreach (var item in duplicateValues)
{
List
string str = string.Join(",", keyList.ToArray());
foreach (var key in keyList)
{
ValidationErrorInfo errorinfo = new ValidationErrorInfo(
"", "", 0, 0, key.ToString(),
"BOM版本为\"" + dataEntities[0].BillNo + "\"的物料清单,子项明细的" + str + "行工位重复,请检查。",
"工位"
);
validateContext.AddError(dataEntities, errorinfo);
}
}
}
}
}
推荐阅读