From 9539e2b96c63509556d8debb391bae034a41c248 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Mon, 3 Mar 2025 17:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E6=8E=A5=E6=9F=9C=E5=8A=A0=E8=8D=AF?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=BA=94=E6=89=B9=E6=AC=A1=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=E8=B0=83=E6=8B=A8=E5=85=A5=E5=BA=93=E4=BF=AE?= =?UTF-8?q?=E6=94=B9type=E3=80=81status=E5=AD=97=E6=AE=B5=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.xaml.cs | 8 ++ DM_Weight/DM_Weight.csproj | 1 + .../ViewModels/EmergencyWindowViewModel.cs | 82 +++++++++++++++++ .../ViewModels/InvoiceInWindowViewModel.cs | 2 +- DM_Weight/ViewModels/MainWindowViewModel.cs | 8 +- DM_Weight/Views/EmergencyWindow.xaml | 91 +++++++++++++++++++ DM_Weight/Views/EmergencyWindow.xaml.cs | 28 ++++++ DM_Weight/util/PromiseUtil.cs | 41 +++++++++ 8 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 DM_Weight/ViewModels/EmergencyWindowViewModel.cs create mode 100644 DM_Weight/Views/EmergencyWindow.xaml create mode 100644 DM_Weight/Views/EmergencyWindow.xaml.cs create mode 100644 DM_Weight/util/PromiseUtil.cs diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index bc0de06..7f338b4 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -32,6 +32,7 @@ namespace DM_Weight /// public partial class App : PrismApplication { + public static bool DbConnectionFail { get; set; } = false; private readonly ILog logger = LogManager.GetLogger(typeof(App)); public App() { @@ -58,6 +59,11 @@ namespace DM_Weight { logger.Error($"发生错误:{e.Exception.Message}"); e.Handled = true; + if (e.Exception.Message.Contains("连接数据库过程中发生错误")) + { + DbConnectionFail = true; + Container.Resolve(); + } } void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) @@ -245,6 +251,8 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); + //紧急开锁页面 + containerRegistry.RegisterForNavigation(); } } } diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index b35d455..0177979 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -71,6 +71,7 @@ + diff --git a/DM_Weight/ViewModels/EmergencyWindowViewModel.cs b/DM_Weight/ViewModels/EmergencyWindowViewModel.cs new file mode 100644 index 0000000..12bee58 --- /dev/null +++ b/DM_Weight/ViewModels/EmergencyWindowViewModel.cs @@ -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 OpenDrawer + { + get => new DelegateCommand((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().taskAsyncLoop(60000, 0, async (options, next, stop) => + { + try + { + var userList = SqlSugarHelper.Db.Queryable() + .First(u => u.UserName == "admin"); + App.DbConnectionFail = false; + DBConnectionStatus = true; + stop(); + } + catch (Exception ex) + { + next(); + } + }); + } + } +} diff --git a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs index b4c2dc6..c59f072 100644 --- a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs @@ -330,7 +330,7 @@ namespace DM_Weight.ViewModels sb.Append(" left join pharmacy_info p1 on p1.pharmacy = i.in_pharmacy_id"); sb.Append(" left join pharmacy_info p2 on p2.pharmacy = i.out_pharmacy_id"); sb.Append(" where i.status=@Status "); - sb.Append(" and i.type!=@type "); + sb.Append(" and i.type=@type "); sb.Append(" and i.cancel_flag=@CancelFlag "); if (OrderDate != null) { diff --git a/DM_Weight/ViewModels/MainWindowViewModel.cs b/DM_Weight/ViewModels/MainWindowViewModel.cs index 411397d..ff8a8d7 100644 --- a/DM_Weight/ViewModels/MainWindowViewModel.cs +++ b/DM_Weight/ViewModels/MainWindowViewModel.cs @@ -76,8 +76,12 @@ namespace DM_Weight.ViewModels //_cHKFunction = cHKFunction; System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { - - _container.RegisterType("LoginWindow"); + if (App.DbConnectionFail) + { + _regionManager.RequestNavigate("MainRegion", "EmergencyWindow"); + } + else + _container.RegisterType("LoginWindow"); _regionManager.RequestNavigate("MainRegion", "LoginWindow"); })); diff --git a/DM_Weight/Views/EmergencyWindow.xaml b/DM_Weight/Views/EmergencyWindow.xaml new file mode 100644 index 0000000..64e451f --- /dev/null +++ b/DM_Weight/Views/EmergencyWindow.xaml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +