HKC/DM_Weight/Views/HomeWindow.xaml.cs

67 lines
2.0 KiB
C#
Raw Normal View History

2024-11-14 16:38:55 +08:00
using DM_Weight.msg;
using DM_Weight.Port;
using log4net.Repository.Hierarchy;
using Prism.Events;
using System;
2023-11-13 11:52:43 +08:00
using System.Collections.Generic;
2024-11-14 16:38:55 +08:00
using System.Configuration;
2023-11-13 11:52:43 +08:00
using System.Linq;
using System.Text;
2024-11-14 16:38:55 +08:00
using System.Threading;
2023-11-13 11:52:43 +08:00
using System.Threading.Tasks;
2024-11-14 16:38:55 +08:00
using System.Timers;
2023-11-13 11:52:43 +08:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DM_Weight.Views
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class HomeWindow : UserControl
{
2024-11-14 16:38:55 +08:00
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
System.Timers.Timer idleTimer;
IEventAggregator _eventAggregator;
public HomeWindow(IEventAggregator eventAggregator)
2023-11-13 11:52:43 +08:00
{
InitializeComponent();
2024-11-14 16:38:55 +08:00
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;
}
2023-11-13 11:52:43 +08:00
}
2024-11-14 16:38:55 +08:00
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();
}
}
2023-11-13 11:52:43 +08:00
}
}