RoadFlow2.1 临时演示

GetJson_Table.ashx.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using System.Web.SessionState;
  7. namespace WebForm.Controls.SelectDictionary
  8. {
  9. /// <summary>
  10. /// GetJson_Table 的摘要说明
  11. /// </summary>
  12. public class GetJson_Table : IHttpHandler, IReadOnlySessionState
  13. {
  14. public void ProcessRequest(HttpContext context)
  15. {
  16. context.Response.ContentType = "text/plain";
  17. string dbconn = context.Request.QueryString["dbconn"];
  18. string dbtable = context.Request.QueryString["dbtable"];
  19. string valuefield = context.Request.QueryString["valuefield"];
  20. string titlefield = context.Request.QueryString["titlefield"];
  21. string parentfield = context.Request.QueryString["parentfield"];
  22. string where = (context.Request.QueryString["where"] ?? "").UrlDecode();
  23. RoadFlow.Platform.DBConnection bdbconn = new RoadFlow.Platform.DBConnection();
  24. var conn = bdbconn.Get(dbconn.ToGuid());
  25. string sql = "select " + valuefield + "," + titlefield + " from " + dbtable + (where.IsNullOrEmpty() ? "" : " where " + where);
  26. DataTable dt = bdbconn.GetDataTable(conn, sql.ReplaceSelectSql());
  27. System.Text.StringBuilder json = new System.Text.StringBuilder(1000);
  28. foreach (System.Data.DataRow dr in dt.Rows)
  29. {
  30. string value = dr[0].ToString();
  31. string title = dt.Columns.Count > 1 ? dr[1].ToString() : value;
  32. string sql1 = "select * from " + dbtable + " where " + parentfield + "='" + value + "'";
  33. bool hasChilds = bdbconn.GetDataTable(conn, sql1.ReplaceSelectSql()).Rows.Count > 0;
  34. json.Append("{");
  35. json.AppendFormat("\"id\":\"{0}\",", value);
  36. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty.ToString());
  37. json.AppendFormat("\"title\":\"{0}\",", title);
  38. json.AppendFormat("\"type\":\"{0}\",", hasChilds ? "1" : "2"); //类型:0根 1父 2子
  39. json.AppendFormat("\"ico\":\"{0}\",", "");
  40. json.AppendFormat("\"hasChilds\":\"{0}\",", hasChilds ? "1" : "0");
  41. json.Append("\"childs\":[]},");
  42. }
  43. context.Response.Write("[" + json.ToString().TrimEnd(',') + "]");
  44. }
  45. public bool IsReusable
  46. {
  47. get
  48. {
  49. return false;
  50. }
  51. }
  52. }
  53. }