如何用代码获取MRP订单供需查询结果数据
遇到一些场景,需要给第三方系统传输MRP订单供需查询结果数据,或者有一些自定义的报表想基于MRP订单供需查询结果的数据来做。但MRP订单供需查询在系统中是属于动态表单,根据运算编号查询当次运算的供需匹配情况,没有现成的API接口获取查询结果数据。本案基于该场景,说明如果用代码调用获取MRP订单供需结果数据。以下示例代码是以菜单点击事件来举例,示例代码如下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.Util; //引用Kingdee.BOS.dll
using Kingdee.BOS.Core.DynamicForm.PlugIn; //引用Kingdee.BOS.Core.dll
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm.DataEntity; //引用Kingdee.BOS.DataEntity.dll
using Kingdee.K3.Core.MFG.PLN.ParamOption; //引用Kingdee.K3.Core.dll
using Kingdee.K3.MFG.ServiceHelper.PLN; //引用Kingdee.K3.MFG.ServiceHelper.dll
using Kingdee.K3.Core.MFG; //引用Kingdee.K3.Core.dll
using Kingdee.K3.Core.MFG.EnumConst; //引用Kingdee.K3.MFG.PLN.Common.Core.dll
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Core.Metadata.FormElement;
namespace MyMRPQueryDSTestPlugIn_240608
{
public partial class MyMRPQueryDSTestPlugIn : AbstractDynamicFormPlugIn
{
/// <summary>
/// 菜单单击事件
/// </summary>
/// <param name="e"></param>
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
//tbGetMRPOrderDSInfos为菜单标识,可随意调整
if (e.BarItemKey.Equals("tbGetMRPOrderDSInfos"))
{
//mrpOdsqOption是获取MRP订单供需结果的主要参数
MRPOrderDSQueryOption mrpOdsqOption = new MRPOrderDSQueryOption();
//获取参与当次运算的销售订单和预测
string computeNo = "MRP000666"; //MRP000666只是举例,实际按业务场景获取
if (computeNo.IsNullOrEmptyOrWhiteSpace()) return;
QueryBuilderParemeter para = new QueryBuilderParemeter()
{
FormId = MFGFormIdConst.SubSys_PLN.PlanMrpCalcBill,
SelectItems = SelectorItemInfo.CreateItems(new string[]
{
CONST_PLN_MRPCALCBILL.CONST_FBillHead.KEY_FID,
CONST_PLN_MRPCALCBILL.CONST_FBillHead.KEY_FBillNo,
CONST_PLN_MRPCALCBILL.CONST_FDemandEntity.KEY_FDRelationFormId,
CONST_PLN_MRPCALCBILL.CONST_FDemandEntity.KEY_FDRelationBillNo,
CONST_PLN_MRPCALCBILL.CONST_FDemandEntity.KEY_FDRelationInterId,
CONST_PLN_MRPCALCBILL.CONST_FDemandEntity.KEY_FDRelationEntryId
}),
};
para.FilterClauseWihtKey = string.Format(" FBillNo='{0}' AND FDRelationFormId IN('SAL_SaleOrder','PLN_FORECAST') ", computeNo);
DynamicObjectCollection dInfos = QueryServiceHelper.GetDynamicObjectCollection(this.Context, para);
if (dInfos.IsEmpty()) return;
//以下是构建选单数据mrpOdsqOption,对应界面的就是选单表体数据
FormMetadata meta = MetaDataServiceHelper.Load(this.Context, "PLN_MRPOrderDSQuery") as FormMetadata;
DynamicObject mrpOrderDSData = new DynamicObject(meta.BusinessInfo.GetDynamicObjectType());
EntryEntity entryEntity = meta.BusinessInfo.GetEntryEntity(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ENTITY_FSelEntity);
DynamicObjectCollection selEntrys = mrpOrderDSData.GetDynamicValue<DynamicObjectCollection>(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ENTITY_ORM_SelEntity);
int seq = 1;
foreach (DynamicObject dInfo in dInfos)
{
DynamicObject selEntry = new DynamicObject(entryEntity.DynamicObjectType);
if (entryEntity.SeqDynamicProperty != null)
{
entryEntity.SeqDynamicProperty.SetValue(selEntry, seq++);
}
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_RelationFormId_Id, dInfo.GetDynamicValue<string>("FDRelationFormId"));
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_RelationInterId, dInfo.GetDynamicValue<long>("FDRelationInterId"));
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_RelationEntryId, dInfo.GetDynamicValue<long>("FDRelationEntryId"));
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_RelationBillNo, dInfo.GetDynamicValue<string>("FDRelationBillNo"));
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_ComputeId, dInfo.GetDynamicValue<string>("FID"));
selEntry.SetDynamicObjectItemValue(CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ORM_MrpBillNo, dInfo.GetDynamicValue<string>("FBillNo"));
selEntrys.Add(selEntry);
}
#region 加载选单引用属性数据
FormOperation formOperation = meta.BusinessInfo.GetForm().FormOperations.Where(w => w.Operation.EqualsIgnoreCase("ExtOrderSelFieldMaps")).FirstOrDefault();
ExtFieldMapOption efmOption = new ExtFieldMapOption();
efmOption.FormId = MFGFormIdConst.SubSys_PLN.PLN_MRPOrderDSQuery;
efmOption.EntryKey = CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ENTITY_FSelEntity;
efmOption.EntryProp = CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.ENTITY_ORM_SelEntity;
efmOption.OperationNumber = "ExtOrderSelFieldMaps";
efmOption.BillFormIdKey = CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.KEY_FRelationFormId;
efmOption.BillInterIdKey = CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.KEY_FRelationInterId;
efmOption.BillEntryIdKey = CONST_PLN_MRPOrderDSQuery.CONST_FSelEntity.KEY_FRelationEntryId;
efmOption.Details = selEntrys.ToList();
efmOption.Data = mrpOrderDSData;
IOperationResult efmResult = SupplyDemandStateRptServiceHelper.LoadCustPropertyByEFM(this.Context, efmOption);
#endregion 加载选单引用属性数据
//把构建的选单表体数据赋值给mrpOdsqOption.SelOrderEntrys作为查询参数
mrpOdsqOption.SelOrderEntrys = selEntrys.ToList();
IOperationResult result = MRPOrderDSQueryServiceHelper.GetMRPOrderDSQuery(this.Context, mrpOdsqOption, "");
List<DynamicObject> infos = result.FuncResult as List<DynamicObject>;
if (!infos.IsEmpty())
{
//infos即是MRP订单供需查询结果数据集,可供二开使用
}
}
}
}
}
如何用代码获取MRP订单供需查询结果数据
本文2024-09-23 03:13:15发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-157466.html