public void GroupTree() { try { using (ProxyBE p = new ProxyBE()) { string UserID = Request["UserID"]; List <User2Role> listUser2Role = new List <User2Role>(); if (!string.IsNullOrEmpty(UserID)) { listUser2Role = p.Client.GetUser2RoleByUserID(SenderUser, new Guid(UserID)); } StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.Append("[{"); jsonBuilder.Append("\"id\":\"0\""); jsonBuilder.Append(",\"text\":\"用户组\""); jsonBuilder.Append(",\"attributes\":{\"IsMenu\":\"0\"}"); #region 用户组 //用户组 SearchUserGroupArgs ugargs = new SearchUserGroupArgs(); SearchResult sr = p.Client.SearchUserGroup(SenderUser, ugargs); if (sr.Total > 0) { jsonBuilder.AppendFormat(",\"children\":"); jsonBuilder.Append("["); for (int j = 0; j < sr.DataSet.Tables[0].Rows.Count; j++) { DataRow drow = sr.DataSet.Tables[0].Rows[j]; // PrivilegeCategory itemPC = listPrivilegeCategory[j]; jsonBuilder.Append("{"); jsonBuilder.AppendFormat("\"id\":\"{0}\"", drow["GroupID"]); jsonBuilder.AppendFormat(",\"text\":\"{0}\"", drow["GroupName"]); jsonBuilder.Append(",\"attributes\":{\"IsMenu\":\"2\",\"ParentID\":\"" + drow["GroupID"] + "\"}"); jsonBuilder.Append("}"); if (j < sr.DataSet.Tables[0].Rows.Count - 1) { jsonBuilder.Append(","); } } jsonBuilder.Append("]"); } #endregion jsonBuilder.Append("}]"); Response.Write(jsonBuilder.ToString()); } } catch (Exception ex) { WriteError(ex.Message, ex); } }
public SearchResult SearchUserGroup(Sender sender, SearchUserGroupArgs args) { try { using (ObjectProxy op = new ObjectProxy()) { return(op.SearchUserGroup(args)); } } catch (Exception ex) { PLogger.LogError(ex); throw ex; } }
/// <summary> /// 树(角色权限树) /// </summary> public void RoleTree() { try { using (ProxyBE p = new ProxyBE()) { string UserID = Request["UserID"]; List <User2Role> listUser2Role = new List <User2Role>(); if (!string.IsNullOrEmpty(UserID)) { listUser2Role = p.Client.GetUser2RoleByUserID(SenderUser, new Guid(UserID)); } StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.Append("[{"); jsonBuilder.Append("\"id\":\"0\""); jsonBuilder.Append(",\"text\":\"角色设置\""); jsonBuilder.Append(",\"attributes\":{\"IsMenu\":\"0\"}"); #region 用户组 //用户组 SearchUserGroupArgs ugargs = new SearchUserGroupArgs(); //ugargs.IsSystem = false; SearchResult sr = p.Client.SearchUserGroup(SenderUser, ugargs); if (sr.Total > 0) { jsonBuilder.AppendFormat(",\"children\":"); jsonBuilder.Append("["); for (int j = 0; j < sr.DataSet.Tables[0].Rows.Count; j++) { DataRow drow = sr.DataSet.Tables[0].Rows[j]; // PrivilegeCategory itemPC = listPrivilegeCategory[j]; jsonBuilder.Append("{"); jsonBuilder.AppendFormat("\"id\":\"{0}\"", drow["GroupID"]); jsonBuilder.AppendFormat(",\"text\":\"{0}\"", drow["GroupName"]); jsonBuilder.AppendFormat(",\"iconCls\":\"{0}\"", "group"); jsonBuilder.Append(",\"attributes\":{\"IsMenu\":\"2\",\"ParentID\":\"" + drow["GroupID"] + "\"}"); jsonBuilder.AppendFormat(",\"children\":"); jsonBuilder.Append("["); #region 角色 //角色 List <Role> listRole = p.Client.GetRolesByGroupID(SenderUser, new Guid((drow["GroupID"].ToString()))); if (listRole != null) { for (int n = 0; n < listRole.Count; n++) { Role itemRole = listRole[n]; //if (itemRole.IsSystem) continue; jsonBuilder.Append("{"); jsonBuilder.AppendFormat("\"id\":\"{0}\"", itemRole.RoleID); jsonBuilder.AppendFormat(",\"text\":\"{0}\"", itemRole.RoleName); jsonBuilder.AppendFormat(",\"iconCls\":\"{0}\"", "user"); if (listUser2Role.Find(pl => pl.RoleID == itemRole.RoleID) != null) { jsonBuilder.AppendFormat(",\"checked\":\"{0}\"", true); } jsonBuilder.Append(",\"attributes\":{\"IsMenu\":\"3\",\"ParentID\":\"" + drow["GroupID"].ToString() + "\"}"); jsonBuilder.Append("}"); if (n < listRole.Count - 1) { jsonBuilder.Append(","); } } } #endregion jsonBuilder.Append("]"); jsonBuilder.Append("}"); if (j < sr.DataSet.Tables[0].Rows.Count - 1) { jsonBuilder.Append(","); } } jsonBuilder.Append("]"); } #endregion jsonBuilder.Append("}]"); Response.Write(jsonBuilder.ToString()); } } catch (Exception ex) { WriteError(ex.Message, ex); } }