diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index d8b9827..5eb9a8d 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -93,7 +93,7 @@
-
+
diff --git a/DM_Weight/Finger/FingerprintUtil.cs b/DM_Weight/Finger/FingerprintUtil.cs
index 0aae4d8..349ff39 100644
--- a/DM_Weight/Finger/FingerprintUtil.cs
+++ b/DM_Weight/Finger/FingerprintUtil.cs
@@ -32,10 +32,10 @@ namespace DM_Weight.Finger
{
_eventAggregator = eventAggregator;
logger.Info($"进入构造器,开始连接指纹机");
- Task.Run(() =>
- {
+ // Task.Run(() =>
+ //{
ConnectionMain();
- });
+ //});
}
public void ConnectionMain()
diff --git a/DM_Weight/ViewModels/EmergencyWindowViewModel.cs b/DM_Weight/ViewModels/EmergencyWindowViewModel.cs
index 3aac44c..5e1803b 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
{
@@ -62,6 +61,9 @@ namespace DM_Weight.ViewModels
}
private DelegateCommand? _exitCommand;
public DelegateCommand ExitCommand => _exitCommand ??= new DelegateCommand(Exit);
+
+ public bool KeepAlive => false;
+
void Exit()
{
Process.GetCurrentProcess().Kill();
@@ -86,5 +88,22 @@ namespace DM_Weight.ViewModels
}
});
}
+
+
+ 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 83e8d4a..ac87407 100644
--- a/DM_Weight/ViewModels/LoginWindowViewModel.cs
+++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs
@@ -60,7 +60,7 @@ namespace DM_Weight.ViewModels
get => ReadAppSetting("loginUser");
}
- private HkcChangeShifts listHkcChangeShifts=new HkcChangeShifts();
+ private HkcChangeShifts listHkcChangeShifts = new HkcChangeShifts();
private FingerprintUtil _fingerprintUtil;
@@ -84,7 +84,7 @@ namespace DM_Weight.ViewModels
get => _portUtil._canBusExsit && !_portUtil.canBusSerial.IsOpen;
}
- private bool _fingerMsg= CHKFunction.HKUserId>=0;
+ private bool _fingerMsg = CHKFunction.HKUserId >= 0;
public bool FingerMsg
{
@@ -99,8 +99,8 @@ namespace DM_Weight.ViewModels
private bool _hikMsg;
public bool HIKMsg
{
- get=>_hikMsg;
- set=>SetProperty(ref _hikMsg, value);
+ get => _hikMsg;
+ set => SetProperty(ref _hikMsg, value);
}
//public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil)
@@ -130,7 +130,7 @@ _exitCommand ??= new DelegateCommand(Exit);
public bool KeepAlive => false;
- void Login()
+ void Login()
{
LoginBtnEnable = false;
if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
@@ -179,7 +179,7 @@ _exitCommand ??= new DelegateCommand(Exit);
Username = "";
Password = "";
}
- else if (userList.Role == null|| userList.Role.Permissions.Count<=0)
+ else if (userList.Role == null || userList.Role.Permissions.Count <= 0)
{
AlertMsg alertMsg = new AlertMsg
{
@@ -200,7 +200,7 @@ _exitCommand ??= new DelegateCommand(Exit);
.Where(cs => cs.State == "0").First();
if (listHkcChangeShifts != null)
{
- if(!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName))
+ if (!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName))
{
AlertMsg alertMsg = new AlertMsg
{
@@ -316,9 +316,9 @@ _exitCommand ??= new DelegateCommand(Exit);
//1仅当班人、审核人可登录
if (LoginUserCheck.Equals("1"))
{
- if(listHkcChangeShifts!=null)
+ if (listHkcChangeShifts != null)
{
- if(listHkcChangeShifts.FromOperator.Equals(user.UserName))
+ if (listHkcChangeShifts.FromOperator.Equals(user.UserName))
{
keys.Add("operator", user);
Operator = user;
@@ -348,7 +348,7 @@ _exitCommand ??= new DelegateCommand(Exit);
RaisePropertyChanged("Reviewer");
}
Username = string.Empty;
- Password =string.Empty;
+ Password = string.Empty;
}
}
}
@@ -371,59 +371,77 @@ _exitCommand ??= new DelegateCommand(Exit);
{
if (msg.Message.Equals("LOGIN"))
{
- UserList userList = SqlSugarHelper.Db.Queryable()
+ try
+ {
- .Includes(u => u.Role)
- .First(u => u.Id == msg.Id);
+ UserList userList = SqlSugarHelper.Db.Queryable()
- if (userList == null)
- {
- AlertMsg alertMsg = new AlertMsg
+ .Includes(u => u.Role)
+ .First(u => u.Id == msg.Id);
+
+ 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");
+ //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+ //{
+ // _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 @@
-
+