检验单样本检测值表体检验值必录校验二开方案
方案整体思路:检验单保存操作上增加二开插件,挂在标准产品保存插件之后,插件中添加校验器,逻辑如下:如果检验单对应的单据类型中未启用样本检测值检验则不校验;如果对应的检验项目的样本量为0则不校验,其余情况下根据检验项目的分析方法校验样本检测值表体对应的检测值是否全部录入,未全部录入则不允许保存;
示例代码如下:
using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Validation;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.Core.MFG;
using Kingdee.K3.Core.MFG.EnumConst;
using Kingdee.K3.MFG.App;
using Kingdee.K3.MFG.App.ServicePlugIn;
using Kingdee.K3.MFG.App.ServiceValidator;
using System; using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS.Util;
namespace Kingdee.K3.MFG.QM.App.ServicePlugIn.InspectBill
{
public class testSave : AbstractMfgOperationPlugIn
{
public override void OnAddValidators(BOS.Core.DynamicForm.PlugIn.Args.AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
//样本检测值必录校验
e.Validators.Add(new InspectValueMustInputValidator()
{
EntityKey = CONST_QM_InspectBill.CONST_FBillHead.ENTITY_FBillHead,
TimingPointString = ",Save,",
Option = this.Option,
});
}
}
public class InspectValueMustInputValidator : AbstractMfgServiceValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
base.Validate(dataEntities, validateContext, ctx);
foreach (ExtendedDataEntity dataEntity in dataEntities)
{
string billTypeId = Convert.ToString(dataEntity.DataEntity[CONST_QM_InspectBill.CONST_FBillHead.ORM_FBillTypeID_Id]);
IBusinessDataService businessDataService =
AppServiceContext.GetService<IBusinessDataService>();
DynamicObject billTypePara = businessDataService.LoadBillTypePara(this.Context, MFGFormIdConst.SubSys_QM.InspectBillTPS, billTypeId);
bool enableInspectValue = billTypePara.GetDynamicObjectItemValue<bool>(CONST_InspectBillTPS.CONST_FBillHead.ORM_EnableSampleInspectValue, false);//启用样本检测值
if(!enableInspectValue) continue;
string billNo = dataEntity.DataEntity.GetDynamicValue<string>(CONST_QM_InspectBill.CONST_FBillHead.ORM_BillNo);
DynamicObjectCollection entryDyObjCol = dataEntity.DataEntity.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FEntity.ENTITY_ORM_Entity);
Dictionary<int, List<int>> UnseqList = new Dictionary<int, List<int>>();
foreach (DynamicObject entryDyObj in entryDyObjCol)
{
int mainSeq = entryDyObj.GetDynamicValue<int>("Seq");
DynamicObjectCollection inspectitemCol = entryDyObj.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FItemDetail.ENTITY_ORM_ItemDetail);//获取检验项目表体
if (inspectitemCol.IsEmpty()) continue;
List<int> seqList = new List<int>();//未全部录入样本检验值的检验项目分录序号
foreach (DynamicObject inspectItem in inspectitemCol)
{
int seq=inspectItem.GetDynamicValue<int>("Seq");
int sampleQty = inspectItem.GetDynamicValue<int>(CONST_QM_InspectBill.CONST_FItemDetail.ORM_SampleQty);//样本量
string analysisMethod = inspectItem.GetDynamicValue<string>(CONST_QM_InspectBill.CONST_FItemDetail.ORM_AnalysisMethod);//分析方法
if (sampleQty <= 0) continue;
DynamicObjectCollection inspectValueCol = inspectItem.GetDynamicValue<DynamicObjectCollection>(CONST_QM_InspectBill.CONST_FValueGrid.ENTITY_ORM_ValueGrid);
if (inspectValueCol.IsEmpty()) continue;
bool isAllInput = true;
switch (analysisMethod)
{
case "1"://定量
if (inspectValueCol.Any(o => o.GetDynamicValue<long>(CONST_QM_InspectBill.CONST_FValueGrid.ORM_InspectValue) <= 0))
isAllInput = false;
break;
case "2"://定性
if (inspectValueCol.Any(o => o.GetDynamicValue<long>(CONST_QM_InspectBill.CONST_FValueGrid.ORM_InspectValueB_Id) <= 0))
isAllInput = false;
break;
case "3"://其他
if (inspectValueCol.Any(o => o.GetDynamicValue<string>(CONST_QM_InspectBill.CONST_FValueGrid.ORM_InspectValueT).IsNullOrEmptyOrWhiteSpace()))
isAllInput = false;
break;
}
if (!isAllInput) seqList.Add(seq);
}
if (seqList.IsEmpty()) continue;
UnseqList.Add(mainSeq, seqList);
}
if (!UnseqList.IsEmpty())
{
foreach (int seq in UnseqList.Keys)
{
List<int> unvalidateSeq = new List<int>();
if (UnseqList.TryGetValue(seq, out unvalidateSeq))
{
string errMsg = string.Format("检验单{0}第{1}行分录对应的检验项目标体第{2}分录下的样本检测值表体检测值未全部录入,不允许保存!", billNo, seq, string.Join(",", unvalidateSeq));
this.vContext.AddError(dataEntity.DataEntity,
dataEntity.DataEntityIndex,
errMsg,
string.Empty);
}
}
}
}
}
}
}
检验单样本检测值表体检验值必录校验二开方案
本文2024-09-23 03:28:41发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-159114.html