Commit 169b3ee9 刘韬

修正字符串切割模板bug

1 个父辈 8f614d2c
...@@ -36,6 +36,7 @@ namespace BLL ...@@ -36,6 +36,7 @@ namespace BLL
} }
public static void AddMatch(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) { public static void AddMatch(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) {
LogNet.log.Info($"Match {matchKey},isMatch:{isMatch},{colName},matchDesc:{matchDesc}");
Match match = new Match(matchKey, isMatch, codeID, colName,matchDesc); Match match = new Match(matchKey, isMatch, codeID, colName,matchDesc);
var ms = MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections; var ms = MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections;
......
...@@ -6,6 +6,7 @@ using System.Collections.Generic; ...@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Xml; using System.Xml;
namespace BLL namespace BLL
...@@ -445,6 +446,7 @@ namespace BLL ...@@ -445,6 +446,7 @@ namespace BLL
} }
} }
LogNet.log.Info($"{mateTemp[index].Name} 匹配数量 [关键字数量:{keyword.Count} = 匹配数量:{matchCount}]");
if (matchCount != 0 && keyword.Count == matchCount) if (matchCount != 0 && keyword.Count == matchCount)
{ {
isMatch = true; isMatch = true;
...@@ -677,6 +679,7 @@ namespace BLL ...@@ -677,6 +679,7 @@ namespace BLL
text = codeMatch[i].CaseSensitive ? codeMatch[i].MiddleText : codeMatch[i].MiddleText.ToUpper(); text = codeMatch[i].CaseSensitive ? codeMatch[i].MiddleText : codeMatch[i].MiddleText.ToUpper();
if (text == "") return null; if (text == "") return null;
index = count = 0; index = count = 0;
while ((index = code.IndexOf(text, index)) != -1) while ((index = code.IndexOf(text, index)) != -1)
{ {
count++; count++;
...@@ -692,7 +695,7 @@ namespace BLL ...@@ -692,7 +695,7 @@ namespace BLL
ismatch = false; ismatch = false;
var mode = codeMatch[i].MatchMiddleType == 0 ? "相等" : codeMatch[i].MatchMiddleType == 1 ? "至多" : "至少"; var mode = codeMatch[i].MatchMiddleType == 0 ? "相等" : codeMatch[i].MatchMiddleType == 1 ? "至多" : "至少";
MatchAnalysis.AddMatch(codeMatch[i].Keyword, ismatch, codeMatch[i].CodeID, $"中间字符:\"{text}\",{mode}匹配:{codeMatch[i].MiddleTextCount}次", ismatch ? "OK" : "NG"); MatchAnalysis.AddMatch(codeMatch[i].Keyword, ismatch, codeMatch[i].CodeID, $"中间字符:\"{text}\",{mode}匹配:{codeMatch[i].MiddleTextCount}次,实际:{count}", ismatch ? "OK" : "NG");
//if (!ismatch) return null; //if (!ismatch) return null;
} }
...@@ -710,7 +713,11 @@ namespace BLL ...@@ -710,7 +713,11 @@ namespace BLL
if (index >= arr.Length) if (index >= arr.Length)
ismatch = false; ismatch = false;
else else
{
code = arr[index]; code = arr[index];
if (string.IsNullOrEmpty(code))
code = " ";
}
} }
else else
{ {
...@@ -722,7 +729,8 @@ namespace BLL ...@@ -722,7 +729,8 @@ namespace BLL
} }
//截取 //截取
if (!ismatch) continue; if (!ismatch)
continue;
int startIndex = codeMatch[i].SubstringStart; int startIndex = codeMatch[i].SubstringStart;
int length = codeMatch[i].SubstringLength; int length = codeMatch[i].SubstringLength;
if (startIndex >= code.Length) if (startIndex >= code.Length)
...@@ -743,18 +751,17 @@ namespace BLL ...@@ -743,18 +751,17 @@ namespace BLL
if (codeMatch[i].MatchISNumber) if (codeMatch[i].MatchISNumber)
{ {
LogNet.log.Info($"开始匹配数字 [{filtercode}]"); LogNet.log.Info($"开始匹配数字 [{filtercode}]");
filtercode = filtercode.Trim().ToLower().Replace("pcs", ""); string analysisReason = filtercode.Trim();
filtercode = filtercode.Replace(",", ""); analysisReason = filtercode.Replace(",", "");
string analysisReason = filtercode; var m = Regex.Match(analysisReason, @"^(\d+)\w{0,3}$");
if (!m.Success)
if (!int.TryParse(filtercode, out int res))
{ {
ismatch = false; ismatch = false;
analysisReason += $" NG"; analysisReason += $" NG";
} }
else else
{ {
filtercode = res.ToString(); filtercode = m.Groups[1].Value;
analysisReason += $" OK"; analysisReason += $" OK";
} }
MatchAnalysis.AddMatch(codeMatch[i].Keyword, ismatch, codeMatch[i].CodeID, $"是否为数字", analysisReason); MatchAnalysis.AddMatch(codeMatch[i].Keyword, ismatch, codeMatch[i].CodeID, $"是否为数字", analysisReason);
......
...@@ -84,7 +84,7 @@ namespace SmartScan ...@@ -84,7 +84,7 @@ namespace SmartScan
private void AddMatch(MaterialCodeMatch match) private void AddMatch(MaterialCodeMatch match)
{ {
FaceButton btn = new() { Text = string.Format("[{0}]", match.Keyword), Margin = new Padding(0, 0, 6, 6), Width = 100, Height = 50 }; FaceButton btn = new() { Text = string.Format("[{0}]", match.Keyword), Margin = new Padding(0, 0, 6, 6), Width = 100, Height = 28 };
btn.Click += Btn_Click; btn.Click += Btn_Click;
btn.Tag = "not"; btn.Tag = "not";
flowLayoutPanel1.Controls.Add(btn); flowLayoutPanel1.Controls.Add(btn);
......
...@@ -22,7 +22,7 @@ namespace SmartScan ...@@ -22,7 +22,7 @@ namespace SmartScan
//this.Height = 738; //this.Height = 738;
this.Top = 15; this.Top = 15;
this.Left = 0; this.Left = 0;
WebService.Open(BLLCommon.config.WebService);//启动条码匹配服务 //WebService.Open(BLLCommon.config.WebService);//启动条码匹配服务
LogNet.log = log4net.LogManager.GetLogger("SmartScan"); LogNet.log = log4net.LogManager.GetLogger("SmartScan");
} }
......
...@@ -310,6 +310,7 @@ namespace SmartScan.PlusSettingFrm ...@@ -310,6 +310,7 @@ namespace SmartScan.PlusSettingFrm
if (isvaor) if (isvaor)
{ {
bool isbarcode = true;
if (codeType.StartsWith("QR Code")) if (codeType.StartsWith("QR Code"))
{ {
int deg = Angle; int deg = Angle;
...@@ -317,23 +318,38 @@ namespace SmartScan.PlusSettingFrm ...@@ -317,23 +318,38 @@ namespace SmartScan.PlusSettingFrm
if (deg > 360) if (deg > 360)
deg = deg - 360; deg = deg - 360;
angle = ScanningCameraAngle(deg,0); angle = ScanningCameraAngle(deg,0);
isbarcode = false;
LogUtil.info($"QR Code转换后角度,Angle:{Angle}, deg:{angle}");
Angle = angle;
} }
else if (codeType.StartsWith("Data Matrix")) else if (codeType.StartsWith("Data Matrix"))
{ {
angle = ScanningCameraAngle(Angle, 0); int deg = Angle;
angle = ScanningCameraAngle(deg, 0);
isbarcode = false;
LogUtil.info($"Data Matrix转换后角度,Angle:{Angle}, deg:{angle}");
Angle = angle;
} }
Angle = Angle + 270;
var dc1 = LabelingPosition.distance(LabelingPosition.PointWithAngle(lable, Angle, 50), centrality); //Angle = Angle + 270;
var dc2 = LabelingPosition.distance(LabelingPosition.PointWithAngle(lable, Angle + 180, 50), centrality); if (isbarcode)
//if (dc2 > dc1) {
// Angle = Angle + 180; var dc1 = LabelingPosition.distance(LabelingPosition.PointWithAngle(lable, Angle, 50), centrality);
if (Angle > 360) var dc2 = LabelingPosition.distance(LabelingPosition.PointWithAngle(lable, Angle + 180, 50), centrality);
Angle = Angle - 360; if (dc2 > dc1)
LogUtil.info($"结合盘心计算后, dc1:{dc1}, dc2:{dc2}, deg:{Angle}"); Angle = Angle + 180;
if (Angle > 360)
Angle = Angle - 360;
LogUtil.info($"结合盘心计算后, dc1:{dc1}, dc2:{dc2}, deg:{Angle}");
}
else
{
LogUtil.info($"二维码转换后角度, deg:{Angle}");
}
angle = Angle + 83 + labelangle; angle = Angle + 83 + labelangle;
if (angle > 360) if (angle > 360)
angle = angle - 360; angle = angle - 360;
if (angle > 360) if (angle > 360)
...@@ -356,13 +372,13 @@ namespace SmartScan.PlusSettingFrm ...@@ -356,13 +372,13 @@ namespace SmartScan.PlusSettingFrm
int rotationAngle = RotateAngle;// 83; int rotationAngle = RotateAngle;// 83;
if (angles < 0) if (angles < 0)
{ {
angle = angles * -1 + rotationAngle; angle = -1 * angles + rotationAngle;
} }
else else
{ {
angle = 360 - angles + rotationAngle; angle = 360 - angles + rotationAngle;
} }
angle += 90; angle -= 90;
if (angle >= 360) if (angle >= 360)
{ {
angle -= 360; angle -= 360;
......
using BLL; using BLL;
using Model; using Model;
using SmartScan.PlusSettingFrm;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
...@@ -24,6 +26,8 @@ namespace SmartScan ...@@ -24,6 +26,8 @@ namespace SmartScan
[STAThread] [STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
//UsrKeywordlabeling.Overwritelabel(new Point() { X = 2050, Y = 1770 },new Point() { X = 2678, Y = 1675 }, true, 0, 91, 0, 180, out int angle, "Data Matrix");
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException; Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
......
...@@ -238,6 +238,7 @@ namespace SmartScan ...@@ -238,6 +238,7 @@ namespace SmartScan
BLLCommon.mateEdit.CurrntBitmap = WebCallWork.DeepClone(image[0]); BLLCommon.mateEdit.CurrntBitmap = WebCallWork.DeepClone(image[0]);
if (!BLL.Config.Backgrounder) if (!BLL.Config.Backgrounder)
picShow.Image = image[0]; picShow.Image = image[0];
Application.DoEvents();
if (BLLCommon.mateEdit.CurrntBitmap!=null) if (BLLCommon.mateEdit.CurrntBitmap!=null)
_ = UnifiedDataHandler.PostSmfImageAsync(BLLCommon.mateEdit.CurrntBitmap, new Dictionary<string, string> { { "cid", BLLCommon.config.CID + "_1" } }, BLLCommon.mateEdit.CurrntBitmap.Width, BLLCommon.mateEdit.CurrntBitmap.Height); _ = UnifiedDataHandler.PostSmfImageAsync(BLLCommon.mateEdit.CurrntBitmap, new Dictionary<string, string> { { "cid", BLLCommon.config.CID + "_1" } }, BLLCommon.mateEdit.CurrntBitmap.Width, BLLCommon.mateEdit.CurrntBitmap.Height);
}else }else
...@@ -272,6 +273,7 @@ namespace SmartScan ...@@ -272,6 +273,7 @@ namespace SmartScan
if (!BLL.Config.Backgrounder) if (!BLL.Config.Backgrounder)
picShow.Image = bmp; picShow.Image = bmp;
BLLCommon.mateEdit.CurrntBitmap = bmp; BLLCommon.mateEdit.CurrntBitmap = bmp;
Application.DoEvents();
}); });
return true; return true;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!