直接从数据库中加载菜单
其中 programName 是你需要加载的模块。
TYPE 是打开的类别
1.菜单:表示是它是一个菜单项。
2.功能:表示需要调用一段代码(Close,CloseThis,Region)等体
3.窗口:以弹出窗品的方式打开。
4页面:以MDIChild的方式,放到主窗体中。
IFShowINMenu :表示是否在菜单中显示。
代码如下:
1 public void loadMenu(T1_QX_MyPermission p, DevExpress.XtraBars.BarSubItem sbarSubItem) 2 { 3 4 #region 菜单 5 MyFLYDataContext dataContext = new MyFLYDataContext(false); 6 var v1 = from t in dataContext.T1_QX_MyPermission 7 where 8 t.FID == p.AutoID 9 select t; 10 11 12 int i = 0; 13 foreach (var vt in v1) 14 { 15 16 //查有没有下级 17 MyFLYDataContext dataContext1 = new MyFLYDataContext(false); 18 var v_Temp = from t in dataContext.T1_QX_MyPermission 19 where 20 t.FID == vt.AutoID 21 select t; 22 i++; 23 if (v_Temp.Count() > 0) 24 { 25 26 DevExpress.XtraBars.BarSubItem barSubItem = new DevExpress.XtraBars.BarSubItem(); 27 barSubItem.Caption = vt.Name; 28 barSubItem.Id = i; 29 barSubItem.Name = "barSubItem" + i.ToString(); 30 if (sbarSubItem != null) 31 { 32 sbarSubItem.AddItem(barSubItem); 33 } 34 else 35 { 36 this.bar2.AddItem(barSubItem); 37 } 38 //加下级菜单 39 loadMenu(vt, barSubItem); 40 41 } 42 else 43 { 44 MyFLYDataContext dataContext2 = new MyFLYDataContext(false); 45 var vx = from t in dataContext.T1_QX_MyPermission 46 where 47 t.FID == vt.AutoID 48 select t; 49 50 51 T1_QX_MyPermission tt = vt; 52 53 DevExpress.XtraBars.BarButtonItem barButtonItem = new DevExpress.XtraBars.BarButtonItem(); 54 barButtonItem.Caption = vt.Name; 55 barButtonItem.Id = i * 100; 56 barButtonItem.Name = "barButtonItem" + (i * 100 ).ToString(); 57 barButtonItem.Tag = tt; 58 #region 事件 59 barButtonItem.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(delegate(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 60 { 61 62 63 //这里加入菜单事件 64 //if (DataBase.DataFunction.checkPermission((List<string>)AppDomain.CurrentDomain.GetData("permissionList"), vtt.AutoID.ToString()))//看有没有权限 65 if (true) 66 { 67 68 T1_QX_MyPermission t = (T1_QX_MyPermission)(e.Item.Tag); 69 DevExpress.XtraEditors.XtraForm formx = null; 70 71 Assembly ASM = Assembly.GetExecutingAssembly(); 72 switch (t.TYPE) 73 { 74 case "页面": 75 formx = ASM.CreateInstance(t.ProgramName) as XtraForm; 76 77 if (OpenOnce(formx) == true) 78 { 79 formx.MdiParent = this; 80 formx.WindowState = FormWindowState.Maximized; 81 formx.Show(); 82 } 83 break; 84 case "功能": 85 MainFunction(t.ProgramCode); 86 break; 87 case "窗口": 88 formx = ASM.CreateInstance(t.ProgramName) as XtraForm; 89 formx.ShowDialog(); 90 break; 91 default: 92 MessageBox.Show("未定义,请联系管理员!"); 93 break; 94 95 } 96 97 98 } 99 else 100 { 101 MessageBox.Show("无此权限", "提示"); 102 } 103 104 }); 105 #endregion 106 if (sbarSubItem != null) 107 { 108 sbarSubItem.AddItem(barButtonItem); 109 } 110 else 111 { 112 this.bar2.AddItem(barButtonItem); 113 } 114 115 116 117 } 118 119 } 120 #endregion 121 }
效果