/// <summary> /// 产生菜单 /// </summary> /// <param name="menu">菜单数据</param> /// <param name="pi">菜单起点</param> /// <returns></returns> private BarSubItem CreateMenu(List <DataMenu> menuList, ref int pi) { // 取数据到变量 string code = menuList[pi].Code; string title = menuList[pi].Title; // 加入下拉菜单 BarSubItem bsimenu = new BarSubItem(); bsimenu.Caption = title; bsimenu.Name = "bsi" + code; string ico = menuList[pi].Ico; if (!ico.IsNullOrEmpty()) // 图标 { if (ico.ToLower().EndsWith("svg")) { bsimenu.ImageOptions.SvgImage = BmpHelper.GetSvg(ico); } else { Image img = BmpHelper.GetIco(ico); bsimenu.LargeGlyph = bsimenu.Glyph = img; } } // 在菜单项下加入菜单(中间项)或子项(功能项) pi++; for (; pi < menuList.Count; pi++) { string code1 = menuList[pi].Code; string title1 = menuList[pi].Title; if (code1.Length == (code.Length + 1) && code1.Substring(0, code.Length) == code) { string modname = menuList[pi].ModuleName; string funname = menuList[pi].ObjectName; string para = menuList[pi].Parameter; int openflag = menuList[pi].WinState; if (string.IsNullOrEmpty(funname)) // 有子菜单 { BarSubItem bsisubmenu = this.CreateMenu(menuList, ref pi); if (bsisubmenu.LinksPersistInfo.Count > 0) // 有子项才加入 { this.ribbon.Items.Add(bsisubmenu); bsimenu.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(bsisubmenu)); } } else { // 是功能加入功能项 BarButtonItem bbi = new BarButtonItem(); bbi.Caption = title1; bbi.Id = this.ribbon.Items.Count; bbi.Name = "bbi" + code1; if (!string.IsNullOrEmpty(menuList[pi].Prompt)) { SuperToolTip stt = new SuperToolTip(); ToolTipItem tti = new ToolTipItem(); tti.Text = menuList[pi].Prompt; stt.Items.Add(tti); bbi.SuperTip = stt; } ico = menuList[pi].Ico; if (!ico.IsNullOrEmpty()) // 图标 { bbi.RibbonStyle = RibbonItemStyles.Default; if (ico.ToLower().EndsWith("svg")) { bbi.ImageOptions.SvgImage = BmpHelper.GetSvg(ico); } else { bbi.Glyph = BmpHelper.GetIco(ico); } } bbi.Tag = ToFunction(menuList[pi]); bbi.ItemClick += new ItemClickEventHandler(this.dynamic_bbi_ItemClick); this.ribbon.Items.Add(bbi); bsimenu.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(bbi)); } } else { pi--; break; } } return(bsimenu); }
/// <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; }