Commit 7e4f909c 刘韬

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

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