Commit 01fa4104 张东亮

1

1 个父辈 25815d1d
......@@ -326,6 +326,8 @@ namespace BLL
public static MyConfig<bool> DataSource_Recursive;
[MyConfigComment("是否启用OCR")]
public static MyConfig<bool> Func_EnabledOCR=true;
[MyConfigComment("RI自动生成时是否添加编号")]
public static MyConfig<bool> AutoRIGenID = false;
//[MyConfigComment("是否启用飞浆OCR识别")]
//public static MyConfig<bool> UsePaddleOCR = true;
......
......@@ -53,7 +53,7 @@ namespace BLL
static bool mesResult = false;
Dictionary<string, string> lastkey = null;
//读码后第一步
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch,out string errmsg)
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
{
errmsg = "";
lastkey = key;
......@@ -77,13 +77,14 @@ namespace BLL
else
key.Add(config.ReelIDKeyWord, Reelidstr);
}
if (extensions !=null && !extensions[0].Control.InvokeRequired)
if (extensions != null && !extensions[0].Control.InvokeRequired)
{
if (key.ContainsKey(Config.DataSource_DataKey) && ExtraFileData.AllData.ContainsKey(key[Config.DataSource_DataKey]))
{
if (key.ContainsKey(Config.DataSource_DataKey) && ExtraFileData.AllData.ContainsKey(key[Config.DataSource_DataKey])) {
var extraData = ExtraFileData.AllData[key[Config.DataSource_DataKey]];
foreach (var d in extraData)
{
key[d.Key]=d.Value;
key[d.Key] = d.Value;
}
}
......@@ -94,7 +95,7 @@ namespace BLL
extensions[i].Control.Text = key[extensions[i].Key];
}
}
if (!updatereelid(key,out errmsg))
if (!updatereelid(key, out errmsg))
return false;
Application.DoEvents();
......@@ -106,14 +107,16 @@ namespace BLL
PrintLabel(null, EventArgs.Empty);
}
}
else {
else
{
//PrintLabel(null, EventArgs.Empty);
}
SaveRetrospect?.Invoke(key);
return true;
}
bool updatereelid(Dictionary<string, string> key,out string errmsg) {
bool updatereelid(Dictionary<string, string> key, out string errmsg)
{
errmsg = "";
if (!string.IsNullOrEmpty(config.HttpReelID))
{
......@@ -124,7 +127,7 @@ namespace BLL
}
//key["ReelID"] = newid;
}
if (extensions!=null && !extensions[0].Control.InvokeRequired)
if (extensions != null && !extensions[0].Control.InvokeRequired)
{
for (int i = 0; i < extensions.Count; i++)
{
......@@ -159,14 +162,16 @@ namespace BLL
string[] keys = ObjConversion.StrGetKey(matchID);
for (int i = 0; i < keys.Length; i++)
{
if (keys[i].ToLower().StartsWith("datetime")) {
if (keys[i].ToLower().StartsWith("datetime"))
{
string ov = string.Format("[{0}]", keys[i]);
var d = keys[i].Split(':');
if (d.Length == 2)
{
matchID = matchID.Replace(ov, DateTime.Now.ToString(d[1]));
}
else {
else
{
matchID = matchID.Replace(ov, DateTime.Now.ToString());
}
continue;
......@@ -180,11 +185,14 @@ namespace BLL
//SaveAddReelID();
var reelID = ReadReelID();
//填充0
string text = matchPrefix+ matchID;
string text = matchPrefix + matchID;
if (Config.AutoRIGenID)
{
if (matchFill)
text += string.Format("{0:d" + matchPlace + "}", reelID);
else
text += reelID.ToString();
}
text += matchPostfix;
return text;
}
......@@ -195,8 +203,9 @@ namespace BLL
try
{
var reelidfile = FilePath.CONFIG_REELID;
if (config.ReelIDAutoResetByDate) {
Directory.CreateDirectory(reelidfile+"_dir");
if (config.ReelIDAutoResetByDate)
{
Directory.CreateDirectory(reelidfile + "_dir");
reelidfile = Path.Combine(FilePath.CONFIG_REELID + "_dir", DateTime.Now.ToString("yyyyMMdd"));
}
if (File.Exists(reelidfile))
......@@ -222,8 +231,9 @@ namespace BLL
return reelID;
}
private void GetHttpReelID(object sender, EventArgs e) {
updatereelid(lastkey,out _);
private void GetHttpReelID(object sender, EventArgs e)
{
updatereelid(lastkey, out _);
}
private void PrintLabel(object sender, EventArgs e)
{
......@@ -243,12 +253,13 @@ namespace BLL
Printing?.Invoke(lastkey);
}
private bool GetHttpReelID(Dictionary<string, string> key,out string errmsg)
private bool GetHttpReelID(Dictionary<string, string> key, out string errmsg)
{
errmsg = "";
string url = config.HttpReelID;
string json = Http.PostJson(url,null, key);
if (json == "") {
string json = Http.PostJson(url, null, key);
if (json == "")
{
errmsg = "Api error";
if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
......@@ -261,7 +272,8 @@ namespace BLL
{
dic = (Dictionary<string, object>)serializer.DeserializeObject(json);
}
catch {
catch
{
errmsg = "Api parse error:\r\n" + json;
if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
......@@ -274,11 +286,11 @@ namespace BLL
if (extensions != null && !extensions[0].Control.InvokeRequired)
new FaceMessageBox("BoxReelIDInfoMaintain", "Api return data error:\r\n" + json, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
else
errmsg="Api return data error:\r\n" + json;
errmsg = "Api return data error:\r\n" + json;
return false;
}
if (Convert.ToInt32(value)!=0)
if (Convert.ToInt32(value) != 0)
{
errmsg = "Api parse error:\r\n" + dic["MSG"].ToString();
if (extensions != null && !extensions[0].Control.InvokeRequired)
......
......@@ -436,7 +436,7 @@ namespace BLL
}
}
if (keyword.Count == matchCount)
if (matchCount != 0 && keyword.Count == matchCount)
{
isMatch = true;
}
......@@ -447,10 +447,10 @@ namespace BLL
ocrlist.Add(o);
//ocrcode.Add(code[j]);
}
int ocrCount= ocrlist.Count;
int ocrCount = ocrlist.Count;
if (ocrlist.Count > 0)
{
LogNet.log.Info($"{mateTemp[index].Name} 开始OCR匹配");
LogNet.log.Info($"{mateTemp[index].Name} 开始OCR匹配 [{ocrCount}]");
for (int i = 0; i < ocrlist.Count; i++)
{
List<MaterialCodeMatch> codeMatch = mateTemp[index].Match.FindAll(match => match.CodeID == ocrlist[i].ID);
......@@ -475,19 +475,20 @@ namespace BLL
}
}
}
if(ocrCount==0&& !isMatch)
if (ocrCount == 0 && !isMatch)
{
isMatch = true;
LogNet.log.Info($"{mateTemp[index].Name} OCR匹配成功");
}
LogNet.log.Info($"{mateTemp[index].Name} 结束OCR匹配 ");
}
}
if (matchCount == 0)
{
return false;
}
else
//if (matchCount == 0)
//{
// return false;
//}
//else
{
if (isMatch)
{
......@@ -495,8 +496,9 @@ namespace BLL
#region Code按照 匹配到的列表重新排序
MatchCodeIndex = MatchCodeIndex.Distinct().ToList();
var code2 = new List<BarcodeInfo>();
foreach(var i in MatchCodeIndex) {
if (code.Count>i)
foreach (var i in MatchCodeIndex)
{
if (code.Count > i)
code2.Add(code[i]);
}
foreach (var c in code)
......
......@@ -144,7 +144,7 @@ namespace SmartScan
private void btn_adddatetime_Click(object sender, EventArgs e)
{
string key = "[datetime:yyyyMMdd]";
string key = "[datetime:yyyyMMddHHmmss]";
TxtReelIDMatch.AppendText(key);
}
}
......
......@@ -235,34 +235,39 @@ namespace paddleOCR
static bool IsInSameLine(TextBlock t1, TextBlock t2)
{
//同一行间隔小于多少像素可以合并
int intervalPixel = ConfigHelper.Config.Get("IntervalPixelInSameLine", 60);
int intervalPixel = ConfigHelper.Config.Get("IntervalPixelInSameLine", 20);
int p1y1 = t1.BoxPoints[0].Y;
int p1y2 = t1.BoxPoints[3].Y;
int p1y2 = t1.BoxPoints[1].Y;
int p1y3 = t1.BoxPoints[2].Y;
int p1y4 = t1.BoxPoints[3].Y;
int p2y1 = t2.BoxPoints[0].Y;
int p2y2 = t2.BoxPoints[3].Y;
int p2y2 = t2.BoxPoints[1].Y;
int p2y3 = t2.BoxPoints[2].Y;
int p2y4 = t2.BoxPoints[3].Y;
int p1x0 = t1.BoxPoints[0].X;
int p1x1 = t1.BoxPoints[1].X;
int p2x0 = t2.BoxPoints[0].X;
int p2x1 = t2.BoxPoints[1].X;
if (p1y1 > p2y2 || p1y2 < p2y1) { return false; }
else
if (p1x0 < p2x0)//t1在左侧
{
if(p1x0<p2x0)//t1在左侧
{
if (Math.Abs(p1x1 - p2x0) > intervalPixel) return false;
if (p1y2 > p2y4 || p1y3 < p2y1) return false;
else if (Math.Abs(p1x1 - p2x0) > intervalPixel) return false;
else
return true;
}
else
{
if (Math.Abs(p2x1 - p1x0) > intervalPixel) return false;
if (p2y2 > p1y4 || p2y3 < p1y1) return false;
else if (Math.Abs(p2x1 - p1x0) > intervalPixel) return false;
else
return true;
}
}
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!