From 834eb24341e32855a731cfaa48851d3f0a650dc5 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期五, 20 十二月 2024 15:49:31 +0800 Subject: [PATCH] 重构Barcode到WMS Business --- Tiger.Business.WMSTests/Tiger.Business.WMSTests.csproj | 23 /dev/null | 650 --------------------- Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.Yada.cs | 54 + Tiger.Business.WMS/WMS_ITEM_Biz.cs | 8 Tiger.Business.WMS/Transaction/Old/OtherInLocationChecking.cs | 2 Tiger.Api.sln | 14 Tiger.Business.WMSTests/Common/CommonTests.cs | 22 Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.cs | 293 +++++++++ Tiger.Business.WMS/Common/Barcode/Barcode.cs | 718 +++++++++++++++++++++++ Tiger.Business.WMS/Transaction/Old/CustSupplyCheckingNew.cs | 2 10 files changed, 1,134 insertions(+), 652 deletions(-) diff --git a/Tiger.Api.sln b/Tiger.Api.sln index c3b08f3..271c82d 100644 --- a/Tiger.Api.sln +++ b/Tiger.Api.sln @@ -43,12 +43,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tiger.IBusiness.MES", "Tiger.IBusiness.MES\Tiger.IBusiness.MES.csproj", "{07B13ED4-77D9-4B9C-9375-91B7ED371422}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "05-寮曠敤渚濊禆", "05-寮曠敤渚濊禆", "{80347AC9-C069-4DF6-B3D3-E8B242E741F5}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiger.Dependencies", "Tiger.Dependencies\Tiger.Dependencies.csproj", "{25510DCE-19CC-4FF6-926B-3036120D37B6}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiger.Api.Core", "Tiger.Api.Core\Tiger.Api.Core.csproj", "{FE25D100-75C9-4DE3-8CDA-EA9AA4677CF4}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiger.Controllers.System", "Tiger.Controllers.System\Tiger.Controllers.System.csproj", "{10DF128C-B6BB-496B-96B0-64512D0E1D00}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiger.Business.WMSTests", "Tiger.Business.WMSTests\Tiger.Business.WMSTests.csproj", "{63B2C6B6-AC76-4CC7-8142-91871D6C45D1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -178,6 +183,14 @@ {10DF128C-B6BB-496B-96B0-64512D0E1D00}.Release|Any CPU.Build.0 = Release|Any CPU {10DF128C-B6BB-496B-96B0-64512D0E1D00}.Release|x86.ActiveCfg = Release|Any CPU {10DF128C-B6BB-496B-96B0-64512D0E1D00}.Release|x86.Build.0 = Release|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Debug|x86.ActiveCfg = Debug|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Debug|x86.Build.0 = Debug|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Release|Any CPU.Build.0 = Release|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Release|x86.ActiveCfg = Release|Any CPU + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -199,6 +212,7 @@ {25510DCE-19CC-4FF6-926B-3036120D37B6} = {80347AC9-C069-4DF6-B3D3-E8B242E741F5} {FE25D100-75C9-4DE3-8CDA-EA9AA4677CF4} = {FF44BF62-08C5-4B52-B24F-54CD79E96848} {10DF128C-B6BB-496B-96B0-64512D0E1D00} = {457563B5-E42C-448A-A924-FBEE9B585A81} + {63B2C6B6-AC76-4CC7-8142-91871D6C45D1} = {CF29B377-FE5A-488A-AF99-DF9D9C6FCA95} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {797A1D83-9F3C-4AEC-8A83-E3468102DBD1} diff --git a/Tiger.Business.WMS/Common/Barcode.Analysis.cs b/Tiger.Business.WMS/Common/Barcode.Analysis.cs deleted file mode 100644 index f90cdbe..0000000 --- a/Tiger.Business.WMS/Common/Barcode.Analysis.cs +++ /dev/null @@ -1,443 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace Tiger.Business.WMS -{ - /// <summary> - /// 鏉$爜鍒嗘瀽鍩虹被 - /// </summary> - public class BarcodeAnalysis - { - /// <summary> - /// 鏉$爜鍒嗘瀽 - /// </summary> - /// <param name="metaSn"></param> - public void Analyse(string metaSn) - { - SN = metaSn; - Type = Types.Illegal; - ItemType = ItemTypes.Unknown; - AnalyseException = null; - try - { - if (!string.IsNullOrEmpty(SN)) - { - string[] parts = (metaSn ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length > 1 && parts.Any(q => q.StartsWith("S"))) - { - foreach (var part in parts.OrderBy(q => q.FirstOrDefault())) - { - var param = part.First().ToString().ToUpper(); - var content = part.Substring(1); - switch (param) - { - case "S"://PAG ID (SN) - var snParts = (content ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); - SN = content; - Type = Types.Other; - if (SN.StartsWith("C") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Middle; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.StartsWith("P") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Outer; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.Length > 13) - { - SupplierCode = SN.Substring(0, 5); - PrintDateStr = SN.Substring(5, 8); - SerialNoStr = SN.Substring(13); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Small; - ItemType = ItemTypes.RawMaterial; - } - } - //鏄惁閲嶆墦鍒ゆ柇 - if(snParts.Count() >1 && snParts[1].Length > 2) - { - ReprintBizCode1 = snParts[1][0].ToString(); - ReprintBizCode2 = snParts[1][1].ToString(); - ReprintNoStr = snParts[1].Substring(2); - } - break; - case "V"://閫佽揣鍗曞彿 - OrderNo = content; - break; - case "P"://鐗╂枡缂栫爜 - ItemCode = content; - break; - case "N"://鐗╂枡缂栫爜 - ItemName = content; - break; - case "Q"://鐗╂枡鏁伴噺 - QtyStr = content; - break; - case "U"://鐗╂枡鍗曚綅 - Unit = content; - break; - case "M"://鍒堕�犲晢鏂欏彿 - OEMItemCode = content; - break; - case "D"://鐢熶骇鏃ユ湡 - DateCode = content; - ProdDateStr = content; - break; - case "L"://鐢熶骇鎵规 - LotNo = content; - break; - case "G"://鐗╂枡姣涢噸 - GrossWeightStr = content; - break; - default: - break; - } - } - } - else if(SN.Length > 10) - { - var snParts = (SN ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); - Type = Types.Other; - if (SN.StartsWith("C") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Middle; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.StartsWith("P") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Outer; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.Length > 13) - { - SupplierCode = SN.Substring(0, 5); - PrintDateStr = SN.Substring(5, 8); - SerialNoStr = SN.Substring(13); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Small; - ItemType = ItemTypes.RawMaterial; - } - } - //鏄惁閲嶆墦鍒ゆ柇 - if (snParts.Count() > 1 && snParts[1].Length > 2) - { - ReprintBizCode1 = snParts[1][0].ToString(); - ReprintBizCode2 = snParts[1][1].ToString(); - ReprintNoStr = snParts[1].Substring(2); - } - } - } - } - catch (Exception ex) - { - AnalyseException = ex; - } - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴祦姘村彿 - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetSerialNo(string str) - { - int serialNo; - try - { - serialNo = Convert.ToInt32(new Regex(@"[^\d]*").Replace(str, "")); - } - catch - { - return null; - } - return serialNo; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥為噸鎵撴祦姘村彿 - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetReprintNo(string str) - { - int qty; - try - { - qty = Convert.ToInt32(str, 16); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetInt32(string str) - { - int qty; - try - { - qty = Convert.ToInt32(str); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private double? GetDouble(string str) - { - double qty; - try - { - qty = Convert.ToDouble(str); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁鏃ユ湡缂栫爜杩斿洖鐢熶骇鏃ユ湡 - /// </summary> - /// <param name="dateStr"></param> - /// <returns></returns> - public static DateTime? GetDateTime(string dateStr) - { - DateTime proddate; - dateStr = dateStr ?? ""; - if (dateStr.Length == 8) - { - try - { - //骞存湀鏃� - proddate = DateTime.ParseExact(dateStr, "yyyyMMdd", new CultureInfo("zh-CN", true)); - } - catch - { - return null; - } - } - else if (dateStr.Length == 6) - { - try - { - //骞存湀鏃� - proddate = DateTime.ParseExact(dateStr, "yyMMdd", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - //骞村懆 - var firstDate = Convert.ToDateTime(dateStr.Substring(0, 4) + "-1-1"); - int weekNum = Convert.ToInt32(dateStr.Substring(4, 2)); - - int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; - DateTime firstSunday = firstDate.AddDays(daysOffset); - var calendar = CultureInfo.CurrentCulture.Calendar; - int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - if (firstWeek <= 1) - { - weekNum -= 1; - } - proddate = firstSunday.AddDays(weekNum * 7 - 1); - if (proddate.Year < firstDate.Year) - { - proddate = firstDate; - } - if (proddate.Year > firstDate.Year) - { - proddate = firstDate.AddYears(1).AddDays(-1); - } - } - catch - { - try - { - //骞存湀 - proddate = DateTime.ParseExact(dateStr, "yyyyMM", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //proddate = DateTime.Now; - return null; - } - } - } - } - } - else if (dateStr.Length == 4) - { - try - { - //骞村懆 - var firstDate = DateTime.ParseExact(dateStr.Substring(0, 2), "yy", CultureInfo.CurrentCulture); - int weekNum = Convert.ToInt32(dateStr.Substring(2, 2)); - - int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; - DateTime firstSunday = firstDate.AddDays(daysOffset); - var calendar = CultureInfo.CurrentCulture.Calendar; - int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - if (firstWeek <= 1) - { - weekNum -= 1; - } - proddate = firstSunday.AddDays(weekNum * 7 - 1); - if (proddate.Year < firstDate.Year) - { - proddate = firstDate; - } - if (proddate.Year > firstDate.Year) - { - proddate = firstDate.AddYears(1).AddDays(-1); - } - } - catch - { - try - { - //骞存湀 - proddate = DateTime.ParseExact(dateStr, "yyMM", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - //骞� - proddate = DateTime.ParseExact(dateStr, "yyyy", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //鏃犳硶璇嗗埆鍒欎娇鐢ㄥ綋鍓嶆椂闂� - //proddate = DateTime.Now; - return null; - } - } - } - } - } - else - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //proddate = DateTime.Now; - return null; - } - } - return proddate; - } - - /// <summary> - /// 鏄惁涓庝紶鍏ョ殑鏉$爜鐩稿悓鐨勭敓浜ф棩鏈� - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public bool IsSameProdDate(string sn) - { - return (ProdDate ?? DateTime.MaxValue).Date == ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; - } - - /// <summary> - /// 鏄惁灏忎簬绛変簬浼犲叆鐨勬潯鐮佺殑鐢熶骇鏃ユ湡 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public bool IsPriorProdDate(string sn) - { - return (ProdDate ?? DateTime.MaxValue).Date <= ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; - } - - /// <summary> - /// 鏄惁闈炴硶鏉$爜 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static bool IsIllegal(string sn) - { - return !new Barcode(sn).IsRegular; - } - - /// <summary> - /// 鑾峰彇鏉$爜绫诲瀷 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static Types GetType(string sn) - { - return new Barcode(sn).Type; - } - - /// <summary> - /// 鍒ゆ柇鏄惁閲嶆墦鐨勬潯鐮� - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static bool IsReprint(string sn) - { - return new Barcode(sn).IsReprintSn; - } - }//endClass -} diff --git a/Tiger.Business.WMS/Common/Barcode.cs b/Tiger.Business.WMS/Common/Barcode.cs deleted file mode 100644 index 3fabc5b..0000000 --- a/Tiger.Business.WMS/Common/Barcode.cs +++ /dev/null @@ -1,650 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace Tiger.Business.WMS -{ - /// <summary> - /// 鏉$爜鍩虹被 - /// </summary> - public class Barcode - { - public Barcode(string metaSn) - { - Analyse(MetaSn = metaSn); - } - - /// <summary> - /// 鏉$爜锛堣В鏋愬悗鐨勬潯鐮侊級 - /// </summary> - public string SN { get; set; } - /// <summary> - /// 鍏冩潯鐮侊紙鎵弿鍒扮殑鏉$爜锛� - /// </summary> - public string MetaSn { get; set; } - /// <summary> - /// 鏉$爜绫诲瀷 - /// </summary> - public Types Type { get; set; } - /// <summary> - /// 鐗╂枡缂栫爜 - /// </summary> - public string ItemCode { get; set; } - /// <summary> - /// 鐗╂枡鍚嶇О - /// </summary> - public string ItemName { get; set; } - /// <summary> - /// 鐗╂枡缂栫爜 - /// </summary> - public ItemTypes ItemType { get; set; } - /// <summary> - /// 鐢熶骇鏃ユ湡缂栫爜 - /// </summary> - public string DateCode { get; set; } - /// <summary> - /// 鐢熶骇鏃ユ湡 - /// </summary> - public string ProdDateStr { get; set; } - /// <summary> - /// 鐢熶骇鏃ユ湡 - /// </summary> - public DateTime? ProdDate { get => GetDateTime(ProdDateStr) ?? GetDateTime(PrintDateStr); } - /// <summary> - /// 鎵撳嵃鏃ユ湡 - /// </summary> - public string PrintDateStr { get; set; } - /// <summary> - /// 渚涘簲鍟嗕唬鐮� - /// </summary> - public string SupplierCode { get; set; } - /// <summary> - /// 鎵规鍙� - /// </summary> - public string LotNo { get; set; } - /// <summary> - /// 璁㈠崟鍙� - /// </summary> - public string OrderNo { get; set; } - /// <summary> - /// 鍒堕�犲晢/浠e伐鍘傛枡鍙� - /// </summary> - public string OEMItemCode { get; set; } - /// <summary> - /// 娴佹按鐮� - /// </summary> - public string SerialNoStr { get; set; } - /// <summary> - /// 娴佹按鐮� - /// </summary> - public int? SerialNo { get => GetSerialNo(SerialNoStr); } - - /// <summary> - /// 鍗曚綅 - /// </summary> - public string Unit { get; set; } - - /// <summary> - /// 鏁伴噺 - /// </summary> - public string QtyStr { get; set; } - /// <summary> - /// 鏁伴噺 - /// </summary> - public decimal? Qty { get => Convert.ToDecimal(GetDouble(QtyStr)); } - - /// <summary> - /// 姣涢噸 - /// </summary> - public string GrossWeightStr { get; set; } - /// <summary> - /// 姣涢噸 - /// </summary> - public double? GrossWeight { get => GetDouble(QtyStr); } - - /// <summary> - /// 鏂欏彿闀垮害 - /// </summary> - public int ItemLength { get; set; } - - /// <summary> - /// 鏂欏彿闀垮害 - /// </summary> - public Exception AnalyseException { get; set; } - - /// <summary> - /// 鏉$爜鏄惁鍚堟硶 - /// </summary> - public bool IsRegular { get => Type != Types.Illegal; } - - /// <summary> - /// 鏉$爜鏄惁鍘熸潗鏂欐潯鐮� - /// </summary> - public bool IsMaterialSN { get => !(new List<ItemTypes>() { ItemTypes.RawMaterial }).Contains(ItemType); } - - /// <summary> - /// 鏍囩閲嶆墦娴佹按鐮佸瓧绗� - /// </summary> - public string ReprintNoStr { get; set; } - /// <summary> - /// 鏍囩閲嶆墦娴佹按鐮� - /// </summary> - public int? ReprintNo => GetReprintNo(ReprintNoStr); - /// <summary> - /// 鏍囩閲嶆墦涓�绾т笟鍔$紪鐮� - /// </summary> - public string ReprintBizCode1 { get; set; } - /// <summary> - /// 鏍囩閲嶆墦浜岀骇涓氬姟缂栫爜 - /// </summary> - public string ReprintBizCode2 { get; set; } - /// <summary> - /// 鏄惁閲嶆墦鏍囩 - /// </summary> - public bool IsReprintSn => SN.Contains("_"); - - /// <summary> - /// 鏄惁鎴枡閲嶆墦鏍囩 - /// </summary> - public bool IsCutSn => ReprintBizCode1 == "C"; - - /// <summary> - /// 鏄惁閫�鏂欓噸鎵撴爣绛� - /// </summary> - public bool IsReturnSn => ReprintBizCode1 == "T"; - /// <summary> - /// 鏄惁浜岀淮鐮� - /// </summary> - public bool IsQRCode => MetaSn.Contains(","); - - public enum Types - { - /// <summary> - /// 闈炴硶鏉$爜 - /// </summary> - [Description("闈炴硶鏉$爜")] - Illegal, - /// <summary> - /// 灏忓寘鏍囩 - /// </summary> - [Description("灏忓寘鏍囩")] - Small, - /// <summary> - /// 涓寘鏍囩 - /// </summary> - [Description("涓寘鏍囩")] - Middle, - /// <summary> - /// 澶栧寘鏍囩 - /// </summary> - [Description("澶栧寘鏍囩")] - Outer, - /// <summary> - /// 鏍堟澘鏉$爜 - /// </summary> - [Description("鏍堟澘鏉$爜")] - Pallet, - /// <summary> - /// 鎴愬搧鏍囩鏉$爜 - /// </summary> - [Description("鎴愬搧鏍囩")] - Product, - /// <summary> - /// 鍏朵粬鏍囩鏉$爜 - /// </summary> - [Description("鍏朵粬鏍囩")] - Other, - } - - public enum ItemTypes - { - [Description("鏈煡绫诲瀷")] - Unknown, - [Description("婀挎晱鍏冧欢")] - HumidityMaterial, - [Description("SMT鍗婃垚鍝�")] - SmtSemiProduct, - [Description("DIP鍗婃垚鍝�")] - DipSemiProduct, - [Description("鎴愬搧")] - Product, - [Description("PCB")] - PCB, - [Description("杈呮枡")] - SubsidiaryMaterial, - [Description("鍘熸潗鏂�")] - RawMaterial, - } - - /// <summary> - /// 鏉$爜鍒嗘瀽 - /// </summary> - /// <param name="metaSn"></param> - public void Analyse(string metaSn) - { - SN = metaSn; - Type = Types.Illegal; - ItemType = ItemTypes.Unknown; - AnalyseException = null; - try - { - if (!string.IsNullOrEmpty(SN)) - { - string[] parts = (metaSn ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length > 1 && parts.Any(q => q.StartsWith("S"))) - { - foreach (var part in parts.OrderBy(q => q.FirstOrDefault())) - { - var param = part.First().ToString().ToUpper(); - var content = part.Substring(1); - switch (param) - { - case "S"://PAG ID (SN) - var snParts = (content ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); - SN = content; - Type = Types.Other; - if (SN.StartsWith("C") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Middle; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.StartsWith("P") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Outer; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.Length > 13) - { - SupplierCode = SN.Substring(0, 5); - PrintDateStr = SN.Substring(5, 8); - SerialNoStr = SN.Substring(13); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Small; - ItemType = ItemTypes.RawMaterial; - } - } - //鏄惁閲嶆墦鍒ゆ柇 - if(snParts.Count() >1 && snParts[1].Length > 2) - { - ReprintBizCode1 = snParts[1][0].ToString(); - ReprintBizCode2 = snParts[1][1].ToString(); - ReprintNoStr = snParts[1].Substring(2); - } - break; - case "V"://閫佽揣鍗曞彿 - OrderNo = content; - break; - case "P"://鐗╂枡缂栫爜 - ItemCode = content; - break; - case "N"://鐗╂枡缂栫爜 - ItemName = content; - break; - case "Q"://鐗╂枡鏁伴噺 - QtyStr = content; - break; - case "U"://鐗╂枡鍗曚綅 - Unit = content; - break; - case "M"://鍒堕�犲晢鏂欏彿 - OEMItemCode = content; - break; - case "D"://鐢熶骇鏃ユ湡 - DateCode = content; - ProdDateStr = content; - break; - case "L"://鐢熶骇鎵规 - LotNo = content; - break; - case "G"://鐗╂枡姣涢噸 - GrossWeightStr = content; - break; - default: - break; - } - } - } - else if(SN.Length > 10) - { - var snParts = (SN ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); - Type = Types.Other; - if (SN.StartsWith("C") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Middle; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.StartsWith("P") && SN.Length > 14) - { - SupplierCode = SN.Substring(1, 5); - PrintDateStr = SN.Substring(6, 8); - SerialNoStr = SN.Substring(14); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Outer; - ItemType = ItemTypes.RawMaterial; - } - } - else if (SN.Length > 13) - { - SupplierCode = SN.Substring(0, 5); - PrintDateStr = SN.Substring(5, 8); - SerialNoStr = SN.Substring(13); - if (ProdDate != null && SerialNo != null) - { - Type = Types.Small; - ItemType = ItemTypes.RawMaterial; - } - } - //鏄惁閲嶆墦鍒ゆ柇 - if (snParts.Count() > 1 && snParts[1].Length > 2) - { - ReprintBizCode1 = snParts[1][0].ToString(); - ReprintBizCode2 = snParts[1][1].ToString(); - ReprintNoStr = snParts[1].Substring(2); - } - } - } - } - catch (Exception ex) - { - AnalyseException = ex; - } - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴祦姘村彿 - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetSerialNo(string str) - { - int serialNo; - try - { - serialNo = Convert.ToInt32(new Regex(@"[^\d]*").Replace(str, "")); - } - catch - { - return null; - } - return serialNo; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥為噸鎵撴祦姘村彿 - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetReprintNo(string str) - { - int qty; - try - { - qty = Convert.ToInt32(str, 16); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private int? GetInt32(string str) - { - int qty; - try - { - qty = Convert.ToInt32(str); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� - /// </summary> - /// <param name="str"></param> - /// <returns></returns> - private double? GetDouble(string str) - { - double qty; - try - { - qty = Convert.ToDouble(str); - } - catch - { - return null; - } - return qty; - } - - /// <summary> - /// 鏍规嵁鏃ユ湡缂栫爜杩斿洖鐢熶骇鏃ユ湡 - /// </summary> - /// <param name="dateStr"></param> - /// <returns></returns> - public static DateTime? GetDateTime(string dateStr) - { - DateTime proddate; - dateStr = dateStr ?? ""; - if (dateStr.Length == 8) - { - try - { - //骞存湀鏃� - proddate = DateTime.ParseExact(dateStr, "yyyyMMdd", new CultureInfo("zh-CN", true)); - } - catch - { - return null; - } - } - else if (dateStr.Length == 6) - { - try - { - //骞存湀鏃� - proddate = DateTime.ParseExact(dateStr, "yyMMdd", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - //骞村懆 - var firstDate = Convert.ToDateTime(dateStr.Substring(0, 4) + "-1-1"); - int weekNum = Convert.ToInt32(dateStr.Substring(4, 2)); - - int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; - DateTime firstSunday = firstDate.AddDays(daysOffset); - var calendar = CultureInfo.CurrentCulture.Calendar; - int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - if (firstWeek <= 1) - { - weekNum -= 1; - } - proddate = firstSunday.AddDays(weekNum * 7 - 1); - if (proddate.Year < firstDate.Year) - { - proddate = firstDate; - } - if (proddate.Year > firstDate.Year) - { - proddate = firstDate.AddYears(1).AddDays(-1); - } - } - catch - { - try - { - //骞存湀 - proddate = DateTime.ParseExact(dateStr, "yyyyMM", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //proddate = DateTime.Now; - return null; - } - } - } - } - } - else if (dateStr.Length == 4) - { - try - { - //骞村懆 - var firstDate = DateTime.ParseExact(dateStr.Substring(0, 2), "yy", CultureInfo.CurrentCulture); - int weekNum = Convert.ToInt32(dateStr.Substring(2, 2)); - - int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; - DateTime firstSunday = firstDate.AddDays(daysOffset); - var calendar = CultureInfo.CurrentCulture.Calendar; - int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - if (firstWeek <= 1) - { - weekNum -= 1; - } - proddate = firstSunday.AddDays(weekNum * 7 - 1); - if (proddate.Year < firstDate.Year) - { - proddate = firstDate; - } - if (proddate.Year > firstDate.Year) - { - proddate = firstDate.AddYears(1).AddDays(-1); - } - } - catch - { - try - { - //骞存湀 - proddate = DateTime.ParseExact(dateStr, "yyMM", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - //骞� - proddate = DateTime.ParseExact(dateStr, "yyyy", new CultureInfo("zh-CN", true)); - } - catch - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //鏃犳硶璇嗗埆鍒欎娇鐢ㄥ綋鍓嶆椂闂� - //proddate = DateTime.Now; - return null; - } - } - } - } - } - else - { - try - { - proddate = Convert.ToDateTime(dateStr); - } - catch - { - //proddate = DateTime.Now; - return null; - } - } - return proddate; - } - - /// <summary> - /// 鏄惁涓庝紶鍏ョ殑鏉$爜鐩稿悓鐨勭敓浜ф棩鏈� - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public bool IsSameProdDate(string sn) - { - return (ProdDate ?? DateTime.MaxValue).Date == ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; - } - - /// <summary> - /// 鏄惁灏忎簬绛変簬浼犲叆鐨勬潯鐮佺殑鐢熶骇鏃ユ湡 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public bool IsPriorProdDate(string sn) - { - return (ProdDate ?? DateTime.MaxValue).Date <= ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; - } - - /// <summary> - /// 鏄惁闈炴硶鏉$爜 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static bool IsIllegal(string sn) - { - return !new Barcode(sn).IsRegular; - } - - /// <summary> - /// 鑾峰彇鏉$爜绫诲瀷 - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static Types GetType(string sn) - { - return new Barcode(sn).Type; - } - - /// <summary> - /// 鍒ゆ柇鏄惁閲嶆墦鐨勬潯鐮� - /// </summary> - /// <param name="sn"></param> - /// <returns></returns> - public static bool IsReprint(string sn) - { - return new Barcode(sn).IsReprintSn; - } - }//endClass -} diff --git a/Tiger.Business.WMS/Common/Barcode/Barcode.cs b/Tiger.Business.WMS/Common/Barcode/Barcode.cs new file mode 100644 index 0000000..2d7878a --- /dev/null +++ b/Tiger.Business.WMS/Common/Barcode/Barcode.cs @@ -0,0 +1,718 @@ +锘縰sing Rhea.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Tiger.Business.WMS +{ + /// <summary> + /// 鏉$爜鍩虹被 + /// </summary> + public class Barcode + { + public Barcode(string metaSn) + { + SetAnalysisRule(); + Analyse(MetaSn = metaSn); + } + + /// <summary> + /// 鏉$爜锛堣В鏋愬悗鐨勬潯鐮侊級 + /// </summary> + private List<BarcodeAnalysis> Analyses { get; set; } = new(); + /// <summary> + /// 鏉$爜锛堣В鏋愬悗鐨勬潯鐮侊級 + /// </summary> + public string SN { get; set; } + /// <summary> + /// 鍏冩潯鐮侊紙鎵弿鍒扮殑鏉$爜锛� + /// </summary> + public string MetaSn { get; set; } + /// <summary> + /// 鏉$爜绫诲瀷 + /// </summary> + public Types Type { get; set; } + /// <summary> + /// 鐗╂枡缂栫爜 + /// </summary> + public ItemTypes ItemType { get; set; } + /// <summary> + /// 鐗╂枡缂栫爜 + /// </summary> + public string ItemCode { get; set; } + /// <summary> + /// 鐗╂枡鍚嶇О + /// </summary> + public string ItemName { get; set; } + /// <summary> + /// 鐢熶骇鏃ユ湡缂栫爜 + /// </summary> + public string DateCode { get; set; } + /// <summary> + /// 鐢熶骇鏃ユ湡 + /// </summary> + public string ProdDateStr { get; set; } + /// <summary> + /// 鐢熶骇鏃ユ湡 + /// </summary> + public DateTime? ProdDate { get => BarcodeAnalysis.GetDateTime(ProdDateStr) ?? BarcodeAnalysis.GetDateTime(PrintDateStr); } + /// <summary> + /// 鎵撳嵃鏃ユ湡 + /// </summary> + public string PrintDateStr { get; set; } + /// <summary> + /// 渚涘簲鍟嗕唬鐮� + /// </summary> + public string SupplierCode { get; set; } + /// <summary> + /// 鎵规鍙� + /// </summary> + public string LotNo { get; set; } + /// <summary> + /// 璁㈠崟鍙� + /// </summary> + public string OrderNo { get; set; } + /// <summary> + /// 璁㈠崟琛屽彿 + /// </summary> + public string OrderLine { get; set; } + /// <summary> + /// 鍒堕�犲晢/浠e伐鍘傛枡鍙� + /// </summary> + public string OEMItemCode { get; set; } + /// <summary> + /// 娴佹按鐮� + /// </summary> + public string SerialNoStr { get; set; } + /// <summary> + /// 娴佹按鐮� + /// </summary> + public int? SerialNo { get => BarcodeAnalysis.GetSerialNo(SerialNoStr); } + + /// <summary> + /// 鍗曚綅 + /// </summary> + public string Unit { get; set; } + + /// <summary> + /// 鏁伴噺 + /// </summary> + public string QtyStr { get; set; } + /// <summary> + /// 鏁伴噺 + /// </summary> + public decimal? Qty { get => Convert.ToDecimal(BarcodeAnalysis.GetDouble(QtyStr)); } + + /// <summary> + /// 姣涢噸 + /// </summary> + public string GrossWeightStr { get; set; } + /// <summary> + /// 姣涢噸 + /// </summary> + public double? GrossWeight { get => BarcodeAnalysis.GetDouble(GrossWeightStr); } + + /// <summary> + /// 鏂欏彿闀垮害 + /// </summary> + public int ItemLength { get; set; } + + /// <summary> + /// 鏉$爜鍒嗘瀽寮傚父淇℃伅 + /// </summary> + public Exception AnalyseException { get; set; } + /// <summary> + /// 鏉$爜鏄惁鍒嗘瀽寮傚父 + /// </summary> + public bool IsException { get => !AnalyseException.IsNullOrEmpty(); } + + /// <summary> + /// 鏉$爜鏄惁鍚堟硶 + /// </summary> + public bool IsRegular { get => Type != Types.Illegal; } + + /// <summary> + /// 鏉$爜鏄惁鍘熸潗鏂欐潯鐮� + /// </summary> + public bool IsMaterialSN { get => !(new List<ItemTypes>() { ItemTypes.RawMaterial }).Contains(ItemType); } + + /// <summary> + /// 鏍囩閲嶆墦娴佹按鐮佸瓧绗� + /// </summary> + public string ReprintNoStr { get; set; } + /// <summary> + /// 鏍囩閲嶆墦娴佹按鐮� + /// </summary> + public int? ReprintNo => BarcodeAnalysis.GetReprintNo(ReprintNoStr); + /// <summary> + /// 鏍囩閲嶆墦涓�绾т笟鍔$紪鐮� + /// </summary> + public string ReprintBizCode1 { get; set; } + /// <summary> + /// 鏍囩閲嶆墦浜岀骇涓氬姟缂栫爜 + /// </summary> + public string ReprintBizCode2 { get; set; } + /// <summary> + /// 鏄惁閲嶆墦鏍囩 + /// </summary> + public bool IsReprintSn => SN.Contains("_"); + + /// <summary> + /// 鏄惁鎴枡閲嶆墦鏍囩 + /// </summary> + public bool IsCutSn => ReprintBizCode1 == "C"; + + /// <summary> + /// 鏄惁閫�鏂欓噸鎵撴爣绛� + /// </summary> + public bool IsReturnSn => ReprintBizCode1 == "T"; + /// <summary> + /// 鏄惁浜岀淮鐮� + /// </summary> + public bool IsQRCode => MetaSn.Contains(","); + + public enum Types + { + /// <summary> + /// 闈炴硶鏉$爜 + /// </summary> + [Description("闈炴硶鏉$爜")] + Illegal, + /// <summary> + /// 鍞竴ID + /// </summary> + [Description("鏈�灏忓寘瑁呮爣绛�")] + MiniPackage, + /// <summary> + /// 涓寘鏍囩 + /// </summary> + [Description("鍐呭寘瑁呮爣绛�")] + InnerPackage, + /// <summary> + /// 澶栧寘鏍囩 + /// </summary> + [Description("澶栧寘瑁呮爣绛�")] + OuterPackage, + /// <summary> + /// 鏍堟澘鏉$爜 + /// </summary> + [Description("鏍堟澘鏉$爜")] + Pallet, + /// <summary> + /// 鍏朵粬鏍囩鏉$爜 + /// </summary> + [Description("鍏朵粬鏍囩")] + Other, + } + + public enum ItemTypes + { + [Description("鏈煡绫诲瀷")] + Unknown, + [Description("婀挎晱鍏冧欢")] + HumidityMaterial, + [Description("鍗婃垚鍝�")] + SemiProduct, + [Description("SMT鍗婃垚鍝�")] + SmtSemiProduct, + [Description("DIP鍗婃垚鍝�")] + DipSemiProduct, + [Description("鎴愬搧")] + Product, + [Description("PCB")] + PCB, + [Description("杈呮枡")] + SubsidiaryMaterial, + [Description("鍘熸潗鏂�")] + RawMaterial, + } + + /// <summary> + /// 璁剧疆鏉$爜鍒嗘瀽楠岃瘉瑙勫垯 + /// </summary> + public void SetAnalysisRule() + { + Analyses.Clear(); + Analyses.Add(new YadaBarcode()); + Analyses.Add(new BarcodeAnalysis()); + } + + /// <summary> + /// 鏉$爜鍒嗘瀽 + /// </summary> + /// <param name="metaSn"></param> + public void Analyse(string metaSn) + { + SN = metaSn; + Type = Types.Illegal; + ItemType = ItemTypes.Unknown; + AnalyseException = null; + try + { + foreach (var rule in Analyses) + { + var result = rule.Analyse(this); + if (result.IsSuccessed) + { + break; + } + } + } + catch (Exception ex) + { + AnalyseException = ex; + } + } + + /// <summary> + /// 鏄惁涓庝紶鍏ョ殑鏉$爜鐩稿悓鐨勭敓浜ф棩鏈� + /// </summary> + /// <param name="sn"></param> + /// <returns></returns> + public bool IsSameProdDate(string sn) + { + return (ProdDate ?? DateTime.MaxValue).Date == ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; + } + + /// <summary> + /// 鏄惁灏忎簬绛変簬浼犲叆鐨勬潯鐮佺殑鐢熶骇鏃ユ湡 + /// </summary> + /// <param name="sn"></param> + /// <returns></returns> + public bool IsPriorProdDate(string sn) + { + return (ProdDate ?? DateTime.MaxValue).Date <= ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; + } + + ///// <summary> + ///// 鏉$爜鍒嗘瀽 + ///// </summary> + ///// <param name="metaSn"></param> + //public void Analyse(string metaSn) + //{ + // SN = metaSn; + // Type = Types.Illegal; + // ItemType = ItemTypes.Unknown; + // AnalyseException = null; + // try + // { + // if (!string.IsNullOrEmpty(SN)) + // { + // string[] parts = (metaSn ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); + // if (parts.Length > 1 && parts.Any(q => q.StartsWith("S"))) + // { + // foreach (var part in parts.OrderBy(q => q.FirstOrDefault())) + // { + // var param = part.First().ToString().ToUpper(); + // var content = part.Substring(1); + // switch (param) + // { + // case "S"://PAG ID (SN) + // var snParts = (content ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); + // SN = content; + // Type = Types.Other; + // if (SN.StartsWith("C") && SN.Length > 14) + // { + // SupplierCode = SN.Substring(1, 5); + // PrintDateStr = SN.Substring(6, 8); + // SerialNoStr = SN.Substring(14); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Middle; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // else if (SN.StartsWith("P") && SN.Length > 14) + // { + // SupplierCode = SN.Substring(1, 5); + // PrintDateStr = SN.Substring(6, 8); + // SerialNoStr = SN.Substring(14); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Outer; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // else if (SN.Length > 13) + // { + // SupplierCode = SN.Substring(0, 5); + // PrintDateStr = SN.Substring(5, 8); + // SerialNoStr = SN.Substring(13); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Small; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // //鏄惁閲嶆墦鍒ゆ柇 + // if(snParts.Count() >1 && snParts[1].Length > 2) + // { + // ReprintBizCode1 = snParts[1][0].ToString(); + // ReprintBizCode2 = snParts[1][1].ToString(); + // ReprintNoStr = snParts[1].Substring(2); + // } + // break; + // case "V"://閫佽揣鍗曞彿 + // OrderNo = content; + // break; + // case "P"://鐗╂枡缂栫爜 + // ItemCode = content; + // break; + // case "N"://鐗╂枡缂栫爜 + // ItemName = content; + // break; + // case "Q"://鐗╂枡鏁伴噺 + // QtyStr = content; + // break; + // case "U"://鐗╂枡鍗曚綅 + // Unit = content; + // break; + // case "M"://鍒堕�犲晢鏂欏彿 + // OEMItemCode = content; + // break; + // case "D"://鐢熶骇鏃ユ湡 + // DateCode = content; + // ProdDateStr = content; + // break; + // case "L"://鐢熶骇鎵规 + // LotNo = content; + // break; + // case "G"://鐗╂枡姣涢噸 + // GrossWeightStr = content; + // break; + // default: + // break; + // } + // } + // } + // else if(SN.Length > 10) + // { + // var snParts = (SN ?? "").Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); + // Type = Types.Other; + // if (SN.StartsWith("C") && SN.Length > 14) + // { + // SupplierCode = SN.Substring(1, 5); + // PrintDateStr = SN.Substring(6, 8); + // SerialNoStr = SN.Substring(14); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Middle; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // else if (SN.StartsWith("P") && SN.Length > 14) + // { + // SupplierCode = SN.Substring(1, 5); + // PrintDateStr = SN.Substring(6, 8); + // SerialNoStr = SN.Substring(14); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Outer; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // else if (SN.Length > 13) + // { + // SupplierCode = SN.Substring(0, 5); + // PrintDateStr = SN.Substring(5, 8); + // SerialNoStr = SN.Substring(13); + // if (ProdDate != null && SerialNo != null) + // { + // Type = Types.Small; + // ItemType = ItemTypes.RawMaterial; + // } + // } + // //鏄惁閲嶆墦鍒ゆ柇 + // if (snParts.Count() > 1 && snParts[1].Length > 2) + // { + // ReprintBizCode1 = snParts[1][0].ToString(); + // ReprintBizCode2 = snParts[1][1].ToString(); + // ReprintNoStr = snParts[1].Substring(2); + // } + // } + // } + // } + // catch (Exception ex) + // { + // AnalyseException = ex; + // } + //} + + ///// <summary> + ///// 鏍规嵁瀛楃涓茶繑鍥炴祦姘村彿 + ///// </summary> + ///// <param name="str"></param> + ///// <returns></returns> + //private int? GetSerialNo(string str) + //{ + // int serialNo; + // try + // { + // serialNo = Convert.ToInt32(new Regex(@"[^\d]*").Replace(str, "")); + // } + // catch + // { + // return null; + // } + // return serialNo; + //} + + ///// <summary> + ///// 鏍规嵁瀛楃涓茶繑鍥為噸鎵撴祦姘村彿 + ///// </summary> + ///// <param name="str"></param> + ///// <returns></returns> + //private int? GetReprintNo(string str) + //{ + // int qty; + // try + // { + // qty = Convert.ToInt32(str, 16); + // } + // catch + // { + // return null; + // } + // return qty; + //} + + ///// <summary> + ///// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� + ///// </summary> + ///// <param name="str"></param> + ///// <returns></returns> + //private int? GetInt32(string str) + //{ + // int qty; + // try + // { + // qty = Convert.ToInt32(str); + // } + // catch + // { + // return null; + // } + // return qty; + //} + + ///// <summary> + ///// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� + ///// </summary> + ///// <param name="str"></param> + ///// <returns></returns> + //private double? GetDouble(string str) + //{ + // double qty; + // try + // { + // qty = Convert.ToDouble(str); + // } + // catch + // { + // return null; + // } + // return qty; + //} + + ///// <summary> + ///// 鏍规嵁鏃ユ湡缂栫爜杩斿洖鐢熶骇鏃ユ湡 + ///// </summary> + ///// <param name="dateStr"></param> + ///// <returns></returns> + //public static DateTime? GetDateTime(string dateStr) + //{ + // DateTime proddate; + // dateStr = dateStr ?? ""; + // if (dateStr.Length == 8) + // { + // try + // { + // //骞存湀鏃� + // proddate = DateTime.ParseExact(dateStr, "yyyyMMdd", new CultureInfo("zh-CN", true)); + // } + // catch + // { + // return null; + // } + // } + // else if (dateStr.Length == 6) + // { + // try + // { + // //骞存湀鏃� + // proddate = DateTime.ParseExact(dateStr, "yyMMdd", new CultureInfo("zh-CN", true)); + // } + // catch + // { + // try + // { + // //骞村懆 + // var firstDate = Convert.ToDateTime(dateStr.Substring(0, 4) + "-1-1"); + // int weekNum = Convert.ToInt32(dateStr.Substring(4, 2)); + + // int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; + // DateTime firstSunday = firstDate.AddDays(daysOffset); + // var calendar = CultureInfo.CurrentCulture.Calendar; + // int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); + // if (firstWeek <= 1) + // { + // weekNum -= 1; + // } + // proddate = firstSunday.AddDays(weekNum * 7 - 1); + // if (proddate.Year < firstDate.Year) + // { + // proddate = firstDate; + // } + // if (proddate.Year > firstDate.Year) + // { + // proddate = firstDate.AddYears(1).AddDays(-1); + // } + // } + // catch + // { + // try + // { + // //骞存湀 + // proddate = DateTime.ParseExact(dateStr, "yyyyMM", new CultureInfo("zh-CN", true)); + // } + // catch + // { + // try + // { + // proddate = Convert.ToDateTime(dateStr); + // } + // catch + // { + // //proddate = DateTime.Now; + // return null; + // } + // } + // } + // } + // } + // else if (dateStr.Length == 4) + // { + // try + // { + // //骞村懆 + // var firstDate = DateTime.ParseExact(dateStr.Substring(0, 2), "yy", CultureInfo.CurrentCulture); + // int weekNum = Convert.ToInt32(dateStr.Substring(2, 2)); + + // int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; + // DateTime firstSunday = firstDate.AddDays(daysOffset); + // var calendar = CultureInfo.CurrentCulture.Calendar; + // int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); + // if (firstWeek <= 1) + // { + // weekNum -= 1; + // } + // proddate = firstSunday.AddDays(weekNum * 7 - 1); + // if (proddate.Year < firstDate.Year) + // { + // proddate = firstDate; + // } + // if (proddate.Year > firstDate.Year) + // { + // proddate = firstDate.AddYears(1).AddDays(-1); + // } + // } + // catch + // { + // try + // { + // //骞存湀 + // proddate = DateTime.ParseExact(dateStr, "yyMM", new CultureInfo("zh-CN", true)); + // } + // catch + // { + // try + // { + // //骞� + // proddate = DateTime.ParseExact(dateStr, "yyyy", new CultureInfo("zh-CN", true)); + // } + // catch + // { + // try + // { + // proddate = Convert.ToDateTime(dateStr); + // } + // catch + // { + // //鏃犳硶璇嗗埆鍒欎娇鐢ㄥ綋鍓嶆椂闂� + // //proddate = DateTime.Now; + // return null; + // } + // } + // } + // } + // } + // else + // { + // try + // { + // proddate = Convert.ToDateTime(dateStr); + // } + // catch + // { + // //proddate = DateTime.Now; + // return null; + // } + // } + // return proddate; + //} + + ///// <summary> + ///// 鏄惁涓庝紶鍏ョ殑鏉$爜鐩稿悓鐨勭敓浜ф棩鏈� + ///// </summary> + ///// <param name="sn"></param> + ///// <returns></returns> + //public bool IsSameProdDate(string sn) + //{ + // return (ProdDate ?? DateTime.MaxValue).Date == ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; + //} + + ///// <summary> + ///// 鏄惁灏忎簬绛変簬浼犲叆鐨勬潯鐮佺殑鐢熶骇鏃ユ湡 + ///// </summary> + ///// <param name="sn"></param> + ///// <returns></returns> + //public bool IsPriorProdDate(string sn) + //{ + // return (ProdDate ?? DateTime.MaxValue).Date <= ((new Barcode(sn)).ProdDate ?? DateTime.MinValue).Date; + //} + + ///// <summary> + ///// 鏄惁闈炴硶鏉$爜 + ///// </summary> + ///// <param name="sn"></param> + ///// <returns></returns> + //public static bool IsIllegal(string sn) + //{ + // return !new Barcode(sn).IsRegular; + //} + + ///// <summary> + ///// 鑾峰彇鏉$爜绫诲瀷 + ///// </summary> + ///// <param name="sn"></param> + ///// <returns></returns> + //public static Types GetType(string sn) + //{ + // return new Barcode(sn).Type; + //} + + ///// <summary> + ///// 鍒ゆ柇鏄惁閲嶆墦鐨勬潯鐮� + ///// </summary> + ///// <param name="sn"></param> + ///// <returns></returns> + //public static bool IsReprint(string sn) + //{ + // return new Barcode(sn).IsReprintSn; + //} + }//endClass +} diff --git a/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.Yada.cs b/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.Yada.cs new file mode 100644 index 0000000..f631495 --- /dev/null +++ b/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.Yada.cs @@ -0,0 +1,54 @@ +锘縰sing Autofac.Features.Metadata; +using MailKit.Search; +using Microsoft.IdentityModel.Tokens; +using Rhea.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using static Tiger.Business.WMS.Barcode; + +namespace Tiger.Business.WMS +{ + /// <summary> + /// 鏉$爜鍒嗘瀽鍩虹被 + /// </summary> + public class YadaBarcode : BarcodeAnalysis + { + /// <summary> + /// 鏉$爜鍒嗘瀽 + /// </summary> + /// <param name="metaSn"></param> + public override Result<Barcode> Analyse(Barcode barcode) + { + var result = new Result<Barcode>(Result.Flags.Failed); + Barcode = barcode; + + if (!string.IsNullOrEmpty(Barcode.MetaSn)) + { + string[] parts = (Barcode.MetaSn ?? "").Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); + //ASN鍗� + if (parts.Length == 5 && (Barcode.MetaSn.StartsWith("ASN") || Barcode.MetaSn.StartsWith("YDASN"))) + { + Barcode.OrderNo = parts[0]; + Barcode.OrderLine = parts[1]; + Barcode.ItemCode = parts[2]; + Barcode.LotNo = parts[3]; + Barcode.SerialNoStr = parts[4]; + Barcode.Type = Types.MiniPackage; + Barcode.ItemType = ItemTypes.RawMaterial; + //鏌ヨ鏉$爜涓绘。锛岃ˉ鍏呭叾浠栬祫鏂� + + result.Flag = Result.Flags.Success; + } + } + + result.Data = Barcode; + return result; + } + + }//endClass +} diff --git a/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.cs b/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.cs new file mode 100644 index 0000000..99a9e73 --- /dev/null +++ b/Tiger.Business.WMS/Common/Barcode/BarcodeAnalysis.cs @@ -0,0 +1,293 @@ +锘縰sing Rhea.Common; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using static Tiger.Business.WMS.Barcode; + +namespace Tiger.Business.WMS +{ + /// <summary> + /// 鏉$爜鍒嗘瀽鍩虹被 + /// </summary> + public class BarcodeAnalysis + { + public Barcode Barcode; + /// <summary> + /// 鏉$爜鍒嗘瀽 + /// </summary> + /// <param name="metaSn"></param> + public virtual Result<Barcode> Analyse(Barcode barcode) + { + var result = new Result<Barcode>(Result.Flags.Failed); + Barcode = barcode; + + if (!string.IsNullOrEmpty(Barcode.MetaSn)) + { + Barcode.QtyStr = "1"; + Barcode.Type = Types.Other; + Barcode.ItemType = ItemTypes.Unknown; + result.Flag = Result.Flags.Success; + } + + result.Data = Barcode; + return result; + } + + /// <summary> + /// 鏍规嵁瀛楃涓茶繑鍥炴祦姘村彿 + /// </summary> + /// <param name="str"></param> + /// <returns></returns> + public static int? GetSerialNo(string str) + { + int serialNo; + try + { + serialNo = Convert.ToInt32(new Regex(@"[^\d]*").Replace(str, "")); + } + catch + { + return null; + } + return serialNo; + } + + /// <summary> + /// 鏍规嵁瀛楃涓茶繑鍥為噸鎵撴祦姘村彿 + /// </summary> + /// <param name="str"></param> + /// <returns></returns> + public static int? GetReprintNo(string str) + { + int qty; + try + { + qty = Convert.ToInt32(str, 16); + } + catch + { + return null; + } + return qty; + } + + /// <summary> + /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� + /// </summary> + /// <param name="str"></param> + /// <returns></returns> + public static int? GetInt32(string str) + { + int qty; + try + { + qty = Convert.ToInt32(str); + } + catch + { + return null; + } + return qty; + } + + /// <summary> + /// 鏍规嵁瀛楃涓茶繑鍥炴暟閲� + /// </summary> + /// <param name="str"></param> + /// <returns></returns> + public static double? GetDouble(string str) + { + double qty; + try + { + qty = Convert.ToDouble(str); + } + catch + { + return null; + } + return qty; + } + + /// <summary> + /// 鏍规嵁鏃ユ湡缂栫爜杩斿洖鐢熶骇鏃ユ湡 + /// </summary> + /// <param name="dateStr"></param> + /// <returns></returns> + public static DateTime? GetDateTime(string dateStr) + { + DateTime proddate; + dateStr = dateStr ?? ""; + if (dateStr.Length == 8) + { + try + { + //骞存湀鏃� + proddate = DateTime.ParseExact(dateStr, "yyyyMMdd", new CultureInfo("zh-CN", true)); + } + catch + { + return null; + } + } + else if (dateStr.Length == 6) + { + try + { + //骞存湀鏃� + proddate = DateTime.ParseExact(dateStr, "yyMMdd", new CultureInfo("zh-CN", true)); + } + catch + { + try + { + //骞村懆 + var firstDate = Convert.ToDateTime(dateStr.Substring(0, 4) + "-1-1"); + int weekNum = Convert.ToInt32(dateStr.Substring(4, 2)); + + int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; + DateTime firstSunday = firstDate.AddDays(daysOffset); + var calendar = CultureInfo.CurrentCulture.Calendar; + int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); + if (firstWeek <= 1) + { + weekNum -= 1; + } + proddate = firstSunday.AddDays(weekNum * 7 - 1); + if (proddate.Year < firstDate.Year) + { + proddate = firstDate; + } + if (proddate.Year > firstDate.Year) + { + proddate = firstDate.AddYears(1).AddDays(-1); + } + } + catch + { + try + { + //骞存湀 + proddate = DateTime.ParseExact(dateStr, "yyyyMM", new CultureInfo("zh-CN", true)); + } + catch + { + try + { + proddate = Convert.ToDateTime(dateStr); + } + catch + { + //proddate = DateTime.Now; + return null; + } + } + } + } + } + else if (dateStr.Length == 4) + { + try + { + //骞村懆 + var firstDate = DateTime.ParseExact(dateStr.Substring(0, 2), "yy", CultureInfo.CurrentCulture); + int weekNum = Convert.ToInt32(dateStr.Substring(2, 2)); + + int daysOffset = DayOfWeek.Monday - firstDate.DayOfWeek; + DateTime firstSunday = firstDate.AddDays(daysOffset); + var calendar = CultureInfo.CurrentCulture.Calendar; + int firstWeek = calendar.GetWeekOfYear(firstDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); + if (firstWeek <= 1) + { + weekNum -= 1; + } + proddate = firstSunday.AddDays(weekNum * 7 - 1); + if (proddate.Year < firstDate.Year) + { + proddate = firstDate; + } + if (proddate.Year > firstDate.Year) + { + proddate = firstDate.AddYears(1).AddDays(-1); + } + } + catch + { + try + { + //骞存湀 + proddate = DateTime.ParseExact(dateStr, "yyMM", new CultureInfo("zh-CN", true)); + } + catch + { + try + { + //骞� + proddate = DateTime.ParseExact(dateStr, "yyyy", new CultureInfo("zh-CN", true)); + } + catch + { + try + { + proddate = Convert.ToDateTime(dateStr); + } + catch + { + //鏃犳硶璇嗗埆鍒欎娇鐢ㄥ綋鍓嶆椂闂� + //proddate = DateTime.Now; + return null; + } + } + } + } + } + else + { + try + { + proddate = Convert.ToDateTime(dateStr); + } + catch + { + //proddate = DateTime.Now; + return null; + } + } + return proddate; + } + + /// <summary> + /// 鏄惁闈炴硶鏉$爜 + /// </summary> + /// <param name="sn"></param> + /// <returns></returns> + public static bool IsIllegal(string sn) + { + return !new Barcode(sn).IsRegular; + } + + /// <summary> + /// 鑾峰彇鏉$爜绫诲瀷 + /// </summary> + /// <param name="sn"></param> + /// <returns></returns> + public static Barcode.Types GetType(string sn) + { + return new Barcode(sn).Type; + } + + /// <summary> + /// 鍒ゆ柇鏄惁閲嶆墦鐨勬潯鐮� + /// </summary> + /// <param name="sn"></param> + /// <returns></returns> + public static bool IsReprint(string sn) + { + return new Barcode(sn).IsReprintSn; + } + }//endClass +} diff --git a/Tiger.Business.WMS/Transaction/Old/CustSupplyCheckingNew.cs b/Tiger.Business.WMS/Transaction/Old/CustSupplyCheckingNew.cs index 0263a49..e5dd55d 100644 --- a/Tiger.Business.WMS/Transaction/Old/CustSupplyCheckingNew.cs +++ b/Tiger.Business.WMS/Transaction/Old/CustSupplyCheckingNew.cs @@ -150,7 +150,7 @@ return action; } //鍒ゆ柇鏉$爜鏄惁涓烘渶灏戝寘瑁� - if (!new[] { Barcode.Types.Small, Barcode.Types.Other }.Contains(curInv.Barcode.Type)) + if (!new[] { Barcode.Types.MiniPackage, Barcode.Types.Other }.Contains(curInv.Barcode.Type)) { action.IsSuccessed = false; action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.TypeError", curInv.SN); diff --git a/Tiger.Business.WMS/Transaction/Old/OtherInLocationChecking.cs b/Tiger.Business.WMS/Transaction/Old/OtherInLocationChecking.cs index 596f267..7f3a804 100644 --- a/Tiger.Business.WMS/Transaction/Old/OtherInLocationChecking.cs +++ b/Tiger.Business.WMS/Transaction/Old/OtherInLocationChecking.cs @@ -124,7 +124,7 @@ return action; } //鍒ゆ柇鏉$爜鏄惁涓烘渶灏戝寘瑁� - if (!new[] { Barcode.Types.Small, Barcode.Types.Other }.Contains(curInv.Barcode.Type)) + if (!new[] { Barcode.Types.MiniPackage, Barcode.Types.Other }.Contains(curInv.Barcode.Type)) { action.IsSuccessed = false; action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.TypeError", curInv.SN); diff --git a/Tiger.Business.WMS/WMS_ITEM_Biz.cs b/Tiger.Business.WMS/WMS_ITEM_Biz.cs index c31f406..624e351 100644 --- a/Tiger.Business.WMS/WMS_ITEM_Biz.cs +++ b/Tiger.Business.WMS/WMS_ITEM_Biz.cs @@ -43,6 +43,10 @@ result.Flag = Result.Flags.Failed; result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure"); } + else if (barcode.IsException) + { + throw barcode.AnalyseException; + } //闈炴硶鏉$爜 else if (!barcode.IsRegular) { @@ -152,6 +156,10 @@ result.Flag = Result.Flags.Failed; result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure"); } + else if (barcode.IsException) + { + throw barcode.AnalyseException; + } //闈炴硶鏉$爜 else if (!barcode.IsRegular) { diff --git a/Tiger.Business.WMSTests/Common/CommonTests.cs b/Tiger.Business.WMSTests/Common/CommonTests.cs new file mode 100644 index 0000000..99ccf75 --- /dev/null +++ b/Tiger.Business.WMSTests/Common/CommonTests.cs @@ -0,0 +1,22 @@ +锘縰sing Microsoft.VisualStudio.TestTools.UnitTesting; +using Tiger.Business.WMS; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tiger.Business.WMS.Tests +{ + [TestClass()] + public class CommonTests + { + [TestMethod()] + public void AnalyseTest() + { + var b = new Barcode("4100-CA1010-T7#202405#1251#0002#10000"); + var b1 = new Barcode("YDASN241000427/10/10090402.0024.00/ASN241000427/42"); + ; + } + } +} \ No newline at end of file diff --git a/Tiger.Business.WMSTests/Tiger.Business.WMSTests.csproj b/Tiger.Business.WMSTests/Tiger.Business.WMSTests.csproj new file mode 100644 index 0000000..41d97ed --- /dev/null +++ b/Tiger.Business.WMSTests/Tiger.Business.WMSTests.csproj @@ -0,0 +1,23 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <LangVersion>latest</LangVersion> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> + <PackageReference Include="MSTest" Version="3.6.1" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\Tiger.Business.WMS\Tiger.Business.WMS.csproj" /> + </ItemGroup> + + <ItemGroup> + <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> + </ItemGroup> + +</Project> -- Gitblit v1.9.3