市长热线演示版

questioncategory.ashx.cs 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using HySoft.Common;
  6. using System.Data;
  7. namespace HySoft.BaseCallCenter.Web.askmanage.ajax
  8. {
  9. /// <summary>
  10. /// questioncategory 的摘要说明
  11. /// </summary>
  12. public class questioncategory : IHttpHandler
  13. {
  14. public void ProcessRequest(HttpContext context)
  15. {
  16. context.Response.ContentType = "text/plain";
  17. string action = CommonRequest.GetQueryString("action");
  18. switch (action)
  19. {
  20. case "getlist":
  21. context.Response.Write(LoadList(context));
  22. break;
  23. case "delete":
  24. context.Response.Write(DeleteById(context));
  25. break;
  26. }
  27. }
  28. #region 删除分类
  29. private string DeleteById(HttpContext context)
  30. {
  31. int res = 0;
  32. string str="error";
  33. DataTable dt = new DataTable();
  34. try
  35. {
  36. dt = new BLL.T_Ask_Question().GetList(" F_CategoryId=" + context.Request.Params["id"] + " ").Tables[0];
  37. res = dt.Rows.Count;
  38. if (res > 0)
  39. {
  40. str = res.ToString();
  41. }
  42. else
  43. {
  44. if (new BLL.T_Ask_QuestionCategory().Delete(Convert.ToInt32(context.Request.Params["id"])))
  45. {
  46. str = "success";
  47. }
  48. else
  49. {
  50. str = "error";
  51. }
  52. }
  53. }
  54. catch (Exception ex)
  55. {
  56. }
  57. finally
  58. {
  59. dt.Clear();
  60. dt.Dispose();
  61. }
  62. return str;
  63. }
  64. #endregion
  65. #region 获取数据
  66. private string LoadList(HttpContext context)
  67. {
  68. string res = "";
  69. DataTable dt = new DataTable();
  70. string sql = " ";
  71. try
  72. {
  73. string strpageindex = context.Request.Params["page"];
  74. int pageindex = 1;
  75. string strpagesize = context.Request.Params["pagesize"];
  76. int pagesize = 10;
  77. if (strpageindex.Trim() != "")
  78. {
  79. try
  80. {
  81. pageindex = Convert.ToInt32(strpageindex);
  82. }
  83. catch
  84. { }
  85. }
  86. if (strpagesize.Trim() != "")
  87. {
  88. try
  89. {
  90. pagesize = Convert.ToInt32(strpagesize);
  91. }
  92. catch
  93. { }
  94. }
  95. int recordCount = 0;
  96. Model.PageData<Model.T_Ask_QuestionCategory> pageModel = new Model.PageData<Model.T_Ask_QuestionCategory>();
  97. dt = BLL.PagerBLL.GetListPager(
  98. "T_Ask_QuestionCategory",
  99. "F_CategoryId",
  100. "*",
  101. sql,
  102. "ORDER BY F_CategoryId desc",
  103. pagesize,
  104. pageindex,
  105. true,
  106. out recordCount);
  107. System.Collections.Generic.List<Model.T_Ask_QuestionCategory> modelList = new BLL.T_Ask_QuestionCategory().DataTableToList(dt);
  108. pageModel.Rows = modelList;
  109. pageModel.Total = recordCount;
  110. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_QuestionCategory>));
  111. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  112. {
  113. //JSON序列化
  114. serializer.WriteObject(stream, pageModel);
  115. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  116. }
  117. }
  118. catch (Exception err)
  119. {
  120. //res = err.ToString();
  121. }
  122. finally
  123. {
  124. dt.Clear();
  125. dt.Dispose();
  126. }
  127. return res;
  128. }
  129. #endregion
  130. public bool IsReusable
  131. {
  132. get
  133. {
  134. return false;
  135. }
  136. }
  137. }
  138. }