/// <summary> /// 得到角色应用刷新JSON /// </summary> /// <returns></returns> public string GetRoleAppRefreshJsonString(Guid roleID, Guid userID, Guid refreshID, string rootDir = "") { RoleApp roleApp = new MyCreek.Platform.RoleApp(); UsersApp UsersApp = new Platform.UsersApp(); AppLibrary Applibary = new AppLibrary(); 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); foreach (DataRow dr in appDt.Rows) { if (!dr["UseMember"].ToString().IsNullOrEmpty() && dr["AppID"].ToString().IsGuid() && !Applibary.GetUseMemberCache(dr["AppID"].ToString().ToGuid()).Contains(userID)) { continue; } json.Append("{"); json.AppendFormat("\"id\":\"{0}\",", dr["ID"].ToString()); json.AppendFormat("\"title\":\"{0}\",", dr["Title"].ToString().Trim()); json.AppendFormat("\"ico\":\"{0}\",", dr["Ico"].ToString().IsNullOrEmpty() ? "" : rootDir + dr["Ico"].ToString()); json.AppendFormat("\"link\":\"{0}\",", getAddress(dr)); json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"].ToString()); json.AppendFormat("\"width\":\"{0}\",", dr["Width"].ToString()); json.AppendFormat("\"height\":\"{0}\",", dr["Height"].ToString()); json.AppendFormat("\"hasChilds\":\"{0}\",", appDt1.Select(string.Format("ParentID='{0}'", dr["id"].ToString())).Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); json.Append("]"); json.Append("}"); if (dr["ID"].ToString() != appDt.Rows[appDt.Rows.Count - 1]["ID"].ToString()) { json.Append(","); } } json.Append("]"); return(json.ToString()); }
/// <summary> /// 得到角色应用JSON /// </summary> /// <param name="roleID"></param> /// <returns></returns> public string GetRoleAppJsonString(Guid roleID, Guid userID, string rootDir = "") { RoleApp RoleApp = new MyCreek.Platform.RoleApp(); UsersApp UsersApp = new Platform.UsersApp(); AppLibrary Applibary = new AppLibrary(); System.Data.DataTable roleAppDt = RoleApp.GetAllDataTableFromCache(); System.Data.DataTable appDt = CloneDataTable(roleAppDt); UsersApp.AppendUserApps(userID, appDt); 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"].ToString()); json.AppendFormat("\"title\":\"{0}\",", rootDr["Title"].ToString().Trim()); json.AppendFormat("\"ico\":\"{0}\",", rootDr["Ico"].ToString().IsNullOrEmpty() ? "" : rootDir + rootDr["Ico"].ToString()); json.AppendFormat("\"link\":\"{0}\",", getAddress(rootDr).ToString()); json.AppendFormat("\"model\":\"{0}\",", rootDr["OpenMode"].ToString()); json.AppendFormat("\"width\":\"{0}\",", rootDr["Width"].ToString()); json.AppendFormat("\"height\":\"{0}\",", rootDr["Height"].ToString()); json.AppendFormat("\"hasChilds\":\"{0}\",", apps.Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); for (int i = 0; i < apps.Length; i++) { DataRow dr = apps[i]; if (!dr["UseMember"].ToString().IsNullOrEmpty() && dr["AppID"].ToString().IsGuid() && !Applibary.GetUseMemberCache(dr["AppID"].ToString().ToGuid()).Contains(userID)) { continue; } var childs = appDt.Select("ParentID='" + dr["ID"].ToString() + "'"); json.Append("{"); json.AppendFormat("\"id\":\"{0}\",", dr["ID"].ToString()); json.AppendFormat("\"title\":\"{0}\",", dr["Title"].ToString()); json.AppendFormat("\"ico\":\"{0}\",", dr["Ico"].ToString().IsNullOrEmpty() ? "" : rootDir + dr["Ico"].ToString()); json.AppendFormat("\"link\":\"{0}\",", getAddress(dr)); json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"].ToString()); json.AppendFormat("\"width\":\"{0}\",", dr["Width"].ToString()); json.AppendFormat("\"height\":\"{0}\",", dr["Height"].ToString()); json.AppendFormat("\"hasChilds\":\"{0}\",", childs.Length > 0 ? "1" : "0"); json.AppendFormat("\"childs\":["); /* DataRow[] apps1 = appDt.Select(string.Format("ParentID='{0}'", dr["ID"].ToString())); * for (int j = 0; j < apps1.Length; j++) * { * DataRow dr1 = apps1[j]; * var childs1 = appDt.Select("ParentID='" + dr1["ID"].ToString() + "'"); * json.Append("{"); * json.AppendFormat("\"id\":\"{0}\",", dr1["ID"]); * json.AppendFormat("\"title\":\"{0}\",", dr1["Title"]); * json.AppendFormat("\"ico\":\"{0}\",", dr1["Ico"].ToString().IsNullOrEmpty() ? "" : rootDir + dr1["Ico"]); * json.AppendFormat("\"link\":\"{0}\",", getAddress(dr1)); * json.AppendFormat("\"model\":\"{0}\",", dr1["OpenMode"]); * json.AppendFormat("\"width\":\"{0}\",", dr1["Width"]); * json.AppendFormat("\"height\":\"{0}\",", dr1["Height"]); * json.AppendFormat("\"hasChilds\":\"{0}\",", childs1.Length > 0 ? "1" : "0"); * json.AppendFormat("\"childs\":["); * json.Append("]"); * json.Append("}"); * if (j < apps1.Length - 1) * { * json.Append(","); * } * }*/ json.Append("]"); json.Append("}"); if (dr["ID"].ToString() != apps[apps.Length - 1]["ID"].ToString()) { json.Append(","); } } json.Append("]"); json.Append("}"); json.Append("]"); return(json.ToString()); }