setting.ashx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <%@ WebHandler Language="C#" Class="setting" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.Data;
  8. using Curtain.DataAccess;
  9. using DK.XuWei.WebMes;
  10. /// <summary>
  11. /// TP_WEB_SETTING
  12. /// xuwei create 2021-03-03
  13. /// </summary>
  14. public class setting : IHttpHandler, IReadOnlySessionState
  15. {
  16. public void ProcessRequest(HttpContext context)
  17. {
  18. context.Response.ContentType = "text/plain";
  19. if (mes.LoginCheck() && context.Request["m"] is object)
  20. {
  21. Button b = new Button();
  22. if(mes.RightCheck(""))
  23. {
  24. b.btnIndex = true;
  25. b.btnInsert = true;
  26. b.btnInsertBatch = false;
  27. b.btnCopy = true;
  28. b.btnUpdate = true;
  29. b.btnDelete = false;
  30. b.btnCancel = false;
  31. b.btnSearch = false;
  32. b.btnDetail = true;
  33. b.btnCheckbox = true;
  34. b.btnExport = false;
  35. b.btnReload = true;
  36. }
  37. switch (context.Request["m"].ToString().ToLower())
  38. {
  39. case "b":
  40. {
  41. //按钮
  42. context.Response.Write(new JsonResult(b).ToJson());
  43. break;
  44. }
  45. case "a":
  46. {
  47. //添加
  48. if (b.btnDetail && context.Request["id"] is object)
  49. context.Response.Write(detail());
  50. else
  51. {
  52. List<xRecord> list = new List<xRecord>();
  53. xRecord r = new xRecord();
  54. list.Add(r);
  55. context.Response.Write(new JsonResult(list).ToJson());
  56. }
  57. break;
  58. }
  59. case "s":
  60. {
  61. //搜索
  62. if (b.btnIndex)
  63. context.Response.Write(search(context.Request.Form));
  64. else
  65. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  66. break;
  67. }
  68. case "t":
  69. {
  70. //详细
  71. if (b.btnDetail)
  72. context.Response.Write(detail());
  73. else
  74. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  75. break;
  76. }
  77. case "i":
  78. {
  79. //插入
  80. if (b.btnInsert)
  81. context.Response.Write(insert(context.Request.Form));
  82. else
  83. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  84. break;
  85. }
  86. case "u":
  87. {
  88. //修改
  89. if (b.btnUpdate)
  90. context.Response.Write(update(context.Request.Form));
  91. else
  92. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  93. break;
  94. }
  95. case "d":
  96. {
  97. //删除
  98. if (b.btnDelete)
  99. context.Response.Write(delete());
  100. else
  101. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  102. break;
  103. }
  104. case "e":
  105. {
  106. //导出
  107. if (b.btnExport)
  108. {
  109. context.Response.Write(export());
  110. }
  111. else
  112. {
  113. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  114. }
  115. break;
  116. }
  117. default:
  118. {
  119. break;
  120. }
  121. }
  122. }
  123. else
  124. {
  125. context.Response.Write(new JsonResult(JsonStatus.loginError).ToJson());
  126. }
  127. }
  128. /// <summary>
  129. /// TP_WEB_SETTING 查询
  130. /// </summary>
  131. /// <returns>json</returns>
  132. private string search(NameValueCollection form)
  133. {
  134. using(IDataAccess conn=DataAccess.Create())
  135. {
  136. int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
  137. int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
  138. string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
  139. string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
  140. string sqlStr = @"
  141. SELECT
  142. m.ID,
  143. m.NAME,
  144. m.VALUE,
  145. m.MEMO,
  146. m.ID AS SID
  147. FROM
  148. TP_WEB_SETTING m
  149. WHERE
  150. 1 = 1
  151. ";
  152. List<CDAParameter> sqlPara = new List<CDAParameter>();
  153. if(!string.IsNullOrEmpty(form["ID"]))
  154. {
  155. sqlStr += " AND m.ID = @ID@ ";
  156. sqlPara.Add(new CDAParameter("ID", form["ID"]));
  157. }
  158. if(!string.IsNullOrEmpty(form["NAME"]))
  159. {
  160. sqlStr += " AND INSTR( m.NAME, @NAME@ ) > 0 ";
  161. sqlPara.Add(new CDAParameter("NAME", form["NAME"]));
  162. }
  163. if(!string.IsNullOrEmpty(form["VALUE"]))
  164. {
  165. sqlStr += " AND INSTR( m.VALUE, @VALUE@ ) > 0 ";
  166. sqlPara.Add(new CDAParameter("VALUE", form["VALUE"]));
  167. }
  168. if(!string.IsNullOrEmpty(form["MEMO"]))
  169. {
  170. sqlStr += " AND INSTR( m.MEMO, @MEMO@ ) > 0 ";
  171. sqlPara.Add(new CDAParameter("MEMO", form["MEMO"]));
  172. }
  173. if(sort != "")
  174. {
  175. sqlStr += " ORDER BY " + sort + " " + order;
  176. }
  177. int total = 0;
  178. DataTable dt = conn.SelectPages(page, rows,out total, sqlStr, sqlPara.ToArray());
  179. return new JsonResult(dt) { total = total}.ToJson();
  180. }
  181. }
  182. /// <summary>
  183. /// 详细 TP_WEB_SETTING
  184. /// </summary>
  185. /// <returns>json</returns>
  186. private string detail()
  187. {
  188. using(IDataAccess conn= DataAccess.Create())
  189. {
  190. DataTable dt = conn.ExecuteDatatable(@"
  191. SELECT
  192. m.NAME,
  193. m.VALUE,
  194. m.MEMO,
  195. m.ID
  196. FROM
  197. TP_WEB_SETTING m
  198. WHERE
  199. m.ID = @ID@
  200. ",
  201. new CDAParameter("ID",HttpContext.Current.Request["id"])
  202. );
  203. return new JsonResult(dt).ToJson();
  204. }
  205. }
  206. /// <summary>
  207. /// 插入 TP_WEB_SETTING
  208. /// </summary>
  209. /// <returns>json</returns>
  210. private string insert(NameValueCollection form)
  211. {
  212. using(IDataAccess conn= DataAccess.Create())
  213. {
  214. int result = conn.ExecuteNonQuery(@"
  215. INSERT INTO TP_WEB_SETTING (
  216. NAME,
  217. VALUE,
  218. MEMO
  219. ) VALUES (
  220. @NAME@,
  221. @VALUE@,
  222. @MEMO@
  223. )
  224. ",
  225. new CDAParameter("NAME",form["NAME"]),
  226. new CDAParameter("VALUE",form["VALUE"]),
  227. new CDAParameter("MEMO",form["MEMO"])
  228. );
  229. return new JsonResult(JsonStatus.success).ToJson();
  230. }
  231. }
  232. /// <summary>
  233. /// 更新 TP_WEB_SETTING
  234. /// </summary>
  235. /// <returns>json</returns>
  236. private string update(NameValueCollection form)
  237. {
  238. using(IDataAccess conn=DataAccess.Create())
  239. {
  240. int result = conn.ExecuteNonQuery(@"
  241. UPDATE TP_WEB_SETTING
  242. SET
  243. NAME = @NAME@,
  244. VALUE = @VALUE@,
  245. MEMO = @MEMO@
  246. WHERE
  247. ID = @ID@
  248. ",
  249. new CDAParameter("NAME",form["NAME"]),
  250. new CDAParameter("VALUE",form["VALUE"]),
  251. new CDAParameter("MEMO",form["MEMO"]),
  252. new CDAParameter("ID",HttpContext.Current.Request["id"])
  253. );
  254. return new JsonResult(JsonStatus.success).ToJson();
  255. }
  256. }
  257. /// <summary>
  258. /// 删除 TP_WEB_SETTING
  259. /// </summary>
  260. /// <returns>json</returns>
  261. private string delete()
  262. {
  263. using(IDataAccess conn= DataAccess.Create())
  264. {
  265. if (HttpContext.Current.Request["id"] is object)
  266. {
  267. int result = conn.ExecuteNonQuery(@"
  268. DELETE
  269. TP_WEB_SETTING
  270. WHERE
  271. INSTR(',' || @ID@ || ',' , ',' || ID || ',') > 0
  272. ",
  273. new CDAParameter("ID", HttpContext.Current.Request["id"])
  274. );
  275. return new JsonResult(JsonStatus.success).ToJson();
  276. }
  277. else
  278. {
  279. return new JsonResult(JsonStatus.otherError).ToJson();
  280. }
  281. }
  282. }
  283. /// <summary>
  284. /// 导出 TP_WEB_SETTING
  285. /// </summary>
  286. /// <returns>json</returns>
  287. private string export()
  288. {
  289. return search(new NameValueCollection());
  290. }
  291. private class Button
  292. {
  293. public bool btnIndex = false;
  294. public bool btnInsert = false;
  295. public bool btnInsertBatch = false;
  296. public bool btnCopy = false;
  297. public bool btnUpdate = false;
  298. public bool btnDelete = false;
  299. public bool btnCancel = false;
  300. public bool btnSearch = false;
  301. public bool btnDetail = false;
  302. public bool btnCheckbox = false;
  303. public bool btnExport = false;
  304. public bool btnReload = false;
  305. }
  306. private class xRecord
  307. {
  308. public string sid { get; set; }
  309. public string NAME { get; set; }
  310. public string VALUE { get; set; }
  311. public string MEMO { get; set; }
  312. }
  313. public bool IsReusable
  314. {
  315. get
  316. {
  317. return false;
  318. }
  319. }
  320. }