RoadFlow2.1 临时演示

GetJson_TableRefresh.ashx.cs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_TableRefresh 的摘要说明
  11. /// </summary>
  12. public class GetJson_TableRefresh : 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"];
  23. string id = context.Request.QueryString["refreshid"];
  24. RoadFlow.Platform.DBConnection bdbconn = new RoadFlow.Platform.DBConnection();
  25. var conn = bdbconn.Get(dbconn.ToGuid());
  26. string sql = "select " + valuefield + "," + titlefield + " from " + dbtable + " where " + parentfield + "='" + id + "'";
  27. DataTable dt = bdbconn.GetDataTable(conn, sql.ReplaceSelectSql());
  28. System.Text.StringBuilder json = new System.Text.StringBuilder(1000);
  29. foreach (System.Data.DataRow dr in dt.Rows)
  30. {
  31. string value = dr[0].ToString();
  32. string title = dt.Columns.Count > 1 ? dr[1].ToString() : value;
  33. string sql1 = "select * from " + dbtable + " where " + parentfield + "='" + value + "'";
  34. bool hasChilds = bdbconn.GetDataTable(conn, sql1.ReplaceSelectSql()).Rows.Count > 0;
  35. json.Append("{");
  36. json.AppendFormat("\"id\":\"{0}\",", value);
  37. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty.ToString());
  38. json.AppendFormat("\"title\":\"{0}\",", title);
  39. json.AppendFormat("\"type\":\"{0}\",", hasChilds ? "1" : "2"); //类型:0根 1父 2子
  40. json.AppendFormat("\"ico\":\"{0}\",", "");
  41. json.AppendFormat("\"hasChilds\":\"{0}\",", hasChilds ? "1" : "0");
  42. json.Append("\"childs\":[]},");
  43. }
  44. context.Response.Write("[" + json.ToString().TrimEnd(',') + "]");
  45. }
  46. public bool IsReusable
  47. {
  48. get
  49. {
  50. return false;
  51. }
  52. }
  53. }
  54. }