9.2、表单插件,BeforeSave点击事件,询问,备注信息没有填写,是否继续原创
金蝶云社区-林荫大道_找工作身份
林荫大道_找工作
15人赞赏了该文章 7,648次浏览 未经作者许可,禁止转载编辑于2020年07月02日 15:27:04
封面



9.1、表单插件,BeforeSave点击事件,校验,不填备注,不让保存



1、注释,上一节代码



2、


//引用提示对话框
using Kingdee.BOS.Core.DynamicForm;



3、


                    //询问式,对话框
                    this.View.ShowMessage("备注信息没有填写,是否继续保存?",
                    //提示信息:是、否
                    MessageBoxOptions.YesNo,
                    new Action<MessageBoxResult>((result) =>
                    {
                    if (result == MessageBoxResult.No)
                    {
                        //如果选择的否,
                        e.Cancel = true;
                    }
                    }));



4、重新生成dll



5、重新打开销售订单,先填写必录信息,不填写备注,点保存,2个弹框同时出现,没有达到预期效果


image.png


6、注释,上面代码



7、


            //不往下继续            
            e.Cancel = true;
            
            
   
            if (Convert.ToString(this.View.Model.GetValue("FNote")) == "")
            {
                //询问式,对话框
                this.View.ShowMessage("备注信息没有填写,是否继续保存?",
                    //提示信息:是、否
                MessageBoxOptions.YesNo,
                new Action<MessageBoxResult>((result) =>
                {
                    if (result == MessageBoxResult.Yes)
                    {
                        //当点是的时候,调用保存操作
                        this.View.InvokeFormOperation("Save");
                    }
                }));
            }



8、重新生成dll



9、重新打开销售订单,先填写必录信息,不填写备注,点保存,只弹窗1个,但是点“是”,没有反应,死循环


image.png




10、注释,上面代码



11、


        public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //如果是保存按钮
            if (e.BarItemKey.Equals("tbSplitSave"))
            {
                //执行询问对话框
            }
        }




image.png


               //如果备注是空,弹出对话框,是否继续        
               //如果点击否,不保存        
               //如果点击是,保存
            
        public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //如果是保存按钮
            if (e.BarItemKey.Equals("tbSplitSave"))
            {
                //不往下继续
                e.Cancel = true;
                //执行询问对话框
                if (Convert.ToString(this.View.Model.GetValue("FNote")) == "")
                {
                    //询问式,对话框
                    this.View.ShowMessage("备注信息没有填写,是否继续保存?",
                        //提示信息:是、否
                    MessageBoxOptions.YesNo,
                    new Action<MessageBoxResult>((result) =>
                    {
                        if (result == MessageBoxResult.Yes)
                        {
                            //当点是的时候,调用保存操作
                            this.View.InvokeFormOperation("Save");
                        }
                    }));
                }
                else
                {
                    //如果备注不为空,直接调用保存操作
                    this.View.InvokeFormOperation("Save");
                }
            }
        }



12、重新生成dll



13、重新打开销售订单,先填写必录信息,不填写备注,点保存,只弹窗1个


               //如果备注是空,弹出对话框,是否继续        
               //如果点击否,不保存        
               //如果点击是,保存


image.png


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS;
using Kingdee.BOS.Core.Bill.PlugIn;
using System.ComponentModel;
//引用提示对话框
using Kingdee.BOS.Core.DynamicForm;


namespace Kingdee.Bos.ProJect.BillBeforeSave.Plugln
{
    [Description("保存前事件BeforeSave")]
    
    [Kingdee.BOS.Util.HotUpdate]
    
    
    public class ClassName:AbstractBillPlugIn
    {
        //保存前事件
        //public override void BeforeSave(BOS.Core.Bill.PlugIn.Args.BeforeSaveEventArgs e)
        //{
            //base.BeforeSave(e);
            //保存的时候,校验,备注,必须填写,弹框提示
            //获取备注的值,当备注等于空的时候
            //if(Convert.ToString(this.View.Model.GetValue("FNote"))=="")
            //{
            //    //取消
            //    e.Cancel = true;
            //    //弹框
            //    this.View.ShowMessage("请填写备注信息");
            //}
            //if (Convert.ToString(this.View.Model.GetValue("FNote")) == "")
            //{
            //        //询问式,对话框
            //        this.View.ShowMessage("备注信息没有填写,是否继续保存?",
            //        //提示信息:是、否
            //        MessageBoxOptions.YesNo,
            //        new Action<MessageBoxResult>((result) =>
            //        {
            //        if (result == MessageBoxResult.No)
            //        {
            //            //如果选择的否,
            //            e.Cancel = true;
            //        }
            //        }));
            //}
            ////不往下继续
            //e.Cancel = true;
            
            //if (Convert.ToString(this.View.Model.GetValue("FNote")) == "")
            //{
            //    //询问式,对话框
            //    this.View.ShowMessage("备注信息没有填写,是否继续保存?",
            //        //提示信息:是、否
            //    MessageBoxOptions.YesNo,
            //    new Action<MessageBoxResult>((result) =>
            //    {
            //        if (result == MessageBoxResult.Yes)
            //        {
            //            //当点是的时候,调用保存操作
            //            this.View.InvokeFormOperation("Save");
            //        }
            //    }));
            //}
        //}
        //如果备注是空,弹出对话框,是否继续
        //如果点击否,不保存
        //如果点击是,保存
        public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            
            
            //如果是保存按钮
            if (e.BarItemKey.Equals("tbSplitSave"))
            {
                //不往下继续
                e.Cancel = true;
                
                
                //执行询问对话框
                if (Convert.ToString(this.View.Model.GetValue("FNote")) == "")
                {
                    //询问式,对话框
                    this.View.ShowMessage("备注信息没有填写,是否继续保存?",
                        //提示信息:是、否
                    MessageBoxOptions.YesNo,
                    new Action<MessageBoxResult>((result) =>
                    {
                        if (result == MessageBoxResult.Yes)
                        {
                            //当点是的时候,调用保存操作
                            this.View.InvokeFormOperation("Save");
                        }
                    }));
                }
                else
                {
                    //如果备注不为空,直接调用保存操作
                    this.View.InvokeFormOperation("Save");
                }
            }
        }
    }
}


总目录链接

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



赞 15