From eb29ee75c7f2f4154b7a3d0c475f94e0b964e996 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 02 四月 2025 18:17:48 +0800
Subject: [PATCH] 优化事务基础写法

---
 Tiger.Business.WMS/Transaction/Yada/Print_BIZ_U9_ASN.cs  |   14 ++--
 Tiger.Business.WMS/Transaction/In_Default.cs             |   16 ++--
 Tiger.Business.WMS/Transaction/Out_Default.cs            |   16 ++--
 Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs  |   23 +++++--
 Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs |   27 ++++----
 Tiger.Business.WMS/Transaction/Yada/Out_BIZ_WMS_PREP.cs  |   31 +++++-----
 Tiger.Business.WMS/Common/WmsTask.cs                     |    9 +++
 Tiger.Business.WMS/Transaction/WMSTransactionBase.cs     |    6 +-
 8 files changed, 81 insertions(+), 61 deletions(-)

diff --git a/Tiger.Business.WMS/Common/WmsTask.cs b/Tiger.Business.WMS/Common/WmsTask.cs
index 6ae26b6..9066eaa 100644
--- a/Tiger.Business.WMS/Common/WmsTask.cs
+++ b/Tiger.Business.WMS/Common/WmsTask.cs
@@ -794,6 +794,15 @@
         }
         #endregion Functions
 
+        /// <summary>
+        /// 閲嶇疆鏈鎵爜淇℃伅
+        /// </summary>
+        public virtual void ResetScan()
+        {
+            //娓呯悊鏆傚瓨鏁版嵁鎻愪氦鎿嶄綔
+            DBCommitList.Clear();
+        }
+
         public override bool Close(bool needSaveHistoryLog = false)
         {
             //needSaveHistoryLog = true;
diff --git a/Tiger.Business.WMS/Transaction/In_Default.cs b/Tiger.Business.WMS/Transaction/In_Default.cs
index 44d7d50..cb890a6 100644
--- a/Tiger.Business.WMS/Transaction/In_Default.cs
+++ b/Tiger.Business.WMS/Transaction/In_Default.cs
@@ -65,7 +65,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -273,7 +273,7 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]鍙兘瀛樻斁涓�涓墿鏂�");
                     action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE);
-                    ResetScan();
+                    ResetTrans();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
 
@@ -293,7 +293,7 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = putonResult.LocaleMsg;
-                    ResetScan();
+                    ResetTrans();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
 
@@ -303,7 +303,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -394,7 +394,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -442,11 +442,11 @@
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
+            base.ResetTrans();
             ResetScanInfo();
             CurScanShelf = null;
         }
diff --git a/Tiger.Business.WMS/Transaction/Out_Default.cs b/Tiger.Business.WMS/Transaction/Out_Default.cs
index 3b2a261..20872e8 100644
--- a/Tiger.Business.WMS/Transaction/Out_Default.cs
+++ b/Tiger.Business.WMS/Transaction/Out_Default.cs
@@ -53,7 +53,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -163,7 +163,7 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = downResult.LocaleMsg;
-                    ResetScan();
+                    ResetTrans();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
 
@@ -178,7 +178,7 @@
             }
             catch (Exception ex)
             {
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -262,7 +262,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -302,18 +302,18 @@
             action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", CurInvItem.SN, CurInvItem.Location?.LOCATION_CODE);
 
             //閲嶇疆宸ュ簭
-            ResetScan();
+            ResetTrans();
             return SetOutPutMqttMsg(action, locale);
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
+            base.ResetTrans();
             Command = null;
             CurInvItem = null;
             CurScanShelf = null;
diff --git a/Tiger.Business.WMS/Transaction/WMSTransactionBase.cs b/Tiger.Business.WMS/Transaction/WMSTransactionBase.cs
index 67ea525..bb96163 100644
--- a/Tiger.Business.WMS/Transaction/WMSTransactionBase.cs
+++ b/Tiger.Business.WMS/Transaction/WMSTransactionBase.cs
@@ -75,7 +75,7 @@
         {
             var action = new ApiAction();
 
-            ResetScan();
+            ResetTrans();
             action.IsSuccessed = true;
             //action.LocaleMsg = new($"鎿嶄綔宸查噸缃紝璇烽噸鏂版壂鎻�");
             action.LocaleMsg = new("WMS.Transaction.Reset");
@@ -83,9 +83,9 @@
             return action;
         }
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public virtual void ResetScan()
+        public virtual void ResetTrans()
         {
             ProcessingSn = null;
         }
diff --git a/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs b/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
index ea22c44..8fbcc2c 100644
--- a/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
@@ -67,7 +67,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -165,7 +165,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{0}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -194,7 +194,7 @@
             action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.CountSuccess", CurSn.First().SN);
 
             //閲嶇疆宸ュ簭
-            ResetScan();
+            ResetTrans();
             return SetOutPutMqttMsg(action, locale); ;
         }
 
@@ -570,15 +570,24 @@
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// </summary>
+        public override void ResetTrans()
+        {
+            ResetScan();
+            CurScanShelf = null;
+            base.ResetTrans();
+        }
+
+        /// <summary>
+        /// 閲嶇疆鏈鎵爜淇℃伅
         /// </summary>
         public override void ResetScan()
         {
-            base.ResetScan();
-            Command = null;
+            Command = "Normal";
             CurInvItem = null;
-            CurScanShelf = null;
             CurSn = null;
+            base.ResetScan();
         }
 
         public override bool Close(bool needSaveHistoryLog = false)
diff --git a/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs b/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
index 1cd1a9b..609996a 100644
--- a/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
@@ -63,7 +63,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -192,7 +192,7 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]鍙兘瀛樻斁涓�涓墿鏂�");
                     action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE);
-                    ResetScan();
+                    ResetTrans();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
 
@@ -223,7 +223,7 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = putonResult.LocaleMsg;
-                    ResetScan();
+                    ResetTrans();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
 
@@ -299,7 +299,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -390,7 +390,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -431,29 +431,30 @@
             action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, CurInvItem.Location.LOCATION_CODE);
 
             //閲嶇疆宸ュ簭
-            ResetScanInfo();
+            ResetScan();
             return SetOutPutMqttMsg(action, locale);
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
-            ResetScanInfo();
+            ResetScan();
             CurScanShelf = null;
+            base.ResetTrans();
         }
 
         /// <summary>
-        /// 閲嶇疆鎵爜淇℃伅
+        /// 閲嶇疆鏈鎵爜淇℃伅
         /// </summary>
-        public void ResetScanInfo()
+        public override void ResetScan()
         {
-            Command = null;
+            Command = "Normal";
             CurInvItem = null;
+            base.ResetScan();
         }
 
         public override bool Close(bool needSaveHistoryLog = false)
diff --git a/Tiger.Business.WMS/Transaction/Yada/Out_BIZ_WMS_PREP.cs b/Tiger.Business.WMS/Transaction/Yada/Out_BIZ_WMS_PREP.cs
index 4847c35..690b95f 100644
--- a/Tiger.Business.WMS/Transaction/Yada/Out_BIZ_WMS_PREP.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/Out_BIZ_WMS_PREP.cs
@@ -95,7 +95,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -141,7 +141,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"澶囨枡浠诲姟鎵弿鍗曟嵁寮傚父(Data: {0})");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Out_BIZ_WMS_PREP.ScanOrderException", input?.Data));
             }
@@ -272,7 +272,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"澶囨枡浠诲姟閫夋嫨瑕佺墿鏂欒寮傚父(Data: {0})");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Out_BIZ_WMS_PREP.SelectItemException", input?.Data));
             }
@@ -581,7 +581,7 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = downResult.LocaleMsg;
-                    ResetScanInfo();
+                    ResetScan();
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
                 else//澶勭悊澶囨枡浠诲姟鏁版嵁
@@ -632,9 +632,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
-                //娓呯悊鏆傚瓨鏁版嵁鎻愪氦鎿嶄綔
-                DBCommitList.Clear();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -735,7 +733,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -775,30 +773,33 @@
             action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", CurInvItem.SN, CurInvItem.Location?.LOCATION_CODE);
 
             //閲嶇疆宸ュ簭
-            ResetScanInfo();
+            ResetScan();
             return SetOutPutMqttMsg(action, locale);
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
-            ResetScanInfo();
+            ResetScan();
             CurPREP = new(MainDB, UserCode, OrgCode);
+            CurPrepDtl = new();
             CurScanShelf = null;
+            base.ResetTrans();
         }
 
         /// <summary>
-        /// 閲嶇疆鎵爜淇℃伅
+        /// 閲嶇疆鏈鎵爜淇℃伅
         /// </summary>
-        public void ResetScanInfo()
+        public override void ResetScan()
         {
             Command = "Normal";
             CurInvItem = null;
+            CurSn = new();
+            base.ResetScan();
         }
 
         public override bool Close(bool needSaveHistoryLog = false)
diff --git a/Tiger.Business.WMS/Transaction/Yada/Print_BIZ_U9_ASN.cs b/Tiger.Business.WMS/Transaction/Yada/Print_BIZ_U9_ASN.cs
index a1d0359..5c963a7 100644
--- a/Tiger.Business.WMS/Transaction/Yada/Print_BIZ_U9_ASN.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/Print_BIZ_U9_ASN.cs
@@ -78,7 +78,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -107,7 +107,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
             return SetOutPutMqttMsg(action, input.Locale);
@@ -229,7 +229,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
             return SetOutPutMqttMsg(action, input.Locale);
@@ -490,18 +490,18 @@
             action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.CountSuccess", string.Join(",", SnList));
 
             //閲嶇疆宸ュ簭
-            ResetScan();
+            ResetTrans();
             return SetOutPutMqttMsg(action, locale); ;
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
+            base.ResetTrans();
             Command = null;
             CurInvItem = null;
             CurScanShelf = null;

--
Gitblit v1.9.3