83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
using DM_Weight.Models;
|
|
using DM_Weight.msg;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.util;
|
|
using log4net;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Threading;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class EmergencyWindowViewModel : BindableBase
|
|
{
|
|
private readonly ILog logger = LogManager.GetLogger(typeof(HomeWindowViewModel));
|
|
IEventAggregator _eventAggregator;
|
|
private PortUtil _portUtil;
|
|
IRegionManager _regionManager;
|
|
private bool _dbConnectionFail = !App.DbConnectionFail;
|
|
public bool DBConnectionStatus { get => _dbConnectionFail; set => SetProperty(ref _dbConnectionFail, value); }
|
|
private int _status;
|
|
|
|
public int Status { get => _status; set => SetProperty(ref _status, value); }
|
|
public EmergencyWindowViewModel(IRegionManager regionManager, PortUtil portUtil, IEventAggregator eventAggregator)
|
|
{
|
|
_portUtil = portUtil;
|
|
_eventAggregator = eventAggregator;
|
|
_regionManager = regionManager;
|
|
CheckDBConnect();
|
|
}
|
|
public DelegateCommand<string> OpenDrawer
|
|
{
|
|
get => new DelegateCommand<string>((DrawerNo) =>
|
|
{
|
|
//应急开锁
|
|
logger.Info($"应急开锁正在打开{DrawerNo}号抽屉");
|
|
Status = 1;
|
|
_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
|
|
_portUtil.WindowName = "EmergencyWindow";
|
|
_portUtil.BoardType = 1;
|
|
_portUtil.ColNos = new int[] { 1 };
|
|
_portUtil.DrawerNo = Convert.ToInt32(DrawerNo);
|
|
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, () => _portUtil.OpenDrawer());
|
|
|
|
}
|
|
);
|
|
}
|
|
public DelegateCommand ReturnLoginDelegate
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
|
});
|
|
}
|
|
//间隔1分钟查询数据库连接状态
|
|
private void CheckDBConnect()
|
|
{
|
|
new PromiseUtil<int>().taskAsyncLoop(60000, 0, async (options, next, stop) =>
|
|
{
|
|
try
|
|
{
|
|
var userList = SqlSugarHelper.Db.Queryable<UserList>()
|
|
.First(u => u.UserName == "admin");
|
|
App.DbConnectionFail = false;
|
|
DBConnectionStatus = true;
|
|
stop();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
next();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|