修改自动退出方法
This commit is contained in:
parent
d582bba6c0
commit
3c6b56f95e
|
@ -37,7 +37,7 @@
|
||||||
<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
|
<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
|
||||||
<add key="returnDrugMode" value="2" />
|
<add key="returnDrugMode" value="2" />
|
||||||
<!-- 自动退出时间,单位秒,为0时不自动退出 -->
|
<!-- 自动退出时间,单位秒,为0时不自动退出 -->
|
||||||
<add key="autoExit" value="3"/>
|
<add key="autoExit" value="0"/>
|
||||||
|
|
||||||
<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
|
<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
|
||||||
<add key="stopRecord" value="180"/>
|
<add key="stopRecord" value="180"/>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
d1p1:Ignorable="d"
|
d1p1:Ignorable="d"
|
||||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
xmlns:local="clr-namespace:DM_Weight"
|
xmlns:local="clr-namespace:DM_Weight"
|
||||||
xmlns:prism="http://prismlibrary.com/">
|
xmlns:prism="http://prismlibrary.com/" Startup="PrismApplication_Startup">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
|
|
@ -24,6 +24,8 @@ using System.Windows.Interop;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using DM_Weight.HIKVISION;
|
using DM_Weight.HIKVISION;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace DM_Weight
|
namespace DM_Weight
|
||||||
{
|
{
|
||||||
|
@ -291,5 +293,45 @@ namespace DM_Weight
|
||||||
logger.Info("结束APP-RegisterTypes");
|
logger.Info("结束APP-RegisterTypes");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PrismApplication_Startup(object sender, StartupEventArgs e)
|
||||||
|
{
|
||||||
|
//获取欲启动程序名
|
||||||
|
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
|
||||||
|
logger.Info($"欲启动程序名:{processName}");
|
||||||
|
//检查程序是否已经启动,已经启动则显示提示退出程序
|
||||||
|
if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
logger.Info($"系统在运行!");
|
||||||
|
//系统在运行
|
||||||
|
RaiseOtherProcess();
|
||||||
|
Application.Current.Shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void RaiseOtherProcess()
|
||||||
|
{
|
||||||
|
Process proc = Process.GetCurrentProcess();
|
||||||
|
foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
|
||||||
|
{
|
||||||
|
if (proc.Id != otherProc.Id)
|
||||||
|
{
|
||||||
|
IntPtr hWnd = otherProc.MainWindowHandle;
|
||||||
|
if (IsIconic(hWnd))
|
||||||
|
{
|
||||||
|
ShowWindowAsync(hWnd, 9);
|
||||||
|
}
|
||||||
|
SetForegroundWindow(hWnd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool IsIconic(IntPtr hWnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
|
|
|
@ -527,6 +527,8 @@ namespace DM_Weight.ViewModels
|
||||||
//接收导航传过来的参数
|
//接收导航传过来的参数
|
||||||
public void OnNavigatedTo(NavigationContext navigationContext)
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_eventAggregator.GetEvent<LoginOutEvent>().Subscribe(SetLoginOut);
|
||||||
_portUtil.dateTime = DateTime.Now;
|
_portUtil.dateTime = DateTime.Now;
|
||||||
//取出user
|
//取出user
|
||||||
UserList = navigationContext.Parameters.GetValue<UserList>("operator");
|
UserList = navigationContext.Parameters.GetValue<UserList>("operator");
|
||||||
|
@ -554,6 +556,7 @@ namespace DM_Weight.ViewModels
|
||||||
Type = MsgType.ERROR
|
Type = MsgType.ERROR
|
||||||
};
|
};
|
||||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//SqlSugarHelper.Db.SqlQueryable<PremissionDm>(sql)
|
//SqlSugarHelper.Db.SqlQueryable<PremissionDm>(sql)
|
||||||
|
@ -566,47 +569,47 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
||||||
int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
|
int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
|
||||||
if (autoExit > 0)
|
//if (autoExit > 0)
|
||||||
{
|
//{
|
||||||
System.Timers.Timer timer = new System.Timers.Timer();
|
// System.Timers.Timer timer = new System.Timers.Timer();
|
||||||
timer.Interval = 100;
|
// timer.Interval = 100;
|
||||||
timer.Elapsed += (sender, e) =>
|
// timer.Elapsed += (sender, e) =>
|
||||||
{
|
// {
|
||||||
// 串口无人操作
|
// // 串口无人操作
|
||||||
bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
// bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
bool allTrue = Array.TrueForAll(boolArrs, b => b==false);
|
// bool allTrue = Array.TrueForAll(boolArrs, b => b==false);
|
||||||
logger.Info($"进入自动退出定时方法{allTrue}");
|
// logger.Info($"进入自动退出定时方法{allTrue}");
|
||||||
//false是关着,true是开着
|
// //false是关着,true是开着
|
||||||
if (allTrue)
|
// if (allTrue)
|
||||||
{
|
// {
|
||||||
//PerformanceCounter pc = new PerformanceCounter("System", "% Idle Time", true);
|
// //PerformanceCounter pc = new PerformanceCounter("System", "% Idle Time", true);
|
||||||
//float systemIdleTime = pc.NextValue();
|
// //float systemIdleTime = pc.NextValue();
|
||||||
//Console.WriteLine($"systemIdleTime:{systemIdleTime}");
|
// //Console.WriteLine($"systemIdleTime:{systemIdleTime}");
|
||||||
|
|
||||||
//// 获取系统空闲时间
|
// //// 获取系统空闲时间
|
||||||
//TimeSpan idleTime = SystemInformation.IdleTime;
|
// //TimeSpan idleTime = SystemInformation.IdleTime;
|
||||||
//// 打印空闲时间
|
// //// 打印空闲时间
|
||||||
//Console.WriteLine("系统空闲时间: " + idleTime.ToString());
|
// //Console.WriteLine("系统空闲时间: " + idleTime.ToString());
|
||||||
long lTime = CheckComputerFreeState.GetLastInputTime();
|
// long lTime = CheckComputerFreeState.GetLastInputTime();
|
||||||
logger.Info($"自动退出时间{lTime}");
|
// logger.Info($"自动退出时间{lTime}");
|
||||||
// 30秒内无人操作鼠标键盘
|
// // 30秒内无人操作鼠标键盘
|
||||||
//if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
|
// //if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
|
||||||
if (lTime > autoExit)
|
// if (lTime > autoExit)
|
||||||
{
|
// {
|
||||||
logger.Info($"设备{autoExit}秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
|
// logger.Info($"设备{autoExit}秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
|
||||||
_chkFunction.HIKStopDVRRecord();
|
// _chkFunction.HIKStopDVRRecord();
|
||||||
Operator = null;
|
// Operator = null;
|
||||||
Reviewer = null;
|
// Reviewer = null;
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
// Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
// {
|
||||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
// _regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||||
timer.Stop();
|
// timer.Stop();
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
timer.Start();
|
// timer.Start();
|
||||||
}
|
//}
|
||||||
#region 温度查询定时
|
#region 温度查询定时
|
||||||
int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
||||||
if (interval > 0)
|
if (interval > 0)
|
||||||
|
@ -650,7 +653,19 @@ namespace DM_Weight.ViewModels
|
||||||
//这个方法用于拦截请求
|
//这个方法用于拦截请求
|
||||||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||||||
{
|
{
|
||||||
|
//退了登录
|
||||||
|
_eventAggregator.GetEvent<LoginOutEvent>().Unsubscribe(SetLoginOut);
|
||||||
|
}
|
||||||
|
private void SetLoginOut()
|
||||||
|
{
|
||||||
|
_chkFunction.HIKStopDVRRecord();
|
||||||
|
Operator = null;
|
||||||
|
Reviewer = null;
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
using System;
|
using DM_Weight.msg;
|
||||||
|
using DM_Weight.Port;
|
||||||
|
using log4net.Repository.Hierarchy;
|
||||||
|
using Prism.Events;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
@ -20,9 +27,40 @@ namespace DM_Weight.Views
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class HomeWindow : UserControl
|
public partial class HomeWindow : UserControl
|
||||||
{
|
{
|
||||||
public HomeWindow()
|
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
||||||
|
System.Timers.Timer idleTimer;
|
||||||
|
IEventAggregator _eventAggregator;
|
||||||
|
public HomeWindow(IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
if (autoExit > 0)
|
||||||
|
{
|
||||||
|
idleTimer = new System.Timers.Timer(autoExit*1000);
|
||||||
|
idleTimer.Elapsed += OnTimerElapsed;
|
||||||
|
this.MouseDown += OnUserActivity;
|
||||||
|
this.MouseMove += OnUserActivity;
|
||||||
|
this.KeyDown += OnUserActivity;
|
||||||
|
idleTimer.Start();
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void OnUserActivity(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
idleTimer.Stop();
|
||||||
|
idleTimer.Start();
|
||||||
|
}
|
||||||
|
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
// 串口无人操作
|
||||||
|
bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
||||||
|
//logger.Info($"进入自动退出定时方法{allTrue}");
|
||||||
|
if (allTrue)
|
||||||
|
{
|
||||||
|
//无人操作,自动退出
|
||||||
|
_eventAggregator.GetEvent<LoginOutEvent>().Publish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Prism.Events;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DM_Weight.msg
|
||||||
|
{
|
||||||
|
public class LoginOutEvent:PubSubEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue