/// <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; }
/// <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> /// 系统初始化处理 /// </summary> public bool Init() { if (EmpInfo.Id <= 0) { this.Close(); return(false); } // 人员基本信息 LogHelper.Info(this, "系统初始化 --- 设置人员有关信息"); this.bsiOper.Caption = EmpInfo.Name + "(" + EmpInfo.BizDeptName + ")"; this.bsiIP.Caption = EnvInfo.ComputerIp; this.bsiUser.Caption = EnvInfo.UserName; this.bbiChangeChoice.Caption = (EmpInfo.InputChoice == "1") ? "首拼" : "五笔"; LinkMacAddress.Caption = "未识别"; for (int i = 0; i < EnvInfo.ComputerMacIpList.Count; i++) { if (i == 0) { LinkMacAddress.Caption = EnvInfo.ComputerMacIpList[i].Mac; } else { var item = new BarHeaderItem { Caption = EnvInfo.ComputerMacIpList[i].Mac, AllowRightClickInMenu = false }; LinkMacAddress.LinksPersistInfo.Add(new LinkPersistInfo(item)); } } //初始化子系统 LogHelper.Info(this, "系统初始化 --- 子系统初始化"); string open_menu_code = InitSubSystem(); //初始化主菜单 LogHelper.Info(this, "系统初始化 --- 生成主菜单"); InitMainMenu(open_menu_code); // 加入可切换的子系统 BarSubItem bsiSystem = new DevExpress.XtraBars.BarSubItem(); bsiSystem.Caption = "系统切换"; bsiSystem.Id = this.ribbon.Items.Count; bsiSystem.Name = "bsiSystem"; this.ribbon.Items.Add(bsiSystem); this.rbPageGroupTools.ItemLinks.Insert(0, bsiSystem); foreach (BDictSystem system in EmpInfo.CanUseSystemList) { if (system.Code != EnvInfo.SystemCode) { BarButtonItem bbi = new BarButtonItem(); bbi.Caption = system.Name; bbi.Id = this.ribbon.Items.Count; bbi.Name = "bbiSystem" + system.Code; bbi.Tag = system.Code; bbi.ItemClick += new ItemClickEventHandler(this.bbiSystem_ItemClick); bbi.RibbonStyle = RibbonItemStyles.Default; if (!string.IsNullOrEmpty(system.Ico)) { bbi.ImageOptions.Image = BmpHelper.GetIco(system.Ico); } this.ribbon.Items.Add(bbi); bsiSystem.LinksPersistInfo.Add(new LinkPersistInfo(bbi)); } } // v9.2以后不加入会出现下拉菜单不能出来!!! ((System.ComponentModel.ISupportInitialize)(this.ribbon)).EndInit(); //初始化外部信息对象, 危机值、关注项由通知 List <string> infoRemoteCodeList = new List <string>(); // TODO: ??? infoRemoteCodeList.Add("foo1"); // 危机值信息 infoRemoteCodeList.Add("foo2"); // 关注项信息 infoRemoteAction = new RemoteInfoReceiver(infoRemoteCodeList, SynCallbackInfo); //RemoteInfoHelper.Subscribe("foo1,foo2"); //初始化内部信息对象 List <string> infoLocalCodeList = new List <string>(); infoLocalCodeList.Add(LocalInfoHelper.OpenForm); // 打开Form infoLocalCodeList.Add(LocalInfoHelper.AddNotice); // 接受通知 infoLocalCodeList.Add(LocalInfoHelper.DelNotice); // 撤销通知 infoLocalAction = new LocalInfoReceiver(infoLocalCodeList, CallbackInfo); for (int index = 0; index < ribbon.Pages.Count; index++) { var item = ribbon.Pages[index]; item.Appearance.Font = new Font(SystemFonts.DefaultFont.Name, SystemFonts.DefaultFont.Size); } for (int index = 0; index < ribbon.Items.Count; index++) { var item = ribbon.Items[index]; item.ItemAppearance.SetFont(new Font(SystemFonts.DefaultFont.Name, SystemFonts.DefaultFont.Size)); } LogHelper.Info(this, "系统初始化 --- 启动定时器"); timer1.Start(); DisplayHelper.Close(); return(true); }