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,24 +18,78 @@ namespace SmartScan ...@@ -18,24 +18,78 @@ 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, "条码规则设置");
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); ShowWindow(formhwnd, SW_RESTORE);
SwitchToThisWindow(formhwnd, true); SwitchToThisWindow(formhwnd, true);
//MessageBox.Show("该程序已经启动", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); }
LogNet.log.Info($"窗体隐藏,查找软件窗口句柄:{formhwnd}");
isShow = true;
break;
}
else
{
// 如果窗体没有隐藏,就直接切换到该窗体并带入到前台
// 因为窗体除了隐藏到托盘,还可以最小化
SwitchToThisWindow(process.MainWindowHandle, true);
LogNet.log.Info($"窗体没有隐藏,查找软件窗口句柄:{formhwnd}");
isShow = true;
break;
}
}
}
}
}
return; return;
} }
if(!isShow)
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); {
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
//BLL.Config.Backgrounder = true; //BLL.Config.Backgrounder = true;
...@@ -79,6 +133,7 @@ namespace SmartScan ...@@ -79,6 +133,7 @@ namespace SmartScan
} }
else else
Application.Run(Common.frmMain); 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);
...@@ -82,15 +81,16 @@ namespace SmartScan ...@@ -82,15 +81,16 @@ namespace SmartScan
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!