分类 工作 下的文章

问题描述:

解决方案:


二开一个表单插件,重新BarItemClick事件,弹出一个动态表单,然后获取动态表单的返回值写回当前界面,代码实例如下:
DynamicFormShowParameter ShowPara = new DynamicFormShowParameter();
            ShowPara.OpenStyle.ShowType = ShowType.Modal;
            ShowPara.FormId = "动态表单的单据标知";
this.View.ShowForm(ShowPara, result =>
            {
                if (result.ReturnData.IsNullOrEmpty()) return; //回调的结果值
}


作者:燕麦片

来源:金蝶云社区

原文链接:https://vip.kingdee.com/knowledge/259027687426252032?productLineId=1&isKnowledge=2&lang=zh-CN

著作权归作者所有。未经允许禁止转载,如需转载请联系作者获得授权。


背景

    需要在A单据中弹出B窗口,同时将某参数传递到B窗口中。


参考示例

    弹出动态表单

        DynamicFormShowParameter para = new DynamicFormShowParameter();         para.FormId = formId; //弹出的单据标识         para.Caption = caption; //标题         para.ParentPageId = this.View.PageId;//父页面         para.OpenStyle.ShowType = ShowType.MainNewTabPage; //弹出方式         para.PageId = Guid.NewGuid().ToString();//页面标识,随机GUID即可                  para.CustomComplexParams.Add(param.Key, param.Value); //添加自定义参数                  this.View.ShowForm(para);


    弹出列表单据


        ListShowParameter para = new ListShowParameter();         para.FormId = formId;         para.ParentPageId = this.View.PageId;         para.OpenStyle.ShowType = ShowType.MainNewTabPage;         para.PageId = Guid.NewGuid().ToString();         para.IsShowFilter = false;         if (!filterShemeId.IsNullOrEmptyOrWhiteSpace())             para.FilterSchemeId = filterShemeId;//增加过滤方案         if (!filter.IsNullOrEmptyOrWhiteSpace())             para.ListFilterParameter.Filter += " and 1=1 ";//增加过滤条件                  this.View.ShowForm(para);


    接收参数示例:

    var customParams_dict = this.View.OpenParameter.GetCustomParameters();                 if (customParams_dict != null && customParams_dict.ContainsKey("参数标识"))           //customParams_dict["参数标识"] //取值


引用组件

    Kingdee.BOS.Core.dll


作者:插秧小能手

来源:金蝶云社区

原文链接:https://vip.kingdee.com/knowledge/535155748502553088?productLineId=1&isKnowledge=2&lang=zh-CN

著作权归作者所有。未经允许禁止转载,如需转载请联系作者获得授权。


创建接口

1、新建类库,此处类库名为WebApiService,添加引用如图所示
153009c28b43462e97ec74854eee73e8.png
2、代码具体实现如下:

  • 增加调用bom展开传入参数model类

 public class BomExpandParam {     ///      /// 需求日期     ///      public DateTime ValidDate { get; set; }     ///      /// bomID     ///      public List<long> BomIds { get; set; }     ///      /// 需求数量     ///      public decimal Qty { get; set; }     ///      /// BOM展开层级数,默认只展开一层 0表示全部展开     ///      public int ExpandLevel { get; set; }     ///是否考虑替代方案:默认不考虑,是否考虑替代:默认不考虑     public bool IsShowSubMtrl { get; set; }     ///      /// 是否展开替代料:默认不考虑     ///      public bool IsExpandSubMtrl { get; set; }     ///      /// 是否隐藏外购BOM:默认考虑     ///      public bool IsHideOutSourceBOM { get; set; } }

  • 增加一个类GetBomExpandService,继承AbstractWebApiBusinessService

using Kingdee.BOS; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.SqlBuilder; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceFacade.KDServiceFx; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.BOS.WebApi.ServicesStub; using Kingdee.K3.BD.ServiceHelper; using Kingdee.K3.Core.BD; using Kingdee.K3.Core.BD.ServiceArgs; using Kingdee.K3.Core.MFG.ENG.BomExpand; using Kingdee.K3.Core.MFG.ENG.ParamOption; using Kingdee.K3.Core.MFG.EntityHelper; using Kingdee.K3.MFG.ServiceHelper.ENG; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace WebApiService {     public class GetBomExpandService : AbstractWebApiBusinessService     {         protected MemBomExpandOption_ForPSV memBomExpandOption = null;         public GetBomExpandService(KDServiceContext context) : base(context)         {         }         ///          /// 传入的数据         ///          /// <param name="info">包含 需求日期  bomID</param>         /// <returns></returns>         public JObject ExecuteService(string info)         {             JObject result = new JObject();             var param = JsonConvert.DeserializeObject<BomExpandParam>(info);             var memBomExpandOption = UpdateBomQueryOption(param);             List<DynamicObject> lstExpandSource = this.BuildBomExpandSourceData(param);             if (lstExpandSource.IsEmpty())             {                 result.Add("Status", "False");                 result.Add("Message", "当前物料对应的BOM不存在,请确认!");                 return result;             }             var queryDatas = GetBomChildData(lstExpandSource, memBomExpandOption);             result.Add("Status", "Success");             result.Add("Data", queryDatas.IsEmpty() ? "" : JsonConvert.SerializeObject(queryDatas));             result.Add("Message", "查询成功");             return result;         } ///          /// 构建bom查询参数         ///          /// <param name="bomExpandParam"></param>         /// <returns></returns>         private MemBomExpandOption_ForPSV UpdateBomQueryOption(BomExpandParam bomExpandParam)         {             MemBomExpandOption_ForPSV memBomExpandOption = new MemBomExpandOption_ForPSV();             //设置BOM展开到几层             memBomExpandOption.ExpandLevelTo = bomExpandParam.ExpandLevel;             DateTime? dtValidDate = bomExpandParam.ValidDate;             if (dtValidDate != null && dtValidDate >= new DateTime(1900, 01, 01))             {                 memBomExpandOption.ValidDate = (DateTime)dtValidDate;             }             //获取工程数据参数             memBomExpandOption.BomExpandCalType = Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType.kdBySystemProfile;             memBomExpandOption.CsdSubstitution = bomExpandParam.IsShowSubMtrl;             memBomExpandOption.IsExpandSubMtrl = bomExpandParam.IsExpandSubMtrl;             memBomExpandOption.IsHideOutSourceBOM = bomExpandParam.IsHideOutSourceBOM;             return memBomExpandOption;         } ///          /// 构建bom展开的源数据         ///          /// <param name="bomIds"></param>         /// <returns></returns>         private List<DynamicObject> BuildBomExpandSourceData(BomExpandParam bomExpandParam)         {             List<DynamicObject> lstExpandSource = new List<DynamicObject>();             QueryBuilderParemeter batchParam = new QueryBuilderParemeter             {                 FormId = "ENG_BOM",                 SelectItems = SelectorItemInfo.CreateItems("FID", "FMaterialId.FMASTERID as MaterialMasterId",                 "FMATERIALID", "FUseOrgId", "FUNITID", "FBaseUnitId", "FParentAuxPropId"),             };             batchParam.ExtJoinTables.Add(new ExtJoinTableDescription             {                 FieldName = "FID",                 TableName = "table(fn_StrSplit(@ids,',',1))",                 TableNameAs = "ts",                 ScourceKey = "FID",             });             List<SqlParam> sqlParam = new List<SqlParam> {                 new SqlParam("@ids",KDDbType.udt_inttable,bomExpandParam.BomIds.Distinct().ToArray()),             };             DynamicObjectCollection bomHeadObjs = QueryServiceHelper.GetDynamicObjectCollection(this.KDContext.Session.AppContext, batchParam, sqlParam);             Dictionary<Int64, DynamicObject> dctBomHeadObjs = bomHeadObjs.ToDictionary(x => Convert.ToInt64(x["FID"])); List<GetUnitConvertRateArgs> converRateArgs = new List<GetUnitConvertRateArgs>();             foreach (DynamicObject bomHeadObj in bomHeadObjs)             {                 long materialId = Convert.ToInt64(bomHeadObj["FMATERIALID"]);                 long masterId = Convert.ToInt64(bomHeadObj["MaterialMasterId"]);                 long unitId = Convert.ToInt64(bomHeadObj["FUNITID"]);                 long baseUnitId = Convert.ToInt64(bomHeadObj["FBaseUnitId"]);                 long supplyOrgId = Convert.ToInt64(bomHeadObj["FUseOrgId"]);                 //此处要对数量进行换算:不能直接传常用单位数量                 converRateArgs.Add(new GetUnitConvertRateArgs()                 {                     PrimaryKey = bomHeadObjs.IndexOf(bomHeadObj),                     MaterialId = materialId,                     MasterId = masterId,                     SourceUnitId = unitId,                     DestUnitId = baseUnitId                 });             }             Dictionary<long, UnitConvert> dctUnitConvert = UnitConvertServiceHelper.GetUnitConvertRateList(this.KDContext.Session.AppContext, converRateArgs); foreach (DynamicObject bomHeadObj in bomHeadObjs)             {                 long bomId = Convert.ToInt64(bomHeadObj["FID"]);                 long materialId = Convert.ToInt64(bomHeadObj["FMATERIALID"]);                 long unitId = Convert.ToInt64(bomHeadObj["FUNITID"]);                 long baseUnitId = Convert.ToInt64(bomHeadObj["FBaseUnitId"]);                 long supplyOrgId = Convert.ToInt64(bomHeadObj["FUseOrgId"]);                 long parentAuxProId = Convert.ToInt64(bomHeadObj["FParentAuxPropId"]);                 BomForwardSourceDynamicRow bomExpandSourceRowView = BomForwardSourceDynamicRow.CreateInstance();                 UnitConvert rate = null;                 decimal dQty = bomExpandParam.Qty;                 if (dctUnitConvert.TryGetValue(bomHeadObjs.IndexOf(bomHeadObj), out rate))                 {                     dQty = rate.ConvertQty(dQty);                 }                 bomExpandSourceRowView.MaterialId_Id = materialId;                 bomExpandSourceRowView.BomId_Id = bomId;                 bomExpandSourceRowView.NeedQty = dQty;                 bomExpandSourceRowView.NeedDate = bomExpandParam.ValidDate;                 bomExpandSourceRowView.UnitId_Id = unitId;                 bomExpandSourceRowView.BaseUnitId_Id = baseUnitId;                 bomExpandSourceRowView.SupplyOrgId_Id = supplyOrgId;                 bomExpandSourceRowView.AuxPropId = parentAuxProId;                 //默认BOM展开过程使用的时间单位为天。                 bomExpandSourceRowView.TimeUnit = ((int)Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_TimeUnit.KdDay).ToString();                 lstExpandSource.Add(bomExpandSourceRowView.DataEntity);             }             return lstExpandSource;         } ///          /// 获取bom子项数据         ///          /// <param name="lstExpandSource"></param>         /// <param name="memBomExpandOption"></param>         /// <returns></returns>         private List<DynamicObject> GetBomChildData(List<DynamicObject> lstExpandSource, MemBomExpandOption_ForPSV memBomExpandOption)         {             memBomExpandOption.IsConvertUnitQty = true;             List<DynamicObject> result = BomQueryServiceHelper.GetBomQueryForwardResult(this.KDContext.Session.AppContext, lstExpandSource, memBomExpandOption);             //根据BOM有无联副产品,更新物料清单正查明细的“存在联副产品”             SetIsExistCoby(result);             return result;         }         ///          /// 根据BOM有无联副产品,更新物料清单正查明细的“存在联副产品”         ///          /// <param name="queryChildData"></param>         private void SetIsExistCoby(List<DynamicObject> queryChildData)         {             if (queryChildData.IsEmpty()) return;             foreach (var query in queryChildData)             {                 var bom = query.GetDynamicValue<DynamicObject>("BomId");                 if (!bom.IsNullOrEmpty())                 {                     var coby = bom.GetDynamicValue<DynamicObjectCollection>("EntryBOMCOBY");                     if (!coby.IsEmpty())                     {                         query.SetDynamicObjectItemValue("IsExistCoby", true);                     }                 }             }         }     } }

  • 至此,api接口已经封装完成。

将此类库生成dll文件,放到应用站点目录下:一般是:./WebSite/bin。

客户端调用此api接口

创建控制台程序,调用此api接口
此工程添加引用如下:Kingdee.BOS.WebApi.Client,首先调用ValidateLogin()验证登录信息,登录成功之后再调用bom展开接口。

调用接口代码实现

using Kingdee.BOS.WebApi.Client; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; namespace HttpRequest {     class Program     {         static void Main(string[] args)         {             try             {                 K3CloudApiClient client = new K3CloudApiClient("http://localhost:1700/");                 var loginResult = client.ValidateLogin("5ef84228d60ade", "Administrator", "********", 2052);                 var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();                 if (resultType == 1)                 {                     BomExpandParam bomExpandParam = new BomExpandParam()                     {                         BomIds = new List<long>() { 193904 },                         ValidDate = DateTime.Now,                         Qty = 1                     };                     string serviceName = "WebApiService.GetBomExpandService.ExecuteService,WebApiService";                     var info = client.Execute<JObject>(serviceName, new object[] { JsonConvert.SerializeObject(bomExpandParam) });                     Console.ReadKey();                 }             }             catch (Exception ex)             {                 Console.WriteLine(ex.Message);             }         }     }     public class ValidModelEntity     {         public string Acctid { get; set; }         public string userName { get; set; }         public string password { get; set; }         public int lcid { get; set; }     } }

结果验证

接口返回结果如下图:其中Data数据就是bom展开结果

7ed0e3cf793e4078aaea28510249eb58.png
1d60f0c7fb1643448ecefca1350d071e.pngde5e19a7bc464ae09b35e981cdb314cf.png

HTTP调用

c77b987dbceb4a40891e5586fd7557d8.png


作者:Tracy_Huang

来源:金蝶云社区

原文链接:https://vip.kingdee.com/knowledge/388095148611278336?productLineId=1&isKnowledge=2&lang=zh-CN

著作权归作者所有。未经允许禁止转载,如需转载请联系作者获得授权。


【应用场景】

需要根据指定bom获取物料清单成本查询结果,并将结果在其他场景使用。



【注意事项】

  1. 该实现方案实现已指定bom内码实现,相关参数都设置为默认,演示通过按钮触发,开发者可根据自身需求将代码封装自定义WebAPI接口。

  2. 星空版本不能低于PT-154002 [8.2.0.20240104]版本



【案例演示】

点击按钮,指定bom版本,获取物料清单成本查询结果。


【实现步骤】

需要引用组件

Kingdee.BOS

Kingdee.BOS.Core

Kingdee.BOS.Orm

Kingdee.K3.BD.ServiceHelper


Kingdee.K3.Core

Kingdee.K3.MFG.ServiceHelper

Kingdee.BOS.ServiceHelper


<1>编写表单插件,代码如下。 

using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Core.SqlBuilder; using Kingdee.BOS.Orm; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Kingdee.K3.BD.ServiceHelper; using Kingdee.K3.Core.BD; using Kingdee.K3.Core.BD.ServiceArgs; using Kingdee.K3.Core.MFG.ENG.BomCost; using Kingdee.K3.Core.MFG.ENG.BomExpand; using Kingdee.K3.Core.MFG.ENG.ParamOption; using Kingdee.K3.MFG.ServiceHelper; using Kingdee.K3.MFG.ServiceHelper.ENG; namespace ITIBB.App.ServicePlugIn.Business.PlugIn {     /// <summary>     /// 自定义按钮 通过传递bom获取物料清单成本查询结果     /// </summary>     [Description("物料清单成本查询按钮调用")]     public class CustomExtBomQueryCost : AbstractDynamicFormPlugIn     {         public override void ButtonClick(ButtonClickEventArgs e)         {             base.ButtonClick(e);             if (e.Key.EqualsIgnoreCase("FButton_qtr"))             {                 //传递参数,指定bom内码                 List<long> bomIds = new List<long>();                 bomIds.Add(144259);                 bomIds.Add(144290);                 //获取bom展开结果                 List<DynamicObject> bomExpandData = this.ExtFillBomChildData(this.View.Context, bomIds);                 //物料清单成本查询相关参数设置                 BomCostArgs bomCostArgs = this.ExtGetQueryViewOption(this.View.Context);                 //调用物料清单成本查询取价接口                 IOperationResult funcResult = BomQueryCostServiceHelper.GetQueryBomPrice(this.Context, bomCostArgs, bomExpandData);                 if (funcResult.IsSuccess)                 {                     //物料清单成本查询数据包                     List<DynamicObject> resultBomDataLst = (List<DynamicObject>)funcResult.FuncResult;                 }             }         }         /// <summary>         /// 构建价格查询参数         /// </summary>         /// <param name="ctx">上下文</param>         private BomCostArgs ExtGetQueryViewOption(Context ctx)         {             BomCostArgs bomCostArgs = new BomCostArgs();             DynamicObject viewDatas = this.View.Model.DataObject;             //需求数量,默认是1             bomCostArgs.NeetQty = 1;             //成本计算方式,默认是1             bomCostArgs.CostType = "1";             //取价截止日期,默认当前时间             bomCostArgs.ExpirationDate = DateTime.Now;             //排除供应商,默认为空             List<long> excSuppliers = new List<long>();             bomCostArgs.ExcSupplierMul = excSuppliers;             //包含委外加工费,默认false             bomCostArgs.IsSubProcessFee = false;             //外购件BOM子项不参与卷算,默认false             bomCostArgs.IsWgCost = false;             //取折后价,默认false             bomCostArgs.IsDiscountedPrice = false;             //bom使用组织,默认当前登录组织             long bomUseOrgId = this.Context.CurrentOrganizationInfo.ID;             bomCostArgs.BomUseOrgId = bomUseOrgId;             //有采购业务优先取采购价格,默认false             bomCostArgs.PurPriceCheck = false;             //以下参数均来自工程数据参数-物料清单成本查询             //取价范围、 优先取使用组织下,使用组织下没有,则取管理中心级别             long takeDays = MFGServiceHelper.GetSystemProfile<long>(this.Context, bomUseOrgId, "MFG_EngParameter", "DateScope", 0);             if (takeDays == 0)             {                 //管理中心取不到,则默认180天                 takeDays = MFGServiceHelper.GetSystemProfile<long>(this.Context, 0, "MFG_EngParameter", "DateScope", 180);             }             bomCostArgs.TakeDays = takeDays;             //单据来源             string priceSourceBill = MFGServiceHelper.GetSystemProfile<string>(this.Context, bomUseOrgId, "MFG_EngParameter", "SourceBill", "");             if (priceSourceBill.IsNullOrEmptyOrWhiteSpace())             {                 //管理中心取不到,则默认采购订单返回                 priceSourceBill = MFGServiceHelper.GetSystemProfile<string>(this.Context, 0, "MFG_EngParameter", "SourceBill", "ORDER");             }             bomCostArgs.PriceSourceBill = priceSourceBill;             //单价金额用量             string costQtyParam = MFGServiceHelper.GetSystemProfile<string>(this.Context, bomUseOrgId, "MFG_EngParameter", "CostQtyParam");             if (costQtyParam.IsNullOrEmptyOrWhiteSpace())             {                 //管理中心取不到,则默认实际用量返回                 costQtyParam = MFGServiceHelper.GetSystemProfile<string>(this.Context, 0, "MFG_EngParameter", "CostQtyParam", "1");             }             bomCostArgs.CostQtyParam = costQtyParam;             //价目表及参考成本汇率来源             string sourceRate = MFGServiceHelper.GetSystemProfile<string>(this.Context, bomUseOrgId, "MFG_EngParameter", "SourceRate");             if (sourceRate.IsNullOrEmptyOrWhiteSpace())             {                 //管理中心取不到,则默认即期汇率返回                 sourceRate = MFGServiceHelper.GetSystemProfile<string>(this.Context, 0, "MFG_EngParameter", "SourceRate", "SPOT");             }             bomCostArgs.SourceRate = sourceRate;             //取价范围、 优先取使用组织下,使用组织下没有,则取管理中心级别             string excSetAccountTpye = MFGServiceHelper.GetSystemProfile<string>(this.Context, bomUseOrgId, "MFG_EngParameter", "ExcSetAccountTpye'", "0");             bomCostArgs.ExcSetAccountTpye = excSetAccountTpye;             //日期排序             string orderByDateField = MFGServiceHelper.GetSystemProfile<string>(this.Context, bomUseOrgId, "MFG_EngParameter", "OrderByDateField", "2");             bomCostArgs.OrderByField = orderByDateField;             //其他扩展选项             bomCostArgs.Option = OperateOption.Create();             return bomCostArgs;         }         private List<DynamicObject> ExtFillBomChildData(Context ctx, List<long> bomIds)         {             List<DynamicObject> bomExpandData = new List<DynamicObject>();             //设置bom展开参数             MemBomExpandOption_ForPSV memBomExpandOption = this.ExtBomQueryExpandOption();             //设置展开数据源             List<DynamicObject> lstExpandSource = this.ExtBuildBomExpandSourceData(ctx, bomIds);             //调用物料清单成本查询bom展开             bomExpandData = BomQueryServiceHelper.GetBomQueryForwardResult(this.Context, lstExpandSource, memBomExpandOption);             //展开结果加载引用属性             FormMetadata formMetadata = (FormMetadata)Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(ctx, "ENG_BomQueryCost", true);             EntryEntity childEntity = formMetadata.BusinessInfo.GetEntryEntity("FBottomEntity");             DBServiceHelper.LoadReferenceObject(this.View.Context, bomExpandData.ToArray(), childEntity.DynamicObjectType, false);             return bomExpandData;         }         /// <summary>         /// 构建bom展开参数,以下参数的设置尽量保持一致         /// </summary>         /// <returns></returns>         private MemBomExpandOption_ForPSV ExtBomQueryExpandOption()         {             //初始化BOM展开选项             MemBomExpandOption_ForPSV memBomExpandOption = new MemBomExpandOption_ForPSV();             //BOM展开层级数 默认30层             memBomExpandOption.ExpandLevelTo = 30;             //是否要展开虚拟物料             memBomExpandOption.ExpandVirtualMaterial = false;             //不要删除虚拟件,否则会造成BOM树表层级中断,个别子项不显示             memBomExpandOption.DeleteVirtualMaterial = false;             //是否删除跳层行             memBomExpandOption.DeleteSkipRow = false;             //是否展开跳层行             memBomExpandOption.ExpandSkipRow = false;             //只显示采购件需指定为false,因为默认值是true             memBomExpandOption.IsShowOutSource = false;             //本次展开GUID             memBomExpandOption.BomExpandId = SequentialGuid.NewGuid().ToString();             //BOM展开的第一层是否考虑成品率 默认为FALSE             memBomExpandOption.ParentCsdYieldRate = true;             //BOM展开的子项是否考虑成品率 默认为FALSE             memBomExpandOption.ChildCsdYieldRate = true;             //展开结果处理方式:采用内存方式不需要保存进数据库             memBomExpandOption.Mode = Kingdee.K3.Core.MFG.EnumConst.Enums.BomExpand.Enu_BomExpandMode.KdMemoryOnly;             //BOM子项生效失效区间内需求日期 此处用当前电脑时间,可以自由指定,标准产品是需求日期             memBomExpandOption.ValidDate = DateTime.Now;             //获取工程数据参数【kdBySystemProfile:取系统参数 kdByPrecisonCal:采用精确计 kdByTolerantCal:采用容错算法】             memBomExpandOption.BomExpandCalType = Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType.kdBySystemProfile;             //BOM展开是否数量单位换算             memBomExpandOption.IsConvertUnitQty = true;             //是否是物料清单成本查询 如果设置为false则结果就是物料清单正查结果             memBomExpandOption.isBomCost = true;             //是否查询当前系统所有bom信息             memBomExpandOption.IsSelectAllBomInfos = true;             //对应标准成本计算方式参数,默认不展开判断是否展开替代料【1:按标准件计算 2:按替代件计算 3:按标准件和替代件较低价】             string costType = "1";             if (costType.EqualsIgnoreCase("1"))             {                 //是否考虑替代方案:默认不考虑,是否考虑替代:默认不考虑                 memBomExpandOption.CsdSubstitution = false;                 //是否展开替代料:默认不考虑                 memBomExpandOption.IsExpandSubMtrl = false;             }             else             {                 //是否考虑替代方案:默认不考虑,是否考虑替代:默认不考虑                 memBomExpandOption.CsdSubstitution = true;                 //是否展开替代料:默认不考虑                 memBomExpandOption.IsExpandSubMtrl = true;             }             //是否展开外购件bom 默认不展开[对应物料清单成本上外购件BOM子项不参与卷算参数]             memBomExpandOption.IsHideOutSourceBOM = false;             return memBomExpandOption;         }         /// <summary>         /// 获得需要展开的BOM展开数据信息         /// </summary>         /// <param name="iFocusRow"></param>         /// <returns></returns>         private List<DynamicObject> ExtBuildBomExpandSourceData(Context ctx, List<long> bomIds)         {             DateTime needDate = DateTime.Now;             List<DynamicObject> lstExpandSource = new List<DynamicObject>();             QueryBuilderParemeter batchParam = new QueryBuilderParemeter             {                 FormId = "ENG_BOM",                 SelectItems = SelectorItemInfo.CreateItems("FID", "FMaterialId.FMASTERID as MaterialMasterId",                 "FMATERIALID", "FUseOrgId", "FUNITID", "FBaseUnitId", "FParentAuxPropId"),             };             batchParam.ExtJoinTables.Add(new ExtJoinTableDescription             {                 FieldName = "FID",                 TableName = "table(fn_StrSplit(@ids,',',1))",                 TableNameAs = "ts",                 ScourceKey = "FID",             });             List<SqlParam> sqlParam = new List<SqlParam> {                 new SqlParam("@ids",KDDbType.udt_inttable,bomIds.Distinct().ToArray()),             };             DynamicObjectCollection bomHeadObjs = QueryServiceHelper.GetDynamicObjectCollection(ctx, batchParam, sqlParam);             Dictionary<Int64, DynamicObject> dctBomHeadObjs = bomHeadObjs.ToDictionary(x => Convert.ToInt64(x["FID"]));             List<GetUnitConvertRateArgs> converRateArgs = new List<GetUnitConvertRateArgs>();             foreach (DynamicObject bomHeadObj in bomHeadObjs)             {                 long materialId = Convert.ToInt64(bomHeadObj["FMATERIALID"]);                 long masterId = Convert.ToInt64(bomHeadObj["MaterialMasterId"]);                 long unitId = Convert.ToInt64(bomHeadObj["FUNITID"]);                 long baseUnitId = Convert.ToInt64(bomHeadObj["FBaseUnitId"]);                 long supplyOrgId = Convert.ToInt64(bomHeadObj["FUseOrgId"]);                 //此处要对数量进行换算:不能直接传常用单位数量                 converRateArgs.Add(new GetUnitConvertRateArgs()                 {                     PrimaryKey = bomHeadObjs.IndexOf(bomHeadObj),                     MasterId = masterId,                     SourceUnitId = unitId,                     DestUnitId = baseUnitId                 });             }             Dictionary<long, UnitConvert> dctUnitConvert = UnitConvertServiceHelper.GetUnitConvertRateList(ctx, converRateArgs);             foreach (DynamicObject bomHeadObj in bomHeadObjs)             {                 long bomId = Convert.ToInt64(bomHeadObj["FID"]);                 long materialId = Convert.ToInt64(bomHeadObj["FMATERIALID"]);                 long unitId = Convert.ToInt64(bomHeadObj["FUNITID"]);                 long baseUnitId = Convert.ToInt64(bomHeadObj["FBaseUnitId"]);                 long supplyOrgId = Convert.ToInt64(bomHeadObj["FUseOrgId"]);                 long parentAuxProId = Convert.ToInt64(bomHeadObj["FParentAuxPropId"]);                 BomForwardSourceDynamicRow bomExpandSourceRowView = BomForwardSourceDynamicRow.CreateInstance();                 UnitConvert rate = null;                 //默认需求数量为1                 decimal dQty = 1;                 if (dctUnitConvert.TryGetValue(bomHeadObjs.IndexOf(bomHeadObj), out rate))                 {                     dQty = rate.ConvertQty(dQty);                 }                 bomExpandSourceRowView.MaterialId_Id = materialId;                 bomExpandSourceRowView.BomId_Id = bomId;                 bomExpandSourceRowView.NeedQty = dQty;                 bomExpandSourceRowView.NeedDate = DateTime.Now;                 bomExpandSourceRowView.UnitId_Id = unitId;                 bomExpandSourceRowView.BaseUnitId_Id = baseUnitId;                 bomExpandSourceRowView.SupplyOrgId_Id = supplyOrgId;                 bomExpandSourceRowView.AuxPropId = parentAuxProId;                 //默认BOM展开过程使用的时间单位为天。                 bomExpandSourceRowView.TimeUnit = ((int)Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_TimeUnit.KdDay).ToString();                 lstExpandSource.Add(bomExpandSourceRowView.DataEntity);             }             return lstExpandSource;         }     } }


<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。

<3>BOSIDE任意单据,添加自定义按钮,命名为FButton_qtr注册表单插件,保存元数据,开发完毕。


【功能验证】

<1>登录业务站点,点击自定义按钮



【参考资料】


自定义WebAPI接口调用BOM展开 (kingdee.com)

https://vip.kingdee.com/article/399149371909894144




金蝶云星空BOS二次开发案例演示】

https://vip.kingdee.com/article/94751030918525696



作者:ITIBB

来源:金蝶云社区

原文链接:https://vip.kingdee.com/knowledge/589519393051028480?productLineId=1&isKnowledge=2&lang=zh-CN

著作权归作者所有。未经允许禁止转载,如需转载请联系作者获得授权。


 //弹出分码动态表单

DynamicFormShowParameter jdForm = new DynamicFormShowParameter();

// 动态表单标识

jdForm.FormId = "SCAG_Demal";

jdForm.CustomComplexParams.Add("materialObj", childMaterial);

jdForm.CustomComplexParams.Add("fmaterialObj", FMATERIALID);

var entrtys = this.View.Model.DataObject[this.View.BusinessInfo.GetEntity("FTreeEntity").DynamicObjectType.Name] as DynamicObjectCollection;

 jdForm.CustomComplexParams.Add("demal", fieldView.TagDynamicProperty.GetValue(entrtys[e.Row]));

 jdForm.CustomComplexParams.Add("BillStatus", this.View.Model.GetValue("FDocumentStatus"));

jdForm.OpenStyle.ShowType = ShowType.ModalInCurrentForm;

 string returnData = string.Empty;

this.View.ShowForm(jdForm, (formRet) =>

                                {

                                    if (formRet.ReturnData != null)

                                    {

                                        returnData = formRet.ReturnData.ToNullString();

                                        string demalValue = string.Empty;

                                        string demalDisplay = string.Empty;

                                        int rowIndex = this.Model.GetEntryCurrentRowIndex("FTreeEntity");

                                        if (!string.IsNullOrWhiteSpace(returnData))

                                        {

                                            string[] returnArray = returnData.Split('∷');

                                            demalValue = returnArray[0];

                                            demalDisplay = returnArray[1];

                                        }

                                        fieldView.DynamicProperty.SetValue(entrtys[e.Row], demalDisplay);

                                        fieldView.TagDynamicProperty.SetValue(entrtys[e.Row], demalValue.GetUtf8Bytes());

                                        this.View.UpdateView("F_SCAG_FYS", e.Row);

                                    }

                                });

        


作者:Lii_Ji

来源:金蝶云社区

原文链接:https://vip.kingdee.com/article/616602992795587840?productLineId=1&lang=zh-CN

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。