指纹登录数据库连接失败跳转紧急开锁页面

This commit is contained in:
maqiao 2025-03-05 09:44:47 +08:00
parent 804643d035
commit 5269c94399
5 changed files with 102 additions and 65 deletions

View File

@ -93,7 +93,7 @@
<!-- 指纹机号码 -->
<add key="machineNumber" value="1"/>
<!-- 指纹机ip -->
<add key="fingerIp" value="192.168.1.201"/>
<add key="fingerIp" value="192.168.50.201"/>
<!-- 多处方取药 0:不启用 1启用-->
<add key="MultiOrder" value="1"/>

View File

@ -32,10 +32,10 @@ namespace DM_Weight.Finger
{
_eventAggregator = eventAggregator;
logger.Info($"进入构造器,开始连接指纹机");
Task.Run(() =>
{
// Task.Run(() =>
//{
ConnectionMain();
});
//});
}
public void ConnectionMain()

View File

@ -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<string> 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)
{
}
}
}

View File

@ -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<UserList>()
try
{
.Includes<RoleDm>(u => u.Role)
.First(u => u.Id == msg.Id);
UserList userList = SqlSugarHelper.Db.Queryable<UserList>()
if (userList == null)
{
AlertMsg alertMsg = new AlertMsg
.Includes<RoleDm>(u => u.Role)
.First(u => u.Id == msg.Id);
if (userList == null)
{
Message = "无此用户",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
Username = "";
Password = "";
}
else if (userList.Role == null)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "用户还未设置权限,请联系管理员",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
Username = "";
Password = "";
}
else
{
//1仅当班人、审核人可登录
if (LoginUserCheck.Equals("1"))
{
//检查当前登录人是否是值班人 (审核人与发药人)
listHkcChangeShifts = SqlSugarHelper.Db.Queryable<HkcChangeShifts>()
.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<SnackbarEvent>().Publish(alertMsg);
Username = "";
Password = "";
return;
}
}
Message = "无此用户",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
Username = "";
Password = "";
}
SetUser(userList);
else if (userList.Role == null)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "用户还未设置权限,请联系管理员",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
Username = "";
Password = "";
}
else
{
//1仅当班人、审核人可登录
if (LoginUserCheck.Equals("1"))
{
//检查当前登录人是否是值班人 (审核人与发药人)
listHkcChangeShifts = SqlSugarHelper.Db.Queryable<HkcChangeShifts>()
.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<SnackbarEvent>().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);
}
}
}

View File

@ -28,7 +28,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Margin="0" Grid.Column="0" Width="280" Visibility="{Binding Is8Drawer, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid Margin="0" Grid.Column="0" Width="280">
<Grid.Background>
<ImageBrush ImageSource="/Images/box.png" />
</Grid.Background>