瀏覽代碼

研发产品查询去重

忠帅 张 2 年之前
父節點
當前提交
7703c866ec
共有 1 個文件被更改,包括 129 次插入118 次删除
  1. 129 118
      wwwroot/api/v001/TestForm/setTestFormGoods.ashx

+ 129 - 118
wwwroot/api/v001/TestForm/setTestFormGoods.ashx

@@ -13,115 +13,123 @@ using DK.XuWei.WebMes;
 public class setTestFormGoods : IHttpHandler
 {
 
-	public void ProcessRequest(HttpContext context)
-	{
-		context.Response.ContentType = "text/plain";
+    public void ProcessRequest(HttpContext context)
+    {
+        context.Response.ContentType = "text/plain";
 
-		using (IDataAccess conn = DataAccess.Create())
-		{
-			//实验单ID
-			string testformid = context.Request["TESTFORMID"];
-			//产品条码
-			string barcode = context.Request["BARCODE"];
-			//用户ID
-			string usercode = context.Request["USERCODE"];
-			//操作方式 add 添加 delete 删除
-			string mode = context.Request["MODE"] is object ? context.Request["MODE"].ToString() : "";
-			if (mode == "add")
-			{
-				//添加产品处理
-				object result0 = conn.ExecuteScalar(@"
+        using (IDataAccess conn = DataAccess.Create())
+        {
+            //实验单ID
+            string testformid = context.Request["TESTFORMID"];
+            //产品条码
+            string barcode = context.Request["BARCODE"];
+            //用户ID
+            string usercode = context.Request["USERCODE"];
+            //操作方式 add 添加 delete 删除
+            string mode = context.Request["MODE"] is object ? context.Request["MODE"].ToString() : "";
+            if (mode == "add")
+            {
+
+                //添加产品处理
+                object result0 = conn.ExecuteScalar(@"
                     SELECT 1 FROM TP_PM_TESTFORM2_GOODS WHERE TESTFORMGUID = @TESTFORMID@ AND BARCODE =@BARCODE@ AND VALUEFLAG = 1
                     ",
-					new CDAParameter("BARCODE", barcode),
-					new CDAParameter("TESTFORMID", testformid)
-				);
-				if (result0 + "" == "1")
-				{
-					context.Response.Write(new JsonResult() { success = false, message = "条码重复", total = 0, rows = "" }.ToJson());
-				}
-				object result1 = conn.ExecuteScalar(@"
+                    new CDAParameter("BARCODE", barcode),
+                    new CDAParameter("TESTFORMID", testformid)
+                );
+                if (result0 + "" == "1")
+                {
+                    context.Response.Write(new JsonResult() { success = false, message = "条码重复", total = 0, rows = "" }.ToJson());
+                    return;
+                }
+                object result1 = conn.ExecuteScalar(@"
                 SELECT DISTINCT 1 FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE =@BARCODE@ AND VALUEFLAG = 1
                 ",
-			 new CDAParameter("BARCODE", barcode)
-		 );
-				string str1 = result1 + "";
-				if (str1 == "")
-				{
-					context.Response.Write(new JsonResult() { success = false, message = "条码不存在", total = 0, rows = "" }.ToJson());
-				}
+             new CDAParameter("BARCODE", barcode)
+         );
+                string str1 = result1 + "";
+                if (str1 == "")
+                {
+                    context.Response.Write(new JsonResult() { success = false, message = "条码不存在", total = 0, rows = "" }.ToJson());
+                    return;
+                }
 
-				else
-				{
+                else
+                {
 
-					//添加产品处理
-					int result = conn.ExecuteNonQuery(@"
+                    //添加产品处理
+                    int result = conn.ExecuteNonQuery(@"
                     INSERT INTO TP_PM_TESTFORM2_GOODS(TESTFORMGUID,BARCODE,VALUEFLAG,CREATEUSERID,UPDATEUSERID,ACCOUNTID)
                     VALUES(@TESTFORMID@, @BARCODE@, 1, (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@), (SELECT USERID FROM TP_MST_USER WHERE USERCODE = @USERCODE@), 1) 
                     ",
-						new CDAParameter("BARCODE", barcode),
-						new CDAParameter("TESTFORMID", testformid),
-						new CDAParameter("USERCODE", usercode)
-					);
+                        new CDAParameter("BARCODE", barcode),
+                        new CDAParameter("TESTFORMID", testformid),
+                        new CDAParameter("USERCODE", usercode)
+                    );
 
-					if (result > 0)
-					{
-						DataTable dtResult = conn.ExecuteDatatable(@"SELECT TESTFLAG FROM TP_PM_TESTFORM2 WHERE ID = @TESTFORMID@",
-						new CDAParameter("TESTFORMID", testformid));
+                    if (result > 0)
+                    {
+                        DataTable dtResult = conn.ExecuteDatatable(@"SELECT TESTFLAG FROM TP_PM_TESTFORM2 WHERE ID = @TESTFORMID@",
+                        new CDAParameter("TESTFORMID", testformid));
 
-						if (dtResult != null && dtResult.Rows.Count > 0)
-						{
-							if (dtResult.Rows[0]["TESTFLAG"].ToString() == "1")
-							{
-								int resultup = conn.ExecuteNonQuery(@"
+                        if (dtResult != null && dtResult.Rows.Count > 0)
+                        {
+                            if (dtResult.Rows[0]["TESTFLAG"].ToString() == "1")
+                            {
+                                int resultup = conn.ExecuteNonQuery(@"
                                      UPDATE TP_PM_GROUTINGDAILYDETAIL 
                                      SET
                                          TESTFORMFLAG =1
                                      WHERE 
                                           BARCODE = @BARCODE@
                                      ", new CDAParameter("BARCODE", barcode)
-							);
-								if (result > 0)
-								{
-									context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
-								}
-								else
-								{
-									context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
-								}
-							}
-							else
-							{
-								int resultup = conn.ExecuteNonQuery(@"
+                            );
+                                if (result > 0)
+                                {
+                                    context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
+                                    return;
+                                }
+                                else
+                                {
+                                    context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
+                                    return;
+                                }
+                            }
+                            else
+                            {
+                                int resultup = conn.ExecuteNonQuery(@"
                                      UPDATE TP_PM_GROUTINGDAILYDETAIL 
                                      SET
                                          TESTFORMFLAG =2
                                      WHERE 
                                           BARCODE = @BARCODE@
                                      ", new CDAParameter("BARCODE", barcode)
-							);
-								if (result > 0)
-								{
-									context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
-								}
-								else
-								{
-									context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
-								}
-							}
-						}
-					}
-					else
-					{
-						context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
-					}
-				}
+                            );
+                                if (result > 0)
+                                {
+                                    context.Response.Write(new JsonResult() { success = true, message = "保存成功", total = result, rows = "" }.ToJson());
+                                    return;
+                                }
+                                else
+                                {
+                                    context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
+                                    return;
+                                }
+                            }
+                        }
+                    }
+                    else
+                    {
+                        context.Response.Write(new JsonResult() { success = false, message = "保存失败", total = 0, rows = "" }.ToJson());
+                        return;
+                    }
+                }
 
-			}
-			if (mode == "delete")
-			{
-				//删除产品处理,valueflag置为0,updateuserid更新为当前用户
-				int result = conn.ExecuteNonQuery(@"
+            }
+            if (mode == "delete")
+            {
+                //删除产品处理,valueflag置为0,updateuserid更新为当前用户
+                int result = conn.ExecuteNonQuery(@"
                             UPDATE TP_PM_TESTFORM2_GOODS 
                             SET
                                 VALUEFLAG = 0,
@@ -132,49 +140,52 @@ public class setTestFormGoods : IHttpHandler
                                 AND TESTFORMGUID = @TESTFORMID@
                                 AND BARCODE = @BARCODE@
                             ",
-					new CDAParameter("BARCODE", barcode),
-					new CDAParameter("TESTFORMID", testformid),
-					new CDAParameter("USERCODE", usercode)
-				);
+                    new CDAParameter("BARCODE", barcode),
+                    new CDAParameter("TESTFORMID", testformid),
+                    new CDAParameter("USERCODE", usercode)
+                );
 
-				if (result > 0)
-				{
-					int resultup = conn.ExecuteNonQuery(@"
+                if (result > 0)
+                {
+                    int resultup = conn.ExecuteNonQuery(@"
 						 UPDATE TP_PM_GROUTINGDAILYDETAIL 
 						 SET
 						     TESTFORMFLAG = 0
 						 WHERE 
 						      BARCODE = @BARCODE@
 						 ",
-				   new CDAParameter("BARCODE", barcode)
-			   );
-					if (result > 0)
-					{
-						context.Response.Write(new JsonResult() { success = true, message = "删除成功", total = result, rows = "" }.ToJson());
-					}
-					else
-					{
-						//context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
-						context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
-					}
-				}
-				else
-				{
-					//context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
-					context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
-				}
-			}
+                   new CDAParameter("BARCODE", barcode)
+               );
+                    if (result > 0)
+                    {
+                        context.Response.Write(new JsonResult() { success = true, message = "删除成功", total = result, rows = "" }.ToJson());
+                        return;
+                    }
+                    else
+                    {
+                        //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
+                        context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
+                        return;
+                    }
+                }
+                else
+                {
+                    //context.Response.Write(new JsonResult(JsonStatus.error).ToJson());
+                    context.Response.Write(new JsonResult() { success = false, message = "删除失败", total = 0, rows = "" }.ToJson());
+                    return;
+                }
+            }
 
-		}
+        }
 
-	}
+    }
 
-	public bool IsReusable
-	{
-		get
-		{
-			return false;
-		}
-	}
+    public bool IsReusable
+    {
+        get
+        {
+            return false;
+        }
+    }
 
 }