using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.App;
using Kingdee.BOS.Util;
using Kingdee.BOS.App.Data;
namespace HW.K3Cloud.ZXB.Plugin
{
[Description("采购订单下推采购入库单携带BOM版本")]
public class PurOrderChonvertPurInStock : AbstractConvertPlugIn
{
/// <summary>
/// 单据下推完毕,结束下推前,触发本事件
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// 重载此事件,以便在调试代码时,观察最终生成的数据包是否符合预期
/// </remarks>
public override void AfterConvert(AfterConvertEventArgs e)
{
base.AfterConvert(e);
// 目标单单据体元数据
Entity entity = e.TargetBusinessInfo.GetEntity("FInStockEntry");
ExtendedDataEntitySet bill = e.Result;
// DynamicObjectCollection rows = bill[0]["InStockEntry"] as DynamicObjectCollection;
ExtendedDataEntity[] rows = e.Result.FindByEntityKey("FInStockEntry");
//
if (rows.Length>0)
{
for (int i=0;i<rows.Length ;i++)
{
DynamicObject row = rows[i].DataEntity as DynamicObject;
Int64 FMaterialId = Convert.ToInt64(row["MaterialId_Id"]);
string Filter = String.Format(" FMATERIALID='{0}' AND FDOCUMENTSTATUS='C' AND FFORBIDSTATUS='A' AND FBOMCATEGORY='1' ", FMaterialId);
DynamicObjectCollection bomIds=UtilZxbK3.GetQueryDatas2("ENG_BOM", Filter,"FID",this.Context);
if (bomIds.Count>0)
{
string FBomId = Convert.ToString(bomIds[0]["FID"]);
DynamicObject BOM=UtilZxbK3.GetObjectByFID("ENG_BOM", this.Context, FBomId);
if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace(BOM))
{
row["BOMId_Id"] = FBomId;
row["BOMId"] = BOM;
}
}
}
}
}
}
}
推荐阅读