RoadFlow2.1 临时演示

Tree1.ashx.cs 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Text;
  6. namespace WebForm.Platform.RoleApp
  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 roleID = context.Request.QueryString["roleid"];
  17. Guid roleGuid;
  18. if (!roleID.IsGuid(out roleGuid))
  19. {
  20. context.Response.Write("[]");
  21. return;
  22. }
  23. RoadFlow.Platform.RoleApp BRoleApp = new RoadFlow.Platform.RoleApp();
  24. var appDt = BRoleApp.GetAllDataTableByRoleID(roleGuid);
  25. if (appDt.Rows.Count == 0)
  26. {
  27. context.Response.Write("[]");
  28. return;
  29. }
  30. var root = appDt.Select("ParentID='" + Guid.Empty.ToString() + "'");
  31. if (root.Length == 0)
  32. {
  33. context.Response.Write("[]");
  34. return;
  35. }
  36. var apps = appDt.Select("ParentID='" + root[0]["ID"].ToString() + "'");
  37. StringBuilder json = new StringBuilder("[", 1000);
  38. System.Data.DataRow rootDr = root[0];
  39. json.Append("{");
  40. json.AppendFormat("\"id\":\"{0}\",", rootDr["ID"]);
  41. json.AppendFormat("\"title\":\"{0}\",", rootDr["Title"]);
  42. json.AppendFormat("\"ico\":\"{0}\",", rootDr["Ico"].ToString().IsNullOrEmpty() ? "" : Common.Tools.BaseUrl + rootDr["Ico"].ToString());
  43. json.AppendFormat("\"link\":\"{0}\",", rootDr["Address"]);
  44. json.AppendFormat("\"type\":\"{0}\",", "0");
  45. json.AppendFormat("\"model\":\"{0}\",", rootDr["OpenMode"]);
  46. json.AppendFormat("\"width\":\"{0}\",", rootDr["Width"]);
  47. json.AppendFormat("\"height\":\"{0}\",", rootDr["Height"]);
  48. json.AppendFormat("\"hasChilds\":\"{0}\",", apps.Length > 0 ? "1" : "0");
  49. json.AppendFormat("\"childs\":[");
  50. for (int i = 0; i < apps.Length; i++)
  51. {
  52. System.Data.DataRow dr = apps[i];
  53. var childs = appDt.Select("ParentID='" + dr["ID"].ToString() + "'");
  54. json.Append("{");
  55. json.AppendFormat("\"id\":\"{0}\",", dr["ID"]);
  56. json.AppendFormat("\"title\":\"{0}\",", dr["Title"]);
  57. json.AppendFormat("\"ico\":\"{0}\",", dr["Ico"].ToString().IsNullOrEmpty() ? "" : Common.Tools.BaseUrl + dr["Ico"].ToString());
  58. json.AppendFormat("\"link\":\"{0}\",", dr["Address"]);
  59. json.AppendFormat("\"type\":\"{0}\",", "0");
  60. json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"]);
  61. json.AppendFormat("\"width\":\"{0}\",", dr["Width"]);
  62. json.AppendFormat("\"height\":\"{0}\",", dr["Height"]);
  63. json.AppendFormat("\"hasChilds\":\"{0}\",", childs.Length > 0 ? "1" : "0");
  64. json.AppendFormat("\"childs\":[");
  65. json.Append("]");
  66. json.Append("}");
  67. if (i < apps.Length - 1)
  68. {
  69. json.Append(",");
  70. }
  71. }
  72. json.Append("]");
  73. json.Append("}");
  74. json.Append("]");
  75. context.Response.Write(json.ToString());
  76. }
  77. public bool IsReusable
  78. {
  79. get
  80. {
  81. return false;
  82. }
  83. }
  84. }
  85. }