fqcconfig.ashx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <%@ WebHandler Language="C#" Class="fqcconfig" %>
  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. using System.Linq;
  11. /// <summary>
  12. /// TP_PM_FQCCONFIG
  13. /// xuwei create 2023-09-07
  14. /// </summary>
  15. public class fqcconfig : IHttpHandler, IReadOnlySessionState
  16. {
  17. public void ProcessRequest(HttpContext context)
  18. {
  19. context.Response.ContentType = "text/plain";
  20. if (mes.LoginCheck() && context.Request["m"] is object)
  21. {
  22. Button b = new Button();
  23. if(mes.RightCheck(""))
  24. {
  25. b.fqcconfigButtonIndex = true;
  26. b.fqcconfigButtonInsert = true;
  27. b.fqcconfigButtonInsertBatch = true;
  28. b.fqcconfigButtonCopy = true;
  29. b.fqcconfigButtonUpdate = true;
  30. b.fqcconfigButtonDelete = true;
  31. b.fqcconfigButtonCancel = true;
  32. b.fqcconfigButtonSearch = true;
  33. b.fqcconfigButtonDetail = true;
  34. b.fqcconfigButtonCheckbox = true;
  35. b.fqcconfigButtonExport = true;
  36. b.fqcconfigButtonReload = 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.fqcconfigButtonDetail && 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. r.DISPLAYNO = "0";
  56. list.Add(r);
  57. context.Response.Write(new JsonResult(list).ToJson());
  58. }
  59. break;
  60. }
  61. case "s":
  62. {
  63. //搜索
  64. if (b.fqcconfigButtonIndex)
  65. context.Response.Write(search(context.Request.Form));
  66. else
  67. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  68. break;
  69. }
  70. case "t":
  71. {
  72. //详细
  73. if (b.fqcconfigButtonDetail)
  74. context.Response.Write(detail());
  75. else
  76. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  77. break;
  78. }
  79. case "i":
  80. {
  81. //插入
  82. if (b.fqcconfigButtonInsert)
  83. context.Response.Write(insert(context.Request.Form));
  84. else
  85. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  86. break;
  87. }
  88. case "u":
  89. {
  90. //修改
  91. if (b.fqcconfigButtonUpdate)
  92. context.Response.Write(update(context.Request.Form));
  93. else
  94. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  95. break;
  96. }
  97. case "d":
  98. {
  99. //删除
  100. if (b.fqcconfigButtonDelete)
  101. context.Response.Write(delete());
  102. else
  103. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  104. break;
  105. }
  106. case "e":
  107. {
  108. //导出
  109. if (b.fqcconfigButtonExport)
  110. {
  111. context.Response.Write(export());
  112. }
  113. else
  114. {
  115. context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
  116. }
  117. break;
  118. }
  119. default:
  120. {
  121. break;
  122. }
  123. }
  124. }
  125. else
  126. {
  127. context.Response.Write(new JsonResult(JsonStatus.loginError).ToJson());
  128. }
  129. }
  130. /// <summary>
  131. /// TP_PM_FQCCONFIG 查询
  132. /// </summary>
  133. /// <returns>json</returns>
  134. private string search(NameValueCollection form)
  135. {
  136. using (IDataAccess conn = DataAccess.Create())
  137. {
  138. int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
  139. int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
  140. string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
  141. string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
  142. //分页查询总数据
  143. string sql = @" WITH RankedEmployees AS (
  144. SELECT
  145. m.CONFIGID AS SID,
  146. m.CONFIGID,
  147. m.OUTQUANTITY,
  148. m.INSPECTIONQUANTITY,
  149. m.MINOUTQUANTITY,
  150. m.DISPLAYNO,
  151. m.REMARKS,
  152. m.VALUEFLAG,
  153. m.ACCOUNTID,
  154. m.CREATETIME,
  155. m.UPDATETIME,
  156. usr.USERCODE AS 更新工号,
  157. us.USERCODE AS 创建工号,
  158. CASE WHEN m.CLASSES = 1 THEN '一天一班' ELSE '一天二班' END AS CLASSES,
  159. m.INSPECTTYPES,
  160. ROW_NUMBER() OVER (ORDER BY m.CONFIGID) AS rn
  161. FROM
  162. TP_PM_FQCCONFIG m
  163. LEFT JOIN TP_MST_USER us ON us.USERID=M.CREATEUSERID
  164. LEFT JOIN TP_MST_USER usr ON usr.USERID=M.CREATEUSERID
  165. WHERE
  166. m.VALUEFLAG = '1'
  167. AND m.ACCOUNTID = @ACCOUNTID@";
  168. sql += form["CONFIGID"] == "" || form["CONFIGID"] == null ? "" : " AND m.CONFIGID = '" + form["CONFIGID"] + "'";
  169. sql += form["INSPECTTYPES"] == "" || form["INSPECTTYPES"] == null ? "" : " AND INSTR( m.INSPECTTYPES," + form["INSPECTTYPES"] + " ) > 0 ";
  170. sql += form["OUTQUANTITY"] == "" || form["OUTQUANTITY"] == null ? "" : " AND INSTR( m.OUTQUANTITY," + form["OUTQUANTITY"] + " ) > 0 ";
  171. sql += form["INSPECTIONQUANTITY"] == "" || form["INSPECTIONQUANTITY"] == null ? "" : " AND INSTR( m.INSPECTIONQUANTITY," + form["INSPECTIONQUANTITY"] + " ) > 0 ";
  172. sql += form["DISPLAYNO"] == "" || form["DISPLAYNO"] == null ? "" : " AND INSTR( m.DISPLAYNO," + form["DISPLAYNO"] + " ) > 0 ";
  173. sql += form["REMARKS"] == "" || form["REMARKS"] == null ? "" : " AND INSTR( m.REMARKS," + form["REMARKS"] + " ) > 0 ";
  174. sql += sort != "" ? sort != "INSPECTTYPENAME"?" ORDER BY " + sort + " " + order : "": "";
  175. sql += ") SELECT * FROM RankedEmployees WHERE rn BETWEEN " + (page == 0 ? (page - 1) * 10 : (page - 1) * 10 + 1) + " AND " + rows * page;
  176. DataTable bt = conn.ExecuteDatatable(sql, new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]));
  177. //添加检验类型中文名称
  178. bt.Columns.Add("INSPECTTYPENAME", typeof(string));
  179. //添加大小件
  180. bt.Columns.Add("CONFIGTYPE", typeof(string));
  181. //查找主键id
  182. var columnValues = bt.AsEnumerable().Select(row => row.Field<decimal>("CONFIGID")).ToList();
  183. //当没有数据时跳出
  184. if (columnValues.Count == 0)
  185. {
  186. return "";
  187. }
  188. //依据主键id查找副表TP_PM_FQCCONFIG_DETAIL
  189. DataTable lbt = conn.ExecuteDatatable(@"SELECT * FROM TP_PM_FQCCONFIG_DETAIL WHERE CONFIGID IN(" + string.Join(",", bt.AsEnumerable().Select(row => row.Field<decimal>("CONFIGID")).ToList()) + ") AND VALUEFLAG = 1");
  190. //依据检验类型通过逗号分割去查找TP_MST_DATADICTIONARY中的数据
  191. DataTable dbt = conn.ExecuteDatatable(@"SELECT * FROM TP_MST_DATADICTIONARY WHERE DICTIONARYID IN(" + string.Join(",", bt.AsEnumerable().Select(row => row.Field<string>("INSPECTTYPES")).ToList()) + ") AND VALUEFLAG = 1");
  192. //循环总数居
  193. for (int i = 0; i < bt.Rows.Count; i++)
  194. {
  195. //查找当前数据的检验类型并按逗号分割
  196. var xbt = bt.AsEnumerable().Where(ex => ex.Field<decimal>("CONFIGID") == decimal.Parse(bt.Rows[i][1].ToString())).Select(ex => ex.Field<string>("INSPECTTYPES")).FirstOrDefault().Split(',').ToList();
  197. //根据TP_MST_DATADICTIONARY包含当前检验类型的数据查找检验类型中文名称
  198. var query = (from row in dbt.AsEnumerable()
  199. where xbt.Contains(row.Field<decimal>("DICTIONARYID").ToString())
  200. select row).Select(row => row.Field<string>("DICTIONARYVALUE")).ToList();
  201. //添加检验类型中文名称(将集合按照逗号分割变为字符串)
  202. bt.Rows[i][16] = string.Join(",", query);
  203. //添加大小件(根据主键id查找副表第一条的计划类型)
  204. bt.Rows[i][17] = lbt.AsEnumerable().Where(ex => ex.Field<decimal>("CONFIGID") == decimal.Parse(bt.Rows[i][1].ToString())).Select(row => row.Field<string>("CONFIGTYPE")).FirstOrDefault();
  205. }
  206. //检验类型进行排序时
  207. if (sort != "" && sort == "INSPECTTYPENAME")
  208. {
  209. //转化为视图
  210. DataView dv = new DataView(bt);
  211. //排序
  212. dv.Sort = "INSPECTTYPENAME " + order;
  213. //将视图转换成表
  214. bt = dv.ToTable(true, "SID", "CONFIGID", "OUTQUANTITY", "INSPECTIONQUANTITY", "MINOUTQUANTITY", "DISPLAYNO", "REMARKS", "VALUEFLAG", "ACCOUNTID", "CREATETIME", "UPDATETIME", "更新工号", "创建工号", "CLASSES", "rn", "INSPECTTYPENAME", "CONFIGTYPE");
  215. }
  216. //查找总数
  217. DataTable dt = conn.ExecuteDatatable(@"SELECT COUNT(* )FROM TP_PM_FQCCONFIG WHERE VALUEFLAG = 1");
  218. return new JsonResult(bt) { total = int.Parse(dt.Rows[0][0].ToString()) }.ToJson();
  219. }
  220. }
  221. /// <summary>
  222. /// 详细 TP_PM_FQCCONFIG
  223. /// </summary>
  224. /// <returns>json</returns>
  225. private string detail()
  226. {
  227. using (IDataAccess conn = DataAccess.Create())
  228. {
  229. //通过id查找总数据
  230. DataTable dt = conn.ExecuteDatatable(@"
  231. SELECT
  232. m.CONFIGID,
  233. m.INSPECTTYPES,
  234. m.OUTQUANTITY,
  235. m.INSPECTIONQUANTITY,
  236. m.MINOUTQUANTITY,
  237. m.DISPLAYNO,
  238. m.REMARKS,
  239. m.VALUEFLAG,
  240. m.ACCOUNTID,
  241. m.CREATEUSERID,
  242. m.CREATETIME,
  243. m.UPDATEUSERID,
  244. CASE WHEN m.CLASSES = 1 THEN '一天一班' ELSE '一天二班' END AS CLASSES,
  245. m.UPDATETIME
  246. FROM
  247. TP_PM_FQCCONFIG m
  248. WHERE
  249. m.VALUEFLAG = '1'
  250. AND m.ACCOUNTID = @ACCOUNTID@
  251. AND m.CONFIGID = @CONFIGID@
  252. ",
  253. new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
  254. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"])
  255. );
  256. //通过主表id查找副表数据
  257. DataTable bt = conn.ExecuteDatatable(@"SELECT * FROM TP_PM_FQCCONFIG_DETAIL WHERE CONFIGID=@CONFIGID@ AND VALUEFLAG = 1", new CDAParameter("CONFIGID", HttpContext.Current.Request["id"]));
  258. //添加大小件
  259. dt.Columns.Add("CONFIGTYPE");
  260. //添加检验类型中文名称
  261. dt.Columns.Add("INSPECTTYPENAME");
  262. //通过检验类型id查找检验类型中文名称
  263. DataTable dbt = conn.ExecuteDatatable(@"SELECT DICTIONARYVALUE FROM TP_MST_DATADICTIONARY WHERE DICTIONARYID IN(" + string.Join(",", dt.AsEnumerable().Select(row => row.Field<string>("INSPECTTYPES")).ToList()) + ") AND VALUEFLAG = 1");
  264. //定义临时变量
  265. string linshi = "";
  266. //循环查找的数据
  267. for (int i = 0; i < dbt.Rows.Count; i++)
  268. {
  269. //进行拼接
  270. linshi += dbt.Rows[i][0];
  271. }
  272. //补齐大小件数据(通过副表查到的数据)
  273. dt.Rows[0][14] = bt.Rows[0][3];
  274. //补齐检验类型中文名称
  275. dt.Rows[0][15] = linshi;
  276. return new JsonResult(dt).ToJson();
  277. }
  278. }
  279. /// <summary>
  280. /// 插入 TP_PM_FQCCONFIG
  281. /// </summary>
  282. /// <returns>json</returns>
  283. private string insert(NameValueCollection form)
  284. {
  285. using (IDataAccess conn = DataAccess.Create())
  286. {
  287. //string primaryKey = conn.GetSequenceNextval("SEQ_TP_PM_FQCCONFIG_ID").ToString();
  288. //string primaryKey = Guid.NewGuid().ToString().Replace("_", "");
  289. //查找(提前拿到)下一条id
  290. DataTable dt = conn.ExecuteDatatable(@"SELECT SEQ_PM_FQCCONFIG_ID.nextval FROM dual");
  291. //添加数据
  292. int result = conn.ExecuteNonQuery(@"
  293. INSERT INTO TP_PM_FQCCONFIG (
  294. CONFIGID,
  295. OUTQUANTITY,
  296. MINOUTQUANTITY,
  297. INSPECTIONQUANTITY,
  298. DISPLAYNO,
  299. REMARKS,
  300. ACCOUNTID,CREATEUSERID,UPDATEUSERID,CLASSES,INSPECTTYPES
  301. ) VALUES (
  302. @CONFIGID@,
  303. @OUTQUANTITY@,
  304. @MINOUTQUANTITY@,
  305. @INSPECTIONQUANTITY@,
  306. @DISPLAYNO@,
  307. @REMARKS@,
  308. @ACCOUNTID@,@CREATEUSERID@,@UPDATEUSERID@, @CLASSES@,'" + form["INSPECTTYPES"] + "' ) ",
  309. new CDAParameter("CONFIGID", dt.Rows[0][0]),
  310. new CDAParameter("OUTQUANTITY", form["OUTQUANTITY"]),
  311. new CDAParameter("MINOUTQUANTITY", form["MINOUTQUANTITY"]),
  312. new CDAParameter("INSPECTIONQUANTITY", form["INSPECTIONQUANTITY"]),
  313. new CDAParameter("DISPLAYNO", form["DISPLAYNO"]),
  314. new CDAParameter("REMARKS", form["REMARKS"]),
  315. new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
  316. new CDAParameter("CREATEUSERID", HttpContext.Current.Session["userId"]),
  317. //班次
  318. new CDAParameter("CLASSES", int.Parse(form["CLASSES"])),
  319. new CDAParameter("UPDATEUSERID", HttpContext.Current.Session["userId"])
  320. );
  321. //通过检验类型去添加副表
  322. foreach (var item in form["INSPECTTYPES"].Split(','))
  323. {
  324. int result2 = conn.ExecuteNonQuery(@"
  325. INSERT INTO TP_PM_FQCCONFIG_DETAIL (
  326. CONFIGID,
  327. INSPECTTYPE,
  328. CONFIGTYPE,
  329. VALUEFLAG
  330. ) VALUES (
  331. @CONFIGID@,
  332. @INSPECTTYPE@,
  333. @CONFIGTYPE@,
  334. @VALUEFLAG@)",
  335. new CDAParameter("CONFIGID", dt.Rows[0][0]),
  336. new CDAParameter("INSPECTTYPE", item),
  337. new CDAParameter("CONFIGTYPE", form["CONFIGTYPE"]),
  338. new CDAParameter("VALUEFLAG", 1)
  339. );
  340. }
  341. return new JsonResult(JsonStatus.success).ToJson();
  342. }
  343. }
  344. /// <summary>
  345. /// 更新 TP_PM_FQCCONFIG
  346. /// </summary>
  347. /// <returns>json</returns>
  348. private string update(NameValueCollection form)
  349. {
  350. using (IDataAccess conn = DataAccess.Create())
  351. {
  352. //通过主表id删除当前副表所关联的所有值
  353. int result = conn.ExecuteNonQuery(@"
  354. UPDATE TP_PM_FQCCONFIG_DETAIL
  355. SET VALUEFLAG = 0 WHERE CONFIGID = @CONFIGID@ ",
  356. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"])
  357. );
  358. //更新主表
  359. int result2 = conn.ExecuteNonQuery(@"
  360. UPDATE TP_PM_FQCCONFIG
  361. SET
  362. INSPECTTYPES = '" + form["INSPECTTYPES"] + "'," +
  363. "OUTQUANTITY = @OUTQUANTITY@, " +
  364. "MINOUTQUANTITY = @MINOUTQUANTITY@," +
  365. " INSPECTIONQUANTITY = @INSPECTIONQUANTITY@," +
  366. " DISPLAYNO = @DISPLAYNO@," +
  367. " REMARKS = @REMARKS@," +
  368. " UPDATEUSERID = @UPDATEUSERID@," +
  369. " CLASSES = @CLASSES@," +
  370. "CONFIGTYPE=@CONFIGTYPE@," +
  371. " UPDATETIME = sysdate" +
  372. " WHERE CONFIGID = @CONFIGID@ ",
  373. new CDAParameter("OUTQUANTITY", form["OUTQUANTITY"]),
  374. new CDAParameter("MINOUTQUANTITY", form["MINOUTQUANTITY"]),
  375. new CDAParameter("INSPECTIONQUANTITY", form["INSPECTIONQUANTITY"]),
  376. new CDAParameter("DISPLAYNO", form["DISPLAYNO"]),
  377. new CDAParameter("REMARKS", form["REMARKS"]),
  378. //班次
  379. new CDAParameter("CLASSES", form["CLASSES"]),
  380. //大小件
  381. new CDAParameter("CONFIGTYPE", form["CONFIGTYPE"]),
  382. new CDAParameter("UPDATEUSERID", HttpContext.Current.Session["userId"]),
  383. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"])
  384. );
  385. //通过检验类型去添加副表
  386. foreach (var item in form["INSPECTTYPES"].Split(','))
  387. {
  388. int result3 = conn.ExecuteNonQuery(@"
  389. INSERT INTO TP_PM_FQCCONFIG_DETAIL (
  390. CONFIGID,
  391. INSPECTTYPE,
  392. CONFIGTYPE,
  393. VALUEFLAG
  394. ) VALUES (
  395. @CONFIGID@,
  396. @INSPECTTYPE@,
  397. @CONFIGTYPE@,
  398. @VALUEFLAG@)",
  399. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"]),
  400. new CDAParameter("INSPECTTYPE", item),
  401. new CDAParameter("CONFIGTYPE", form["CONFIGTYPE"]),
  402. new CDAParameter("VALUEFLAG", 1)
  403. );
  404. }
  405. return new JsonResult(JsonStatus.success).ToJson();
  406. }
  407. }
  408. /// <summary>
  409. /// 删除 TP_PM_FQCCONFIG
  410. /// </summary>
  411. /// <returns>json</returns>
  412. private string delete()
  413. {
  414. using(IDataAccess conn= DataAccess.Create())
  415. {
  416. if (HttpContext.Current.Request["id"] is object)
  417. {
  418. int result = conn.ExecuteNonQuery(@"
  419. DELETE
  420. TP_PM_FQCCONFIG
  421. WHERE
  422. INSTR(',' || @CONFIGID@ || ',' , ',' || CONFIGID || ',') > 0
  423. ",
  424. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"])
  425. );
  426. int result2 = conn.ExecuteNonQuery(@"
  427. DELETE
  428. TP_PM_FQCCONFIG_DETAIL
  429. WHERE
  430. INSTR(',' || @CONFIGID@ || ',' , ',' || CONFIGID || ',') > 0
  431. ",
  432. new CDAParameter("CONFIGID", HttpContext.Current.Request["id"])
  433. );
  434. return new JsonResult(JsonStatus.success).ToJson();
  435. }
  436. else
  437. {
  438. return new JsonResult(JsonStatus.otherError).ToJson();
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// 导出 TP_PM_FQCCONFIG
  444. /// </summary>
  445. /// <returns>json</returns>
  446. private string export()
  447. {
  448. return search(new NameValueCollection());
  449. }
  450. private class Button
  451. {
  452. public bool fqcconfigButtonIndex = false;
  453. public bool fqcconfigButtonInsert = false;
  454. public bool fqcconfigButtonInsertBatch = false;
  455. public bool fqcconfigButtonCopy = false;
  456. public bool fqcconfigButtonUpdate = false;
  457. public bool fqcconfigButtonDelete = false;
  458. public bool fqcconfigButtonCancel = false;
  459. public bool fqcconfigButtonSearch = false;
  460. public bool fqcconfigButtonDetail = false;
  461. public bool fqcconfigButtonCheckbox = false;
  462. public bool fqcconfigButtonExport = false;
  463. public bool fqcconfigButtonReload = false;
  464. }
  465. private class xRecord
  466. {
  467. public string sid { get; set; }
  468. public string INSPECTTYPE { get; set; }
  469. public string OUTQUANTITY { get; set; }
  470. public string INSPECTIONQUANTITY { get; set; }
  471. public string DISPLAYNO { get; set; }
  472. public string REMARKS { get; set; }
  473. }
  474. public bool IsReusable
  475. {
  476. get
  477. {
  478. return false;
  479. }
  480. }
  481. }