市长热线演示版

question.ashx.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. /// question 的摘要说明
  11. /// </summary>
  12. public class question : 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 "getlistbypager":
  24. context.Response.Write(LoadListByPager(context));
  25. break;
  26. case "getselectlist":
  27. context.Response.Write(LoadSelectList(context));
  28. break;
  29. case "delete":
  30. context.Response.Write(DeleteById(context));
  31. break;
  32. }
  33. }
  34. #region 删除试题
  35. private string DeleteById(HttpContext context)
  36. {
  37. string str = "error";
  38. try
  39. {
  40. if (new BLL.T_Ask_Question().Delete(Convert.ToInt32(context.Request.Params["id"])))
  41. {
  42. if (new BLL.T_Ask_QuestionItems().DeleteByQuestionId(Convert.ToInt32(context.Request.Params["id"])))
  43. {
  44. str = "success";
  45. }
  46. else
  47. {
  48. str = "error";
  49. }
  50. str = "success";
  51. }
  52. else
  53. {
  54. str = "error";
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. }
  60. return str;
  61. }
  62. #endregion
  63. #region 获取数据
  64. private string LoadList(HttpContext context)
  65. {
  66. string res = "";
  67. DataTable dt = new DataTable();
  68. string sql = " ";
  69. try
  70. {
  71. string strpageindex = context.Request.Params["page"];
  72. int pageindex = 1;
  73. string strpagesize = context.Request.Params["pagesize"];
  74. int pagesize = 10;
  75. string categoryid = context.Request.Params["categoryid"];
  76. string selecttype = context.Request.Params["selecttype"];
  77. string key = context.Request.Params["key"];
  78. if (categoryid.Trim() != "")
  79. {
  80. sql += " and F_CategoryId=" + categoryid + " ";
  81. }
  82. if (selecttype.Trim() != "")
  83. {
  84. sql += " and F_Type=" + selecttype + " ";
  85. }
  86. if (key.Trim() != "")
  87. {
  88. sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
  89. }
  90. if (strpageindex.Trim() != "")
  91. {
  92. try
  93. {
  94. pageindex = Convert.ToInt32(strpageindex);
  95. }
  96. catch
  97. { }
  98. }
  99. if (strpagesize.Trim() != "")
  100. {
  101. try
  102. {
  103. pagesize = Convert.ToInt32(strpagesize);
  104. }
  105. catch
  106. { }
  107. }
  108. int recordCount = 0;
  109. Model.PageData<Model.T_Ask_Question> pageModel = new Model.PageData<Model.T_Ask_Question>();
  110. dt = BLL.PagerBLL.GetListPager(
  111. "vw_Ask_Question",
  112. "F_QuestionId",
  113. "*",
  114. " and F_DeleteFlag=0 " + sql,
  115. "ORDER BY F_QuestionId desc",
  116. pagesize,
  117. pageindex,
  118. true,
  119. out recordCount);
  120. System.Collections.Generic.List<Model.T_Ask_Question> modelList = new BLL.T_Ask_Question().DataTableToList(dt);
  121. pageModel.Rows = modelList;
  122. pageModel.Total = recordCount;
  123. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_Question>));
  124. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  125. {
  126. //JSON序列化
  127. serializer.WriteObject(stream, pageModel);
  128. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  129. }
  130. }
  131. catch (Exception err)
  132. {
  133. //res = err.ToString();
  134. }
  135. finally
  136. {
  137. dt.Clear();
  138. dt.Dispose();
  139. }
  140. return res;
  141. }
  142. #endregion
  143. #region 获取数据
  144. private string LoadListByPager(HttpContext context)
  145. {
  146. string res = "";
  147. DataTable dt = new DataTable();
  148. string sql = " ";
  149. try
  150. {
  151. string pagerid = context.Request.Params["pagerid"];
  152. string userid = context.Request.Params["userid"];
  153. string strpageindex = context.Request.Params["page"];
  154. int pageindex = 1;
  155. string strpagesize = context.Request.Params["pagesize"];
  156. int pagesize = 10;
  157. string categoryid = context.Request.Params["categoryid"];
  158. string selecttype = context.Request.Params["selecttype"];
  159. string key = context.Request.Params["key"];
  160. if (categoryid.Trim() != "")
  161. {
  162. sql += " and F_CategoryId=" + categoryid + " ";
  163. }
  164. if (selecttype.Trim() != "")
  165. {
  166. sql += " and F_Type=" + selecttype + " ";
  167. }
  168. if (key.Trim() != "")
  169. {
  170. sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
  171. }
  172. if (pagerid.Trim() != "")
  173. {
  174. sql += " and F_QuestionId not in (SELECT [F_QuestionId] FROM [T_Ask_PagerItems] where [F_PagerId]=" + pagerid + ") ";
  175. }
  176. else
  177. {
  178. sql += " and F_QuestionId not in (SELECT [ExpandIntField1] FROM [T_Sys_TempItems] where [F_UserId]=" + userid + " and F_TempName='T_Ask_PagerItems') ";
  179. }
  180. if (strpageindex.Trim() != "")
  181. {
  182. try
  183. {
  184. pageindex = Convert.ToInt32(strpageindex);
  185. }
  186. catch
  187. { }
  188. }
  189. if (strpagesize.Trim() != "")
  190. {
  191. try
  192. {
  193. pagesize = Convert.ToInt32(strpagesize);
  194. }
  195. catch
  196. { }
  197. }
  198. int recordCount = 0;
  199. Model.PageData<Model.T_Ask_Question> pageModel = new Model.PageData<Model.T_Ask_Question>();
  200. dt = BLL.PagerBLL.GetListPager(
  201. "vw_Ask_Question",
  202. "F_QuestionId",
  203. "*",
  204. " and F_DeleteFlag=0 " + sql,
  205. "ORDER BY F_QuestionId desc",
  206. pagesize,
  207. pageindex,
  208. true,
  209. out recordCount);
  210. System.Collections.Generic.List<Model.T_Ask_Question> modelList = new BLL.T_Ask_Question().DataTableToList(dt);
  211. pageModel.Rows = modelList;
  212. pageModel.Total = recordCount;
  213. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_Question>));
  214. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  215. {
  216. //JSON序列化
  217. serializer.WriteObject(stream, pageModel);
  218. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  219. }
  220. }
  221. catch (Exception err)
  222. {
  223. //res = err.ToString();
  224. }
  225. finally
  226. {
  227. dt.Clear();
  228. dt.Dispose();
  229. }
  230. return res;
  231. }
  232. #endregion
  233. #region 获取数据
  234. private string LoadSelectList(HttpContext context)
  235. {
  236. string res = "";
  237. DataTable dt = new DataTable();
  238. string sql = " ";
  239. try
  240. {
  241. string pagerid = context.Request.Params["pagerid"];
  242. string userid = context.Request.Params["userid"];
  243. string strpageindex = context.Request.Params["page"];
  244. int pageindex = 1;
  245. string strpagesize = context.Request.Params["pagesize"];
  246. int pagesize = 10;
  247. //string arrid = context.Request.Params["arrid"];
  248. //string categoryid = context.Request.Params["categoryid"];
  249. //string selecttype = context.Request.Params["selecttype"];
  250. //string key = context.Request.Params["key"];
  251. //if (categoryid.Trim() != "")
  252. //{
  253. // sql += " and F_CategoryId=" + categoryid + " ";
  254. //}
  255. //if (selecttype.Trim() != "")
  256. //{
  257. // sql += " and F_Type=" + selecttype + " ";
  258. //}
  259. //if (key.Trim() != "")
  260. //{
  261. // sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
  262. //}
  263. //if (arrid.Trim() != "")
  264. //{
  265. // sql += " and F_QuestionId in(" + arrid + ") ";
  266. //}
  267. //else
  268. //{
  269. // sql += " and 1=0 ";
  270. //}
  271. if (strpageindex.Trim() != "")
  272. {
  273. try
  274. {
  275. pageindex = Convert.ToInt32(strpageindex);
  276. }
  277. catch
  278. { }
  279. }
  280. if (strpagesize.Trim() != "")
  281. {
  282. try
  283. {
  284. pagesize = Convert.ToInt32(strpagesize);
  285. }
  286. catch
  287. { }
  288. }
  289. int recordCount = 0;
  290. Model.PageData<Model.T_Ask_PagerItemsQuestion> pageModel = new Model.PageData<Model.T_Ask_PagerItemsQuestion>();
  291. if (pagerid.Trim() != "")
  292. {
  293. sql += " and [F_PagerId]=" + pagerid + " ";
  294. dt = BLL.PagerBLL.GetListPager(
  295. "vw_Ask_PagerQuestion",
  296. "F_ItemId",
  297. "*",
  298. " and F_DeleteFlag=0 " + sql,
  299. "ORDER BY F_Sort ",
  300. pagesize,
  301. pageindex,
  302. true,
  303. out recordCount);
  304. }
  305. else
  306. {
  307. sql += " and F_QuestionId in (SELECT [ExpandIntField1] FROM [T_Sys_TempItems] where [F_UserId]=" + userid + " and F_TempName='T_Ask_PagerItems') ";
  308. dt = BLL.PagerBLL.GetListPager(
  309. "vw_Ask_Question LEFT OUTER JOIN T_Sys_TempItems ON vw_Ask_Question.F_QuestionId = T_Sys_TempItems.ExpandIntField1",
  310. "F_QuestionId",
  311. "vw_Ask_Question.*,T_Sys_TempItems.ExpandIntField3 as F_Sort,T_Sys_TempItems.F_Id as F_ItemId",
  312. " and F_DeleteFlag=0 " + sql,
  313. "ORDER BY T_Sys_TempItems.ExpandIntField3 ",
  314. pagesize,
  315. pageindex,
  316. true,
  317. out recordCount);
  318. }
  319. System.Collections.Generic.List<Model.T_Ask_PagerItemsQuestion> modelList = new BLL.T_Ask_Question().DataTableToPagerItemList(dt);
  320. pageModel.Rows = modelList;
  321. pageModel.Total = recordCount;
  322. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_PagerItemsQuestion>));
  323. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  324. {
  325. //JSON序列化
  326. serializer.WriteObject(stream, pageModel);
  327. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  328. }
  329. }
  330. catch (Exception err)
  331. {
  332. //res = err.ToString();
  333. }
  334. finally
  335. {
  336. dt.Clear();
  337. dt.Dispose();
  338. }
  339. return res;
  340. }
  341. #endregion
  342. public bool IsReusable
  343. {
  344. get
  345. {
  346. return false;
  347. }
  348. }
  349. }
  350. }