配套材料采购申请将源单上的字段数据携带到采购申请单原创
8人赞赏了该文章
1,070次浏览
编辑于2021年07月20日 15:12:44
配套材料采购申请将源单上的字段数据携带到采购申请单
目前此需求通版不支持,可以写插件二开实现。
下面示例如果在配套采购申请功能里将销售订单的扩展字段数据携带到采购申请单。
在采购申请、销售订单表体分别添加扩展二开文本类型字段 F_TES_EKZD
编写插件,该插件继承配套采购申请动态表单的表单插件,重写生成采购申请单后事件AssortReqEdit
using Kingdee.BOS; using Kingdee.BOS.Orm.DataEntity; using Kingdee.K3.SCM.Purchase.Business.PlugIn; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; namespace TestCloud { [Description("重写配套材料采购申请逻辑插件")] public class TestAssortReqEdit : AssortReqEdit { /// <summary> /// 重写生成采购申请单后事件 /// </summary> /// <param name="reqDatas">申请单数据包</param> public override void AfterGenerateReqs(List<DynamicObject> reqDatas) { base.AfterGenerateReqs(reqDatas); if (reqDatas == null || reqDatas.Count == 0) { return; } //判断当前配套来源单据是什么,这里演示来源单据是销售订单 if (OpenSourceBill == "SAL_SaleOrder") { DataTable dt = new DataTable(); dt.Columns.Add("FBILLNO"); dt.Columns.Add("FSEQ"); char spliteSymbol_1 = ','; char spliteSymbol_2 = '_'; //根据配套来源行号字段获取源单数据信息 foreach (var billItem in reqDatas) { var entrys = billItem["ReqEntry"] as DynamicObjectCollection; foreach (var entryItem in entrys) { string srcRowInfoItem = Convert.ToString(entryItem["ASSORTBILLSEQ"]); if (string.IsNullOrWhiteSpace(srcRowInfoItem) == false) { var srcRowInfoItemArr = srcRowInfoItem.Split(spliteSymbol_1); if (srcRowInfoItemArr != null && srcRowInfoItemArr.Length > 0) { foreach (var item in srcRowInfoItemArr) { var subiItem = item.Split(spliteSymbol_2); string itemSrcBillNo = subiItem[0]; string itemSrcSeq = subiItem[1]; DataRow row = dt.NewRow(); row[0] = itemSrcBillNo; row[1] = itemSrcSeq; dt.Rows.Add(row); } } } } } if (dt.Rows.Count == 0) { return; } //批量从数据库过滤取数 BatchSqlParam sqlParam = new BatchSqlParam("T_SAL_ORDER", dt); sqlParam.TableAliases = "TR"; sqlParam.AddJoinExpression(" INNER JOIN T_SAL_ORDERENTRY T ON T.FID=TR.FID "); sqlParam.AddWhereExpression("FBILLNO", KDDbType.String, "FBILLNO", "TR"); sqlParam.AddWhereExpression("FSEQ", KDDbType.Int64, "FSEQ", "T"); string selectFieldSql = @" distinct TR.FBILLNO,T.FSEQ,T.F_TES_EKZD"; Dictionary<string, DynamicObject> dbRstValues = new Dictionary<string, DynamicObject>(); var dbCols = Kingdee.BOS.App.Data.DBUtils.ExecuteDynamicObject(this.Context, sqlParam, selectFieldSql); foreach (var item in dbCols) { string key = Convert.ToString(item["FBILLNO"]) + spliteSymbol_2 + Convert.ToString(item["FSEQ"]); dbRstValues[key] = item; } //批量回填字段 foreach (var billItem in reqDatas) { var entrys = billItem["ReqEntry"] as DynamicObjectCollection; foreach (var entryItem in entrys) { string srcRowInfoItem = Convert.ToString(entryItem["ASSORTBILLSEQ"]); if (string.IsNullOrWhiteSpace(srcRowInfoItem) == false) { var srcRowInfoItemArr = srcRowInfoItem.Split(spliteSymbol_1); if (srcRowInfoItemArr != null && srcRowInfoItemArr.Length > 0) { foreach (var item in srcRowInfoItemArr) { if (dbRstValues.ContainsKey(item)) { entryItem["F_TES_EKZD"] = Convert.ToString(dbRstValues[item]["F_TES_EKZD"]); } } } } } } } } } }
3.然后在配套采购申请动态表单的表单插件上注册插件,并反启用通版的插件,如下图:
推荐阅读