连接数据库异常添加紧急开锁功能
This commit is contained in:
parent
53eb6d07cc
commit
735785fecb
|
@ -32,6 +32,7 @@ namespace DM_Weight
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : PrismApplication
|
public partial class App : PrismApplication
|
||||||
{
|
{
|
||||||
|
public static bool DbConnectionFail { get; set; } = false;
|
||||||
private readonly ILog logger = LogManager.GetLogger(typeof(App));
|
private readonly ILog logger = LogManager.GetLogger(typeof(App));
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
|
@ -58,6 +59,11 @@ namespace DM_Weight
|
||||||
{
|
{
|
||||||
logger.Error($"发生错误:{e.Exception.Message}");
|
logger.Error($"发生错误:{e.Exception.Message}");
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
if (e.Exception.Message.Contains("连接数据库过程中发生错误"))
|
||||||
|
{
|
||||||
|
DbConnectionFail = true;
|
||||||
|
Container.Resolve<MainWindow>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
||||||
|
@ -258,6 +264,9 @@ namespace DM_Weight
|
||||||
|
|
||||||
|
|
||||||
containerRegistry.RegisterForNavigation<EmptyWindow, EmptyWindowViewModel>();
|
containerRegistry.RegisterForNavigation<EmptyWindow, EmptyWindowViewModel>();
|
||||||
|
//紧急开锁页面
|
||||||
|
containerRegistry.RegisterForNavigation<EmergencyWindow, EmergencyWindowViewModel>();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,8 +78,12 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
//_container.RegisterType<object, LoginWindow>("LoginWindow");
|
//_container.RegisterType<object, LoginWindow>("LoginWindow");
|
||||||
//_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
|
//_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
|
||||||
|
if (App.DbConnectionFail)
|
||||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
{
|
||||||
|
_regionManager.RequestNavigate("MainRegion", "EmergencyWindow");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
<UserControl x:Class="DM_Weight.Views.EmergencyWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:DM_Weight.Views"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
xmlns:pagination="clr-namespace:DM_Weight.Components.pagination"
|
||||||
|
xmlns:prism="http://prismlibrary.com/"
|
||||||
|
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||||
|
xmlns:convert="clr-namespace:DM_Weight.Converter"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="80"></RowDefinition>
|
||||||
|
<RowDefinition></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid Background="#00bcd4">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Image Grid.Column="0" Margin="30 0 30 0" HorizontalAlignment="Left" Width="Auto" Height="26" Source="/Images/logo.png" />
|
||||||
|
</Grid>
|
||||||
|
<Grid Grid.Row="1" Margin="6">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid Margin="0" Grid.Column="0" Width="280" Visibility="{Binding Is8Drawer, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||||
|
<Grid.Background>
|
||||||
|
<ImageBrush ImageSource="/Images/box.png" />
|
||||||
|
</Grid.Background>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="200" />
|
||||||
|
<RowDefinition />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid Grid.Row="1" Height="470" Margin="0 50 0 0">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.Resources>
|
||||||
|
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
|
||||||
|
<Setter Property="Foreground" Value="#00a0ea" />
|
||||||
|
<Setter Property="BorderBrush" Value="#00a0ea" />
|
||||||
|
</Style>
|
||||||
|
</Grid.Resources>
|
||||||
|
<Button Grid.Row="0" Width="210" Content="1" Command="{Binding OpenDrawer}" CommandParameter="1" />
|
||||||
|
<Button Grid.Row="1" Width="210" Content="2" Command="{Binding OpenDrawer}" CommandParameter="2" />
|
||||||
|
<Button Grid.Row="2" Width="210" Content="3" Command="{Binding OpenDrawer}" CommandParameter="3" />
|
||||||
|
<Button Grid.Row="3" Width="210" Content="4" Command="{Binding OpenDrawer}" CommandParameter="4" />
|
||||||
|
<Button Grid.Row="4" Width="210" Content="5" Command="{Binding OpenDrawer}" CommandParameter="5" />
|
||||||
|
<Button Grid.Row="5" Width="210" Content="6" Command="{Binding OpenDrawer}" CommandParameter="6" />
|
||||||
|
<Button Grid.Row="6" Width="210" Content="7" Command="{Binding OpenDrawer}" CommandParameter="7" />
|
||||||
|
<Button Grid.Row="7" Width="210" Content="8" Command="{Binding OpenDrawer}" CommandParameter="8" />
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
<Grid Grid.Column="1">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
|
<Button Margin="0 0 6 0" Content="返回登录" Command="{Binding ReturnLoginDelegate}" CommandParameter="0"
|
||||||
|
Visibility="{Binding DBConnectionStatus, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MaterialDesignOutlinedLightButton}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Row="1">
|
||||||
|
<GroupBox Width="800px"
|
||||||
|
Header="重要提示"
|
||||||
|
Style="{StaticResource MaterialDesignGroupBox}"
|
||||||
|
Margin="16"
|
||||||
|
materialDesign:ColorZoneAssist.Mode="SecondaryMid">
|
||||||
|
<TextBlock Foreground="Red" FontWeight="Bold" FontSize="16" Text="数据库连接失败,此页面为紧急开锁页面!!!" />
|
||||||
|
</GroupBox>
|
||||||
|
</StackPanel>
|
||||||
|
<!--<materialDesign:Snackbar
|
||||||
|
Background="{Binding SnackbarBackground}"
|
||||||
|
MessageQueue="{Binding SnackbarMessageQueue}"/>-->
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
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>
|
||||||
|
/// EmergencyWindow.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class EmergencyWindow : UserControl
|
||||||
|
{
|
||||||
|
public EmergencyWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue