public virtual object GetOrgTree(HttpContext context) { YZRequest request = new YZRequest(context); string path = request.GetString("node", null); string srcoupath = request.GetString("srcoupath", null); GetRootOUsType getRootOUsType = request.GetEnum <GetRootOUsType>("getRootOUsType", GetRootOUsType.All); if (YZStringHelper.EquName(path, "root")) { path = null; } JObject rv = new JObject(); using (BPMConnection cn = new BPMConnection()) { cn.WebOpen(); JArray children = new JArray(); rv[YZJsonProperty.children] = children; if (String.IsNullOrEmpty(path)) { SecurityToken token = cn.Token; JObject dirParentItem = null; this.Expand(cn, children, path, token, ref dirParentItem, getRootOUsType, srcoupath); if (dirParentItem != null) { dirParentItem["dirou"] = true; //没必要列出所在部门的子部门 //dirParentItem["expanded"] = false; //dirParentItem.ChildItems.Clear(); } } else { OUCollection ous = OU.GetChildren(cn, path); foreach (OU ou in ous) { JObject item = new JObject(); item["leaf"] = false; item["text"] = ou.Name; item["iconCls"] = "folder"; item["id"] = ou.FullName; item["enpandable"] = true; children.Add(item); item["data"] = this.GetNodeData(ou); } } } //输出数据 return(rv); }
protected virtual void Expand(BPMConnection cn, JArray items, string path, SecurityToken token, ref JObject dirParentItem, GetRootOUsType getRootOUsType, string srcoupath) { OUCollection ous; if (String.IsNullOrEmpty(path)) { if (getRootOUsType != GetRootOUsType.All && !String.IsNullOrEmpty(srcoupath)) { ous = cn.GetRootOUs(srcoupath, getRootOUsType); } else { ous = cn.GetRootOUs(); } } else { ous = OU.GetChildren(cn, path); } bool parentOuExpanded = false; foreach (OU ou in ous) { JObject item = new JObject(); item["leaf"] = false; item["text"] = ou.Name; item["iconCls"] = "folder"; item["id"] = ou.FullName; item["expandable"] = true; items.Add(item); item["data"] = this.GetNodeData(ou); if ((ous.Count == 1 && String.IsNullOrEmpty(path)) || (!parentOuExpanded && token.ContainsSID(ou.SID))) { dirParentItem = item; parentOuExpanded = true; item["expanded"] = true; JArray children = new JArray(); item[YZJsonProperty.children] = children; Expand(cn, children, ou.FullName, token, ref dirParentItem, getRootOUsType, srcoupath); } } }