电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

二开案例.单据插件.元数据缓存刷新之菜单异常

来源:金蝶云社区作者:金蝶2024-09-231

二开案例.单据插件.元数据缓存刷新之菜单异常

【应用场景】

菜单元数据因为未知原因偶发性的被损坏,导致菜单显示异常。


【案例演示】

应付单,模拟菜单元数据被损坏的场景下,如何快速重新加载干净的元数据。


【实现步骤】

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

using Kingdee.BOS;

using Kingdee.BOS.Cache;

using Kingdee.BOS.Core.Bill;

using Kingdee.BOS.Core.Bill.PlugIn;

using Kingdee.BOS.Core.Bill.PlugIn.Args;

using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;

using Kingdee.BOS.Core.Metadata;

using Kingdee.BOS.Core.Metadata.ControlElement;

using Kingdee.BOS.ServiceHelper;

using Kingdee.BOS.Util;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Linq;


namespace Jac.XkDemo.BOS.Business.PlugIn

{

    /// <summary>

    /// 【单据插件】元数据缓存刷新之菜单异常

    /// </summary>

    [Description("【单据插件】元数据缓存刷新之菜单异常"), HotUpdate]

    public class ReloadMetadataForMenuBillPlugIn : AbstractBillPlugIn

    {

        private BusinessInfo businessInfo;

        private LayoutInfo layoutInfo;

        private string barItemKey = "tbClose";


        public override void OnSetBusinessInfo(SetBusinessInfoArgs e)

        {

            base.OnSetBusinessInfo(e);

            if (!CheckMetadata(this.View))

            {

                var meta = GetNewMetadata(this.View);

                if (meta != null)

                {

                    this.businessInfo = meta.BusinessInfo;

                    this.layoutInfo = meta.GetLayoutInfo();

                    e.BillBusinessInfo = this.businessInfo;

                    e.BusinessInfo = this.businessInfo;

                }

            }

        }


        public override void OnSetLayoutInfo(SetLayoutInfoArgs e)

        {

            base.OnSetLayoutInfo(e);

            e.BillLayoutInfo = this.layoutInfo;

            e.LayoutInfo = this.layoutInfo;

        }


        public override void AfterCreateModelData(EventArgs e)

        {

            base.AfterCreateModelData(e);

            if (!CheckMetadata(this.View))

            {

                GetNewMetadata(this.View);

                throw new Exception("创建新数据包后检测到元数据异常,请关闭当前界面后重试!");

            }

        }


        public override void LoadData(LoadDataEventArgs e)

        {

            base.LoadData(e);

            if (!CheckMetadata(this.View))

            {

                GetNewMetadata(this.View);

                throw new Exception("加载数据前检测到元数据异常,请关闭当前界面后重试!");

            }

        }


        public override void AfterLoadData(EventArgs e)

        {

            base.AfterLoadData(e);

            if (!CheckMetadata(this.View))

            {

                GetNewMetadata(this.View);

                throw new Exception("加载数据后检测到元数据异常,请关闭当前界面后重试!");

            }

        }


        public override void BarItemClick(BarItemClickEventArgs e)

        {

            base.BarItemClick(e);

            if (e.BarItemKey == "test")

            {

                // 测试代码

                //var menu = this.View.LayoutInfo.GetFormAppearance().Menu;

                //var barItem = menu.BarItems.FirstOrDefault(o => o.Key.EqualsIgnoreCase(barItemKey));

                //if (barItem != null)

                //{

                //    barItem.Enabled = 1;

                //    //barItem.Visible = 0;

                //}

            }

        }


        /// <summary>

        /// 清除元数据缓存,返回新的元数据

        /// </summary>

        /// <param name="view"></param>

        /// <returns></returns>

        private FormMetadata GetNewMetadata(IBillView view)

        {

            var ctx = view.Context;

            var businessInfo = view.BusinessInfo;

            var formId = businessInfo.GetForm().Id;

            var layoutId = view.OpenParameter.LayoutId;

            // 清除元数据缓存

            ClearMetaCache(ctx, formId);

            // 重新加载元数据

            var meta = FormMetaDataCache.GetCachedFormMetaData(ctx, formId, layoutId);

            return meta;

        }


        /// <summary>

        /// 清除元数据(清内存缓存和数据库缓存)

        /// </summary>

        /// <param name="ctx"></param>

        /// <param name="formId"></param>

        private void ClearMetaCache(Context ctx, string formId)

        {

            var ids = new List<string>();

            // 获取与当前表单有关系的所有表单Id

            var sql = string.

二开案例.单据插件.元数据缓存刷新之菜单异常

【应用场景】菜单元数据因为未知原因偶发性的被损坏,导致菜单显示异常。【案例演示】应付单,模拟菜单元数据被损坏的场景下,如何快速重新...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信