Commit 7e4f909c 刘韬

修正外部导入数据没有参数reelid拼接的问题

1 个父辈 e58e7e7d
using System;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using Asa.FaceControl;
using Model;
using Asa;
using Newtonsoft.Json;
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.IO;
using static BLL.Extension;
using System.Web.UI;
using Asa.FaceControl;
using System.Configuration;
using System.Linq;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using static BLL.BLLCommon;
using static BLL.Replacekeywords;
using RestSharp;
using System.Web;
using Http = Model.Http;
using System.Drawing;
using DocumentFormat.OpenXml.Spreadsheet;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Presentation;
using static BLL.BLLCommon;
using TcpKPIO;
namespace BLL
{
......@@ -44,19 +30,19 @@ namespace BLL
string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_MACRO_KEY);
macroKey.AddRange(lines);
}
macroKeyValue= new();
macroKeyValue = new();
if (System.IO.File.Exists(FilePath.CONFIG_MACRO_Value))
{
string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_MACRO_Value);
macroKeyValue.AddRange(lines);
}
}
private DebounceHelper<FaceComboBox,string> debounceHelper;
private DebounceHelper<FaceComboBox, string> debounceHelper;
public General(Config config)
{
this.config = config;
ReadMacro();
debounceHelper = new DebounceHelper<FaceComboBox,string>(500); // 设置抗抖动的间隔,单位为毫秒
debounceHelper = new DebounceHelper<FaceComboBox, string>(500); // 设置抗抖动的间隔,单位为毫秒
debounceHelper.DebouncedTextChanged += DebounceHelper_DebouncedTextChanged;
}
......@@ -73,7 +59,7 @@ namespace BLL
.OrderBy(tit => tit)
.ToArray();
s.Items.AddRange(data);
//s.SelectedIndex = -1;
//s.Enabled = true;
//s.Text = e;
......@@ -98,25 +84,25 @@ namespace BLL
public void Load(List<ExtensionControl> extensions)
{
this.extensions = extensions;
this.extensions = extensions;
}
static bool mesResult = false;
bool islast=false;
bool islast = false;
Dictionary<string, string> lastkey = null;
// 用于存储上一次的 key
private Dictionary<string, string> lastKeys;
// 定义事件
protected virtual void OnKeySet(string[] originalCode, Dictionary<string, string> key, bool hasMatch)
{
extension.set( originalCode, key, hasMatch);
extension.set(originalCode, key, hasMatch);
}
protected virtual void CheckText(string text)
{
extension.Check(text);
extension.Check(text);
}
//public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
//{
......@@ -148,7 +134,7 @@ namespace BLL
var now = DateTime.Now;
// 比较当前 key 和上次的 key
bool isSame = false;
bool isFirstCapture=lastKeys==null;
bool isFirstCapture = lastKeys == null;
try
{
......@@ -202,25 +188,9 @@ namespace BLL
}
}
#endregion
// 添加或替换自增ID
string reelIdKeyWord = config.ReelIDKeyWord;
if (!string.IsNullOrEmpty(config.ReelIDKeyWord) && isdisplay)
{
var Reelidstr = GetReelid();
if (key.ContainsKey(config.ReelIDKeyWord))
{
key[config.ReelIDKeyWord] = Reelidstr;
}
else
{
key.Add(config.ReelIDKeyWord, Reelidstr);
}
}
//客户定制key
string exKey = ConfigHelper.Config.Get("Ex_UserDataKey", "Manufactured_Date");
if (macroKey.Contains(exKey))
......@@ -352,53 +322,66 @@ namespace BLL
}
// 添加或替换自增ID
string reelIdKeyWord = config.ReelIDKeyWord;
if (!string.IsNullOrEmpty(config.ReelIDKeyWord) && isdisplay)
{
var Reelidstr = GetReelid();
if (key.ContainsKey(config.ReelIDKeyWord))
{
key[config.ReelIDKeyWord] = Reelidstr;
}
else
{
key.Add(config.ReelIDKeyWord, Reelidstr);
}
}
// 如果有字段更新,则再次调用OnKeySet更新WPF界面
OnKeySet(originalCode, key, hasMatch);
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
{
lastKeys = new Dictionary<string, string>(key); // 更新 lastKey
}
//第二次刷新界面
for (int i = 0; i < extensions.Count; i++)
{
#region 如果是下拉框加载内容
if (extensions[i].Type == "ComboBox")
{
lastKeys = new Dictionary<string, string>(key); // 更新 lastKey
var s = extensions[i].Control as Asa.FaceControl.FaceComboBox;
s.Items.Clear();
var data = ExtraFileData.DataTitle
.Where(a => a.Contains(extensions[i].Control.Text))
.Distinct()
.OrderBy(tit => tit)
.ToArray();
s.Items.AddRange(data);
s.Text = "";
s.SelectedIndex = -1;
s.Enabled = true;
}
//第二次刷新界面
for (int i = 0; i < extensions.Count; i++)
#endregion
extensions[i].Control.ForeColor = System.Drawing.Color.White;
if (key.ContainsKey(extensions[i].Key))
{
#region 如果是下拉框加载内容
if (extensions[i].Type == "ComboBox")
{
var s = extensions[i].Control as Asa.FaceControl.FaceComboBox;
s.Items.Clear();
var data = ExtraFileData.DataTitle
.Where(a => a.Contains(extensions[i].Control.Text))
.Distinct()
.OrderBy(tit => tit)
.ToArray();
s.Items.AddRange(data);
s.Text = "";
s.SelectedIndex = -1;
s.Enabled = true;
}
#endregion
extensions[i].Control.ForeColor = System.Drawing.Color.White;
if (key.ContainsKey(extensions[i].Key))
{
extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", "");
}
if (extensions[i].LinkName == "ischeckresult")
{
extensions[i].Control.Text = BLLCommon.extension.labelText;
}
extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", "");
}
if (extensions[i].LinkName == "ischeckresult")
{
extensions[i].Control.Text = BLLCommon.extension.labelText;
}
}
//if (BLLCommon.config.CheckFunction)
//{
......@@ -410,10 +393,10 @@ namespace BLL
//}
//else
//{
if (!updatereelid(key, out errmsg))
return false;
// }
if (!updatereelid(key, out errmsg))
return false;
// }
Application.DoEvents();
......@@ -436,7 +419,7 @@ namespace BLL
// return false;
//}
return true;
return true;
}
bool updatereelid(Dictionary<string, string> key, out string errmsg)
{
......@@ -470,9 +453,9 @@ namespace BLL
}
//SaveRetrospect?.Invoke(key);
return true;
}
public void Update()
......@@ -555,7 +538,7 @@ namespace BLL
}
}
string finalText = processedPattern ;
string finalText = processedPattern;
LogNet.log.Info(string.Format("GetReelid pattern={0}, id={1}, text={2}", matchPattern, reelID, finalText));
......@@ -677,14 +660,15 @@ namespace BLL
{
if (BLLCommon.config.Language.Equals("English"))
{
bool result = MessageboxNeo.Show( "", "Whether to skip this operation?","NEO SCAN",true );
bool result = MessageboxNeo.Show("", "Whether to skip this operation?", "NEO SCAN", true);
if (result)
{
lastKeys = null;
BLLCommon.extension.labelText = "Waiting";
}
}else if (BLLCommon.config.Language.Equals("日语"))
}
else if (BLLCommon.config.Language.Equals("日语"))
{
bool result = MessageboxNeo.Show("",
"この操作をスキップしますか?",
......@@ -701,12 +685,12 @@ namespace BLL
}
else
{
bool result = MessageboxNeo.Show( "",
bool result = MessageboxNeo.Show("",
"是否跳过此操作?",
"NEO SCAN",
true);
if (result)
{
lastKeys = null;
......@@ -714,33 +698,33 @@ namespace BLL
BLLCommon.extension.labelText = "等待中";
}
}
}
public void CheckClear()
{
}
private void ComboBoxTextChanged(object sender, EventArgs e)
{
var txt = ((FaceComboBox)sender).Text;
debounceHelper.HandleTextChanged((FaceComboBox)sender,txt);
debounceHelper.HandleTextChanged((FaceComboBox)sender, txt);
}
private Dictionary<string, string> UpdateLastKey( Dictionary<string, string> lastkey)
private Dictionary<string, string> UpdateLastKey(Dictionary<string, string> lastkey)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();
if (lastkey == null)
return null;
foreach(var temp in lastkey.Keys)
return null;
foreach (var temp in lastkey.Keys)
{
keyValues.Add(temp, lastkey[temp]);
if (temp.Contains(":"))
{
string date = temp.Split(':')[1];
if(int.TryParse(date, out int value)&&value==0&& int.TryParse(lastkey[temp], out int value2))
if (int.TryParse(date, out int value) && value == 0 && int.TryParse(lastkey[temp], out int value2))
{
keyValues[temp] = value2.ToString($"D{date.Length}");
}
......@@ -753,17 +737,17 @@ namespace BLL
LogNet.log.Info("Enter PrintLabel Method");
if (lastkey == null) return;
for (int i = 0; i < extensions.Count; i++)
{
{
if (extensions[i].Key == "") continue;
if (lastkey.ContainsKey(extensions[i].Key))
lastkey[extensions[i].Key] = extensions[i].Control.Text;
else
lastkey.Add(extensions[i].Key, extensions[i].Control.Text);
}
lastkey= UpdateLastKey(lastkey);
lastkey = UpdateLastKey(lastkey);
LogNet.log.Info("lastkey:" + JsonConvert.SerializeObject(lastkey));
#region 判断指定关键字是否存在内容
List<string> strings = new List<string>();
......@@ -776,12 +760,12 @@ namespace BLL
lastkey.TryGetValue(item, out string value);
if (string.IsNullOrWhiteSpace(value))
{
strings.Add(item);
}
}
}
LogNet.log.Info("DataSource_ForceMatching:"+string.Join(",", strings));
LogNet.log.Info("DataSource_ForceMatching:" + string.Join(",", strings));
#endregion
for (int i = 0; i < extensions.Count; i++)
{
......@@ -805,7 +789,7 @@ namespace BLL
}
}
#endregion
Printing?.Invoke(lastkey);
bool close = ConfigHelper.Config.Get("isprinclose", false);
if (close)
......@@ -831,7 +815,7 @@ namespace BLL
/// <param name="errmsg"></param>
/// <param name="dic">返回请求后,替换完成的键值对</param>
/// <returns></returns>
private bool GetHttpReelID(Dictionary<string, string> key, out string errmsg,out Dictionary<string,object> dic)
private bool GetHttpReelID(Dictionary<string, string> key, out string errmsg, out Dictionary<string, object> dic)
{
errmsg = "";
dic = null;
......@@ -841,9 +825,9 @@ namespace BLL
{
errmsg = "Api error";
if (extensions != null && !extensions[0].Control.InvokeRequired)
MessageboxNeo.Show("BoxReelIDInfoMaintain", errmsg,"NEO SCAN",true);
// new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
MessageboxNeo.Show("BoxReelIDInfoMaintain", errmsg, "NEO SCAN", true);
// new FaceMessageBox("BoxReelIDInfoMaintain", errmsg, System.Windows.Forms.MessageBoxButtons.OK, true).ShowDialog();
return false;
}
JavaScriptSerializer serializer = new();
......@@ -931,7 +915,7 @@ namespace BLL
catch (Exception ex)
{
LogNet.log.Error($"替换数据时出错:{ex.Message}");
}
}
}
private void GetDataButtonClick(object sender, EventArgs e)
......@@ -943,15 +927,15 @@ namespace BLL
foreach (var items in extensions.Where(a => (a.Type == "TextBox" || a.Type == "ComboBox") && a.Key == datakey))
{
string value = items.Control.Text;
var data = ExtraFileData.AllData[value];
var data = ExtraFileData.AllData[value];
foreach (var item in data)
{
var ext = extensions.Where(a =>( a.Type == "TextBox" || a.Type == "ComboBox" )&& a.Key == item.Key).ToList();
var ext = extensions.Where(a => (a.Type == "TextBox" || a.Type == "ComboBox") && a.Key == item.Key).ToList();
foreach (var Control in ext)
{
Control.Control.Text = item.Value;
valuePairs.Add(Control.Key, item.Value);
}
}
}
}
......@@ -959,12 +943,12 @@ namespace BLL
}
catch (Exception)
{
LogNet.log.Info("GetDataButtonClick:请求本地文件数据替换出错!");
}
LogNet.log.Info("GetDataButtonClick:请求本地文件数据替换出错!");
}
}
public void DrawTextBackground(Dictionary<string, string> key)
{
if (extensions != null && extensions.Count>0&& !extensions[0].Control.InvokeRequired)
if (extensions != null && extensions.Count > 0 && !extensions[0].Control.InvokeRequired)
{
bool focused = false; // 用于跟踪是否已经聚焦到第一个匹配的文本框
for (int i = 0; i < extensions.Count; i++)
......@@ -991,7 +975,7 @@ namespace BLL
public void Print(bool match, Dictionary<string, string> key)
{
if (extensions != null && extensions.Count > 0 && !extensions[0].Control.InvokeRequired)
{
{
//自动打印and模板匹配成功,只负责打印标签
if (config.AutoPrint && match)
{
......@@ -999,7 +983,7 @@ namespace BLL
PrintLabel(true, EventArgs.Empty);
}
//bool close = ConfigHelper.Config.Get("isprinclose", false);
}
}
////进行追溯配置保存
//SaveRetrospect?.Invoke(key);
}
......@@ -1007,12 +991,12 @@ namespace BLL
public Dictionary<string, string> ReplaceData(Dictionary<string, string> key)
{
string err = null;
Dictionary<string, object> dic=new Dictionary<string, object>();
Dictionary<string, object> dic = new Dictionary<string, object>();
if (!GetHttpReelID(key, out err, out dic))
{
return key;
}
return dic?.ToDictionary(a=>a.Key,a=>a.Value.ToString());
}
return dic?.ToDictionary(a => a.Key, a => a.Value.ToString());
}
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!