Commit 505fe44b 刘韬

修正不显示匹配成功模板名称的问题

1 个父辈 1a150e20
......@@ -20,8 +20,9 @@ namespace BLL
{
public class Extension : IDisposable
{
public delegate void KeySet(string[] originalCode, Dictionary<string, string> key, bool hasMatch);
public delegate void KeySet(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch);
public event KeySet KeySets;
public event Func<Dictionary<string, string>> GetUIKeyWords;
public delegate void Check1(string text);
public event Check1 Checks;
public event IExtension.PrintDelegate Printing;
......@@ -106,9 +107,9 @@ namespace BLL
currentExtension.Dispose();
}
public string labelText = "等待中";
public void set(string[] originalCode, Dictionary<string, string> key, bool hasMatch)
public void set(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch)
{
KeySets?.Invoke(originalCode, key, hasMatch);
KeySets?.Invoke(templateName, originalCode, key, hasMatch);
}
public void Check(string text)
{
......@@ -646,9 +647,9 @@ namespace BLL
General.CheckClear();
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key,bool hasMatch, out string errmsg)
public bool SetKey(string templateName,string[] originalCode, Dictionary<string, string> key,bool hasMatch, out string errmsg)
{
return currentExtension.SetKey(originalCode, key, hasMatch, out errmsg);
return currentExtension.SetKey(templateName,originalCode, key, hasMatch, out errmsg);
}
public void Print(bool hasMatch, Dictionary<string, string> key)
{
......@@ -797,7 +798,9 @@ namespace BLL
System.Windows.Forms.HorizontalAlignment alignment = (System.Windows.Forms.HorizontalAlignment)Enum.Parse(typeof(System.Windows.Forms.HorizontalAlignment), obj.ToString());
info.SetValue(ctl, alignment);
}
public Dictionary<string, string> GetUIKeywords() {
return GetUIKeyWords?.Invoke();
}
}
}
......@@ -73,7 +73,7 @@ namespace BLL
Update();
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
{
errmsg = "";
LogNet.log.Info("SetKey()");
......
using Asa.FaceControl;
using DocumentFormat.OpenXml.Drawing.Charts;
using Model;
using Newtonsoft.Json;
using System;
......@@ -7,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Windows.Threading;
using static BLL.BLLCommon;
using static BLL.Replacekeywords;
using Http = Model.Http;
......@@ -96,9 +98,12 @@ namespace BLL
// 定义事件
protected virtual void OnKeySet(string[] originalCode, Dictionary<string, string> key, bool hasMatch)
protected virtual void OnKeySet(string templateName,string[] originalCode, Dictionary<string, string> key, bool hasMatch)
{
extension.set(originalCode, key, hasMatch);
extension.set(templateName , originalCode, key, hasMatch);
}
public Dictionary<string, string> GetUIKeywords() {
return extension.GetUIKeywords();
}
protected virtual void CheckText(string text)
{
......@@ -127,7 +132,7 @@ namespace BLL
//读码后第一步
//
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
{
errmsg = "";
mesResult = false;
......@@ -240,7 +245,8 @@ namespace BLL
var extraData = ExtraFileData.AllData[CleanData];
foreach (var d in extraData)
{
key[d.Key] = d.Value;
if (!string.IsNullOrEmpty(d.Value))
key[d.Key] = d.Value;
}
}
}
......@@ -322,7 +328,8 @@ namespace BLL
}
LogNet.log.Info($"OnKeySet1");
OnKeySet(templateName, originalCode, key, hasMatch);
// 添加或替换自增ID
string reelIdKeyWord = config.ReelIDKeyWord;
if (!string.IsNullOrEmpty(config.ReelIDKeyWord) && isdisplay)
......@@ -341,9 +348,8 @@ namespace BLL
// 如果有字段更新,则再次调用OnKeySet更新WPF界面
LogNet.log.Info($"OnKeySet");
OnKeySet(originalCode, key, hasMatch);
LogNet.log.Info($"OnKeySet2");
OnKeySet(templateName, originalCode, key, hasMatch);
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
{
......@@ -424,6 +430,21 @@ namespace BLL
return true;
}
public static void DoEvents()
{
var frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame),
frame);
Dispatcher.PushFrame(frame);
}
private static object ExitFrame(object frame)
{
((DispatcherFrame)frame).Continue = false;
return null;
}
bool updatereelid(Dictionary<string, string> key, out string errmsg)
{
errmsg = "";
......@@ -532,14 +553,17 @@ namespace BLL
// 对于字符类型,直接保留不替换
continue;
}
// 3. 处理普通关键字(从UI控件获取值)
if (extensions != null)
{
int index = extensions.FindIndex(match => match.Key == key);
if (index == -1) continue;
processedPattern = processedPattern.Replace(keyPlaceholder, extensions[index].Control.Text);
}
var uikey = GetUIKeywords();
if (uikey.ContainsKey(key))
processedPattern = processedPattern.Replace(keyPlaceholder, uikey[key]);
//// 3. 处理普通关键字(从UI控件获取值)
//if (extensions != null)
//{
// int index = extensions.FindIndex(match => match.Key == key);
// if (index == -1) continue;
// processedPattern = processedPattern.Replace(keyPlaceholder, extensions[index].Control.Text);
//}
}
string finalText = processedPattern;
......@@ -878,7 +902,7 @@ namespace BLL
}
}
if (!string.IsNullOrEmpty(key["ReelID"]))
if (key.ContainsKey("ReelID") && !string.IsNullOrEmpty(key["ReelID"]))
{
return true;
}
......
......@@ -63,7 +63,7 @@ namespace BLL
}
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
{
errmsg = "";
for (int i = 0; i < extensions.Count; i++)
......
......@@ -52,7 +52,7 @@ namespace BLL
}
static bool mesResult = false;
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
{
errmsg = "";
mesResult = false;
......
......@@ -45,7 +45,7 @@ namespace BLL
//mesConn = Http.Ping(mesIP);
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
{
errmsg = "";
return true;
......
......@@ -78,7 +78,7 @@ namespace BLL
}
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
{
errmsg = "";
for (int i = 0; i < extensions.Count; i++)
......
......@@ -15,7 +15,7 @@ namespace Model
public void Load(List<ExtensionControl> extensions);
public bool SetKey(string[] originalCode, Dictionary<string, string> key,bool hasMatch, out string errmsg);
public bool SetKey(string templateName, string[] originalCode, Dictionary<string, string> key,bool hasMatch, out string errmsg);
public void Update();
public void Dispose();
......
......@@ -975,6 +975,8 @@ namespace SmartScan
scanWork = new();
scanWork.generals = new General(BLLCommon.config);
BLLCommon.extension.KeySets += OnBllKeySet;
BLLCommon.extension.GetUIKeyWords += Extension_GetUIKeyWords;
BLLCommon.extension.Checks += Extension_Checks; ;
scanWork.Check2s += Extension_Checks;
......@@ -1027,6 +1029,11 @@ namespace SmartScan
changeBtnStartText();
}
private Dictionary<string, string> Extension_GetUIKeyWords()
{
return wpfControl.GetRecognitionData();
}
private void Extension_Checks(string text)
{
......@@ -1060,9 +1067,10 @@ namespace SmartScan
}
private void OnBllKeySet(string[] originalCode, Dictionary<string, string> key, bool hasMatch)
private void OnBllKeySet(string templateName, string[] originalCode, Dictionary<string, string> key, bool hasMatch)
{
LogNet.log.Info($"OnBllKeySet hasMatch:{hasMatch}, key:" + JsonConvert.SerializeObject(key));
LogNet.log.Info($"OnBllKeySet templateName:{templateName}, hasMatch:{hasMatch}, key:" + JsonConvert.SerializeObject(key));
wpfControl.templateName = templateName;
// 1. 更新UI显示原始码
wpfControl.UpdateOriginalCodeDisplay(originalCode);
......
......@@ -205,14 +205,14 @@ namespace SmartScan
}
Check2s?.Invoke("text");
bool hasMatch = MatchingTemplate();
bool hasMatch = MatchingTemplate(out string templateName);
LogNet.log.Info($"模板匹配耗时{reckontime.ElapsedMilliseconds}ms");
reckontime.Restart();
//Common.frmMain.SetWaittingMsg(Language.Dialog("MaterialProcessing"),5);//计算结果...
Common.frmMain.Invoke(delegate ()
{
SetKey(hasMatch);
SetKey(hasMatch, templateName);
});
Common.frmMain.Showlogs("");
......@@ -296,8 +296,8 @@ namespace SmartScan
originalCodeText = code;
originalCodeIsUsed = null;
var hasMatch = MatchingTemplate();
SetKey(hasMatch);
var hasMatch = MatchingTemplate(out string templateName);
SetKey(hasMatch, templateName);
isTouch = true;
LogNet.log.Info("Work scan code is done");
......@@ -705,8 +705,9 @@ namespace SmartScan
}
public bool MatchingTemplate()
public bool MatchingTemplate(out string templateName)
{
templateName = "";
LogNet.log.Info("Work MatchingTemplate");
//没有条码也继续进行模板匹配
//if (workCodeInfo.Count == 0) return false;
......@@ -714,7 +715,7 @@ namespace SmartScan
bool rtn = BLLCommon.mateEdit.MatchingTemplate(workCodeInfo, BLLCommon.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out AMatch aMatch);
BLL.MatchAnalysis.ShowResult();
templateName = mateName;
Common.frmMain.Invoke(delegate ()
{
if (rtn)
......@@ -724,6 +725,7 @@ namespace SmartScan
{
btnMatchedName.Visible = true;
btnMatchedName.Text = mateName;
}
}
else
......@@ -744,13 +746,13 @@ namespace SmartScan
}
public bool Ispring=true;
public bool needPrint = false;
public void SetKey(bool hasMatch)
public void SetKey(bool hasMatch,string templateName)
{
LogNet.log.Info("Work SetKey hasMatch:" + hasMatch);
//if (workCodeKeyword.Count == 0){ return;}
//if(hasMatch)
Ispring = true;
bool a= BLLCommon.extension.SetKey(originalCodeText, workCodeKeyword, hasMatch, out _);
bool a= BLLCommon.extension.SetKey(templateName,originalCodeText, workCodeKeyword, hasMatch, out _);
LoadingScreen.Instance.Hide();
Common.frmMain.Showlogs("");
// 通过检查结果状态来判断是否需要打印
......
......@@ -22,8 +22,8 @@ namespace SmartScan
CboDataType.Items.Add("Excel/CSV");
CboDataType.SelectedIndex = 0;
TxtDataSource.TextChanged += TxtDataSource_TextChanged;
TxtDataSource.Text = Config.DataSource_FilePath;
ChkRecursive.Checked= Config.DataSource_Recursive;
//TxtDataSource.Text = Config.DataSource_FilePath;
//ChkRecursive.Checked= Config.DataSource_Recursive;
Asa.FaceControl.Language.SetLanguage(this);
}
......@@ -99,6 +99,7 @@ namespace SmartScan
}
TxtDataSource.Text = Config.DataSource_FilePath;
ChkRecursive.Checked = Config.DataSource_Recursive;
return but_StartService;
}
......
......@@ -32,6 +32,7 @@ namespace SmartScan.SetControl.WPF
// 识别数据
private Dictionary<string, string> recognizedData = new Dictionary<string, string>();
public string templateName = "";
// 事件
public event EventHandler<string> DataUpdated;
public event EventHandler PrintLabelRequested;
......@@ -427,7 +428,7 @@ namespace SmartScan.SetControl.WPF
if (key.Contains("\t"))
{
string[] parts = key.Split('\t');
if (parts.Length > 2)
if (parts.Length > 2 && !string.IsNullOrWhiteSpace(parts[1]))
return $"{parts[0]} ({parts[1]})";
else return $"{parts[0]}";
}
......@@ -894,7 +895,7 @@ namespace SmartScan.SetControl.WPF
TextBlock titleBlock = new TextBlock
{
// Text = YU == "zh-CN" ? "识别结果" : (YU == "ja-JP" ? "認識結果" : "Recognition Result"),
Text = Asa.FaceControl.Language.Dialog("NS_KetRight_TextBlock", "识别结果"),
Text = Asa.FaceControl.Language.Dialog("NS_KetRight_TextBlock", "识别结果") + " : " + templateName,
FontSize = 16,
Margin = new Thickness(0, 0, 0, 10),
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f0f0f0"))
......
......@@ -333,7 +333,7 @@
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="15 0 0 0">
<Button Content="−" Style="{StaticResource NavigationButtonStyle}" Click="DecreaseButton_Click" Tag="TxtSplitIndex"/>
<Border Background="#333333" BorderBrush="#555555" BorderThickness="1" Width="25" Height="25" Margin="5" CornerRadius="2">
<TextBlock x:Name="TxtSplitIndex" Text="0" FontFamily="微软雅黑" FontSize="14" Foreground="White"
<TextBlock x:Name="TxtSplitIndex" Text="1" FontFamily="微软雅黑" FontSize="14" Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Button Content="+" Style="{StaticResource NavigationButtonStyle}" Click="IncreaseButton_Click" Tag="TxtSplitIndex"/>
......
......@@ -323,7 +323,7 @@ namespace SmartScan.SetControl.WPF
if (target != null)
{
int value;
if (int.TryParse(target.Text, out value) && value > 0)
if (int.TryParse(target.Text, out value) && value > 1)
{
target.Text = (value - 1).ToString();
CheckMatchForUserControl(match, userControl);
......@@ -650,7 +650,7 @@ namespace SmartScan.SetControl.WPF
if (userControl.ChkSplitBarcode.IsChecked == true && userControl.CboSplitChar.SelectedItem != null)
{
string splitChar = userControl.CboSplitChar.SelectedItem.ToString();
string[] parts = result.Split(new string[] { splitChar }, StringSplitOptions.RemoveEmptyEntries);
string[] parts = result.Split(splitChar.ToCharArray());
int splitIndex = int.Parse(userControl.TxtSplitIndex.Text) - 1; // UI显示从1开始,数组从0开始
if (splitIndex >= 0 && splitIndex < parts.Length)
......
......@@ -190,7 +190,7 @@ namespace SmartScan
try
{
//bool hasMatch = scanWork.MatchingTemplate();
BLLCommon.extension.SetKey(scanWork.originalCodeText, aaa, true, out _);
BLLCommon.extension.SetKey("AI",scanWork.originalCodeText, aaa, true, out _);
BLLCommon.extension.Print(true, aaa);
}
catch (Exception ex)
......@@ -275,7 +275,7 @@ namespace SmartScan
// workCodeKeyword[item.Key]= item.Value.Replace("<OCR>", "");
keys.Add(item.Key, item.Value.Replace("<OCR>", ""));
}
if (!BLLCommon.extension.SetKey(null, keys, rtn, out string errmsg))
if (!BLLCommon.extension.SetKey(mateName,null, keys, rtn, out string errmsg))
{
webResultCode = new WebResultCode() { ErrorCode = -2, Msg = errmsg };
}
......@@ -448,7 +448,7 @@ namespace SmartScan
{
keys.Add(item.Key, item.Value.Replace("<OCR>", ""));
}
if (!BLLCommon.extension.SetKey(null, keys, rtn, out string errmsg))
if (!BLLCommon.extension.SetKey(mateName,null, keys, rtn, out string errmsg))
{
return new WebResultCode() { ErrorCode = -2, Msg = errmsg };
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!