From 3e7b82e73d972972bab8c67dac7a5a6078f30a8b Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期五, 18 七月 2025 13:33:14 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.DAL/Common.cs | 59 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Wms/WMS.DAL/Common.cs b/Wms/WMS.DAL/Common.cs index 44f6d0c..e64bffa 100644 --- a/Wms/WMS.DAL/Common.cs +++ b/Wms/WMS.DAL/Common.cs @@ -20,7 +20,7 @@ { //public static readonly DataContext Db = new DataContext(); - + private readonly object GetMaxNoLock = new object(); /// <summary> /// 鑾峰彇娣卞害涓�1鐨勫偍浣嶅彿锛堟牴鎹繁搴︿负2鐨勫偍浣嶅彿锛� /// </summary> @@ -163,40 +163,43 @@ /// <returns></returns> public string GetMaxNo(string codeFlag) { - try - { - var maxNo = ""; - //鑾峰彇寮傚父鍙� - maxNo = SelectMaxNo(codeFlag); - if (!string.IsNullOrEmpty(maxNo)) + lock (GetMaxNoLock) + { + try { - maxNo = maxNo.Substring(codeFlag.Length); - } - //鑾峰彇鏁版嵁搴撴椂闂村叓浣� - string date = DateTime.Now.ToString("yyyyMMdd").Trim(); - string no = ""; - if (string.IsNullOrEmpty(maxNo)) - { - no = codeFlag + date + "00001"; - } - else - { - if (maxNo.Substring(0, 8) == date) + var maxNo = ""; + //鑾峰彇寮傚父鍙� + maxNo = SelectMaxNo(codeFlag); + if (!string.IsNullOrEmpty(maxNo)) { - int lastNo = Convert.ToInt32(maxNo.Substring(8, 5)) + 1; - no = codeFlag + date + (lastNo.ToString().PadLeft(5, '0')); + maxNo = maxNo.Substring(codeFlag.Length); } - else + //鑾峰彇鏁版嵁搴撴椂闂村叓浣� + string date = DateTime.Now.ToString("yyyyMMdd").Trim(); + string no = ""; + if (string.IsNullOrEmpty(maxNo)) { no = codeFlag + date + "00001"; } + else + { + if (maxNo.Substring(0, 8) == date) + { + int lastNo = Convert.ToInt32(maxNo.Substring(8, 5)) + 1; + no = codeFlag + date + (lastNo.ToString().PadLeft(5, '0')); + } + else + { + no = codeFlag + date + "00001"; + } + } + return no; } - return no; - } - catch (Exception e) - { - Console.WriteLine(e); - throw; + catch (Exception e) + { + Console.WriteLine(e); + throw; + } } } /// <summary> -- Gitblit v1.8.0