batchscrap.ashx 13 KB

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