Example #1
0
        /// <summary>
        /// 得到角色应用刷新JSON
        /// </summary>
        /// <returns></returns>
        public string GetRoleAppRefreshJsonString(Guid roleID, Guid userID, Guid refreshID, string rootDir = "")
        {
            RoleApp       roleApp   = new RoadFlow.Platform.RoleApp();
            UsersApp      UsersApp  = new Platform.UsersApp();
            AppLibraryBLL Applibary = new AppLibraryBLL();
            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().Convert <Guid>()).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());
        }
Example #2
0
        /// <summary>
        /// 得到角色应用JSON
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public string GetRoleAppJsonString(Guid roleID, Guid userID, string rootDir = "")
        {
            RoleApp       RoleApp   = new RoadFlow.Platform.RoleApp();
            UsersApp      UsersApp  = new Platform.UsersApp();
            AppLibraryBLL Applibary = new AppLibraryBLL();

            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().Convert <Guid>()).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\":[");
                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());
        }