From 714a037b71353ec9ff7ef268f554a1bacb3dd0fa Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Wed, 15 Jan 2025 18:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=97=B6=E5=85=88=E8=B7=B3=E8=BD=ACEmptyWindow?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=B8=8D=E6=89=A7=E8=A1=8COnNavigatedFrom?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.config | 2 +- DM_Weight/App.xaml.cs | 3 + DM_Weight/DM_Weight.csproj | 1 + DM_Weight/Port/PortUtil.cs | 1 + .../ViewModels/AddToJiaoJieDialogViewModel.cs | 8 +- .../ViewModels/AddToJiaoJieWindowViewModel.cs | 1 + .../DrawerAddDrugWindowViewModel.cs | 2 +- DM_Weight/ViewModels/EmptyWindowViewModel.cs | 12 +++ DM_Weight/ViewModels/HomeWindowViewModel.cs | 80 ++++++++++++------- DM_Weight/ViewModels/LoginWindowViewModel.cs | 29 ++++--- DM_Weight/ViewModels/MainWindowViewModel.cs | 12 +-- DM_Weight/Views/EmptyWindow.xaml | 12 +++ DM_Weight/Views/EmptyWindow.xaml.cs | 28 +++++++ DM_Weight/util/PromiseUtil.cs | 41 ++++++++++ 14 files changed, 181 insertions(+), 51 deletions(-) create mode 100644 DM_Weight/ViewModels/EmptyWindowViewModel.cs create mode 100644 DM_Weight/Views/EmptyWindow.xaml create mode 100644 DM_Weight/Views/EmptyWindow.xaml.cs create mode 100644 DM_Weight/util/PromiseUtil.cs diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 9346b5d..c08f6ad 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -37,7 +37,7 @@ - + diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 28ee337..6444de0 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -256,6 +256,9 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); + + containerRegistry.RegisterForNavigation(); + } } } diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index 98c1fd7..2b270b6 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -71,6 +71,7 @@ + diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs index 7334281..1d82d86 100644 --- a/DM_Weight/Port/PortUtil.cs +++ b/DM_Weight/Port/PortUtil.cs @@ -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"); diff --git a/DM_Weight/ViewModels/AddToJiaoJieDialogViewModel.cs b/DM_Weight/ViewModels/AddToJiaoJieDialogViewModel.cs index f30129c..6565e95 100644 --- a/DM_Weight/ViewModels/AddToJiaoJieDialogViewModel.cs +++ b/DM_Weight/ViewModels/AddToJiaoJieDialogViewModel.cs @@ -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; } } diff --git a/DM_Weight/ViewModels/AddToJiaoJieWindowViewModel.cs b/DM_Weight/ViewModels/AddToJiaoJieWindowViewModel.cs index 9f482c3..99660e5 100644 --- a/DM_Weight/ViewModels/AddToJiaoJieWindowViewModel.cs +++ b/DM_Weight/ViewModels/AddToJiaoJieWindowViewModel.cs @@ -470,6 +470,7 @@ namespace DM_Weight.ViewModels //} //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } + int AddToJiaoJieClickNum = 1; //设置选中药箱的复选框状态 private void SetIsSelected(ChannelStock channelStock) { diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index 6a45b98..144057f 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -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); diff --git a/DM_Weight/ViewModels/EmptyWindowViewModel.cs b/DM_Weight/ViewModels/EmptyWindowViewModel.cs new file mode 100644 index 0000000..2909812 --- /dev/null +++ b/DM_Weight/ViewModels/EmptyWindowViewModel.cs @@ -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 + { + } +} diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index 0820fae..1f8d920 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -161,7 +161,7 @@ namespace DM_Weight.ViewModels // } // } // } - SetProperty(ref _selectedChildMenu, value); + SetProperty(ref _selectedChildMenu, value); //} } } @@ -215,12 +215,14 @@ 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(() => - { - _regionManager.RequestNavigate("MainRegion", "LoginWindow"); - })); - //_regionManager.RequestNavigate("MainRegion", "BeforeLogin"); - + //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"); + } else { @@ -490,7 +492,7 @@ namespace DM_Weight.ViewModels //public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); } //private void CheckAction() //{ - //GetWD(); + //GetWD(); //} @@ -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,34 +542,57 @@ 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().taskAsyncLoop(1000, 0, async (options, next, stop) => { - // 串口无人操作 - if (!_portUtil.Operate) + try { - // 30秒内无人操作鼠标键盘 - if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) + if (!_portUtil.Operate) { - logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录"); - //_chkFunction.HIKStopDVRRecord(); - Operator = null; - Reviewer = null; - Application.Current.Dispatcher.Invoke(() => + // 无人操作鼠标键盘 + if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) { - _regionManager.RequestNavigate("MainRegion", "LoginWindow"); - timer.Stop(); - }); + 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(() => + //{ + stop(); + System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => + { + _regionManager.RequestNavigate("ContentRegion", "EmptyWindow"); + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + })); + //}); + //timer.Dispose(); + } + else + { + if (Operator == null) + { + stop(); + } + else + { + next(); + } + } + } + else + { + _portUtil.dateTime = DateTime.Now; + next(); } } - }; - timer.Start(); + catch (Exception ex) + { + logger.Info($"自动退出异常:{ex.Message}"); + } + }); } //#region 温度查询定时 //int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index 2ed9559..575e020 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; @@ -117,7 +117,7 @@ namespace DM_Weight.ViewModels //_chkFunction= chcFunction; _regionManager = regionManager; _eventAggregator = eventAggregator; - _eventAggregator.GetEvent().Subscribe(LoginEvent); + //_eventAggregator.GetEvent().Subscribe(LoginEvent); } private DelegateCommand? _loginCommand; @@ -131,7 +131,7 @@ _exitCommand ??= new DelegateCommand(Exit); public bool KeepAlive => false; - void Login() + void Login() { LoginBtnEnable = false; if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) @@ -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,7 +257,8 @@ _exitCommand ??= new DelegateCommand(Exit); keys.Add("operator", user); //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //{ - _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); + logger.Info("跳转home页面"); + _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); //})); } // 双人登录模式 @@ -273,7 +274,7 @@ _exitCommand ??= new DelegateCommand(Exit); RaisePropertyChanged("Reviewer"); //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //{ - _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); + _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); //})); } @@ -297,7 +298,7 @@ _exitCommand ??= new DelegateCommand(Exit); RaisePropertyChanged("Operator"); //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //{ - _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); + _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().Subscribe(LoginEvent); + _eventAggregator.GetEvent().Subscribe(LoginEvent); } diff --git a/DM_Weight/ViewModels/MainWindowViewModel.cs b/DM_Weight/ViewModels/MainWindowViewModel.cs index a7196b9..8aea2f0 100644 --- a/DM_Weight/ViewModels/MainWindowViewModel.cs +++ b/DM_Weight/ViewModels/MainWindowViewModel.cs @@ -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("LoginWindow"); - _regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow"); + //_container.RegisterType("LoginWindow"); + //_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow"); - //})); + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + + })); } void doMyPrismEvent2(AlertMsg msg) diff --git a/DM_Weight/Views/EmptyWindow.xaml b/DM_Weight/Views/EmptyWindow.xaml new file mode 100644 index 0000000..1a02820 --- /dev/null +++ b/DM_Weight/Views/EmptyWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/DM_Weight/Views/EmptyWindow.xaml.cs b/DM_Weight/Views/EmptyWindow.xaml.cs new file mode 100644 index 0000000..b327868 --- /dev/null +++ b/DM_Weight/Views/EmptyWindow.xaml.cs @@ -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 +{ + /// + /// EmptyWindow.xaml 的交互逻辑 + /// + public partial class EmptyWindow : UserControl + { + public EmptyWindow() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/util/PromiseUtil.cs b/DM_Weight/util/PromiseUtil.cs new file mode 100644 index 0000000..1638a60 --- /dev/null +++ b/DM_Weight/util/PromiseUtil.cs @@ -0,0 +1,41 @@ +using SharpPromise; +using System; +using System.Threading.Tasks; + +namespace DM_Weight.util +{ + public class PromiseUtil + { + + public int _delay { get; set; } + + public T? _data { get; set; } + + public async Task taskAsyncLoop(int delay, T data, Action, 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; + }); + } + } + } +}