RoadFlow2.1 临时演示

GetJson_SQL.ashx.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.SessionState;
  6. namespace WebForm.Controls.SelectDictionary
  7. {
  8. /// <summary>
  9. /// GetJson_SQL 的摘要说明
  10. /// </summary>
  11. public class GetJson_SQL : IHttpHandler, IReadOnlySessionState
  12. {
  13. public void ProcessRequest(HttpContext context)
  14. {
  15. context.Response.ContentType = "text/plain";
  16. if (!Common.Tools.CheckLogin(false))
  17. {
  18. context.Response.Write("{}");
  19. context.Response.End();
  20. return;
  21. }
  22. string dbconn = context.Request.QueryString["dbconn"];
  23. string sql = context.Request.QueryString["sql"];
  24. RoadFlow.Platform.DBConnection conn = new RoadFlow.Platform.DBConnection();
  25. var conn1 = conn.Get(dbconn.ToGuid());
  26. System.Data.DataTable dt = conn.GetDataTable(conn1, sql.UrlDecode().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. json.Append("{");
  33. json.AppendFormat("\"id\":\"{0}\",", value);
  34. json.AppendFormat("\"parentID\":\"{0}\",", Guid.Empty.ToString());
  35. json.AppendFormat("\"title\":\"{0}\",", title);
  36. json.AppendFormat("\"type\":\"{0}\",", "2"); //类型:0根 1父 2子
  37. json.AppendFormat("\"ico\":\"{0}\",", "");
  38. json.AppendFormat("\"hasChilds\":\"{0}\",", "0");
  39. json.Append("\"childs\":[]},");
  40. }
  41. context.Response.Write("[" + json.ToString().TrimEnd(',') + "]");
  42. }
  43. public bool IsReusable
  44. {
  45. get
  46. {
  47. return false;
  48. }
  49. }
  50. }
  51. }