diff --git a/DM_Weight/ViewModels/EmergencyWindowViewModel.cs b/DM_Weight/ViewModels/EmergencyWindowViewModel.cs index f41c762..e860938 100644 --- a/DM_Weight/ViewModels/EmergencyWindowViewModel.cs +++ b/DM_Weight/ViewModels/EmergencyWindowViewModel.cs @@ -18,7 +18,7 @@ using System.Windows.Threading; namespace DM_Weight.ViewModels { - public class EmergencyWindowViewModel : BindableBase + public class EmergencyWindowViewModel : BindableBase, IRegionMemberLifetime, INavigationAware { private readonly ILog logger = LogManager.GetLogger(typeof(HomeWindowViewModel)); IEventAggregator _eventAggregator; @@ -34,7 +34,6 @@ namespace DM_Weight.ViewModels _portUtil = portUtil; _eventAggregator = eventAggregator; _regionManager = regionManager; - CheckDBConnect(); } public DelegateCommand OpenDrawer { @@ -86,5 +85,21 @@ namespace DM_Weight.ViewModels } }); } + public bool KeepAlive => false; + public void OnNavigatedTo(NavigationContext navigationContext) + { + DBConnectionStatus = !App.DbConnectionFail; + CheckDBConnect(); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } } } diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index 575e020..4f6160c 100644 --- a/DM_Weight/ViewModels/LoginWindowViewModel.cs +++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs @@ -375,63 +375,77 @@ _exitCommand ??= new DelegateCommand(Exit); logger.Info($"msg.Message:{msg.Message};{msg.Message.Equals("LOGIN")}"); if (msg.Message.Equals("LOGIN")) { - UserList userList = new UserList(); - userList = SqlSugarHelper.Db.Queryable() - .Includes(u => u.Role) - .Where(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString()) - .WithCacheIF(false).First(); - //.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString()); + try + { - logger.Info($"userList==null?{userList == null}"); - if (userList == null) - { - AlertMsg alertMsg = new AlertMsg + UserList userList = new UserList(); + userList = SqlSugarHelper.Db.Queryable() + .Includes(u => u.Role) + .Where(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString()) + .WithCacheIF(false).First(); + //.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString()); + + + logger.Info($"userList==null?{userList == null}"); + if (userList == null) { - Message = "无此用户", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - Username = ""; - Password = ""; - } - else if (userList.Role == null) - { - AlertMsg alertMsg = new AlertMsg - { - Message = "用户还未设置权限,请联系管理员", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - Username = ""; - Password = ""; - } - else - { - //1仅当班人、审核人可登录 - if (LoginUserCheck.Equals("1")) - { - //检查当前登录人是否是值班人 (审核人与发药人) - listHkcChangeShifts = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.State == "0").First(); - if (listHkcChangeShifts != null) + AlertMsg alertMsg = new AlertMsg { - if (!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName)) - { - AlertMsg alertMsg = new AlertMsg - { - Message = "仅值班人可登录,当前登录人非值班人", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - Username = ""; - Password = ""; - return; - } - - } + Message = "无此用户", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Username = ""; + Password = ""; } - SetUser(userList); + else if (userList.Role == null) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "用户还未设置权限,请联系管理员", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Username = ""; + Password = ""; + } + else + { + //1仅当班人、审核人可登录 + if (LoginUserCheck.Equals("1")) + { + //检查当前登录人是否是值班人 (审核人与发药人) + listHkcChangeShifts = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.State == "0").First(); + if (listHkcChangeShifts != null) + { + if (!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName)) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "仅值班人可登录,当前登录人非值班人", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Username = ""; + Password = ""; + return; + } + + } + } + SetUser(userList); + } + } + catch (Exception ex) + { + if (ex.Message.Contains("连接数据库过程中发生错误")) + { + App.DbConnectionFail = true; + _regionManager.RequestNavigate("MainRegion", "EmergencyWindow"); + } + logger.Info(ex.Message); } } } diff --git a/DM_Weight/Views/EmergencyWindow.xaml b/DM_Weight/Views/EmergencyWindow.xaml index 6c4c23d..47fbaa3 100644 --- a/DM_Weight/Views/EmergencyWindow.xaml +++ b/DM_Weight/Views/EmergencyWindow.xaml @@ -28,7 +28,7 @@ - +