Commit b5f34519 张东亮

1

1 个父辈 b1a35793
...@@ -24,7 +24,6 @@ namespace SmartScan ...@@ -24,7 +24,6 @@ namespace SmartScan
FileInfo fileInfo = new FileInfo(current.MainModule.FileName); FileInfo fileInfo = new FileInfo(current.MainModule.FileName);
DateTime dateTime = fileInfo.LastWriteTime; DateTime dateTime = fileInfo.LastWriteTime;
string version = $"{dateTime.Year%10}.{dateTime.Month}.{dateTime.Day.ToString("00")}{dateTime.Hour.ToString("00")}"; string version = $"{dateTime.Year%10}.{dateTime.Month}.{dateTime.Day.ToString("00")}{dateTime.Hour.ToString("00")}";
LogNet.log = log4net.LogManager.GetLogger("SmartScan");
LogNet.log.Info($"===== 程序开始 {version} ====="); LogNet.log.Info($"===== 程序开始 {version} =====");
Common.config = new BLL.Config(); Common.config = new BLL.Config();
......
...@@ -18,67 +18,122 @@ namespace SmartScan ...@@ -18,67 +18,122 @@ namespace SmartScan
[STAThread] [STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
LogNet.log = log4net.LogManager.GetLogger("SmartScan");
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
bool isShow = false;
Environment.CurrentDirectory = Application.StartupPath; Environment.CurrentDirectory = Application.StartupPath;
_ = new Mutex(true, Application.ProductName, out bool ret); _ = new Mutex(true, Application.ProductName, out bool ret);
if (!ret) if (!ret)
{ {
IntPtr formhwnd = FindWindow(null, "BarCode Rule Setting"); IntPtr formhwnd = FindWindow(null, "BarCode Rule Setting");
if (formhwnd == IntPtr.Zero) if (formhwnd == IntPtr.Zero)
formhwnd = FindWindow(null, "条码规则设置"); formhwnd = FindWindow(null, "条码规则设置");
ShowWindow(formhwnd, SW_RESTORE);
SwitchToThisWindow(formhwnd, true);
//MessageBox.Show("该程序已经启动", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//BLL.Config.Backgrounder = true;
bool back = BLL.Config.Backgrounder;
bool hide = false;
if (args.Length > 0)
hide = args[0].ToLower() == "hide";
// if (Config.UsePaddleOCR)
{
var paddle = "paddleOCR.exe";
Process process = new Process();
process.StartInfo = new ProcessStartInfo();
process.StartInfo.FileName = paddle;
process.StartInfo.WorkingDirectory = ".\\paddle";
if (File.Exists(".\\paddle\\paddleOCR.exe"))
process.Start();
LogNet.log.Info($"查找条码规则窗口句柄:{formhwnd}");
if(formhwnd != IntPtr.Zero)
{
ShowWindow(formhwnd, SW_RESTORE);
SwitchToThisWindow(formhwnd, true);
}
else
{
Process currentproc = Process.GetCurrentProcess();
Process[] processcollection = Process.GetProcessesByName(Application.ProductName);
// 该程序已经运行,
if (processcollection.Length >= 1)
{
foreach (Process process in processcollection)
{
if (process.Id != currentproc.Id)
{
// 如果进程的句柄为0,即代表没有找到该窗体,即该窗体隐藏的情况时
if (process.MainWindowHandle.ToInt32().Equals(0))
{
string formTitle = "物料注册系统";
// 获得窗体句柄
formhwnd = FindWindow(null, formTitle);
if( formhwnd != IntPtr.Zero )
{
// 重新显示该窗体并切换到带入到前台
ShowWindow(formhwnd, SW_RESTORE);
SwitchToThisWindow(formhwnd, true);
}
else
{
formTitle = "Material Registration System";
formhwnd = FindWindow(null, formTitle);
// 重新显示该窗体并切换到带入到前台
ShowWindow(formhwnd, SW_RESTORE);
SwitchToThisWindow(formhwnd, true);
}
LogNet.log.Info($"窗体隐藏,查找软件窗口句柄:{formhwnd}");
isShow = true;
break;
}
else
{
// 如果窗体没有隐藏,就直接切换到该窗体并带入到前台
// 因为窗体除了隐藏到托盘,还可以最小化
SwitchToThisWindow(process.MainWindowHandle, true);
LogNet.log.Info($"窗体没有隐藏,查找软件窗口句柄:{formhwnd}");
isShow = true;
break;
}
}
}
}
}
return;
} }
//else
//{
// var onnxexe = "onnx\\OcrLiteOnnxForm.exe";
// Process process1 = Process.Start(onnxexe);
//}
if(!isShow)
Application.Run(new FrmLoading(back)); //预加载,完成后自动退出
Common.frmMain = new FrmMain();
Common.frmWaitting = new FrmWaitting();
if (back)
{ {
var fsp = new FrmSetPlus(); Application.EnableVisualStyles();
if (hide) Application.SetCompatibleTextRenderingDefault(false);
fsp.WindowState = FormWindowState.Minimized; //BLL.Config.Backgrounder = true;
bool back = BLL.Config.Backgrounder;
Application.Run(fsp); bool hide = false;
if (args.Length > 0)
hide = args[0].ToLower() == "hide";
// if (Config.UsePaddleOCR)
{
var paddle = "paddleOCR.exe";
Process process = new Process();
process.StartInfo = new ProcessStartInfo();
process.StartInfo.FileName = paddle;
process.StartInfo.WorkingDirectory = ".\\paddle";
if (File.Exists(".\\paddle\\paddleOCR.exe"))
process.Start();
}
//else
//{
// var onnxexe = "onnx\\OcrLiteOnnxForm.exe";
// Process process1 = Process.Start(onnxexe);
//}
Application.Run(new FrmLoading(back)); //预加载,完成后自动退出
Common.frmMain = new FrmMain();
Common.frmWaitting = new FrmWaitting();
if (back)
{
var fsp = new FrmSetPlus();
if (hide)
fsp.WindowState = FormWindowState.Minimized;
Application.Run(fsp);
}
else
Application.Run(Common.frmMain);
} }
else
Application.Run(Common.frmMain);
Exit(); Exit();
} }
......
...@@ -64,8 +64,7 @@ namespace SmartScan ...@@ -64,8 +64,7 @@ namespace SmartScan
if (workCodeInfo.Count == 0) if (workCodeInfo.Count == 0)
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败" }; return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败" };
Common.mateEdit.CurrntBitmap = bitmap;
bool rtn = Common.mateEdit.MatchingTemplate(workCodeInfo, Common.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out originalCodeIsUsed); bool rtn = Common.mateEdit.MatchingTemplate(workCodeInfo, Common.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out originalCodeIsUsed);
LogNet.log.Info("Work SetKey hasMatch:" + rtn); LogNet.log.Info("Work SetKey hasMatch:" + rtn);
...@@ -76,22 +75,23 @@ namespace SmartScan ...@@ -76,22 +75,23 @@ namespace SmartScan
webResultCode = new WebResultCode() { ErrorCode = -2, Msg = errmsg }; webResultCode = new WebResultCode() { ErrorCode = -2, Msg = errmsg };
} }
if (webResultCode != null || !rtn) if (webResultCode != null || !rtn)
return webResultCode; return webResultCode;
LogNet.log.Info("Work scan is done"); LogNet.log.Info("Work scan is done");
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>(); List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
foreach (var wc in workCodeKeyword) { foreach (var wc in workCodeKeyword)
result.Add(new KeyValuePair<string, string>(wc.Key,wc.Value)); {
result.Add(new KeyValuePair<string, string>(wc.Key, wc.Value));
} }
return new WebResultCode() { workCodeKeyword = result, workCodeInfo = workCodeInfo }; return new WebResultCode() { workCodeKeyword = result, workCodeInfo = workCodeInfo };
} }
catch (Exception ex) catch (Exception ex)
{ {
LogNet.log.Error("ProcessBitmap", ex); LogNet.log.Error("ProcessBitmap", ex);
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败:"+ ex }; return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败:" + ex };
} }
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!