10.1、表单插件,AfterSave,保存成功后,触发,反写原创
21人赞赏了该文章
1.2万次浏览
编辑于2020年07月02日 15:27:47
续
4.1、表单插件,表单常用方法,获取单据标题 this.View.GetFormTitle()
业务场景:销售订单下推销售出库单,在销售出库单填写项目名称,点保存,反写到销售订单上面
通过数据库,找到销售出库单关联销售订单,行内码,更新销售订单,项目名称;
1、打开VS,新建一个类库,具体可以参考4.1 ,1-7步
2、打开BOS,销售订单和销售出库单,都新建一个单据体文本字段,项目名称 F_YDIE_ProjectName
3、把项目名称,移到到最前面
4、
//保存后,触发 public override void AfterSave(BOS.Core.Bill.PlugIn.Args.AfterSaveEventArgs e) { base.AfterSave(e); }
5、
//如果保存成功,则触发 if(e.OperationResult.IsSuccess) { }
6、
//引用Kingdee.BOS.App.Data,才能执行sql using Kingdee.BOS.App.Data;
7、
--T_SAL_ORDERENTRY --销售订单,单据体明细表 F_YDIE_ProjectName --待更新的字段 --T_SAL_OUTSTOCKENTRY --销售出库单,单据体明细表 F_YDIE_ProjectName --待更新的字段 --FID update t1 set F_YDIE_ProjectName =F_YDIE_ProjectName from T_SAL_ORDERENTRY t1 --销售订单和销售出库单关联 where
8、
--FSOEntryId在T_SAL_OUTSTOCKENTRY_R表; --F_YDIE_ProjectName在T_SAL_OUTSTOCKENTRY表 select FSOEntryId, * from T_SAL_OUTSTOCKENTRY_R
select FSOEntryId,F_YDIE_ProjectName from T_SAL_OUTSTOCKENTRY_R x INNER JOIN T_SAL_OUTSTOCKENTRY y on x.FENTRYID = y.FENTRYID
8、
//执行sql DBUtils.Execute
9、
if(e.OperationResult.IsSuccess) { // 方言,转义"/*dialect*/ //销售出库单,反写到销售订单上面 //获取FID this.View.Model.DataObject["Id"].ToString() string sql = @"/*dialect*/update t1 set F_YDIE_ProjectName =t2.F_YDIE_ProjectName from T_SAL_ORDERENTRY t1, (select FSOEntryId,F_YDIE_ProjectName from T_SAL_OUTSTOCKENTRY_R x INNER JOIN T_SAL_OUTSTOCKENTRY y on x.FENTRYID = y.FENTRYID where x.FID ="+this.View.Model.DataObject["Id"].ToString()+") t2 "+ "where t1.FENTRYID =t2.FSOENTRYID"; //执行sql DBUtils.Execute(this.Context,sql);
10、重新生成dll
11、最终效果,重新打开销售订单,下推销售出库单,填写项目名称,反写到销售订单上面
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using System.ComponentModel; //引用Kingdee.BOS.App.Data,才能执行sql using Kingdee.BOS.App.Data; namespace Kingdee.Bos.ProJct.BillAfterSavePlugln { [Description("保存后,触发")] [Kingdee.BOS.Util.HotUpdate] public class ClassName:AbstractBillPlugIn { //保存后,触发 public override void AfterSave(BOS.Core.Bill.PlugIn.Args.AfterSaveEventArgs e) { base.AfterSave(e); //如果保存成功,则触发 if(e.OperationResult.IsSuccess) { // 方言,转义"/*dialect*/ //销售出库单,反写到销售订单上面 //获取FID this.View.Model.DataObject["Id"].ToString() string sql = @"/*dialect*/update t1 set F_YDIE_ProjectName =t2.F_YDIE_ProjectName from T_SAL_ORDERENTRY t1, (select FSOEntryId,F_YDIE_ProjectName from T_SAL_OUTSTOCKENTRY_R x INNER JOIN T_SAL_OUTSTOCKENTRY y on x.FENTRYID = y.FENTRYID where x.FID ="+this.View.Model.DataObject["Id"].ToString()+") t2 "+ "where t1.FENTRYID =t2.FSOENTRYID"; //执行sql DBUtils.Execute(this.Context,sql); } } } }
总目录链接
https://vip.kingdee.com/article/64993872014591232
Kingdee.Bos.Test10.zip(16.11KB)