二开案例.表单插件.禁用插件

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

二开案例.表单插件.禁用插件

【应用场景】

运行时,通过插件,禁用其它的插件。



【案例演示】

采购订单,表单插件,B插件会在界面上显示消息,通过A插件禁用B插件。

上传图片




【实现步骤】

<1>编写表单插件DisablePlugInTestFormPlugIn,用于禁用插件测试,该插件会在单据打开时输出一个信息,代码如下。

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
    
    /// <summary>
    /// 【表单插件】禁用插件测试
    /// </summary>
    [Description("【表单插件】禁用插件测试"), HotUpdate]
    public class DisablePlugInTestFormPlugIn : AbstractDynamicFormPlugIn
    {
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            this.View.ShowMessage("哈哈哈!!!");
        }
    }
}


<2>编写Python插件,用于禁用插件测试,该插件会在单据打开时输出一个信息,代码如下。

上传图片

# 【Python】【表单插件】禁用插件测试
def AfterBindData(e):
    this.View.ShowMessage("嘿嘿嘿!!!")


<3>编写表单插件DisablePlugInFormPlugIn,用于禁用插件DisablePlugInFormPlugIn和Python插件,代码如下。

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
    /// <summary>
    /// 【表单插件】禁用插件
    /// </summary>
    [Description("【表单插件】禁用插件"), HotUpdate]
    public class DisablePlugInFormPlugIn : AbstractDynamicFormPlugIn
    {
        public override void OnInitializeService(InitializeServiceEventArgs e)
        {
            base.OnInitializeService(e);
            RemovePlugIn();
        }
        public override void OnSetBusinessInfo(SetBusinessInfoArgs e)
        {
            base.OnSetBusinessInfo(e);
            //RemovePlugIn();
        }
        public override void OnInitialize(InitializeEventArgs e)
        {
            base.OnInitialize(e);
            //RemovePlugIn();
        }
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //RemovePlugIn();
        }
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            // 显示当前页面正在使用的表单插件
            //var logs = new List<string>();
            //var viewPlugInProxy = this.View.GetService<DynamicFormViewPlugInProxy>();
            //logs.Add("插件数量:" + viewPlugInProxy.PlugIns.Count);
            //logs.AddRange(viewPlugInProxy.PlugIns.Select(plugIn => plugIn.GetType().FullName));
            //var msg = string.Join("\r\n", logs);
            //this.View.ShowMessage(msg);
        }
        /// <summary>
        /// 移除插件演示
        /// 将此方法,放在合适的插件事件中,即可即时移除当前View下的指定的插件。
        /// </summary>
        private void RemovePlugIn()
        {
            var plugInClassFullName = typeof(DisablePlugInTestFormPlugIn).FullName;
            RemoveCSharpPlugIn(plugInClassFullName);
            RemovePythonPlugIn("嘿嘿嘿");
        }
        /// <summary>
        /// 移除C#插件
        /// </summary>
        /// <param name="plugInClassFullName">插件类全名</param>
        private void RemoveCSharpPlugIn(string plugInClassFullName)
        {
            if (this.View == null)
            {
                return;
            }
            #region ViewPlugInProxy
            var viewPlugInProxy = this.View.GetService<DynamicFormViewPlugInProxy>();
            if (viewPlugInProxy != null)
            {
                //viewPlugInProxy.PlugIns.RemoveAll(plugIn =>plugIn.GetType().FullName == plugInClassFullName);
                var viewPlugIn = viewPlugInProxy.PlugIns.FirstOrDefault(o => o.GetType().FullName == plugInClassFullName);
                if (viewPlugIn != null)
                {
                    viewPlugInProxy.PlugIns.Remove(viewPlugIn);
                }
            }
            #endregion
            #region ModelPlugInProxy
            var modelPlugInProxy = this.View.GetService<DynamicFormModelPlugInProxy>();
            if (modelPlugInProxy != null)
            {
                //modelPlugInProxy.PlugIns.RemoveAll(plugIn => plugIn.GetType().FullName == plugInClassFullName);
                var modelPlugIn = modelPlugInProxy.PlugIns.FirstOrDefault(o => o.GetType().FullName == plugInClassFullName);
                if (modelPlugIn != null)
                {
                    modelPlugInProxy.PlugIns.Remove(modelPlugIn);
                }
            }
            #endregion
        }
        /// <summary>
        /// 移除Python插件
        /// </summary>
        /// <param name="pythonCode">Python插件的代码的部分或者全部,用于精确匹配某个Python插件</param>
        private void RemovePythonPlugIn(string pythonCode)
        {
            if (this.View == null)
            {
                return;
            }
            #region ViewPlugInProxy
            var viewPlugInProxy = this.View.GetService<DynamicFormViewPlugInProxy>();
            if (viewPlugInProxy != null)
            {
                PythonBillPlugIn viewPlugIn = null;
                foreach (var plugIn in viewPlugInProxy.PlugIns)
                {
                    if (plugIn.GetType().Name == "PythonBillPlugIn")
                    {
                        // private ScriptString scriptString;
                        var pythonPlugIn = (PythonBillPlugIn) plugIn;
                        var scriptString = pythonPlugIn.GetType().GetField("scriptString", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pythonPlugIn) as ScriptString;
                        if (scriptString != null && scriptString.ToString().Contains(pythonCode))
                        {
                            viewPlugIn = pythonPlugIn;
                        }
                    }
                }
                if (viewPlugIn != null)
                {
                    viewPlugInProxy.PlugIns.Remove(viewPlugIn);
                }
            }
            #endregion
            #region ModelPlugInProxy
            var modelPlugInProxy = this.View.GetService<DynamicFormModelPlugInProxy>();
            if (modelPlugInProxy != null)
            {
                PythonBillPlugIn modelPlugIn = null;
                foreach (var plugIn in modelPlugInProxy.PlugIns)
                {
                    if (plugIn.GetType().FullName == "Kingdee.BOS.Core.Bill.PlugIn.PythonBillPlugIn")
                    {
                        // private ScriptString scriptString;
                        var pythonPlugIn = (PythonBillPlugIn) plugIn;
                        var scriptString = pythonPlugIn.GetType().GetField("scriptString", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pythonPlugIn) as ScriptString;
                        if (scriptString != null && scriptString.ToString().Contains(pythonCode))
                        {
                            modelPlugIn = pythonPlugIn;
                        }
                    }
                }
                if (modelPlugIn != null)
                {
                    modelPlugInProxy.PlugIns.Remove(modelPlugIn);
                }
            }
            #endregion
        }
    }
}


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

上传图片


<5>BOSIDE扩展采购订单,注册表单插件和Python插件,保存元数据,开发完毕。

上传图片



【功能验证】

<1>登录业务站点,打开采购订单,界面上并不会出现提示信息,说明禁用插件的功能已生效。

不注册插件DisablePlugInFormPlugIn的效果:

上传图片

注册插件DisablePlugInFormPlugIn后的效果:

上传图片

---------------------------------------------------------------------------------------------------------













【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696

二开案例.表单插件.禁用插件

【应用场景】运行时,通过插件,禁用其它的插件。【案例演示】采购订单,表单插件,B插件会在界面上显示消息,通过A插件禁用B插件。【实现...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息