setTestFormGoods.ashx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <%@ WebHandler Language="C#" Class="setTestFormGoods" %>
  2. using System;
  3. using System.Web;
  4. using System.Data;
  5. using Curtain.DataAccess;
  6. using DK.XuWei.WebMes;
  7. /// <summary>
  8. /// 添加产品到实验单
  9. /// xuwei add 2021-08-31
  10. /// </summary>
  11. public class setTestFormGoods : IHttpHandler
  12. {
  13. public void ProcessRequest(HttpContext context)
  14. {
  15. context.Response.ContentType = "text/plain";
  16. using (IDataAccess conn = DataAccess.Create())
  17. {
  18. //实验单ID
  19. string testformid = context.Request["TESTFORMID"];
  20. //产品条码
  21. string barcode = context.Request["BARCODE"];
  22. //用户ID
  23. string usercode = context.Request["USERCODE"];
  24. //操作方式 add 添加 delete 删除
  25. string mode = context.Request["MODE"] is object ? context.Request["MODE"].ToString() : "";
  26. if (mode == "add")
  27. {
  28. //添加产品处理
  29. object result0 = conn.ExecuteScalar(@"
  30. SELECT 1 FROM TP_PM_TESTFORM2_GOODS WHERE TESTFORMGUID = @TESTFORMID@ AND BARCODE =@BARCODE@ AND VALUEFLAG = 1
  31. ",
  32. new CDAParameter("BARCODE", barcode),
  33. new CDAParameter("TESTFORMID", testformid)
  34. );
  35. if (result0 + "" == "1")
  36. {
  37. context.Response.Write(new JsonResult() { success = false, message = "条码重复", total = 0, rows = "" }.ToJson());
  38. return;
  39. }
  40. object result1 = conn.ExecuteScalar(@"
  41. SELECT DISTINCT 1 FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE =@BARCODE@ AND VALUEFLAG = 1
  42. ",
  43. new CDAParameter("BARCODE", barcode)
  44. );
  45. string str1 = result1 + "";
  46. if (str1 == "")
  47. {
  48. context.Response.Write(new JsonResult() { success = false, message = "条码不存在", total = 0, rows = "" }.ToJson());
  49. return;
  50. }
  51. else
  52. {
  53. //添加产品处理
  54. int result = conn.ExecuteNonQuery(@"
  55. INSERT INTO TP_PM_TESTFORM2_GOODS(TESTFORMGUID,BARCODE,VALUEFLAG,CREATEUSERID,UPDATEUSERID,ACCOUNTID)
  56. VALUES(@TESTFORMID@, @BARCODE@, 1, (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@), (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@), 1)
  57. ",
  58. new CDAParameter("BARCODE", barcode),
  59. new CDAParameter("TESTFORMID", testformid),
  60. new CDAParameter("USERCODE", usercode)
  61. );
  62. if (result > 0)
  63. {
  64. DataTable dtResult = conn.ExecuteDatatable(@"SELECT TESTFLAG FROM TP_PM_TESTFORM2 WHERE ID = @TESTFORMID@",
  65. new CDAParameter("TESTFORMID", testformid));
  66. if (dtResult != null && dtResult.Rows.Count > 0)
  67. {
  68. if (dtResult.Rows[0]["TESTFLAG"].ToString() == "1")
  69. {
  70. int resultup = conn.ExecuteNonQuery(@"
  71. UPDATE TP_PM_GROUTINGDAILYDETAIL
  72. SET
  73. TESTFORMFLAG =1
  74. WHERE
  75. BARCODE = @BARCODE@
  76. ", new CDAParameter("BARCODE", barcode)
  77. );
  78. if (result > 0)
  79. {
  80. context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
  81. return;
  82. }
  83. else
  84. {
  85. context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
  86. return;
  87. }
  88. }
  89. else
  90. {
  91. int resultup = conn.ExecuteNonQuery(@"
  92. UPDATE TP_PM_GROUTINGDAILYDETAIL
  93. SET
  94. TESTFORMFLAG =2
  95. WHERE
  96. BARCODE = @BARCODE@
  97. ", new CDAParameter("BARCODE", barcode)
  98. );
  99. if (result > 0)
  100. {
  101. context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
  102. return;
  103. }
  104. else
  105. {
  106. context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
  107. return;
  108. }
  109. }
  110. }
  111. }
  112. else
  113. {
  114. context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
  115. return;
  116. }
  117. }
  118. }
  119. if (mode == "delete")
  120. {
  121. //删除产品处理,valueflag置为0,updateuserid更新为当前用户
  122. int result = conn.ExecuteNonQuery(@"
  123. UPDATE TP_PM_TESTFORM2_GOODS
  124. SET
  125. VALUEFLAG = 0,
  126. UPDATEUSERID = (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@),
  127. UPDATETIME = SYSDATE
  128. WHERE
  129. VALUEFLAG = 1
  130. AND TESTFORMGUID = @TESTFORMID@
  131. AND BARCODE = @BARCODE@
  132. ",
  133. new CDAParameter("BARCODE", barcode),
  134. new CDAParameter("TESTFORMID", testformid),
  135. new CDAParameter("USERCODE", usercode)
  136. );
  137. if (result > 0)
  138. {
  139. int resultup = conn.ExecuteNonQuery(@"
  140. UPDATE TP_PM_GROUTINGDAILYDETAIL
  141. SET
  142. TESTFORMFLAG = 0
  143. WHERE
  144. BARCODE = @BARCODE@
  145. ",
  146. new CDAParameter("BARCODE", barcode)
  147. );
  148. if (result > 0)
  149. {
  150. context.Response.Write(new JsonResult() { success = true, message = "删除成功", total = result, rows = "" }.ToJson());
  151. return;
  152. }
  153. else
  154. {
  155. //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
  156. context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
  157. return;
  158. }
  159. }
  160. else
  161. {
  162. //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
  163. context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
  164. return;
  165. }
  166. }
  167. }
  168. }
  169. public bool IsReusable
  170. {
  171. get
  172. {
  173. return false;
  174. }
  175. }
  176. }