Commit f88539ce LN

欧姆龙外部数据源多标题匹配功能修改。增加重新匹配按钮。

1 个父辈 7c33e71c
......@@ -342,9 +342,12 @@ namespace BLL
public static MyConfig<string> DataSource_Encoding;
[MyConfigComment("数据源匹配Key")]
public static MyConfig<string> DataSource_DataKey;
[MyConfigComment("数据源匹配Key_其他项")]
[MyConfigComment("数据源匹配Key_其他项_关键字=标题")]
public static MyConfig<string[]> DataSource_DataKey_Others= new string[] { };
[MyConfigComment("数据源匹配_是否可以修改内容重新匹配")]
public static MyConfig<bool> DataSource_CanReMatch = false ;
[MyConfigComment("数据源列标题")]
public static MyConfig<string> DataSource_DataTitle;
......
......@@ -272,6 +272,22 @@ namespace BLL
}
key = ExtraFileData.MatchFileData(key, out bool findOk);
bool hasDataSource = (!string.IsNullOrEmpty(Config.DataSource_DataKey)) ||
(Config.DataSource_DataKey_Others.Val != null && Config.DataSource_DataKey_Others.Val.Length > 0);
if (hasDataSource && ExtraFileData.hasFileData() && (!findOk) && Config.DataSource_CanReMatch)
{
CheckText("ReMatch_Show");
LogNet.log.Info($"未匹配到数据源 ReMatch_Show");
}
else
{
LogNet.log.Info($" ReMatch_Hide");
CheckText("ReMatch_Hide");
}
//if (BLLCommon.config.CheckFunction)
//{
// if (isFirstCapture)
......@@ -291,48 +307,9 @@ namespace BLL
// }
if (extensions != null && !extensions[0].Control.InvokeRequired)
{
//使用key填充时,请处理字段开头的<OCR>字段
//查询excel数据填充
bool findOk = false;
if (key.ContainsKey(Config.DataSource_DataKey))
{
string CleanData = key[Config.DataSource_DataKey].Replace("<OCR>", "");
if (key.ContainsKey(Config.DataSource_DataKey) && ExtraFileData.AllData.ContainsKey(CleanData))
{
var extraData =ExtraFileData.GetSelectDataSource(CleanData);
findOk = true;
foreach (var d in extraData)
{
if (!string.IsNullOrEmpty(d.Value))
key[d.Key] = d.Value;
}
}
}
if (!findOk && Config.DataSource_DataKey_Others.Val != null && Config.DataSource_DataKey_Others.Val.Length > 0)
{
string[] otherKeys = Config.DataSource_DataKey_Others.Val;
foreach (string oKey in otherKeys)
{
if (key.ContainsKey(oKey))
{
string CleanData = key[oKey].Replace("<OCR>", "");
if (key.ContainsKey(oKey) && ExtraFileData.AllData.ContainsKey(CleanData))
{
var extraData = ExtraFileData.GetSelectDataSource(CleanData);
findOk = true;
foreach (var d in extraData)
{
if (!string.IsNullOrEmpty(d.Value))
key[d.Key] = d.Value;
}
break;
}
}
}
}
LogNet.log.Info($"OnKeySet3");
OnKeySet(templateName, originalCode, key, hasMatch);
......@@ -345,50 +322,8 @@ namespace BLL
string text = Language.Dialog("Waiting");
BLLCommon.extension.labelText = text;
CheckText(text);
//if (BLLCommon.config.Language.Equals("English"))
//{
// BLLCommon.extension.labelText = "Waiting";
// CheckText("Waiting");
//}
//else if (BLLCommon.config.Language.Equals("日语"))
//{
// BLLCommon.extension.labelText = "待機中";
// CheckText("待機中");
//}
//else
//{
// BLLCommon.extension.labelText = "等待中";
// CheckText("等待中");
//}
islast = false;
}
// 创建不包含自增ID的临时字典进行比较
//var keyWithoutReelID = new Dictionary<string, string>(key);
//var lastKeysWithoutReelID = new Dictionary<string, string>(lastKeys);
//// 从比较中排除自增ID
//if (!string.IsNullOrEmpty(reelIdKeyWord))
//{
// keyWithoutReelID.Remove(reelIdKeyWord);
// lastKeysWithoutReelID.Remove(reelIdKeyWord);
//}
//// 比较不包含自增ID的字典
//isSame = keyWithoutReelID.Count == lastKeysWithoutReelID.Count &&
// !keyWithoutReelID.Except(lastKeysWithoutReelID).Any();
//if (isSame)
//{
// BLLCommon.extension.labelText = "OK";
// CheckText("OK");
// lastKeys = null;
// islast = true;
// // 两次的 key 相同,可添加相应逻辑
//}
//else
//{ // 两次的 key 不同,可添加相应逻辑
// BLLCommon.extension.labelText = "NG";
// CheckText("NG");
//}
}
else
{
......@@ -702,10 +637,10 @@ namespace BLL
}
return keyValues;
}
private void PrintLabel(object sender, EventArgs e)
private void PrintLabel(Dictionary<string,string> printKey)
{
LogNet.log.Info("Enter PrintLabel Method: "+ JsonConvert.SerializeObject(lastkey));
if (lastkey == null) return;
LogNet.log.Info("Enter PrintLabel Method: "+ JsonConvert.SerializeObject(printKey));
if (printKey == null) return;
......@@ -717,8 +652,8 @@ namespace BLL
// else
// lastkey.Add(extensions[i].Key, extensions[i].Control.Text);
//}
lastkey = UpdateLastKey(lastkey);
LogNet.log.Info("lastkey:" + JsonConvert.SerializeObject(lastkey));
printKey = UpdateLastKey(printKey);
LogNet.log.Info("lastkey:" + JsonConvert.SerializeObject(printKey));
#region 判断指定关键字是否存在内容
List<string> strings = new List<string>();
string str = ConfigHelper.Config.Get("DataSource_ForceMatching", "");
......@@ -727,7 +662,7 @@ namespace BLL
string[] arr = str.Split(',');
foreach (var item in arr)
{
lastkey.TryGetValue(item, out string value);
printKey.TryGetValue(item, out string value);
if (string.IsNullOrWhiteSpace(value))
{
......@@ -748,19 +683,20 @@ namespace BLL
#region 点击打印按钮,rid内容为空时,生成rid
if (!string.IsNullOrEmpty(config.ReelIDKeyWord))
{
if (lastkey.ContainsKey(config.ReelIDKeyWord))
if (printKey.ContainsKey(config.ReelIDKeyWord))
{
string rid = lastkey[config.ReelIDKeyWord];
string rid = printKey[config.ReelIDKeyWord];
if (string.IsNullOrWhiteSpace(rid))
{
var Reelidstr = GetReelid();
lastkey[config.ReelIDKeyWord] = Reelidstr;
printKey[config.ReelIDKeyWord] = Reelidstr;
}
}
}
#endregion
Printing?.Invoke(lastkey);
Printing?.Invoke(printKey);
bool close = ConfigHelper.Config.Get("isprinclose", false);
if (close)
{
......@@ -772,7 +708,7 @@ namespace BLL
}
}
//进行追溯配置保存
SaveRetrospect?.Invoke(lastkey);
SaveRetrospect?.Invoke(printKey);
for (int i = 0; i < extensions.Count; i++)
{
extensions[i].Control.BackColor = System.Drawing.Color.FromArgb(255, 20, 20, 20);
......@@ -952,7 +888,8 @@ namespace BLL
//if (config.AutoPrint && match)
{
isprint = true;
PrintLabel(true, EventArgs.Empty);
//PrintLabel(true, EventArgs.Empty);
PrintLabel(key);
}
//bool close = ConfigHelper.Config.Get("isprinclose", false);
}
......
......@@ -68,11 +68,19 @@ namespace BLL
[HandleProcessCorruptedStateExceptions]
public static string StartCplusOcr(string imgPath)
{
try
{
LogNet.log.Error("进入OcrGet请求");
string json=Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}");
string json = Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}");
LogNet.log.Error($"返回数据为:{json}");
Result result= JsonConvert.DeserializeObject<Result>(json);
return result?.data??"";
Result result = JsonConvert.DeserializeObject<Result>(json);
return result?.data ?? "";
}
catch (AccessViolationException ex)
{
LogNet.log.Error("StartCplusOcr 出现 AccessViolationException 异常:" + ex.ToString());
}
return "";
}
public static string StartPythonOcr(string imgPath)
{
......
using Asa.FaceControl;
using Asa.FaceControl;
using BLL;
using HandyControl.Tools.Extension;
using Model;
......@@ -432,6 +432,7 @@ namespace SmartScan
wpfControl = new NS_KetRight();
// 订阅打印标签事件
wpfControl.PrintLabelRequested += WpfControl_PrintLabelRequested;
wpfControl.ReMatchRequested += WpfControl_ReMatchRequested;
wpfControl.Cherkfun += WpfControl_Cherkfun;
wpfControl.ISPrint += WpfControl_ISPrint; ;
// 创建 ElementHost 来托管 WPF 控件
......@@ -523,6 +524,12 @@ namespace SmartScan
}
}
private void WpfControl_ReMatchRequested(object sender, EventArgs e)
{
LogNet.log.Error($"点击 重新匹配 按钮,:templateName={wpfControl.templateName}");
scanWork.ReMatchFileData(wpfControl.templateName);
}
private List<string> GetRequiredFields()
{
// 返回所需的字段列表
......@@ -914,6 +921,16 @@ namespace SmartScan
wpfControl.SetSkipButtonVisibility(false);
return;
}
if (text == "ReMatch_Show")
{
wpfControl.SetReMatchButtonVisibility(true);
return;
}
if (text == "ReMatch_Hide")
{
wpfControl.SetReMatchButtonVisibility(false);
return;
}
if (text == "OK")
{
wpfControl.SetResultOK();
......
......@@ -460,5 +460,7 @@ Dialog_NoKeywordSelected 未选择关键字! No keyword selected!
Dialog_SelectDatasetTitle 数据集选择 Data Set Selection
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} matched multiple rows of data. Please select:
Dialog_WPF_Ok 确定 SURE
Dialog_NS_KetRight_ReMatch 重新匹配 Retry matching
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 Cannot retry matching. No data in the field.
......@@ -376,7 +376,7 @@ NS_KW_name 在界面中显示的名称 インターフェースに表示され
NS_KW_ID 唯一键自增 ユニークキー自動増分
LblContent 生成条件 生成条件
LblPrefix 开头字符 先頭キャラクタ
LblPostfix 结尾字符 先頭キャラクタ
LblPostfix 结尾字符 末尾キャラクタ
LblPlaces 数字位数 数字桁数
NS_KW_WEISHU 位数不足前面补0 桁数不足の際、前に0を補完
NS_KW_H 标准字段 標準フィールド
......@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,,
FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,,
Dialog_About_About 关于 About 微软雅黑,12,,
Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,,
Dialog_Using_OCR_Result 是否使用OCR识别结果? OCR の認識結果を使用しますか
Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか?
Dialog_Waiting 等待中 待機中
Dialog_WPFWorkMode_Printer 打印机 プリンター
......@@ -527,4 +528,6 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ
Dialog_SelectDatasetTitle 数据集选择 データセット選択
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください
Dialog_WPF_Ok 确定 確認
Dialog_NS_KetRight_ReMatch 重新匹配 再マッチング
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
......@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,,
FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,,
Dialog_About_About 关于 About 微软雅黑,12,,
Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,,
Dialog_Using_OCR_Result 是否使用OCR识别结果? OCR の認識結果を使用しますか
Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか?
Dialog_Waiting 等待中 待機中
Dialog_WPFWorkMode_Printer 打印机 プリンター
......@@ -527,5 +528,7 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ
Dialog_SelectDatasetTitle 数据集选择 データセット選択
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください
Dialog_WPF_Ok 确定 確認
Dialog_NS_KetRight_ReMatch 重新匹配 再マッチング
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
......@@ -517,6 +517,7 @@ FrmSet_LblFilestatus 文件状态: 文件状态: Arial,12,,
FrmSet_LblContent 标签数据源 标签数据源 Arial,12,,
Dialog_About_About 关于 关于
Dialog_About_mrs 物料注册系统 物料注册系统
Dialog_Using_OCR_Result 是否使用OCR识别结果? 是否使用OCR识别结果?
Dialog_NS_KetRight_PrintLabel 打印标签 打印标签
Dialog_NS_KetRight_Skip 跳过 跳过
Dialog_NS_KetRight_Title 元件信息 元件信息
......@@ -556,5 +557,6 @@ Dialog_NoValidParametersAvailable 没有可用的打印参数? 没有可用的
Dialog_NoKeywordSelected 未选择关键字! 未选择关键字!
Dialog_SelectDatasetTitle 数据集选择 数据集选择
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 匹配到多行数据,请选择:
Dialog_WPF_Ok 确定 确定
Dialog_NS_KetRight_ReMatch 重新匹配 重新匹配
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 无法重新匹配,字段没有数据
......@@ -151,6 +151,7 @@ namespace SmartScan
{
AddCodeCenter();
});
CheckText("ReMatch_Hide");//隐藏二次匹配按钮。
LogNet.log.Info($"获取图片耗时{reckontime.ElapsedMilliseconds}ms");
//Common.frmMain.SetWaittingMsg(Language.Dialog("MaterialTemplateMatching"),5);//模版匹配...
reckontime.Restart();
......@@ -235,6 +236,21 @@ namespace SmartScan
}
}
public void ReMatchFileData(string templateName)
{
//重新匹配外部数据源
Dictionary<string, string> lastKey = BLLCommon.extension.GetUIKeywords();
if (lastKey == null)
lastKey = new Dictionary<string, string>(workCodeKeyword);
else
lastKey = new Dictionary<string, string>(lastKey, StringComparer.OrdinalIgnoreCase);
Common.frmMain.Invoke(new Action(() =>
{
BLLCommon.extension.SetKey(templateName, originalCodeText, lastKey, true, out _);
}));
}
private bool DidRegisterValidate(Dictionary<string, string> content, out string errmsg)
{
errmsg = "";
......
......@@ -36,6 +36,7 @@ namespace SmartScan.SetControl.WPF
// 事件
public event EventHandler<string> DataUpdated;
public event EventHandler PrintLabelRequested;
public event EventHandler ReMatchRequested;//重新匹配
public event EventHandler Cherkfun;
public event EventHandler ISPrint;
......@@ -241,6 +242,7 @@ namespace SmartScan.SetControl.WPF
}
private Button printButton;
private Button skipButton;
private Button reMatchButton;
/// <summary>
/// 设置按钮
......@@ -354,6 +356,21 @@ namespace SmartScan.SetControl.WPF
};
// 添加结果TextBlock到容器
mainContainer.Children.Add(printButton);
// 重新匹配按钮(默认隐藏)
reMatchButton = new Button
{
Content = LanguageWwitchover.Dialog("NS_KetRight_ReMatch","重新匹配"),
Margin = new Thickness(0, 5, 0, 5),
Padding = new Thickness(10, 5, 10, 5),
Foreground = Brushes.White,
Height = 35,
//Width = 150, // 移除固定宽度,使其与打印按钮保持一致
Visibility = Visibility.Collapsed,
Name = "btnReMatch",
Template = template
};
reMatchButton.Click += ReMatchButton_Click;
mainContainer.Children.Add(reMatchButton);
// 添加按钮到容器
StackPanel resultAndSkipPanel = new StackPanel
{
......@@ -376,6 +393,28 @@ namespace SmartScan.SetControl.WPF
//ButtonsPanel.Children.Add(printButton);
}
private void ReMatchButton_Click(object sender, RoutedEventArgs e)
{
try
{ // 检查是否所有字段都为空
bool allFieldsEmpty = recognizedData.All(kvp => string.IsNullOrWhiteSpace(kvp.Value));
if (allFieldsEmpty)
{
string text = LanguageWwitchover.Dialog("ReMatchButtonNoData", "无法重新匹配,字段没有数据");
bool result = NeoAlertBox.Show("", text, AlertType.Warning, "NEO SCAN", true);
LogNet.log.Info("无法重新匹配,字段没有数据: " + JsonConvert.SerializeObject(recognizedData.Where(kvp => string.IsNullOrWhiteSpace(kvp.Value))));
if (!result)
return;
}
ReMatchRequested?.Invoke(this, EventArgs.Empty);
}
catch (Exception ex)
{
LogNet.log.Error("ReMatchButton_Click " + ex.ToString());
}
}
/// <summary>
/// 设置跳过按钮的可见性
......@@ -388,6 +427,13 @@ namespace SmartScan.SetControl.WPF
skipButton.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
}
}
public void SetReMatchButtonVisibility(bool isVisible)
{
if (reMatchButton != null)
{
reMatchButton.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
}
}
/// <summary>
/// 更新界面语言
/// </summary>
......@@ -409,6 +455,10 @@ namespace SmartScan.SetControl.WPF
{
skipButton.Content = LanguageWwitchover.Dialog("NS_KetRight_Skip", "跳过");
}
if (reMatchButton != null)
{
reMatchButton.Content = LanguageWwitchover.Dialog("NS_KetRight_ReMatch","重新匹配");
}
// 更新识别结果标签
UpdateRight();
......@@ -860,31 +910,6 @@ namespace SmartScan.SetControl.WPF
lbl_red.Text = LanguageWwitchover.Dialog("NS_KetRight_Red", "红色 - 无法识别或有问题");
//if (YU == "English")
//{
// YU = "en-US";
// lbl_Green.Text = "Green - Completely correct";
// lbl_yellow.Text = "Yellow - OCR recognition result,\r\n needs verification";
// lbl_red.Text = "Red -Unable to recognize or \r\n has issues";
//}
//else if (YU == "日语")
//{
// YU = "ja-JP";
// lbl_Green.Text = "緑色 - 完全正確";
// lbl_yellow.Text = "黄色 - OCR認識結果、検証が必要";
// lbl_red.Text = "赤色 - 識別不能または問題あり";
//}
//else
//{
// YU = "zh-CN";
// lbl_Green.Text = "绿色 - 完全正确";
// lbl_yellow.Text = "黄色 - OCR识别结果,需要验证";
// lbl_red.Text = "红色 - 无法识别或有问题";
//}
resultPanel.Children.Clear();
// 计算识别率
int totalFields = fieldValidStatus.Count;
......@@ -1149,7 +1174,7 @@ namespace SmartScan.SetControl.WPF
private void PrintLabel_Click(object sender, RoutedEventArgs e)
{
// 检查是否所有字段都为空
bool allFieldsEmpty = recognizedData.Any(kvp => string.IsNullOrWhiteSpace(kvp.Value));
bool allFieldsEmpty = recognizedData.All(kvp => string.IsNullOrWhiteSpace(kvp.Value));
if (allFieldsEmpty)
{
......
......@@ -679,7 +679,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>rem copy C:\Neotel\DLL\Halcon\halcondotnet.dll $(TargetDir)halcondotnet.dll
start $(TargetDir)</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!