连接数据库异常添加紧急开锁功能
This commit is contained in:
		
							parent
							
								
									12c2cc4e22
								
							
						
					
					
						commit
						fb168eda34
					
				| 
						 | 
				
			
			@ -37,7 +37,7 @@
 | 
			
		|||
		<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
 | 
			
		||||
		<add key="returnDrugMode" value="2" />
 | 
			
		||||
		<!-- 自动退出时间,单位秒,为0时不自动退出 -->
 | 
			
		||||
		<add key="autoExit" value="5"/>
 | 
			
		||||
		<add key="autoExit" value="0"/>
 | 
			
		||||
		
 | 
			
		||||
		<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
 | 
			
		||||
		<add key="stopRecord" value="180"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,6 +34,7 @@ namespace DM_Weight
 | 
			
		|||
    /// </summary>
 | 
			
		||||
    public partial class App : PrismApplication
 | 
			
		||||
    {
 | 
			
		||||
        public static bool DbConnectionFail { get; set; } = false;
 | 
			
		||||
        private readonly ILog logger = LogManager.GetLogger(typeof(App));
 | 
			
		||||
        public App()
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -62,8 +63,12 @@ namespace DM_Weight
 | 
			
		|||
        {
 | 
			
		||||
            logger.Error($"发生错误:{e.Exception.Message}");
 | 
			
		||||
            e.Handled = true;
 | 
			
		||||
            if (e.Exception.Message.Contains("连接数据库过程中发生错误"))
 | 
			
		||||
            {
 | 
			
		||||
                DbConnectionFail = true;
 | 
			
		||||
                Container.Resolve<MainWindow>();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -294,6 +299,8 @@ namespace DM_Weight
 | 
			
		|||
            //containerRegistry.RegisterForNavigation<MachineRecordWindow, MachineRecordWindowViewModel>();
 | 
			
		||||
 | 
			
		||||
            containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>();
 | 
			
		||||
            //紧急开锁页面
 | 
			
		||||
            containerRegistry.RegisterForNavigation<EmergencyWindow, EmergencyWindowViewModel>();
 | 
			
		||||
 | 
			
		||||
            logger.Info("结束APP-RegisterTypes");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,89 @@
 | 
			
		|||
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;
 | 
			
		||||
 | 
			
		||||
namespace DM_Weight.ViewModels
 | 
			
		||||
{
 | 
			
		||||
    public class EmergencyWindowViewModel : BindableBase
 | 
			
		||||
    {
 | 
			
		||||
        private readonly ILog logger = LogManager.GetLogger(typeof(HomeWindowViewModel));
 | 
			
		||||
        IEventAggregator _eventAggregator;
 | 
			
		||||
        private PortUtil _portUtil;
 | 
			
		||||
        IRegionManager _regionManager;
 | 
			
		||||
        SocketHelper _socketHelper;
 | 
			
		||||
        private bool _dbConnectionFail = !App.DbConnectionFail;
 | 
			
		||||
        public bool DBConnectionStatus { get=>_dbConnectionFail; set => SetProperty(ref _dbConnectionFail, value); }
 | 
			
		||||
        public EmergencyWindowViewModel(IRegionManager regionManager, PortUtil portUtil, IEventAggregator eventAggregator, SocketHelper socketHelper)
 | 
			
		||||
        {
 | 
			
		||||
            _portUtil = portUtil;
 | 
			
		||||
            _eventAggregator = eventAggregator; 
 | 
			
		||||
            _regionManager = regionManager; 
 | 
			
		||||
            _socketHelper = socketHelper;
 | 
			
		||||
            CheckDBConnect();
 | 
			
		||||
        }
 | 
			
		||||
        public DelegateCommand<string> UpdateDrawerNo
 | 
			
		||||
        {
 | 
			
		||||
            get => new DelegateCommand<string>((DrawerNo) =>
 | 
			
		||||
            {
 | 
			
		||||
                //应急开锁
 | 
			
		||||
                logger.Info($"应急开锁正在打开{DrawerNo}号药箱");
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Info($"发送开{DrawerNo}号药箱指令");
 | 
			
		||||
                    _socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(Convert.ToInt32(DrawerNo) - 1) });
 | 
			
		||||
                    _socketHelper.dateTime = DateTime.Now;
 | 
			
		||||
                    logger.Info($"发开{DrawerNo}号药箱指令完成");
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception ex)
 | 
			
		||||
                {
 | 
			
		||||
                    AlertMsg alertMsg = new AlertMsg
 | 
			
		||||
                    {
 | 
			
		||||
                        Message = $"网口连接异常,开药箱正在重试{ex.Message}",
 | 
			
		||||
                        Type = MsgType.ERROR,
 | 
			
		||||
                    };
 | 
			
		||||
                    _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        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();
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -83,9 +83,16 @@ namespace DM_Weight.ViewModels
 | 
			
		|||
 | 
			
		||||
            //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
 | 
			
		||||
            //{
 | 
			
		||||
 | 
			
		||||
            _container.RegisterType<object, LoginWindow>("LoginWindow");
 | 
			
		||||
            _regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
 | 
			
		||||
            if (App.DbConnectionFail)
 | 
			
		||||
            {
 | 
			
		||||
                //_container.RegisterType<object, EmergencyWindow>("EmergencyWindow");
 | 
			
		||||
                _regionManager.RequestNavigate("MainRegion", "EmergencyWindow");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _container.RegisterType<object, LoginWindow>("LoginWindow");
 | 
			
		||||
                _regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
 | 
			
		||||
            }
 | 
			
		||||
            _socketHelper = socketHelper;
 | 
			
		||||
            new PromiseUtil<int>().taskAsyncLoop(1200000, 0, async (options, next, stop) =>
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,90 @@
 | 
			
		|||
<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">
 | 
			
		||||
    <UserControl.Resources>
 | 
			
		||||
    </UserControl.Resources>
 | 
			
		||||
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.ColumnDefinitions>
 | 
			
		||||
            <ColumnDefinition Width="Auto" />
 | 
			
		||||
            <ColumnDefinition Width="Auto" />
 | 
			
		||||
        </Grid.ColumnDefinitions>
 | 
			
		||||
        <Grid Margin="26" Grid.Column="0">
 | 
			
		||||
            <Grid.Resources>
 | 
			
		||||
                <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
 | 
			
		||||
                    <Setter Property="Foreground" Value="#00a0ea" />
 | 
			
		||||
                    <Setter Property="BorderBrush" Value="#00a0ea" />                  
 | 
			
		||||
                </Style>
 | 
			
		||||
            </Grid.Resources>
 | 
			
		||||
 | 
			
		||||
            <Grid>
 | 
			
		||||
                <Grid.RowDefinitions>
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                    <RowDefinition />
 | 
			
		||||
                </Grid.RowDefinitions>
 | 
			
		||||
                <Grid.ColumnDefinitions>
 | 
			
		||||
                    <ColumnDefinition />
 | 
			
		||||
                    <ColumnDefinition />
 | 
			
		||||
                </Grid.ColumnDefinitions>
 | 
			
		||||
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="0" Grid.Column="0" Width="150" Content="1号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="1" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="1" Grid.Column="0" Width="150" Content="2号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="2" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="2" Grid.Column="0" Width="150" Content="3号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="3" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="3" Grid.Column="0" Width="150" Content="4号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="4" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="4" Grid.Column="0" Width="150" Content="5号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="5" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="5" Grid.Column="0" Width="150" Content="6号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="6" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="6" Grid.Column="0" Width="150" Content="7号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="7" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="7" Grid.Column="0" Width="150" Content="8号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="8" />
 | 
			
		||||
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="8" Grid.Column="0" Width="150" Content="9号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="9" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="0" Grid.Column="1" Width="150" Content="10号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="10" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="1" Grid.Column="1" Width="150" Content="11号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="11" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="2" Grid.Column="1" Width="150" Content="12号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="12" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="3" Grid.Column="1" Width="150" Content="13号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="13" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="4" Grid.Column="1" Width="150" Content="14号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="14" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="5" Grid.Column="1" Width="150" Content="15号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="15" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="6" Grid.Column="1" Width="150" Content="16号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="16" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="7" Grid.Column="1" Width="150" Content="17号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="17" />
 | 
			
		||||
                <Button Margin="0 0  3 0" Grid.Row="8" Grid.Column="1" Width="150" Content="18号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="18" />
 | 
			
		||||
            </Grid>
 | 
			
		||||
        </Grid>
 | 
			
		||||
        <Grid Grid.Column="1" Margin="0 60 0 0">
 | 
			
		||||
            <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 DBConnectionFail, 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>
 | 
			
		||||
</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