Commit f88539ce LN

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

1 个父辈 7c33e71c
...@@ -342,9 +342,12 @@ namespace BLL ...@@ -342,9 +342,12 @@ namespace BLL
public static MyConfig<string> DataSource_Encoding; public static MyConfig<string> DataSource_Encoding;
[MyConfigComment("数据源匹配Key")] [MyConfigComment("数据源匹配Key")]
public static MyConfig<string> DataSource_DataKey; public static MyConfig<string> DataSource_DataKey;
[MyConfigComment("数据源匹配Key_其他项")] [MyConfigComment("数据源匹配Key_其他项_关键字=标题")]
public static MyConfig<string[]> DataSource_DataKey_Others= new string[] { }; public static MyConfig<string[]> DataSource_DataKey_Others= new string[] { };
[MyConfigComment("数据源匹配_是否可以修改内容重新匹配")]
public static MyConfig<bool> DataSource_CanReMatch = false ;
[MyConfigComment("数据源列标题")] [MyConfigComment("数据源列标题")]
public static MyConfig<string> DataSource_DataTitle; public static MyConfig<string> DataSource_DataTitle;
......
...@@ -232,7 +232,7 @@ namespace BLL ...@@ -232,7 +232,7 @@ namespace BLL
// 如果有字段更新,则再次调用OnKeySet更新WPF界面 // 如果有字段更新,则再次调用OnKeySet更新WPF界面
LogNet.log.Info($"OnKeySet2"); LogNet.log.Info($"OnKeySet2");
OnKeySet(templateName, originalCode, key, hasMatch); OnKeySet(templateName, originalCode, key, hasMatch);
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction) if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
{ {
...@@ -272,6 +272,22 @@ namespace BLL ...@@ -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 (BLLCommon.config.CheckFunction)
//{ //{
// if (isFirstCapture) // if (isFirstCapture)
...@@ -285,54 +301,15 @@ namespace BLL ...@@ -285,54 +301,15 @@ namespace BLL
if (!updatereelid(key, out errmsg)) if (!updatereelid(key, out errmsg))
{ {
LogNet.log.Info($"updatereelid false"); LogNet.log.Info($"updatereelid false");
return false; return false;
} }
// } // }
if (extensions != null && !extensions[0].Control.InvokeRequired) 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"); LogNet.log.Info($"OnKeySet3");
OnKeySet(templateName, originalCode, key, hasMatch); OnKeySet(templateName, originalCode, key, hasMatch);
...@@ -345,50 +322,8 @@ namespace BLL ...@@ -345,50 +322,8 @@ namespace BLL
string text = Language.Dialog("Waiting"); string text = Language.Dialog("Waiting");
BLLCommon.extension.labelText = text; BLLCommon.extension.labelText = text;
CheckText(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; 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 else
{ {
...@@ -396,7 +331,7 @@ namespace BLL ...@@ -396,7 +331,7 @@ namespace BLL
{ {
string text = Language.Dialog("Waiting"); string text = Language.Dialog("Waiting");
BLLCommon.extension.labelText = text; BLLCommon.extension.labelText = text;
CheckText(text); CheckText(text);
islast = false; islast = false;
} }
...@@ -407,7 +342,7 @@ namespace BLL ...@@ -407,7 +342,7 @@ namespace BLL
Application.DoEvents(); Application.DoEvents();
...@@ -702,10 +637,10 @@ namespace BLL ...@@ -702,10 +637,10 @@ namespace BLL
} }
return keyValues; 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)); LogNet.log.Info("Enter PrintLabel Method: "+ JsonConvert.SerializeObject(printKey));
if (lastkey == null) return; if (printKey == null) return;
...@@ -717,8 +652,8 @@ namespace BLL ...@@ -717,8 +652,8 @@ namespace BLL
// else // else
// lastkey.Add(extensions[i].Key, extensions[i].Control.Text); // lastkey.Add(extensions[i].Key, extensions[i].Control.Text);
//} //}
lastkey = UpdateLastKey(lastkey); printKey = UpdateLastKey(printKey);
LogNet.log.Info("lastkey:" + JsonConvert.SerializeObject(lastkey)); LogNet.log.Info("lastkey:" + JsonConvert.SerializeObject(printKey));
#region 判断指定关键字是否存在内容 #region 判断指定关键字是否存在内容
List<string> strings = new List<string>(); List<string> strings = new List<string>();
string str = ConfigHelper.Config.Get("DataSource_ForceMatching", ""); string str = ConfigHelper.Config.Get("DataSource_ForceMatching", "");
...@@ -727,7 +662,7 @@ namespace BLL ...@@ -727,7 +662,7 @@ namespace BLL
string[] arr = str.Split(','); string[] arr = str.Split(',');
foreach (var item in arr) foreach (var item in arr)
{ {
lastkey.TryGetValue(item, out string value); printKey.TryGetValue(item, out string value);
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))
{ {
...@@ -748,19 +683,20 @@ namespace BLL ...@@ -748,19 +683,20 @@ namespace BLL
#region 点击打印按钮,rid内容为空时,生成rid #region 点击打印按钮,rid内容为空时,生成rid
if (!string.IsNullOrEmpty(config.ReelIDKeyWord)) 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)) if (string.IsNullOrWhiteSpace(rid))
{ {
var Reelidstr = GetReelid(); var Reelidstr = GetReelid();
lastkey[config.ReelIDKeyWord] = Reelidstr; printKey[config.ReelIDKeyWord] = Reelidstr;
} }
} }
} }
#endregion #endregion
Printing?.Invoke(lastkey); Printing?.Invoke(printKey);
bool close = ConfigHelper.Config.Get("isprinclose", false); bool close = ConfigHelper.Config.Get("isprinclose", false);
if (close) if (close)
{ {
...@@ -772,7 +708,7 @@ namespace BLL ...@@ -772,7 +708,7 @@ namespace BLL
} }
} }
//进行追溯配置保存 //进行追溯配置保存
SaveRetrospect?.Invoke(lastkey); SaveRetrospect?.Invoke(printKey);
for (int i = 0; i < extensions.Count; i++) for (int i = 0; i < extensions.Count; i++)
{ {
extensions[i].Control.BackColor = System.Drawing.Color.FromArgb(255, 20, 20, 20); extensions[i].Control.BackColor = System.Drawing.Color.FromArgb(255, 20, 20, 20);
...@@ -888,7 +824,7 @@ namespace BLL ...@@ -888,7 +824,7 @@ namespace BLL
{ {
LogNet.log.Error($"替换数据时出错:{ex.Message}"); LogNet.log.Error($"替换数据时出错:{ex.Message}");
} }
} }
//private void GetDataButtonClick(object sender, EventArgs e) //private void GetDataButtonClick(object sender, EventArgs e)
//{ //{
...@@ -952,7 +888,8 @@ namespace BLL ...@@ -952,7 +888,8 @@ namespace BLL
//if (config.AutoPrint && match) //if (config.AutoPrint && match)
{ {
isprint = true; isprint = true;
PrintLabel(true, EventArgs.Empty); //PrintLabel(true, EventArgs.Empty);
PrintLabel(key);
} }
//bool close = ConfigHelper.Config.Get("isprinclose", false); //bool close = ConfigHelper.Config.Get("isprinclose", false);
} }
......
using BLL; using BLL;
using ClosedXML.Excel; using ClosedXML.Excel;
using Model; using Model;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BLL namespace BLL
{ {
public class ExtraFileData public class ExtraFileData
{ {
public delegate Dictionary<string, string> DataSelectDelegate(string datakey, List<Dictionary<string, string>> dataList); public delegate Dictionary<string, string> DataSelectDelegate(string datakey, List<Dictionary<string, string>> dataList);
public static event DataSelectDelegate DataSelectingEvent; public static event DataSelectDelegate DataSelectingEvent;
public static Dictionary<string, List< Dictionary<string, string>>> AllData = new Dictionary<string,List< Dictionary<string, string>>>(); public static Dictionary<string, List<Dictionary<string, string>>> AllData = new Dictionary<string, List<Dictionary<string, string>>>();
public static List<string> Titles = new List<string>(); public static List<string> Titles = new List<string>();
public static List<string> DataTitle = new List<string>(); public static List<string> DataTitle = new List<string>();
public static void Init() { public static void Init()
{
var ext = Path.GetExtension(Config.DataSource_FilePath); var ext = Path.GetExtension(Config.DataSource_FilePath);
if (string.IsNullOrEmpty(ext)) if (string.IsNullOrEmpty(ext))
{ {
return; return;
} }
ext = ext.ToLower(); ext = ext.ToLower();
AllData.Clear(); AllData.Clear();
if (ext == ".xlsx") if (ext == ".xlsx")
LoadXLSALlData(); LoadXLSALlData();
...@@ -47,7 +49,7 @@ namespace BLL ...@@ -47,7 +49,7 @@ namespace BLL
{ {
var ext = Path.GetExtension(Config.DataSource_FilePath); var ext = Path.GetExtension(Config.DataSource_FilePath);
var path = Path.GetDirectoryName(Config.DataSource_FilePath); var path = Path.GetDirectoryName(Config.DataSource_FilePath);
files=Directory.GetFiles(path, "*" + ext); files = Directory.GetFiles(path, "*" + ext);
} }
else else
{ {
...@@ -58,7 +60,7 @@ namespace BLL ...@@ -58,7 +60,7 @@ namespace BLL
AllData.Clear(); AllData.Clear();
foreach (var file in files) foreach (var file in files)
{ {
LogNet.log.Info("数据源加载文件:"+file); LogNet.log.Info("数据源加载文件:" + file);
try try
{ {
using var sm = new StreamReader(file, Encoding.GetEncoding(Config.DataSource_Encoding)); using var sm = new StreamReader(file, Encoding.GetEncoding(Config.DataSource_Encoding));
...@@ -80,7 +82,7 @@ namespace BLL ...@@ -80,7 +82,7 @@ namespace BLL
keydata = datas[i]; keydata = datas[i];
} }
} }
if (!string.IsNullOrEmpty(keydata) ) if (!string.IsNullOrEmpty(keydata))
{ {
List<Dictionary<string, string>> keyList = new List<Dictionary<string, string>>() { }; List<Dictionary<string, string>> keyList = new List<Dictionary<string, string>>() { };
if (AllData.ContainsKey(keydata)) if (AllData.ContainsKey(keydata))
...@@ -96,10 +98,11 @@ namespace BLL ...@@ -96,10 +98,11 @@ namespace BLL
DataTitle.Add(keydata); DataTitle.Add(keydata);
} }
} }
} }
} }
catch(Exception ex) { catch (Exception ex)
{
LogNet.log.Info("数据源加载文件出错:" + ex.ToString()); LogNet.log.Info("数据源加载文件出错:" + ex.ToString());
} }
} }
...@@ -108,7 +111,7 @@ namespace BLL ...@@ -108,7 +111,7 @@ namespace BLL
public static List<string> ParseCSVFileTitle(string filename) public static List<string> ParseCSVFileTitle(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
return new List<string>() ; return new List<string>();
using var sm = new StreamReader(filename, Encoding.GetEncoding(Config.DataSource_Encoding.Val)); using var sm = new StreamReader(filename, Encoding.GetEncoding(Config.DataSource_Encoding.Val));
var titleline = sm.ReadLine(); var titleline = sm.ReadLine();
...@@ -117,8 +120,10 @@ namespace BLL ...@@ -117,8 +120,10 @@ namespace BLL
} }
public static void LoadXLSALlData() { public static void LoadXLSALlData()
if (!File.Exists(Config.DataSource_FilePath)) { {
if (!File.Exists(Config.DataSource_FilePath))
{
return; return;
//throw new FileNotFoundException(Config.DataSource_String); //throw new FileNotFoundException(Config.DataSource_String);
} }
...@@ -162,7 +167,7 @@ namespace BLL ...@@ -162,7 +167,7 @@ namespace BLL
emptyrow++; emptyrow++;
} }
} }
if (!string.IsNullOrEmpty(keydata)) if (!string.IsNullOrEmpty(keydata))
{ {
List<Dictionary<string, string>> keyList = new List<Dictionary<string, string>>() { }; List<Dictionary<string, string>> keyList = new List<Dictionary<string, string>>() { };
...@@ -199,7 +204,7 @@ namespace BLL ...@@ -199,7 +204,7 @@ namespace BLL
if (!File.Exists(filename)) if (!File.Exists(filename))
return titles; return titles;
LogNet.log.Info("filename:"+ filename); LogNet.log.Info("filename:" + filename);
XLWorkbook wb = new XLWorkbook(filename); XLWorkbook wb = new XLWorkbook(filename);
IXLWorksheet ws = wb.Worksheet(1); IXLWorksheet ws = wb.Worksheet(1);
for (int i = 1; i < 50; i++) for (int i = 1; i < 50; i++)
...@@ -222,17 +227,19 @@ namespace BLL ...@@ -222,17 +227,19 @@ namespace BLL
} }
public static Encoding GetEncoding(string coding) { public static Encoding GetEncoding(string coding)
{
try try
{ {
return Encoding.GetEncoding(coding); return Encoding.GetEncoding(coding);
} }
catch { catch
{
return Encoding.UTF8; return Encoding.UTF8;
} }
} }
public static Dictionary<string, string> GetSelectDataSource(string dataKey) public static Dictionary<string, string> GetSelectDataSource(string dataKey)
{ {
List<Dictionary<string, string>> aExtraData = ExtraFileData.AllData[dataKey]; List<Dictionary<string, string>> aExtraData = ExtraFileData.AllData[dataKey];
if (aExtraData.Count == 1) if (aExtraData.Count == 1)
...@@ -247,10 +254,198 @@ namespace BLL ...@@ -247,10 +254,198 @@ namespace BLL
return aExtraData[0]; return aExtraData[0];
} }
LogNet.log.Info("匹配到数据源:" + dataKey+" 共有 "+aExtraData.Count+"条数据,弹框让用户选择"); LogNet.log.Info("匹配到数据源:" + dataKey + " 共有 " + aExtraData.Count + "条数据,弹框让用户选择");
Dictionary<string, string> selecValue = DataSelectingEvent?.Invoke(dataKey, aExtraData); Dictionary<string, string> selecValue = DataSelectingEvent?.Invoke(dataKey, aExtraData);
return selecValue; return selecValue;
} }
} }
public static bool hasFileData()
{
return AllData != null && AllData.Count > 0;
}
private static Dictionary<string, string> GetOtherKeys()
{
Dictionary<string, string> otherKeys = new Dictionary<string, string>();
try
{
if (Config.DataSource_DataKey_Others.Val != null && Config.DataSource_DataKey_Others.Val.Length > 0)
{
string[] keys = Config.DataSource_DataKey_Others.Val;
foreach (string key in keys)
{
bool add = false;
if (key.Contains("="))
{
string[] paramArray = key.Split('=');
if (paramArray.Length == 2)
{
otherKeys.Add(paramArray[0], paramArray[1]);
add = true;
}
}
if (!add)
{
otherKeys.Add(key, key);
}
}
}
}
catch (Exception ex)
{
LogNet.log.Info("GetOtherKeys 获取其他字段出错:" + ex.ToString());
}
return otherKeys;
}
/// <summary>
/// 匹配数据源
/// </summary>
/// <param name="key"></param>
/// <param name="findOk"></param>
/// <returns></returns>
public static Dictionary<string, string> MatchFileData(Dictionary<string, string> key, out bool findOk)
{
findOk = false;
try
{
//使用key填充时,请处理字段开头的<OCR>字段
//查询excel数据填充
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;
Dictionary<string, string> otherKeys = GetOtherKeys();
//foreach (var d in extraData)
//{
// if (!string.IsNullOrEmpty(d.Value))
// key[d.Key] = d.Value;
//}
key = UpdateData(key, extraData, otherKeys);
LogNet.log.Info("匹配到数据源:" + Config.DataSource_DataKey + "=" + CleanData + " 数据: " + JsonConvert.SerializeObject(extraData));
return key;
}
}
if (!findOk && Config.DataSource_DataKey_Others.Val != null && Config.DataSource_DataKey_Others.Val.Length > 0)
{
Dictionary<string, string> otherKeys = GetOtherKeys();
foreach (string oKey in otherKeys.Keys)
{
if (key.ContainsKey(oKey))
{
string CleanData = key[oKey].Replace("<OCR>", "");
if (String.IsNullOrEmpty(CleanData))
{
continue;
}
string titleValue = otherKeys[oKey];
//循环所有数据
if (titleValue == Config.DataSource_DataTitle && 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;
//}
key = UpdateData(key, extraData, otherKeys);
LogNet.log.Info("匹配到数据源:" + titleValue + "=" + CleanData + " 数据: " + JsonConvert.SerializeObject(extraData));
break;
}
else
{
List<Dictionary<string, string>> findData = new List<Dictionary<string, string>>();
//查找其他列
foreach (List<Dictionary<string, string>> sourceData in AllData.Values)
{
foreach (Dictionary<string, string> data in sourceData)
{
if (data.ContainsKey(titleValue) && data[titleValue] == CleanData)
{
findData.Add(data);
}
}
}
if (findData.Count > 0)
{
var findDataMap = new Dictionary<string, string>();
if (findData.Count == 1 || DataSelectingEvent == null)
{
findOk = true;
findDataMap = findData[0];
LogNet.log.Info("匹配到数据源:" + titleValue + "=" + CleanData + " 共有 " + 1 + "条数据: " + JsonConvert.SerializeObject(findData[0]));
}
else
{
LogNet.log.Info("匹配到数据源:" + titleValue + "=" + CleanData + " 共有 " + findData.Count + "条数据,弹框让用户选择");
findDataMap = DataSelectingEvent?.Invoke(titleValue + "=" + CleanData, findData);
if (findDataMap != null && findDataMap.Count > 0)
{
findOk = true;
}
}
if (findOk)
{
key= UpdateData(key, findDataMap, otherKeys);
}
}
}
}
}
}
}
catch (Exception ex)
{
LogNet.log.Error("MatchFileData 出错:" + ex.ToString());
}
return key;
}
private static Dictionary<string,string> UpdateData(Dictionary<string, string> key,Dictionary<string,string> findDataMap,Dictionary<string,string> otherKeys)
{
Dictionary<string, string> titleKey = new Dictionary<string, string>();
foreach (string otherKey in otherKeys.Keys)
{
string value = otherKeys[otherKey];
titleKey[value] = otherKey;
}
foreach (var d in findDataMap)
{
if (!string.IsNullOrEmpty(d.Value))
{
if (titleKey.ContainsKey(d.Key))
{
string softKey = titleKey[d.Key];
key[softKey] = d.Value;
}
else
{
key[d.Key] = d.Value;
}
}
}
return key;
}
} }
} }
...@@ -66,13 +66,21 @@ namespace BLL ...@@ -66,13 +66,21 @@ namespace BLL
} }
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static string StartCplusOcr(string imgPath) public static string StartCplusOcr(string imgPath)
{ {
LogNet.log.Error("进入OcrGet请求"); try
string json=Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}"); {
LogNet.log.Error($"返回数据为:{json}"); LogNet.log.Error("进入OcrGet请求");
Result result= JsonConvert.DeserializeObject<Result>(json); string json = Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}");
return result?.data??""; LogNet.log.Error($"返回数据为:{json}");
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) public static string StartPythonOcr(string imgPath)
{ {
......
...@@ -33,7 +33,7 @@ namespace SmartScan ...@@ -33,7 +33,7 @@ namespace SmartScan
BLLCommon.config.SoftVersion = version; BLLCommon.config.SoftVersion = version;
//BLL.Config.Backgrounder = back; //BLL.Config.Backgrounder = back;
ExtraFileData.Init(); ExtraFileData.Init();
BLLCommon.extraKey = ExtraFileData.Titles; BLLCommon.extraKey = ExtraFileData.Titles;
Asa.FaceControl.Language.LoadPath(FilePath.LANGUAGE_DIR); Asa.FaceControl.Language.LoadPath(FilePath.LANGUAGE_DIR);
LogNet.log.Debug("加载语言文件夹:" + FilePath.LANGUAGE_DIR); LogNet.log.Debug("加载语言文件夹:" + FilePath.LANGUAGE_DIR);
Asa.FaceControl.Language.LoadLanguage(BLLCommon.config.Language); Asa.FaceControl.Language.LoadLanguage(BLLCommon.config.Language);
......
using Asa.FaceControl; using Asa.FaceControl;
using BLL; using BLL;
using HandyControl.Tools.Extension; using HandyControl.Tools.Extension;
using Model; using Model;
...@@ -432,6 +432,7 @@ namespace SmartScan ...@@ -432,6 +432,7 @@ namespace SmartScan
wpfControl = new NS_KetRight(); wpfControl = new NS_KetRight();
// 订阅打印标签事件 // 订阅打印标签事件
wpfControl.PrintLabelRequested += WpfControl_PrintLabelRequested; wpfControl.PrintLabelRequested += WpfControl_PrintLabelRequested;
wpfControl.ReMatchRequested += WpfControl_ReMatchRequested;
wpfControl.Cherkfun += WpfControl_Cherkfun; wpfControl.Cherkfun += WpfControl_Cherkfun;
wpfControl.ISPrint += WpfControl_ISPrint; ; wpfControl.ISPrint += WpfControl_ISPrint; ;
// 创建 ElementHost 来托管 WPF 控件 // 创建 ElementHost 来托管 WPF 控件
...@@ -523,6 +524,12 @@ namespace SmartScan ...@@ -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() private List<string> GetRequiredFields()
{ {
// 返回所需的字段列表 // 返回所需的字段列表
...@@ -914,6 +921,16 @@ namespace SmartScan ...@@ -914,6 +921,16 @@ namespace SmartScan
wpfControl.SetSkipButtonVisibility(false); wpfControl.SetSkipButtonVisibility(false);
return; return;
} }
if (text == "ReMatch_Show")
{
wpfControl.SetReMatchButtonVisibility(true);
return;
}
if (text == "ReMatch_Hide")
{
wpfControl.SetReMatchButtonVisibility(false);
return;
}
if (text == "OK") if (text == "OK")
{ {
wpfControl.SetResultOK(); wpfControl.SetResultOK();
......
...@@ -460,5 +460,7 @@ Dialog_NoKeywordSelected 未选择关键字! No keyword selected! ...@@ -460,5 +460,7 @@ Dialog_NoKeywordSelected 未选择关键字! No keyword selected!
Dialog_SelectDatasetTitle 数据集选择 Data Set Selection Dialog_SelectDatasetTitle 数据集选择 Data Set Selection
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} matched multiple rows of data. Please select: Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} matched multiple rows of data. Please select:
Dialog_WPF_Ok 确定 SURE 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 在界面中显示的名称 インターフェースに表示され ...@@ -376,7 +376,7 @@ NS_KW_name 在界面中显示的名称 インターフェースに表示され
NS_KW_ID 唯一键自增 ユニークキー自動増分 NS_KW_ID 唯一键自增 ユニークキー自動増分
LblContent 生成条件 生成条件 LblContent 生成条件 生成条件
LblPrefix 开头字符 先頭キャラクタ LblPrefix 开头字符 先頭キャラクタ
LblPostfix 结尾字符 先頭キャラクタ LblPostfix 结尾字符 末尾キャラクタ
LblPlaces 数字位数 数字桁数 LblPlaces 数字位数 数字桁数
NS_KW_WEISHU 位数不足前面补0 桁数不足の際、前に0を補完 NS_KW_WEISHU 位数不足前面补0 桁数不足の際、前に0を補完
NS_KW_H 标准字段 標準フィールド NS_KW_H 标准字段 標準フィールド
...@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,, ...@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,,
FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,, FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,,
Dialog_About_About 关于 About 微软雅黑,12,, Dialog_About_About 关于 About 微软雅黑,12,,
Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,, Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,,
Dialog_Using_OCR_Result 是否使用OCR识别结果? OCR の認識結果を使用しますか
Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか? Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか?
Dialog_Waiting 等待中 待機中 Dialog_Waiting 等待中 待機中
Dialog_WPFWorkMode_Printer 打印机 プリンター Dialog_WPFWorkMode_Printer 打印机 プリンター
...@@ -527,4 +528,6 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ ...@@ -527,4 +528,6 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ
Dialog_SelectDatasetTitle 数据集选择 データセット選択 Dialog_SelectDatasetTitle 数据集选择 データセット選択
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください
Dialog_WPF_Ok 确定 確認 Dialog_WPF_Ok 确定 確認
Dialog_NS_KetRight_ReMatch 重新匹配 再マッチング
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
...@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,, ...@@ -484,6 +484,7 @@ FrmSet_LblFieldSize 用紙サイズ 用紙サイズ 微软雅黑,12,,
FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,, FrmSet_pnlPrintTmpLstOp ラベルテンプレート操作 ラベルテンプレート操作 微软雅黑,12,,
Dialog_About_About 关于 About 微软雅黑,12,, Dialog_About_About 关于 About 微软雅黑,12,,
Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,, Dialog_About_mrs 物料注册系统 材料登録システム 微软雅黑,12,,
Dialog_Using_OCR_Result 是否使用OCR识别结果? OCR の認識結果を使用しますか
Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか? Dialog_SkipOperation 是否跳过此操作? この操作をスキップしますか?
Dialog_Waiting 等待中 待機中 Dialog_Waiting 等待中 待機中
Dialog_WPFWorkMode_Printer 打印机 プリンター Dialog_WPFWorkMode_Printer 打印机 プリンター
...@@ -527,5 +528,7 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ ...@@ -527,5 +528,7 @@ NoKeywordSelected 未选择关键字! キーワードが選択されていませ
Dialog_SelectDatasetTitle 数据集选择 データセット選択 Dialog_SelectDatasetTitle 数据集选择 データセット選択
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 複数行のデータがマッチしました。選択してください
Dialog_WPF_Ok 确定 確認 Dialog_WPF_Ok 确定 確認
Dialog_NS_KetRight_ReMatch 重新匹配 再マッチング
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
...@@ -517,6 +517,7 @@ FrmSet_LblFilestatus 文件状态: 文件状态: Arial,12,, ...@@ -517,6 +517,7 @@ FrmSet_LblFilestatus 文件状态: 文件状态: Arial,12,,
FrmSet_LblContent 标签数据源 标签数据源 Arial,12,, FrmSet_LblContent 标签数据源 标签数据源 Arial,12,,
Dialog_About_About 关于 关于 Dialog_About_About 关于 关于
Dialog_About_mrs 物料注册系统 物料注册系统 Dialog_About_mrs 物料注册系统 物料注册系统
Dialog_Using_OCR_Result 是否使用OCR识别结果? 是否使用OCR识别结果?
Dialog_NS_KetRight_PrintLabel 打印标签 打印标签 Dialog_NS_KetRight_PrintLabel 打印标签 打印标签
Dialog_NS_KetRight_Skip 跳过 跳过 Dialog_NS_KetRight_Skip 跳过 跳过
Dialog_NS_KetRight_Title 元件信息 元件信息 Dialog_NS_KetRight_Title 元件信息 元件信息
...@@ -556,5 +557,6 @@ Dialog_NoValidParametersAvailable 没有可用的打印参数? 没有可用的 ...@@ -556,5 +557,6 @@ Dialog_NoValidParametersAvailable 没有可用的打印参数? 没有可用的
Dialog_NoKeywordSelected 未选择关键字! 未选择关键字! Dialog_NoKeywordSelected 未选择关键字! 未选择关键字!
Dialog_SelectDatasetTitle 数据集选择 数据集选择 Dialog_SelectDatasetTitle 数据集选择 数据集选择
Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 匹配到多行数据,请选择: Dialog_SelectDatasetMessage {0} 匹配到多行数据,请选择: {0} 匹配到多行数据,请选择:
Dialog_WPF_Ok 确定 确定 Dialog_NS_KetRight_ReMatch 重新匹配 重新匹配
Dialog_ReMatchButtonNoData 无法重新匹配,字段没有数据 无法重新匹配,字段没有数据
...@@ -151,6 +151,7 @@ namespace SmartScan ...@@ -151,6 +151,7 @@ namespace SmartScan
{ {
AddCodeCenter(); AddCodeCenter();
}); });
CheckText("ReMatch_Hide");//隐藏二次匹配按钮。
LogNet.log.Info($"获取图片耗时{reckontime.ElapsedMilliseconds}ms"); LogNet.log.Info($"获取图片耗时{reckontime.ElapsedMilliseconds}ms");
//Common.frmMain.SetWaittingMsg(Language.Dialog("MaterialTemplateMatching"),5);//模版匹配... //Common.frmMain.SetWaittingMsg(Language.Dialog("MaterialTemplateMatching"),5);//模版匹配...
reckontime.Restart(); reckontime.Restart();
...@@ -158,7 +159,7 @@ namespace SmartScan ...@@ -158,7 +159,7 @@ namespace SmartScan
Common.frmMain.Showlogs(""); Common.frmMain.Showlogs("");
LogNet.log.Info($"WaitLabelRecheck:{WaitLabelRecheck},CheckFunction:{BLLCommon.config.CheckFunction}"); LogNet.log.Info($"WaitLabelRecheck:{WaitLabelRecheck},CheckFunction:{BLLCommon.config.CheckFunction}");
if (WaitLabelRecheck && BLLCommon.config.CheckFunction) if (WaitLabelRecheck && BLLCommon.config.CheckFunction)
{ {
LoadingScreen.Instance.Hide(); LoadingScreen.Instance.Hide();
originalCodeText = Camera.GetBarCodeText(workCodeInfo); originalCodeText = Camera.GetBarCodeText(workCodeInfo);
// 检查条码内容是否与文件中的内容匹配 // 检查条码内容是否与文件中的内容匹配
...@@ -235,6 +236,21 @@ namespace SmartScan ...@@ -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) private bool DidRegisterValidate(Dictionary<string, string> content, out string errmsg)
{ {
errmsg = ""; errmsg = "";
......
...@@ -36,6 +36,7 @@ namespace SmartScan.SetControl.WPF ...@@ -36,6 +36,7 @@ namespace SmartScan.SetControl.WPF
// 事件 // 事件
public event EventHandler<string> DataUpdated; public event EventHandler<string> DataUpdated;
public event EventHandler PrintLabelRequested; public event EventHandler PrintLabelRequested;
public event EventHandler ReMatchRequested;//重新匹配
public event EventHandler Cherkfun; public event EventHandler Cherkfun;
public event EventHandler ISPrint; public event EventHandler ISPrint;
...@@ -241,6 +242,7 @@ namespace SmartScan.SetControl.WPF ...@@ -241,6 +242,7 @@ namespace SmartScan.SetControl.WPF
} }
private Button printButton; private Button printButton;
private Button skipButton; private Button skipButton;
private Button reMatchButton;
/// <summary> /// <summary>
/// 设置按钮 /// 设置按钮
...@@ -347,13 +349,28 @@ namespace SmartScan.SetControl.WPF ...@@ -347,13 +349,28 @@ namespace SmartScan.SetControl.WPF
printButton.Template = template; printButton.Template = template;
printButton.Click += PrintLabel_Click; printButton.Click += PrintLabel_Click;
skipButton.Click += SkipButton_Click; // 添加跳过按钮的事件处理 skipButton.Click += SkipButton_Click; // 添加跳过按钮的事件处理
// 创建一个容器来存放所有元素 // 创建一个容器来存放所有元素
StackPanel mainContainer = new StackPanel StackPanel mainContainer = new StackPanel
{ {
Margin = new Thickness(0, 0, 0, 10) Margin = new Thickness(0, 0, 0, 10)
}; };
// 添加结果TextBlock到容器 // 添加结果TextBlock到容器
mainContainer.Children.Add(printButton); 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 StackPanel resultAndSkipPanel = new StackPanel
{ {
...@@ -376,6 +393,28 @@ namespace SmartScan.SetControl.WPF ...@@ -376,6 +393,28 @@ namespace SmartScan.SetControl.WPF
//ButtonsPanel.Children.Add(printButton); //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> /// <summary>
/// 设置跳过按钮的可见性 /// 设置跳过按钮的可见性
...@@ -388,6 +427,13 @@ namespace SmartScan.SetControl.WPF ...@@ -388,6 +427,13 @@ namespace SmartScan.SetControl.WPF
skipButton.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed; skipButton.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
} }
} }
public void SetReMatchButtonVisibility(bool isVisible)
{
if (reMatchButton != null)
{
reMatchButton.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
}
}
/// <summary> /// <summary>
/// 更新界面语言 /// 更新界面语言
/// </summary> /// </summary>
...@@ -409,6 +455,10 @@ namespace SmartScan.SetControl.WPF ...@@ -409,6 +455,10 @@ namespace SmartScan.SetControl.WPF
{ {
skipButton.Content = LanguageWwitchover.Dialog("NS_KetRight_Skip", "跳过"); skipButton.Content = LanguageWwitchover.Dialog("NS_KetRight_Skip", "跳过");
} }
if (reMatchButton != null)
{
reMatchButton.Content = LanguageWwitchover.Dialog("NS_KetRight_ReMatch","重新匹配");
}
// 更新识别结果标签 // 更新识别结果标签
UpdateRight(); UpdateRight();
...@@ -860,31 +910,6 @@ namespace SmartScan.SetControl.WPF ...@@ -860,31 +910,6 @@ namespace SmartScan.SetControl.WPF
lbl_red.Text = LanguageWwitchover.Dialog("NS_KetRight_Red", "红色 - 无法识别或有问题"); 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(); resultPanel.Children.Clear();
// 计算识别率 // 计算识别率
int totalFields = fieldValidStatus.Count; int totalFields = fieldValidStatus.Count;
...@@ -1149,7 +1174,7 @@ namespace SmartScan.SetControl.WPF ...@@ -1149,7 +1174,7 @@ namespace SmartScan.SetControl.WPF
private void PrintLabel_Click(object sender, RoutedEventArgs e) 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) if (allFieldsEmpty)
{ {
......
...@@ -679,7 +679,7 @@ ...@@ -679,7 +679,7 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>rem copy C:\Neotel\DLL\Halcon\halcondotnet.dll $(TargetDir)halcondotnet.dll <PostBuildEvent>
start $(TargetDir)</PostBuildEvent> </PostBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!