簡單實現設定分級使用者可見選單使用
阿新 • • 發佈:2018-12-09
#region 獲取buttonitem的名稱 public ArrayList mainFormCon() { ArrayList nameList = new ArrayList(); foreach (Control ctl in this.ribbonControl1.Controls) { nameList = GetControls2(ctl, nameList); } return nameList; } private ArrayList GetControls2(Control fatherControl, ArrayList nameList) { System.Reflection.FieldInfo[] fieldInfo = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); for (int i = 0; i < fieldInfo.Length; i++) { if (fieldInfo[i].FieldType.FullName.ToString().StartsWith("DevComponents.DotNetBar.ButtonItem")) { nameList.Add(fieldInfo[i].Name.ToString()); } } return nameList; } public string getText(string name) { object o = this.GetType().GetField(name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); return o.ToString(); } public void serVisible(string rolelevel) { db dbHelp = new db(); DataTable dt = dbHelp.GetDataTable("select * from UserPermissionSetting"); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][rolelevel].ToString()=="False") { try { string name=dt.Rows[i]["MenuName"].ToString(); object o = this.GetType().GetField(name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); ((ButtonItem)o).Visible = false; //".Visible=false"; } catch (Exception) { throw; } } } } #endregion
設定分級使用者可見選單使用