Beispiel #1
0
 private DataFunction ToFunction(DataMenu menu)
 {
     return(new DataFunction(menu.Title, menu.ModuleName, menu.ObjectName, menu.Parameter, menu.WinState));
 }
Beispiel #2
0
        /// <summary>
        /// 形成Page及Item
        /// </summary>
        private void Create_Page(string open_menu_code)
        {
            //  取菜单表
            //  获取可用菜单信息
            String roles = EmpInfo.Roles;

            var parmList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("systemId", EnvInfo.SystemId.ToString()),
                new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()),
                new KeyValuePair <string, string>("roles", EmpInfo.Roles),
            };
            CustomException ce       = null;
            List <DataMenu> menuList = HttpDataHelper.GetWithInfo <List <DataMenu> >("BASE", "/sys/menu", out ce, parmList);

            // 删除失效菜单(模块或对象不可用)
            for (int i = menuList.Count - 1; i >= 0; i--)
            {
                if (!String.IsNullOrEmpty(menuList[i].ObjectCode) && (String.IsNullOrEmpty(menuList[i].ObjectName) || String.IsNullOrEmpty(menuList[i].ModuleName)))
                {
                    menuList.RemoveAt(i);
                }
            }

            int             num         = 0;
            string          curPageOrd  = "";
            RibbonPage      rbPage      = new RibbonPage();
            RibbonPageGroup rbPageGroup = new RibbonPageGroup();

            for (int i = 0; i < menuList.Count; i++)
            {
                string code  = menuList[i].Code;
                string title = menuList[i].Title;

                if (code.Length == 1)        //  对应页
                {
                    rbPage      = new RibbonPage(title);
                    rbPage.Name = "rbPage" + code;
                    this.ribbon.Pages.Insert(num, rbPage);
                    this.ribbon.Pages[num].Visible = false;
                    curPageOrd = code;
                    num++;
                }

                if (code.Length == 2)                              //  对应页组
                {
                    int funcount = CountFunctionItem(menuList, i); //  是否存在功能
                    if (funcount > 0 && num > 0 && curPageOrd == code.Substring(0, 1))
                    {
                        this.ribbon.Pages[num - 1].Visible = true;
                        //  加入页组
                        rbPageGroup      = new RibbonPageGroup("");
                        rbPageGroup.Name = "rbPageGroup" + code;
                        rbPageGroup.ShowCaptionButton = false;

                        rbPage.Groups.Add(rbPageGroup);

                        string funname = menuList[i].ObjectName;
                        if (!string.IsNullOrEmpty(funname))
                        {
                            BarButtonItem bbi = new BarButtonItem();
                            bbi.Caption = title;
                            bbi.Id      = this.ribbon.Items.Count;
                            bbi.Name    = "bbi" + code;

                            if (!string.IsNullOrEmpty(menuList[i].Prompt))
                            {
                                SuperToolTip stt = new SuperToolTip();
                                ToolTipItem  tti = new ToolTipItem();
                                tti.Text = menuList[i].Prompt;
                                stt.Items.Add(tti);
                                bbi.SuperTip = stt;
                            }

                            string ico = menuList[i].Ico;
                            if (!ico.IsNullOrEmpty())                               //  图标
                            {
                                if (ico.ToLower().EndsWith("svg"))
                                {
                                    bbi.ImageOptions.SvgImage = BmpHelper.GetSvg(ico);
                                }
                                else
                                {
                                    bbi.LargeGlyph = BmpHelper.GetIco(ico);
                                }

                                bbi.RibbonStyle = RibbonItemStyles.Default;
                            }
                            bbi.Tag = ToFunction(menuList[i]);

                            bbi.ItemClick += new ItemClickEventHandler(this.dynamic_bbi_ItemClick);
                            this.ribbon.Items.Add(bbi);
                            rbPageGroup.ItemLinks.Add(bbi);
                            rbPageGroup.Visible = true;
                        }
                        else
                        {
                            BarSubItem bsimenu = this.CreateMenu(menuList, ref i);              //  产生菜单

                            if (bsimenu.LinksPersistInfo.Count > 0 || bsimenu.Tag != null)      //  有子项才加入
                            {
                                this.ribbon.Items.Add(bsimenu);
                                rbPageGroup.ItemLinks.Add(bsimenu);
                                rbPageGroup.Visible = true;
                            }
                        }
                    }
                }
            }

            this.ribbon.SelectedPage = this.ribbon.Pages[0];
            //  找自动打开菜单
            if (open_menu_code != null)
            {
                DataMenu default_menu = menuList.Find(o => o.Code == open_menu_code);
                if (default_menu != null && !String.IsNullOrEmpty(default_menu.ObjectName) && !String.IsNullOrEmpty(default_menu.ModuleName))
                {
                    Execute(ToFunction(default_menu));
                }
            }
            return;
        }