protected void AddSubMenu(SysMenu parent, ToolStripMenuItem add) { if ((parent.SubMenus == null) || (parent.SubMenus.Count <= 0) || (add == null)) { return; } SysMenu mitem; for (int i = 0; i < parent.SubMenus.Count; i++) { mitem = parent.SubMenus[i]; ToolStripMenuItem addmi = new ToolStripMenuItem(); addmi.Name = mitem.MCode + "-" + mitem.MFunction; addmi.Text = mitem.MName; add.DropDownItems.Add(addmi); if (!String.IsNullOrEmpty(mitem.MFunction)) { MenuAuth ma = new MenuAuth(); ma.MID = mitem.MID; ma.MCode = mitem.MCode; ma.MFunction = mitem.MFunction; ma.MShortcut = mitem.MShortcut; ma.Auth = mitem.MAuth; Program.ManInfo.Auths.Add(ma); } if (mitem.IsLine) { add.DropDownItems.Add(new ToolStripSeparator()); } if ((mitem.SubMenus != null) && (mitem.SubMenus.Count > 0)) { AddSubMenu(mitem, addmi); } else { addmi.Click += new EventHandler(Menu_Click); } } }
protected void CreateUserMenu() { SqlBaseProvider.GetManMenus(Program.ManInfo, Program.ManInfo.Man.ManID); SysMenuGroups mgs = Program.ManInfo.Menus; if ((mgs == null) || (mgs.Count <= 0)) { return; } int i, j, k; msMain.Items.Clear(); for (i = 0; i < mgs.Count; i++) { SysMenuGroup mgitem = mgs[i]; if ((mgitem.Menus == null) || (mgitem.Menus.Count <= 0)) { continue; } ToolStripMenuItem gi = new ToolStripMenuItem(); gi.Name = "MenuGroup" + mgitem.MgID.ToString(); gi.Text = mgitem.MgName; for (j = 0; j < mgitem.Menus.Count; j++) { SysMenu mitem = mgitem.Menus[j]; ToolStripMenuItem mi = new ToolStripMenuItem(); mi.Name = mitem.MCode + "-" + mitem.MFunction; mi.Text = mitem.MName; if (!String.IsNullOrEmpty(mitem.MFunction)) { MenuAuth ma = new MenuAuth(); ma.MID = mitem.MID; ma.MCode = mitem.MCode; ma.MFunction = mitem.MFunction; ma.MShortcut = mitem.MShortcut; ma.Auth = mitem.MAuth; Program.ManInfo.Auths.Add(ma); } gi.DropDownItems.Add(mi); if (mitem.IsLine) { gi.DropDownItems.Add(new ToolStripSeparator()); } if ((mitem.SubMenus != null) && (mitem.SubMenus.Count > 0)) { AddSubMenu(mitem, mi); } else { if (!String.IsNullOrEmpty(mitem.MFunction)) { mi.Click += new EventHandler(Menu_Click); } } } msMain.Items.Add(gi); } RibTabs rts = Program.ManInfo.Ribbons; RibTab rt; bool isRibTab = false; ribMain.Tabs.Clear(); for (i = 0; i < rts.Count; i++) { isRibTab = false; rt = rts[i]; // Ribbon Tab's Panels Count为0,则不做处理 if (rt.Panels.Count <= 0) { continue; } // 判断该Tab下的所有Panel是否包含了按钮,如果没有,则不做处理 for (j = 0; j < rt.Panels.Count; j++) { if (rt.Panels[j].Buttons.Count <= 0) { continue; } else { isRibTab = true; break; } } if (!isRibTab) { continue; } RibbonTab rTab = new RibbonTab(); rTab.Text = rt.RibTabName; for (j = 0; j < rt.Panels.Count; j++) { if (rt.Panels[j].Buttons.Count > 0) { RibbonPanel rPanel = new RibbonPanel(); rPanel.Text = rt.Panels[j].RibPanelName; for (k = 0; k < rt.Panels[j].Buttons.Count; k++) { RibbonButton rButton = new RibbonButton(); rButton.Text = rt.Panels[j].Buttons[k].RibBtnName; if (!String.IsNullOrEmpty(rt.Panels[j].Buttons[k].MFunction)) { rButton.Function = rt.Panels[j].Buttons[k].RibCode + "-" + rt.Panels[j].Buttons[k].MCode + "-" + rt.Panels[j].Buttons[k].MFunction; rButton.Click += new EventHandler(Ribbon_Click); } if (rt.Panels[j].Buttons[k].RibImageIndex > -1) { if (ilRibbon.Images.Count > rt.Panels[j].Buttons[k].RibImageIndex) { rButton.Image = ilRibbon.Images[rt.Panels[j].Buttons[k].RibImageIndex]; } } rPanel.Items.Add(rButton); } rTab.Panels.Add(rPanel); } } ribMain.Tabs.Add(rTab); } }