Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit f88539ce
由
LN
编写于
2026-01-19 15:05:46 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
欧姆龙外部数据源多标题匹配功能修改。增加重新匹配按钮。
1 个父辈
7c33e71c
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
371 行增加
和
160 行删除
BLL/Config.cs
BLL/Extension/Item_General.cs
BLL/ExtraFileData.cs
BLL/PaddleOCRHelper.cs
SmartScan/Form/FrmLoading.cs
SmartScan/Form/FrmMain.cs
SmartScan/Language/NS100.xlsx
SmartScan/Language/en-US.lngres
SmartScan/Language/ja-JP.lngres
SmartScan/Language/jn-JS.lngres
SmartScan/Language/zh-CN.lngres
SmartScan/ScanWork.cs
SmartScan/SetControl/WPF/NS_KetRight.xaml.cs
SmartScan/SmartScan.csproj
BLL/Config.cs
查看文件 @
f88539c
...
...
@@ -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
;
...
...
BLL/Extension/Item_General.cs
查看文件 @
f88539c
...
...
@@ -232,7 +232,7 @@ namespace BLL
// 如果有字段更新,则再次调用OnKeySet更新WPF界面
LogNet
.
log
.
Info
(
$
"OnKeySet2"
);
OnKeySet
(
templateName
,
originalCode
,
key
,
hasMatch
);
OnKeySet
(
templateName
,
originalCode
,
key
,
hasMatch
);
if
(
lastKeys
==
null
&&
!
islast
&&
BLLCommon
.
config
.
CheckFunction
)
{
...
...
@@ -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)
...
...
@@ -285,54 +301,15 @@ namespace BLL
if
(!
updatereelid
(
key
,
out
errmsg
))
{
LogNet
.
log
.
Info
(
$
"updatereelid false"
);
return
false
;
}
// }
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
{
...
...
@@ -396,7 +331,7 @@ namespace BLL
{
string
text
=
Language
.
Dialog
(
"Waiting"
);
BLLCommon
.
extension
.
labelText
=
text
;
CheckText
(
text
);
CheckText
(
text
);
islast
=
false
;
}
...
...
@@ -407,7 +342,7 @@ namespace BLL
Application
.
DoEvents
();
...
...
@@ -702,10 +637,10 @@ namespace BLL
}
return
keyValues
;
}
private
void
PrintLabel
(
object
sender
,
EventArgs
e
)
{
LogNet
.
log
.
Info
(
"Enter PrintLabel Method: "
+
JsonConvert
.
SerializeObject
(
lastk
ey
));
if
(
lastk
ey
==
null
)
return
;
private
void
PrintLabel
(
Dictionary
<
string
,
string
>
printKey
)
{
LogNet
.
log
.
Info
(
"Enter PrintLabel Method: "
+
JsonConvert
.
SerializeObject
(
printK
ey
));
if
(
printK
ey
==
null
)
return
;
...
...
@@ -717,8 +652,8 @@ namespace BLL
// else
// lastkey.Add(extensions[i].Key, extensions[i].Control.Text);
//}
lastkey
=
UpdateLastKey
(
lastk
ey
);
LogNet
.
log
.
Info
(
"lastkey:"
+
JsonConvert
.
SerializeObject
(
lastk
ey
));
printKey
=
UpdateLastKey
(
printK
ey
);
LogNet
.
log
.
Info
(
"lastkey:"
+
JsonConvert
.
SerializeObject
(
printK
ey
));
#
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
)
{
lastk
ey
.
TryGetValue
(
item
,
out
string
value
);
printK
ey
.
TryGetValue
(
item
,
out
string
value
);
if
(
string
.
IsNullOrWhiteSpace
(
value
))
{
...
...
@@ -748,19 +683,20 @@ namespace BLL
#
region
点击打印按钮,
rid
内容为空时,生成
rid
if
(!
string
.
IsNullOrEmpty
(
config
.
ReelIDKeyWord
))
{
if
(
lastk
ey
.
ContainsKey
(
config
.
ReelIDKeyWord
))
if
(
printK
ey
.
ContainsKey
(
config
.
ReelIDKeyWord
))
{
string
rid
=
lastk
ey
[
config
.
ReelIDKeyWord
];
string
rid
=
printK
ey
[
config
.
ReelIDKeyWord
];
if
(
string
.
IsNullOrWhiteSpace
(
rid
))
{
var
Reelidstr
=
GetReelid
();
lastk
ey
[
config
.
ReelIDKeyWord
]
=
Reelidstr
;
printK
ey
[
config
.
ReelIDKeyWord
]
=
Reelidstr
;
}
}
}
#
endregion
Printing
?.
Invoke
(
lastk
ey
);
Printing
?.
Invoke
(
printK
ey
);
bool
close
=
ConfigHelper
.
Config
.
Get
(
"isprinclose"
,
false
);
if
(
close
)
{
...
...
@@ -772,7 +708,7 @@ namespace BLL
}
}
//进行追溯配置保存
SaveRetrospect
?.
Invoke
(
lastk
ey
);
SaveRetrospect
?.
Invoke
(
printK
ey
);
for
(
int
i
=
0
;
i
<
extensions
.
Count
;
i
++)
{
extensions
[
i
].
Control
.
BackColor
=
System
.
Drawing
.
Color
.
FromArgb
(
255
,
20
,
20
,
20
);
...
...
@@ -888,7 +824,7 @@ namespace BLL
{
LogNet
.
log
.
Error
(
$
"替换数据时出错:{ex.Message}"
);
}
}
}
//private void GetDataButtonClick(object sender, EventArgs e)
//{
...
...
@@ -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);
}
...
...
BLL/ExtraFileData.cs
查看文件 @
f88539c
using
BLL
;
using
ClosedXML.Excel
;
using
Model
;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
namespace
BLL
{
public
class
ExtraFileData
{
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
>
DataTitle
=
new
List
<
string
>();
public
static
void
Init
()
{
public
static
void
Init
()
{
var
ext
=
Path
.
GetExtension
(
Config
.
DataSource_FilePath
);
if
(
string
.
IsNullOrEmpty
(
ext
))
{
return
;
}
ext
=
ext
.
ToLower
();
ext
=
ext
.
ToLower
();
AllData
.
Clear
();
if
(
ext
==
".xlsx"
)
LoadXLSALlData
();
...
...
@@ -47,7 +49,7 @@ namespace BLL
{
var
ext
=
Path
.
GetExtension
(
Config
.
DataSource_FilePath
);
var
path
=
Path
.
GetDirectoryName
(
Config
.
DataSource_FilePath
);
files
=
Directory
.
GetFiles
(
path
,
"*"
+
ext
);
files
=
Directory
.
GetFiles
(
path
,
"*"
+
ext
);
}
else
{
...
...
@@ -58,7 +60,7 @@ namespace BLL
AllData
.
Clear
();
foreach
(
var
file
in
files
)
{
LogNet
.
log
.
Info
(
"数据源加载文件:"
+
file
);
LogNet
.
log
.
Info
(
"数据源加载文件:"
+
file
);
try
{
using
var
sm
=
new
StreamReader
(
file
,
Encoding
.
GetEncoding
(
Config
.
DataSource_Encoding
));
...
...
@@ -80,7 +82,7 @@ namespace BLL
keydata
=
datas
[
i
];
}
}
if
(!
string
.
IsNullOrEmpty
(
keydata
)
)
if
(!
string
.
IsNullOrEmpty
(
keydata
))
{
List
<
Dictionary
<
string
,
string
>>
keyList
=
new
List
<
Dictionary
<
string
,
string
>>()
{
};
if
(
AllData
.
ContainsKey
(
keydata
))
...
...
@@ -96,10 +98,11 @@ namespace BLL
DataTitle
.
Add
(
keydata
);
}
}
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
LogNet
.
log
.
Info
(
"数据源加载文件出错:"
+
ex
.
ToString
());
}
}
...
...
@@ -108,7 +111,7 @@ namespace BLL
public
static
List
<
string
>
ParseCSVFileTitle
(
string
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
));
var
titleline
=
sm
.
ReadLine
();
...
...
@@ -117,8 +120,10 @@ namespace BLL
}
public
static
void
LoadXLSALlData
()
{
if
(!
File
.
Exists
(
Config
.
DataSource_FilePath
))
{
public
static
void
LoadXLSALlData
()
{
if
(!
File
.
Exists
(
Config
.
DataSource_FilePath
))
{
return
;
//throw new FileNotFoundException(Config.DataSource_String);
}
...
...
@@ -162,7 +167,7 @@ namespace BLL
emptyrow
++;
}
}
if
(!
string
.
IsNullOrEmpty
(
keydata
))
{
List
<
Dictionary
<
string
,
string
>>
keyList
=
new
List
<
Dictionary
<
string
,
string
>>()
{
};
...
...
@@ -199,7 +204,7 @@ namespace BLL
if
(!
File
.
Exists
(
filename
))
return
titles
;
LogNet
.
log
.
Info
(
"filename:"
+
filename
);
LogNet
.
log
.
Info
(
"filename:"
+
filename
);
XLWorkbook
wb
=
new
XLWorkbook
(
filename
);
IXLWorksheet
ws
=
wb
.
Worksheet
(
1
);
for
(
int
i
=
1
;
i
<
50
;
i
++)
...
...
@@ -222,17 +227,19 @@ namespace BLL
}
public
static
Encoding
GetEncoding
(
string
coding
)
{
public
static
Encoding
GetEncoding
(
string
coding
)
{
try
{
return
Encoding
.
GetEncoding
(
coding
);
}
catch
{
catch
{
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
];
if
(
aExtraData
.
Count
==
1
)
...
...
@@ -247,10 +254,198 @@ namespace BLL
return
aExtraData
[
0
];
}
LogNet
.
log
.
Info
(
"匹配到数据源:"
+
dataKey
+
" 共有 "
+
aExtraData
.
Count
+
"条数据,弹框让用户选择"
);
LogNet
.
log
.
Info
(
"匹配到数据源:"
+
dataKey
+
" 共有 "
+
aExtraData
.
Count
+
"条数据,弹框让用户选择"
);
Dictionary
<
string
,
string
>
selecValue
=
DataSelectingEvent
?.
Invoke
(
dataKey
,
aExtraData
);
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
;
}
}
}
BLL/PaddleOCRHelper.cs
查看文件 @
f88539c
...
...
@@ -66,13 +66,21 @@ namespace BLL
}
[
HandleProcessCorruptedStateExceptions
]
public
static
string
StartCplusOcr
(
string
imgPath
)
public
static
string
StartCplusOcr
(
string
imgPath
)
{
LogNet
.
log
.
Error
(
"进入OcrGet请求"
);
string
json
=
Http
.
Get
(
$
"{baseUrl}?ver=cplus&imgPath={imgPath}"
);
LogNet
.
log
.
Error
(
$
"返回数据为:{json}"
);
Result
result
=
JsonConvert
.
DeserializeObject
<
Result
>(
json
);
return
result
?.
data
??
""
;
try
{
LogNet
.
log
.
Error
(
"进入OcrGet请求"
);
string
json
=
Http
.
Get
(
$
"{baseUrl}?ver=cplus&imgPath={imgPath}"
);
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
)
{
...
...
SmartScan/Form/FrmLoading.cs
查看文件 @
f88539c
...
...
@@ -33,7 +33,7 @@ namespace SmartScan
BLLCommon
.
config
.
SoftVersion
=
version
;
//BLL.Config.Backgrounder = back;
ExtraFileData
.
Init
();
BLLCommon
.
extraKey
=
ExtraFileData
.
Titles
;
BLLCommon
.
extraKey
=
ExtraFileData
.
Titles
;
Asa
.
FaceControl
.
Language
.
LoadPath
(
FilePath
.
LANGUAGE_DIR
);
LogNet
.
log
.
Debug
(
"加载语言文件夹:"
+
FilePath
.
LANGUAGE_DIR
);
Asa
.
FaceControl
.
Language
.
LoadLanguage
(
BLLCommon
.
config
.
Language
);
...
...
SmartScan/Form/FrmMain.cs
查看文件 @
f88539c
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
();
...
...
SmartScan/Language/NS100.xlsx
查看文件 @
f88539c
此文件类型无法预览
SmartScan/Language/en-US.lngres
查看文件 @
f88539c
...
...
@@ -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.
SmartScan/Language/ja-JP.lngres
查看文件 @
f88539c
...
...
@@ -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 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
SmartScan/Language/jn-JS.lngres
查看文件 @
f88539c
...
...
@@ -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 无法重新匹配,字段没有数据 再マッチングできません。フィールドにデータがありません。
SmartScan/Language/zh-CN.lngres
查看文件 @
f88539c
...
...
@@ -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 无法重新匹配,字段没有数据 无法重新匹配,字段没有数据
SmartScan/ScanWork.cs
查看文件 @
f88539c
...
...
@@ -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
();
...
...
@@ -158,7 +159,7 @@ namespace SmartScan
Common
.
frmMain
.
Showlogs
(
""
);
LogNet
.
log
.
Info
(
$
"WaitLabelRecheck:{WaitLabelRecheck},CheckFunction:{BLLCommon.config.CheckFunction}"
);
if
(
WaitLabelRecheck
&&
BLLCommon
.
config
.
CheckFunction
)
{
{
LoadingScreen
.
Instance
.
Hide
();
originalCodeText
=
Camera
.
GetBarCodeText
(
workCodeInfo
);
// 检查条码内容是否与文件中的内容匹配
...
...
@@ -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
=
""
;
...
...
SmartScan/SetControl/WPF/NS_KetRight.xaml.cs
查看文件 @
f88539c
...
...
@@ -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>
/// 设置按钮
...
...
@@ -347,13 +349,28 @@ namespace SmartScan.SetControl.WPF
printButton
.
Template
=
template
;
printButton
.
Click
+=
PrintLabel_Click
;
skipButton
.
Click
+=
SkipButton_Click
;
// 添加跳过按钮的事件处理
// 创建一个容器来存放所有元素
// 创建一个容器来存放所有元素
StackPanel
mainContainer
=
new
StackPanel
{
Margin
=
new
Thickness
(
0
,
0
,
0
,
10
)
};
// 添加结果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
.
A
ny
(
kvp
=>
string
.
IsNullOrWhiteSpace
(
kvp
.
Value
));
bool
allFieldsEmpty
=
recognizedData
.
A
ll
(
kvp
=>
string
.
IsNullOrWhiteSpace
(
kvp
.
Value
));
if
(
allFieldsEmpty
)
{
...
...
SmartScan/SmartScan.csproj
查看文件 @
f88539c
...
...
@@ -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!
Cancel
请
注册
或
登录
后发表评论