setTestFormGoods.ashx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 DISTINCT 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. string str = result0 + "";
  36. object result1 = conn.ExecuteScalar(@"
  37. SELECT DISTINCT 1 FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE =@BARCODE@ AND VALUEFLAG = 1
  38. ",
  39. new CDAParameter("BARCODE",barcode)
  40. ) ;
  41. string str1 = result1+ "";
  42. int result = 0;
  43. if (str == "1" || str1 == "")
  44. {
  45. if (str == "1")
  46. {
  47. context.Response.Write(new JsonResult() { success = false,message = "条码重复",total = 0,rows = "" }.ToJson()) ;
  48. }
  49. if (str1 == "")
  50. {
  51. context.Response.Write(new JsonResult() { success = false,message = "条码不存在",total = 0,rows = "" }.ToJson()) ;
  52. }
  53. }
  54. else
  55. {
  56. result = conn.ExecuteNonQuery(@"
  57. INSERT INTO TP_PM_TESTFORM2_GOODS (
  58. TESTFORMGUID,
  59. BARCODE,
  60. ACCOUNTID,CREATEUSERID,UPDATEUSERID
  61. ) SELECT
  62. @TESTFORMGUID@ AS TESTFORMGUID,
  63. @BARCODE@ AS BARCODE,
  64. 1 AS ACCOUNTID,
  65. (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@) AS CREATEUSERID,
  66. (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@) AS UPDATEUSERID
  67. FROM DUAL
  68. ",
  69. new CDAParameter("TESTFORMGUID",testformid),
  70. new CDAParameter("BARCODE",barcode),
  71. new CDAParameter("USERCODE", usercode)
  72. );
  73. int resultup = conn.ExecuteNonQuery(@"
  74. UPDATE TP_PM_GROUTINGDAILYDETAIL
  75. SET
  76. TESTFORMFLAG =1
  77. WHERE
  78. BARCODE = @BARCODE@
  79. ",
  80. new CDAParameter("BARCODE",barcode)
  81. );
  82. }
  83. if (result > 0)
  84. {
  85. context.Response.Write(new JsonResult() { success = true,message = "保存成功",total = result,rows = "" }.ToJson()) ;
  86. }
  87. else {
  88. //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
  89. context.Response.Write(new JsonResult() { success = false,message = "无相关测试单",total = 0,rows = "" }.ToJson()) ;
  90. }
  91. }
  92. if (mode == "delete")
  93. {
  94. int resultup = conn.ExecuteNonQuery(@"
  95. UPDATE TP_PM_GROUTINGDAILYDETAIL
  96. SET
  97. TESTFORMFLAG =0
  98. WHERE
  99. BARCODE = @BARCODE@
  100. ",
  101. new CDAParameter("BARCODE",barcode)
  102. );
  103. int result = conn.ExecuteNonQuery(@"
  104. DELETE
  105. TP_PM_TESTFORM2_GOODS
  106. WHERE
  107. VALUEFLAG = 1
  108. AND TESTFORMGUID = @TESTFORMID@
  109. AND BARCODE = @BARCODE@
  110. ",
  111. new CDAParameter("BARCODE", barcode),
  112. new CDAParameter("TESTFORMID", testformid)
  113. );
  114. if (result > 0)
  115. {
  116. context.Response.Write(new JsonResult() { success = true,message = "删除成功",total = result,rows = "" }.ToJson()) ;
  117. }
  118. else {
  119. //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
  120. context.Response.Write(new JsonResult() { success = false,message = "删除失败",total = 0,rows = "" }.ToJson()) ;
  121. }
  122. }
  123. context.Response.Write(new JsonResult(JsonStatus.success).ToJson());
  124. }
  125. }
  126. public bool IsReusable
  127. {
  128. get
  129. {
  130. return false;
  131. }
  132. }
  133. }