public object GetAllPrivilege() { var Mod = PrivilegeDescription.PrivilegeType(); using (DBConnection dbc = new DBConnection()) { StringBuilder sb = new StringBuilder(); sb.Append(" select t.orderno,"); sb.Append(" substr(ModuleName, 0, instr(ModuleName, '-') -1) as Mod,"); sb.Append(" substr(ModuleName,"); sb.Append(" instr(ModuleName, '-') + 1,"); sb.Append(" (length(ModuleName) - instr(ModuleName, '-'))) as Item"); sb.Append(" ,t.privilegecode"); sb.Append(" from TZCLZ_T_YH_QX t"); var Items = dbc.ExecuteDataTable(sb.ToString()); return(new { Mod = Mod, Items = Items }); } }
/// <summary> /// 检测权限字符串 /// </summary> /// <param name="str">权限字符串</param> /// <returns>Boolean</returns> /// <remarks></remarks> public bool CheckPrivilegeString(string str) { if (str == null) { return(true); } if (str.Length == 0) { return(true); } string[] pstrs = str.Split(','); List <Guid> lst = new List <Guid>(); try { foreach (string pstr in pstrs) { string clsName = null; int iLastDot = pstr.LastIndexOf("."); if (iLastDot == -1) { return(false); } clsName = pstr.Substring(0, iLastDot); Type tp = Type.GetType(clsName); System.Reflection.FieldInfo fld = default(System.Reflection.FieldInfo); fld = tp.GetField(pstr.Substring(iLastDot + 1, pstr.Length - iLastDot - 1), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); if (fld == null) { return(false); } PrivilegeDescription pd = (PrivilegeDescription)fld.GetValue(null); lst.Add(pd); } return(CheckPrivilege(lst.ToArray())); } catch (Exception ex) { return(false); } }