MatchAnalysis.cs
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using CameraVisionLib.Model;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public class MatchAnalysis
{
public static void StartNewAnalysis(List<BarcodeInfo> code)
{
MatchTemplateList = new ();
}
static string CurrnetTemplateName="";
static BarcodeInfo CurrnetBarcode;
static public void SetTemplatename(string name) {
CurrnetTemplateName = name;
if (!MatchTemplateList.ContainsKey(CurrnetTemplateName))
{
MatchTemplateList.Add(CurrnetTemplateName, new TemplateCollection());
}
}
static public void SetBarcode(BarcodeInfo name)
{
CurrnetBarcode = name;
if (!MatchTemplateList[CurrnetTemplateName].BarcodeMatchs.ContainsKey(name.Text))
{
MatchTemplateList[CurrnetTemplateName].BarcodeMatchs.Add(name.Text, new BarcodeMatch(name));
MatchTemplateList[CurrnetTemplateName].barcodeInfos.Add(name);
}
}
public static void AddMatch(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) {
Match match = new Match(matchKey, isMatch, codeID, colName,matchDesc);
var ms = MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections;
if (!ms.ContainsKey(matchKey))
ms.Add(matchKey,new MatchCollection());
ms[matchKey].Matchs.Add(match);
if (!MatchTemplateList[CurrnetTemplateName].MatchCollections.ContainsKey(matchKey))
{
MatchTemplateList[CurrnetTemplateName].MatchCollections.Add(matchKey, new MatchCollection());
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].barcodeInfo = CurrnetBarcode;
}
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].Matchs.Add(match);
}
public static void MatchResult(string matchKey, bool isMatch) {
if (!MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections.ContainsKey(matchKey))
return;
MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections[matchKey].isMatch = isMatch;
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey]=MatchTemplateList[CurrnetTemplateName].BarcodeMatchs[CurrnetBarcode.Text].MatchCollections[matchKey];
MatchTemplateList[CurrnetTemplateName].MatchCollections[matchKey].barcodeInfo = CurrnetBarcode;
}
public static void TemplateResult(bool isMatch) {
MatchTemplateList[CurrnetTemplateName].isMatch = isMatch;
}
static Dictionary<string, TemplateCollection> MatchTemplateList;
public static void ShowResult()
{
return;
foreach (var tp in MatchTemplateList) {
LogNet.log.Info($"开始解析模版:{tp.Key}");
foreach (var m in tp.Value.MatchCollections) {
LogNet.log.Info($"开始解析关键字:{m.Key}");
LogNet.log.Info($"匹配到关键字:{m.Key}");
string matchlist = m.Value.barcodeInfo.Text + "\t";
foreach (var item in m.Value.Matchs)
{
matchlist += $"{item.colName},{item.isMatch}\t";
}
LogNet.log.Info(matchlist);
}
}
}
public class TemplateCollection
{
public Dictionary<string, BarcodeMatch> BarcodeMatchs=new ();
public List<BarcodeInfo> barcodeInfos = new();
public Dictionary<string, MatchCollection> MatchCollections = new();
public bool isMatch;
}
public class MatchCollection
{
public string MatchKey;
public List<Match> Matchs = new ();
public BarcodeInfo barcodeInfo;
public bool isMatch;
public string result;
}
public class BarcodeMatch {
public BarcodeInfo barcode;
public Dictionary<string, MatchCollection> MatchCollections = new();
public bool isMatch=false;
public BarcodeMatch(BarcodeInfo barcode)
{
this.barcode = barcode;
}
}
public class Match {
public string matchKey;
public bool isMatch;
public int codeID;
public string colName;
public string matchDesc;
public Match(string matchKey, bool isMatch, int codeID, string colName,string matchDesc) {
this.matchKey = matchKey;
this.isMatch = isMatch;
this.codeID = codeID;
this.colName = colName;
this.matchDesc = matchDesc;
}
}
}
}