/// <summary> /// 得到角色应用JSON /// </summary> /// <param name="roleID"></param> /// <returns></returns> public string GetRoleAppJsonString(Guid roleID) { Business.Platform.RoleApp RoleApp = new Business.Platform.RoleApp(); System.Data.DataTable appDt = RoleApp.GetAllDataTableFromCache(); if (appDt.Rows.Count == 0) { return("[]"); } var root = appDt.Select(string.Format("ParentID='{0}' AND RoleID='{1}'", Guid.Empty.ToString(), roleID)); if (root.Length == 0) { return("[]"); } var apps = appDt.Select(string.Format("ParentID='{0}'", root[0]["ID"].ToString())); System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000); System.Data.DataRow rootDr = root[0]; json.Append("{"); json.AppendFormat("\"id\":\"{0}\",", rootDr["ID"]); json.AppendFormat("\"title\":\"{0}\",", rootDr["Title"].ToString().Trim()); json.AppendFormat("\"ico\":\"{0}\",", ""); json.AppendFormat("\"link\":\"{0}\",", getAddress(rootDr)); json.AppendFormat("\"model\":\"{0}\",", rootDr["OpenMode"]); json.AppendFormat("\"width\":\"{0}\",", rootDr["Width"]); json.AppendFormat("\"height\":\"{0}\",", rootDr["Height"]); json.AppendFormat("\"hasChilds\":\"{0}\",", apps.Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); for (int i = 0; i < apps.Length; i++) { DataRow dr = apps[i]; var childs = appDt.Select("ParentID='" + dr["ID"].ToString() + "'"); json.Append("{"); json.AppendFormat("\"id\":\"{0}\",", dr["ID"]); json.AppendFormat("\"title\":\"{0}\",", dr["Title"]); json.AppendFormat("\"ico\":\"{0}\",", ""); json.AppendFormat("\"link\":\"{0}\",", getAddress(rootDr)); json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"]); json.AppendFormat("\"width\":\"{0}\",", dr["Width"]); json.AppendFormat("\"height\":\"{0}\",", dr["Height"]); json.AppendFormat("\"hasChilds\":\"{0}\",", childs.Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); json.Append("]"); json.Append("}"); if (i < apps.Length - 1) { json.Append(","); } } json.Append("]"); json.Append("}"); json.Append("]"); return(json.ToString()); }
/// <summary> /// 得到角色应用刷新JSON /// </summary> /// <returns></returns> public string GetRoleAppRefreshJsonString(Guid roleID, Guid userID, Guid refreshID, string rootDir = "") { Business.Platform.RoleApp roleApp = new Business.Platform.RoleApp(); Business.Platform.UsersApp UsersApp = new Platform.UsersApp(); DataTable roleAppDt = roleApp.GetAllDataTableFromCache(); DataTable appDt1 = CloneDataTable(roleAppDt); UsersApp.AppendUserApps(userID, appDt1); var dv = appDt1.DefaultView; dv.RowFilter = string.Format("ParentID='{0}'", refreshID); dv.Sort = "Sort"; var appDt = dv.ToTable(); if (appDt.Rows.Count == 0) { return("[]"); } int count = appDt.Rows.Count; System.Text.StringBuilder json = new System.Text.StringBuilder("[", count * 100); int i = 0; foreach (DataRow dr in appDt.Rows) { json.Append("{"); json.AppendFormat("\"id\":\"{0}\",", dr["ID"]); json.AppendFormat("\"title\":\"{0}\",", dr["Title"].ToString().Trim()); json.AppendFormat("\"ico\":\"{0}\",", dr["Ico"].ToString().IsNullOrEmpty() ? "" : rootDir + dr["Ico"]); json.AppendFormat("\"link\":\"{0}\",", getAddress(dr)); json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"]); json.AppendFormat("\"width\":\"{0}\",", dr["Width"]); json.AppendFormat("\"height\":\"{0}\",", dr["Height"]); json.AppendFormat("\"hasChilds\":\"{0}\",", appDt1.Select(string.Format("ParentID='{0}'", dr["id"])).Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); json.Append("]"); json.Append("}"); if (i++ < count - 1) { json.Append(","); } } json.Append("]"); return(json.ToString()); }