市长热线演示版

questionitems.ashx.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. /// questionitems 的摘要说明
  11. /// </summary>
  12. public class questionitems : 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 "add":
  24. context.Response.Write(Add(context));
  25. break;
  26. case "modify":
  27. context.Response.Write(Modify(context));
  28. break;
  29. case "move":
  30. context.Response.Write(Move(context));
  31. break;
  32. case "delete":
  33. context.Response.Write(Delete(context));
  34. break;
  35. case "gettemplist":
  36. context.Response.Write(LoadTempList(context));
  37. break;
  38. case "addtemp":
  39. context.Response.Write(AddTemp(context));
  40. break;
  41. case "modifytemp":
  42. context.Response.Write(ModifyTemp(context));
  43. break;
  44. case "movetemp":
  45. context.Response.Write(MoveTemp(context));
  46. break;
  47. case "deletetemp":
  48. context.Response.Write(DeleteTemp(context));
  49. break;
  50. }
  51. }
  52. #region 选项数据操作
  53. #region 获取数据
  54. private string LoadList(HttpContext context)
  55. {
  56. string res = "";
  57. DataTable dt = new DataTable();
  58. string sql = " ";
  59. try
  60. {
  61. string strpageindex = context.Request.Params["page"];
  62. int pageindex = 1;
  63. string strpagesize = context.Request.Params["pagesize"];
  64. int pagesize = 10;
  65. string questionid = "0";
  66. try
  67. {
  68. questionid = context.Request.Params["questionid"];
  69. if (questionid.Trim() != "")
  70. {
  71. sql = " and F_QuestionId=" + questionid + " ";
  72. }
  73. }
  74. catch
  75. { }
  76. if (strpageindex.Trim() != "")
  77. {
  78. try
  79. {
  80. pageindex = Convert.ToInt32(strpageindex);
  81. }
  82. catch
  83. { }
  84. }
  85. if (strpagesize.Trim() != "")
  86. {
  87. try
  88. {
  89. pagesize = Convert.ToInt32(strpagesize);
  90. }
  91. catch
  92. { }
  93. }
  94. int recordCount = 0;
  95. Model.PageData<Model.T_Ask_QuestionItems> pageModel = new Model.PageData<Model.T_Ask_QuestionItems>();
  96. dt = BLL.PagerBLL.GetListPager(
  97. "T_Ask_QuestionItems",
  98. "F_ItemId",
  99. "*",
  100. " " + sql,
  101. "ORDER BY F_Sort ",
  102. pagesize,
  103. pageindex,
  104. true,
  105. out recordCount);
  106. System.Collections.Generic.List<Model.T_Ask_QuestionItems> modelList = new BLL.T_Ask_QuestionItems().DataTableToList(dt);
  107. pageModel.Rows = modelList;
  108. pageModel.Total = recordCount;
  109. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_QuestionItems>));
  110. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  111. {
  112. //JSON序列化
  113. serializer.WriteObject(stream, pageModel);
  114. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  115. }
  116. }
  117. catch (Exception err)
  118. {
  119. //res = err.ToString();
  120. }
  121. finally
  122. {
  123. dt.Clear();
  124. dt.Dispose();
  125. }
  126. return res;
  127. }
  128. #endregion
  129. #region 添加数据
  130. private string Add(HttpContext context)
  131. {
  132. string res = "error";
  133. try
  134. {
  135. Model.T_Ask_QuestionItems itemmodel = new Model.T_Ask_QuestionItems();
  136. itemmodel.F_ItemName = "";
  137. int questionid = 0;
  138. try
  139. {
  140. questionid = Convert.ToInt32(context.Request.Params["questionid"]);
  141. }
  142. catch
  143. { }
  144. itemmodel.F_QuestionId = questionid;
  145. string sort = "0";
  146. try
  147. {
  148. sort = context.Request.Params["sort"];
  149. if (sort.Trim() != "")
  150. {
  151. itemmodel.F_Sort = Convert.ToInt32(sort) + 1;
  152. }
  153. }
  154. catch
  155. { }
  156. string sorttype = "1";
  157. try
  158. {
  159. sorttype = context.Request.Params["sorttype"];
  160. if (sorttype.Trim() != "")
  161. {
  162. itemmodel.F_SortModel = Convert.ToInt32(sorttype);
  163. }
  164. }
  165. catch
  166. { }
  167. int itemid = new BLL.T_Ask_QuestionItems().Add(itemmodel);
  168. if (itemid > 0)
  169. {
  170. res = "success";
  171. }
  172. }
  173. catch
  174. { }
  175. return res;
  176. }
  177. #endregion
  178. #region 修改数据
  179. private string Modify(HttpContext context)
  180. {
  181. string res = "error";
  182. try
  183. {
  184. Model.T_Ask_QuestionItems model = new BLL.T_Ask_QuestionItems().GetModel(Convert.ToInt32(context.Request.Params["itemid"]));
  185. model.F_ItemName = context.Request.Params["itemvalue"];
  186. if (new BLL.T_Ask_QuestionItems().Update(model))
  187. {
  188. res = "success";
  189. }
  190. }
  191. catch
  192. { }
  193. return res;
  194. }
  195. #endregion
  196. #region 移动排序
  197. private string Move(HttpContext context)
  198. {
  199. string res = "error";
  200. DataTable dt = new DataTable();
  201. try
  202. {
  203. //ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&itemid=" + itemid+"&sort="+sort+"&movetype="+type
  204. string sql = "";
  205. string order = "";
  206. int sort = Convert.ToInt32(context.Request.Params["sort"]);
  207. int itemid = Convert.ToInt32(context.Request.Params["itemid"]);
  208. int questionid = Convert.ToInt32(context.Request.Params["questionid"]);
  209. sql += " F_QuestionId=" + questionid + " ";
  210. int newsort = 0;
  211. int newitemid = 0;
  212. if (context.Request.Params["movetype"] == "-1")
  213. {
  214. sql += " and F_Sort<" + sort.ToString();
  215. order = " order by F_Sort desc";
  216. }
  217. else
  218. {
  219. sql += " and F_Sort>" + sort.ToString();
  220. order = " order by F_Sort ";
  221. }
  222. dt = new BLL.T_Ask_QuestionItems().GetList(sql + " " + order).Tables[0];
  223. if (dt.Rows.Count > 0)
  224. {
  225. newitemid = Convert.ToInt32(dt.Rows[0]["F_ItemId"].ToString());
  226. newsort = Convert.ToInt32(dt.Rows[0]["F_Sort"].ToString());
  227. }
  228. Model.T_Ask_QuestionItems newmodel = new BLL.T_Ask_QuestionItems().GetModel(newitemid);
  229. newmodel.F_Sort = sort;
  230. if (new BLL.T_Ask_QuestionItems().Update(newmodel))
  231. {
  232. res = "success";
  233. }
  234. Model.T_Ask_QuestionItems model = new BLL.T_Ask_QuestionItems().GetModel(itemid);
  235. model.F_Sort = newsort;
  236. if (new BLL.T_Ask_QuestionItems().Update(model))
  237. {
  238. res = "success";
  239. }
  240. }
  241. catch
  242. { }
  243. finally
  244. {
  245. dt.Clear();
  246. dt.Dispose();
  247. }
  248. return res;
  249. }
  250. #endregion
  251. #region 删除数据
  252. private string Delete(HttpContext context)
  253. {
  254. string res = "error";
  255. try
  256. {
  257. if (new BLL.T_Ask_QuestionItems().Delete(Convert.ToInt32(context.Request.Params["itemid"])))
  258. {
  259. res = "success";
  260. }
  261. }
  262. catch
  263. { }
  264. return res;
  265. }
  266. #endregion
  267. #endregion
  268. #region 选项临时数据操作
  269. #region 获取临时数据
  270. private string LoadTempList(HttpContext context)
  271. {
  272. string res = "";
  273. DataTable dt = new DataTable();
  274. string sql = " ";
  275. try
  276. {
  277. string strpageindex = context.Request.Params["page"];
  278. int pageindex = 1;
  279. string strpagesize = context.Request.Params["pagesize"];
  280. int pagesize = 10;
  281. string userid = "0";
  282. try
  283. {
  284. userid = context.Request.Params["userid"];
  285. if (userid.Trim() != "")
  286. {
  287. sql = " and F_UserId=" + userid + " ";
  288. }
  289. }
  290. catch
  291. { }
  292. if (strpageindex.Trim() != "")
  293. {
  294. try
  295. {
  296. pageindex = Convert.ToInt32(strpageindex);
  297. }
  298. catch
  299. { }
  300. }
  301. if (strpagesize.Trim() != "")
  302. {
  303. try
  304. {
  305. pagesize = Convert.ToInt32(strpagesize);
  306. }
  307. catch
  308. { }
  309. }
  310. int recordCount = 0;
  311. Model.PageData<Model.T_Ask_QuestionItems> pageModel = new Model.PageData<Model.T_Ask_QuestionItems>();
  312. dt = BLL.PagerBLL.GetListPager(
  313. "T_Sys_TempItems",
  314. "F_Id",
  315. "*",
  316. " and F_TempName='T_Ask_QuestionItems' " + sql,
  317. "ORDER BY ExpandIntField3 ",
  318. pagesize,
  319. pageindex,
  320. true,
  321. out recordCount);
  322. System.Collections.Generic.List<Model.T_Ask_QuestionItems> modelList = new BLL.T_Ask_QuestionItems().TempDataTableToList(dt);
  323. pageModel.Rows = modelList;
  324. pageModel.Total = recordCount;
  325. System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_QuestionItems>));
  326. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  327. {
  328. //JSON序列化
  329. serializer.WriteObject(stream, pageModel);
  330. res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
  331. }
  332. }
  333. catch (Exception err)
  334. {
  335. //res = err.ToString();
  336. }
  337. finally
  338. {
  339. dt.Clear();
  340. dt.Dispose();
  341. }
  342. return res;
  343. }
  344. #endregion
  345. #region 添加临时数据
  346. private string AddTemp(HttpContext context)
  347. {
  348. string res = "error";
  349. try
  350. {
  351. Model.T_Sys_TempItems model = new Model.T_Sys_TempItems();
  352. model.F_TempName = "T_Ask_QuestionItems";
  353. string userid = "0";
  354. try
  355. {
  356. userid = context.Request.Params["userid"];
  357. if (userid.Trim() != "")
  358. {
  359. model.F_UserId = Convert.ToInt32(userid);
  360. }
  361. }
  362. catch
  363. { }
  364. string questionid="0";
  365. try
  366. {
  367. questionid = context.Request.Params["questionid"];
  368. if (questionid.Trim() != "")
  369. {
  370. model.ExpandIntField1 = Convert.ToInt32(questionid);
  371. }
  372. }
  373. catch
  374. { }
  375. string sort = "0";
  376. try
  377. {
  378. sort = context.Request.Params["sort"];
  379. if (sort.Trim() != "")
  380. {
  381. model.ExpandIntField3 = Convert.ToInt32(sort) + 1;
  382. }
  383. }
  384. catch
  385. { }
  386. string sorttype = "1";
  387. try
  388. {
  389. sorttype = context.Request.Params["sorttype"];
  390. if (sorttype.Trim() != "")
  391. {
  392. model.ExpandIntField4 = Convert.ToInt32(sorttype);
  393. }
  394. }
  395. catch
  396. { }
  397. model.ExpandVchField1 = "";
  398. int i=new BLL.T_Sys_TempItems().Add(model);
  399. if (i > 0)
  400. {
  401. res = "success";
  402. }
  403. }
  404. catch
  405. { }
  406. return res;
  407. }
  408. #endregion
  409. #region 修改临时数据
  410. private string ModifyTemp(HttpContext context)
  411. {
  412. string res = "error";
  413. try
  414. {
  415. Model.T_Sys_TempItems model = new BLL.T_Sys_TempItems().GetModel(Convert.ToInt32(context.Request.Params["itemid"]));
  416. model.ExpandVchField1 = context.Request.Params["itemvalue"];
  417. if (new BLL.T_Sys_TempItems().Update(model))
  418. {
  419. res = "success";
  420. }
  421. }
  422. catch
  423. { }
  424. return res;
  425. }
  426. #endregion
  427. #region 移动排序
  428. private string MoveTemp(HttpContext context)
  429. {
  430. string res = "error";
  431. DataTable dt = new DataTable();
  432. try
  433. {
  434. //ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&itemid=" + itemid+"&sort="+sort+"&movetype="+type
  435. string sql = "";
  436. string order = "";
  437. int sort = Convert.ToInt32(context.Request.Params["sort"]);
  438. int itemid = Convert.ToInt32(context.Request.Params["itemid"]);
  439. int newsort = 0;
  440. int newitemid = 0;
  441. if (context.Request.Params["movetype"] == "-1")
  442. {
  443. sql = " ExpandIntField3<" + sort.ToString();
  444. order = " order by ExpandIntField3 desc";
  445. }
  446. else
  447. {
  448. sql = " ExpandIntField3>" + sort.ToString();
  449. order = " order by ExpandIntField3 ";
  450. }
  451. dt = new BLL.T_Sys_TempItems().GetList(sql + " " + order).Tables[0];
  452. if (dt.Rows.Count > 0)
  453. {
  454. newitemid = Convert.ToInt32(dt.Rows[0]["F_Id"].ToString());
  455. newsort = Convert.ToInt32(dt.Rows[0]["ExpandIntField3"].ToString());
  456. }
  457. Model.T_Sys_TempItems newmodel = new BLL.T_Sys_TempItems().GetModel(newitemid);
  458. newmodel.ExpandIntField3 = sort;
  459. if (new BLL.T_Sys_TempItems().Update(newmodel))
  460. {
  461. res = "success";
  462. }
  463. Model.T_Sys_TempItems model = new BLL.T_Sys_TempItems().GetModel(itemid);
  464. model.ExpandIntField3 = newsort;
  465. if (new BLL.T_Sys_TempItems().Update(model))
  466. {
  467. res = "success";
  468. }
  469. }
  470. catch
  471. { }
  472. finally
  473. {
  474. dt.Clear();
  475. dt.Dispose();
  476. }
  477. return res;
  478. }
  479. #endregion
  480. #region 删除临时数据
  481. private string DeleteTemp(HttpContext context)
  482. {
  483. string res = "error";
  484. try
  485. {
  486. if (new BLL.T_Sys_TempItems().Delete(Convert.ToInt32(context.Request.Params["itemid"])))
  487. {
  488. res = "success";
  489. }
  490. }
  491. catch
  492. { }
  493. return res;
  494. }
  495. #endregion
  496. #endregion
  497. public bool IsReusable
  498. {
  499. get
  500. {
  501. return false;
  502. }
  503. }
  504. }
  505. }