Beispiel #1
0
        public string Tree1()
        {
            string  rootid   = Request.QueryString["rootid"];
            string  showtype = Request.QueryString["showtype"];
            DeptBLL deptBll  = BLLFactory <DeptBLL> .Instance;

            System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000);

            string rootID;
            Dept   root;

            if (!string.IsNullOrEmpty(rootid))
            {
                root = deptBll.FindByID(rootid);
            }
            else
            {
                root = deptBll.GetTopGroup();
            }

            List <User> users = new List <User>();

            UserBLL busers = BLLFactory <UserBLL> .Instance;

            users = busers.Find("DeptID='" + root.ID + "'"); //busers.GetUsersByDept(root.ID);

            json.Append("{");
            json.AppendFormat("\"id\":\"{0}\",", root.ID);
            json.AppendFormat("\"parentID\":\"{0}\",", root.PID);
            json.AppendFormat("\"title\":\"{0}\",", root.Name);
            json.AppendFormat("\"ico\":\"{0}\",", Url.Content("~/Assets/WorkFlow/images/ico/icon_site.gif"));
            json.AppendFormat("\"link\":\"{0}\",", "");
            json.AppendFormat("\"type\":\"{0}\",", 2);
            json.AppendFormat("\"hasChilds\":\"{0}\",", 1);
            json.Append("\"childs\":[");

            var orgs  = deptBll.GetChilds(root.ID);
            int count = orgs.Count;

            int i = 0;

            foreach (var org in orgs)
            {
                json.Append("{");
                json.AppendFormat("\"id\":\"{0}\",", org.ID);
                json.AppendFormat("\"parentID\":\"{0}\",", org.PID);
                json.AppendFormat("\"title\":\"{0}\",", org.Name);
                json.AppendFormat("\"ico\":\"{0}\",", "");
                json.AppendFormat("\"link\":\"{0}\",", "");
                json.AppendFormat("\"type\":\"{0}\",", 2);
                json.AppendFormat("\"hasChilds\":\"{0}\",", 1);
                json.Append("\"childs\":[");
                json.Append("]");
                json.Append("}");
                if (i++ < count - 1 || users.Count > 0)
                {
                    json.Append(",");
                }
            }

            if (users.Count > 0)
            {
                //var userRelations = new RoadFlow.Platform.UsersRelation().GetAllByOrganizeID(root.ID);
                //var userList
                int count1 = users.Count;
                int j      = 0;
                foreach (var user in users)
                {
                    //var ur = userRelations.Find(p => p.UserID == user.ID);
                    json.Append("{");
                    json.AppendFormat("\"id\":\"{0}\",", user.ID);
                    json.AppendFormat("\"parentID\":\"{0}\",", root.ID);
                    json.AppendFormat("\"title\":\"{0}\",", user.FullName);//, ur != null && ur.IsMain == 0 ? "<span style='color:#999;'>[兼职]</span>" : "");
                    json.AppendFormat("\"ico\":\"{0}\",", "");
                    json.AppendFormat("\"link\":\"{0}\",", "");
                    json.AppendFormat("\"type\":\"{0}\",", "4");
                    json.AppendFormat("\"hasChilds\":\"{0}\",", "0");
                    json.Append("\"childs\":[");
                    json.Append("]");
                    json.Append("}");
                    if (j++ < count1 - 1)
                    {
                        json.Append(",");
                    }
                }
            }


            json.Append("]");
            json.Append("}");
            json.Append("]");

            return(json.ToString());
        }