跳转登录页面时先跳转EmptyWindow避免不执行OnNavigatedFrom方法

This commit is contained in:
maqiao 2025-01-15 18:57:17 +08:00
parent 58a6035add
commit 714a037b71
14 changed files with 181 additions and 51 deletions

View File

@ -37,7 +37,7 @@
<!-- 按处方还药或者按取药记录还药 1:处方ReturnDrugWindow22药品ReturnDrugWindow-->
<add key="returnDrugMode" value="1" />
<!-- 自动退出时间单位秒为0时不自动退出 -->
<add key="autoExit" value="0"/>
<add key="autoExit" value="5"/>
<!-- 无操作退出录像时间单位秒为0时不退出录像 -->
<add key="stopRecord" value="180"/>

View File

@ -256,6 +256,9 @@ namespace DM_Weight
containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>();
containerRegistry.RegisterForNavigation<EmptyWindow, EmptyWindowViewModel>();
}
}
}

View File

@ -71,6 +71,7 @@
<PackageReference Include="MaterialDesignThemes" Version="4.8.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="SharpPromise" Version="1.7.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.67" />
<PackageReference Include="SuperSimpleTcp" Version="3.0.10" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />

View File

@ -1338,6 +1338,7 @@ namespace DM_Weight.Port
{
try
{
logger.Info($"写数量:{drawerNo}-{colNo}{quantity}");
canBusSerial.DiscardInBuffer();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
string strQuantity = quantity.ToString("X");

View File

@ -436,7 +436,7 @@ namespace DM_Weight.ViewModels
//newStock.NeedNum = 0;
//newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity;
UpdateJJStock.Add(newStock);
csStock.TakeQuantity = 0;
csStockList[j].TakeQuantity = 0;
jiaoStock.NeedNum = jiaoStock.NeedNum - csStock.TakeQuantity;
}
else
@ -454,13 +454,13 @@ namespace DM_Weight.ViewModels
newStock.ManuNo = jiaoStock.ManuNo;
newStock.DrawerNo = jiaoStock.DrawerNo;
newStock.DrugId = jiaoStock.DrugId;
newStock.AddToJJNum = addNum;
newStock.AddToJJNum = jiaoStock.NeedNum;
newStock.Id = jjStockManuNo.Id;
//newStock.MachineId = jiaoStock.MachineId;
//newStock.NeedNum = 0;
//newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity;
UpdateJJStock.Add(newStock);
csStock.TakeQuantity = csStock.TakeQuantity - jiaoStock.NeedNum;
csStockList[j].TakeQuantity = csStock.TakeQuantity - jiaoStock.NeedNum;
jiaoStock.NeedNum = 0;
break;
}
@ -500,7 +500,7 @@ namespace DM_Weight.ViewModels
newStock.MachineId = jiaoStock.MachineId;
newStock.DrawerType = 1;
AddJJStock.Add(newStock);
csStock.TakeQuantity = csStock.TakeQuantity - newStock.AddToJJNum;
csStockList[j].TakeQuantity = csStock.TakeQuantity - newStock.AddToJJNum;
break;
}
}

View File

@ -470,6 +470,7 @@ namespace DM_Weight.ViewModels
//}
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
}
int AddToJiaoJieClickNum = 1;
//设置选中药箱的复选框状态
private void SetIsSelected(ChannelStock channelStock)
{

View File

@ -356,7 +356,7 @@ namespace DM_Weight.ViewModels
for (int i = 0; i < singleChannels.Count; i++)
{
_portUtil.WriteQuantityMethod((singleChannels[i].Quantity + singleChannels[i].AddQuantity), singleChannels[i].DrawerNo, singleChannels[i].ColNo);
//await _portUtil.WriteChannelInfoMethod(2, (singleChannels[i].Quantity + singleChannels[i].AddQuantity).ToString(), singleChannels[i].DrawerNo, singleChannels[i].ColNo);
//await _portUtil.WriteChannelIn foMethod(2, (singleChannels[i].Quantity + singleChannels[i].AddQuantity).ToString(), singleChannels[i].DrawerNo, singleChannels[i].ColNo);
//await Task.Delay(200);
//await _portUtil.ShowContentMethod(singleChannels[i].DrawerNo, singleChannels[i].ColNo);
Thread.Sleep(150);

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.ViewModels
{
internal class EmptyWindowViewModel
{
}
}

View File

@ -215,10 +215,12 @@ namespace DM_Weight.ViewModels
logger.Info($"用户【{Operator?.Nickname}】退出登录");
Operator = null;
Reviewer = null;
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{
_regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
}));
//}));
//_regionManager.RequestNavigate("MainRegion", "BeforeLogin");
}
@ -522,6 +524,7 @@ namespace DM_Weight.ViewModels
Reviewer = null;
Application.Current.Dispatcher.Invoke(() =>
{
_regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
});
AlertMsg alertMsg = new AlertMsg
@ -539,35 +542,58 @@ namespace DM_Weight.ViewModels
SelectedChildMenu = premissions[0].Children[0];
_regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath);
FindDrawerCount();
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
if (autoExit > 0)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += (sender, e) =>
//int interval = autoExit * 1000;
new PromiseUtil<int>().taskAsyncLoop(1000, 0, async (options, next, stop) =>
{
try
{
// 串口无人操作
if (!_portUtil.Operate)
{
// 30秒内无人操作鼠标键盘
// 无人操作鼠标键盘
if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
{
logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
//_chkFunction.HIKStopDVRRecord();
logger.Info($"设备{autoExit}内无人操作,用户【{Operator?.Nickname}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{CheckComputerFreeState.GetLastInputTime()},autoExit:{autoExit}");
Operator = null;
Reviewer = null;
Application.Current.Dispatcher.Invoke(() =>
//Application.Current.Dispatcher.Invoke(() =>
//{
stop();
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
_regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
timer.Stop();
}));
//});
//timer.Dispose();
}
else
{
if (Operator == null)
{
stop();
}
else
{
next();
}
}
}
else
{
_portUtil.dateTime = DateTime.Now;
next();
}
}
catch (Exception ex)
{
logger.Info($"自动退出异常:{ex.Message}");
}
});
}
}
};
timer.Start();
}
//#region 温度查询定时
//int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
//if (interval > 0)

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;
@ -117,7 +117,7 @@ namespace DM_Weight.ViewModels
//_chkFunction= chcFunction;
_regionManager = regionManager;
_eventAggregator = eventAggregator;
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
//_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
}
private DelegateCommand? _loginCommand;
@ -180,7 +180,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
{
@ -201,7 +201,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
{
@ -257,6 +257,7 @@ _exitCommand ??= new DelegateCommand(Exit);
keys.Add("operator", user);
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{
logger.Info("跳转home页面");
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
//}));
}
@ -317,9 +318,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;
@ -349,7 +350,7 @@ _exitCommand ??= new DelegateCommand(Exit);
RaisePropertyChanged("Reviewer");
}
Username = string.Empty;
Password =string.Empty;
Password = string.Empty;
}
}
}
@ -368,8 +369,10 @@ _exitCommand ??= new DelegateCommand(Exit);
{
FingerMsg = !msg.Result;
}
logger.Info($"LoginBtnEnable:{LoginBtnEnable}");
if (LoginBtnEnable)
{
logger.Info($"msg.Message:{msg.Message};{msg.Message.Equals("LOGIN")}");
if (msg.Message.Equals("LOGIN"))
{
UserList userList = new UserList();
@ -380,7 +383,7 @@ _exitCommand ??= new DelegateCommand(Exit);
//.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString());
logger.Info($"userList==null?{userList == null}");
if (userList == null)
{
AlertMsg alertMsg = new AlertMsg
@ -447,7 +450,7 @@ _exitCommand ??= new DelegateCommand(Exit);
public void OnNavigatedTo(NavigationContext navigationContext)
{
//FingerMsg = !_fingerprintUtil.bIsConnected;
//_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
}

View File

@ -73,13 +73,15 @@ namespace DM_Weight.ViewModels
_regionManager = regionManager;
_container = container;
//_cHKFunction = cHKFunction;
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
_container.RegisterType<object, LoginWindow>("LoginWindow");
_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
//_container.RegisterType<object, LoginWindow>("LoginWindow");
//_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
//}));
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
}));
}
void doMyPrismEvent2(AlertMsg msg)

View File

@ -0,0 +1,12 @@
<UserControl x:Class="DM_Weight.Views.EmptyWindow"
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"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!--空白页面用于退出登录时先跳转该页面再退出登录ContentRegion先跳转到该页面让上一个页面先进OnNavigatedFrom。-->
</Grid>
</UserControl>

View File

@ -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>
/// EmptyWindow.xaml 的交互逻辑
/// </summary>
public partial class EmptyWindow : UserControl
{
public EmptyWindow()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,41 @@
using SharpPromise;
using System;
using System.Threading.Tasks;
namespace DM_Weight.util
{
public class PromiseUtil<T>
{
public int _delay { get; set; }
public T? _data { get; set; }
public async Task taskAsyncLoop(int delay, T data, Action<PromiseUtil<T>, Action, Action> action)
{
_data = data;
_delay = 0;
while (_delay >= 0)
{
await new Promise(async (Action onResolve, Action onReject) =>
{
await Task.Delay(_delay);
try
{
await Task.Run(() => action(this, onResolve, onReject));
}
catch (Exception ex)
{
onReject();
}
}).Then(() =>
{
_delay = delay;
}).Catch((Exception e) =>
{
_delay = -1;
});
}
}
}
}