RoadFlow2.1 临时演示

Tree1.ashx.cs 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Dynamic;
  6. namespace WebForm.Platform.Members
  7. {
  8. /// <summary>
  9. /// Tree1 的摘要说明
  10. /// </summary>
  11. public class Tree1 : IHttpHandler
  12. {
  13. public void ProcessRequest(HttpContext context)
  14. {
  15. context.Response.ContentType = "text/plain";
  16. string rootid = context.Request.QueryString["rootid"] ?? "";
  17. string showtype = context.Request.QueryString["showtype"] ?? "";
  18. RoadFlow.Platform.Organize BOrganize = new RoadFlow.Platform.Organize();
  19. RoadFlow.Platform.Users busers = new RoadFlow.Platform.Users();
  20. RoadFlow.Platform.WorkGroup BWorkGroup = new RoadFlow.Platform.WorkGroup();
  21. System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000);
  22. if ("1" == showtype)
  23. {
  24. #region 显示工作组
  25. var workGroups = BWorkGroup.GetAll();
  26. json.Append("{");
  27. json.AppendFormat("\"id\":\"{0}\",", Guid.Empty);
  28. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty);
  29. json.AppendFormat("\"title\":\"{0}\",", "工作组");
  30. json.AppendFormat("\"ico\":\"{0}\",", Common.Tools.BaseUrl + "/images/ico/group.gif");
  31. json.AppendFormat("\"link\":\"{0}\",", "");
  32. json.AppendFormat("\"type\":\"{0}\",", 5);
  33. json.AppendFormat("\"hasChilds\":\"{0}\",", workGroups.Count);
  34. json.Append("\"childs\":[");
  35. int countwg = workGroups.Count;
  36. int iwg = 0;
  37. foreach (var wg in workGroups)
  38. {
  39. json.Append("{");
  40. json.AppendFormat("\"id\":\"{0}\",", wg.ID);
  41. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty);
  42. json.AppendFormat("\"title\":\"{0}\",", wg.Name);
  43. json.AppendFormat("\"ico\":\"{0}\",", "");
  44. json.AppendFormat("\"link\":\"{0}\",", "");
  45. json.AppendFormat("\"type\":\"{0}\",", 5);
  46. json.AppendFormat("\"hasChilds\":\"{0}\",", 0);
  47. json.Append("\"childs\":[");
  48. json.Append("]");
  49. json.Append("}");
  50. if (iwg++ < countwg - 1)
  51. {
  52. json.Append(",");
  53. }
  54. }
  55. json.Append("]");
  56. json.Append("}");
  57. json.Append("]");
  58. context.Response.Write(json.ToString());
  59. context.Response.End();
  60. #endregion
  61. }
  62. if (rootid.IsNullOrEmpty())
  63. {
  64. rootid = BOrganize.GetRoot().ID.ToString();
  65. }
  66. string[] rootIDArray = rootid.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
  67. int m = 0;
  68. foreach (string rootID in rootIDArray)
  69. {
  70. List<RoadFlow.Data.Model.Users> users = new List<RoadFlow.Data.Model.Users>();
  71. Guid rootGuid = Guid.Empty;
  72. if (rootID.IsGuid(out rootGuid))
  73. {
  74. var root = BOrganize.Get(rootGuid);
  75. if (root != null)
  76. {
  77. users = busers.GetAllByOrganizeID(rootGuid);
  78. json.Append("{");
  79. json.AppendFormat("\"id\":\"{0}\",", root.ID);
  80. json.AppendFormat("\"parentID\":\"{0}\",", root.ParentID);
  81. json.AppendFormat("\"title\":\"{0}\",", root.Name);
  82. json.AppendFormat("\"ico\":\"{0}\",", rootIDArray.Length == 1 ? Common.Tools.BaseUrl + "/images/ico/icon_site.gif" : "");
  83. json.AppendFormat("\"link\":\"{0}\",", "");
  84. json.AppendFormat("\"type\":\"{0}\",", root.Type);
  85. json.AppendFormat("\"hasChilds\":\"{0}\",", root.ChildsLength == 0 && users.Count == 0 ? "0" : "1");
  86. json.Append("\"childs\":[");
  87. }
  88. }
  89. else if (rootID.StartsWith(RoadFlow.Platform.Users.PREFIX))
  90. {
  91. var root = busers.Get(busers.RemovePrefix1(rootID).ToGuid());
  92. if (root != null)
  93. {
  94. json.Append("{");
  95. json.AppendFormat("\"id\":\"{0}\",", root.ID);
  96. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty);
  97. json.AppendFormat("\"title\":\"{0}\",", root.Name);
  98. json.AppendFormat("\"ico\":\"{0}\",", Common.Tools.BaseUrl + "/images/ico/contact_grey.png");
  99. json.AppendFormat("\"link\":\"{0}\",", "");
  100. json.AppendFormat("\"type\":\"{0}\",", "4");
  101. json.AppendFormat("\"hasChilds\":\"{0}\",", "0");
  102. json.Append("\"childs\":[");
  103. }
  104. }
  105. else if (rootID.StartsWith(RoadFlow.Platform.WorkGroup.PREFIX))
  106. {
  107. var root = BWorkGroup.Get(BWorkGroup.RemovePrefix1(rootID).ToGuid());
  108. if (root != null)
  109. {
  110. users = BOrganize.GetAllUsers(rootID);
  111. json.Append("{");
  112. json.AppendFormat("\"id\":\"{0}\",", root.ID);
  113. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty);
  114. json.AppendFormat("\"title\":\"{0}\",", root.Name);
  115. json.AppendFormat("\"ico\":\"{0}\",", "");
  116. json.AppendFormat("\"link\":\"{0}\",", "");
  117. json.AppendFormat("\"type\":\"{0}\",", "5");
  118. json.AppendFormat("\"hasChilds\":\"{0}\",", users.Count > 0 ? "1" : "0");
  119. json.Append("\"childs\":[");
  120. }
  121. }
  122. #region 只有一个根时显示二级
  123. if (rootIDArray.Length == 1)
  124. {
  125. List<RoadFlow.Data.Model.Organize> orgs = rootID.IsGuid() ? BOrganize.GetChilds(rootGuid)
  126. : new List<RoadFlow.Data.Model.Organize>();
  127. int count = orgs.Count;
  128. int i = 0;
  129. foreach (var org in orgs)
  130. {
  131. json.Append("{");
  132. json.AppendFormat("\"id\":\"{0}\",", org.ID);
  133. json.AppendFormat("\"parentID\":\"{0}\",", org.ParentID);
  134. json.AppendFormat("\"title\":\"{0}\",", org.Name);
  135. json.AppendFormat("\"ico\":\"{0}\",", "");
  136. json.AppendFormat("\"link\":\"{0}\",", "");
  137. json.AppendFormat("\"type\":\"{0}\",", org.Type);
  138. json.AppendFormat("\"hasChilds\":\"{0}\",", org.ChildsLength);
  139. json.Append("\"childs\":[");
  140. json.Append("]");
  141. json.Append("}");
  142. if (i++ < count - 1 || users.Count > 0)
  143. {
  144. json.Append(",");
  145. }
  146. }
  147. if (users.Count > 0)
  148. {
  149. var userRelations = new RoadFlow.Platform.UsersRelation().GetAllByOrganizeID(rootGuid);
  150. int count1 = users.Count;
  151. int j = 0;
  152. foreach (var user in users)
  153. {
  154. var ur = userRelations.Find(p => p.UserID == user.ID);
  155. json.Append("{");
  156. json.AppendFormat("\"id\":\"{0}\",", user.ID);
  157. json.AppendFormat("\"parentID\":\"{0}\",", rootGuid);
  158. json.AppendFormat("\"title\":\"{0}{1}\",", user.Name, ur != null && ur.IsMain == 0 ? "<span style='color:#999;'>[兼职]</span>" : "");
  159. json.AppendFormat("\"ico\":\"{0}\",", Common.Tools.BaseUrl + "/images/ico/contact_grey.png");
  160. json.AppendFormat("\"link\":\"{0}\",", "");
  161. json.AppendFormat("\"type\":\"{0}\",", "4");
  162. json.AppendFormat("\"hasChilds\":\"{0}\",", "0");
  163. json.Append("\"childs\":[");
  164. json.Append("]");
  165. json.Append("}");
  166. if (j++ < count1 - 1)
  167. {
  168. json.Append(",");
  169. }
  170. }
  171. }
  172. }
  173. #endregion
  174. json.Append("]");
  175. json.Append("}");
  176. if (m++ < rootIDArray.Length - 1)
  177. {
  178. json.Append(",");
  179. }
  180. }
  181. json.Append("]");
  182. context.Response.Write(json.ToString());
  183. }
  184. public bool IsReusable
  185. {
  186. get
  187. {
  188. return false;
  189. }
  190. }
  191. }
  192. }