diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index c98ea2a..4a9d65d 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -276,6 +276,8 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + logger.Info("结束APP-RegisterTypes"); } diff --git a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs index 5a16251..b37df28 100644 --- a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs +++ b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs @@ -73,14 +73,14 @@ namespace DM_Weight.ViewModels get => _btnIsEnable; set => SetProperty(ref _btnIsEnable, value); } - //冰箱状态:true关;false开 + //冰箱状态:true关1;false开0 private bool _fridgeState; public bool FridgeState { get => _fridgeState; set => SetProperty(ref _fridgeState, value); } - //报警状态:true关;false开 + //报警状态:true关1;false开0 private bool _alarmState; public bool AlarmState { @@ -88,9 +88,7 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _alarmState, value); } - private int _defaultLoginMode;//1开0关 - private int _defaultAlarmMode;//1开0关 private float retTemperature = Convert.ToSingle(ConfigurationManager.AppSettings["temperatureValue"]); @@ -120,30 +118,32 @@ namespace DM_Weight.ViewModels //{ // ConfigurationManager.RefreshSection("FridgeState"); //发送冰箱使能/失能指令 - if (_fridgeState) + if (FridgeState) { await _portUtil.FridgeOff(1); Thread.Sleep(100); - CommonClass.SaveAppSetting("FridgeState", "0"); + CommonClass.SaveAppSetting("FridgeState", "1"); } else { await _portUtil.FridegOpen(1); Thread.Sleep(100); - CommonClass.SaveAppSetting("FridgeState", "1"); + CommonClass.SaveAppSetting("FridgeState", "0"); + //冰箱打开定时获取冰箱温度 + _eventAggregator.GetEvent().Publish(); } //发送警报使能/失能指令 - if (_alarmState) + if (AlarmState) { await _portUtil.FridgeAlarmOff(1); Thread.Sleep(100); - CommonClass.SaveAppSetting("AlarmState", "0"); + CommonClass.SaveAppSetting("AlarmState", "1"); } else { await _portUtil.FridgeAlarmOn(1); Thread.Sleep(100); - CommonClass.SaveAppSetting("AlarmState", "1"); + CommonClass.SaveAppSetting("AlarmState", "0"); } //设定冰箱1温度区间 string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-'); @@ -209,10 +209,9 @@ namespace DM_Weight.ViewModels public void OnNavigatedTo(NavigationContext navigationContext) { - _fridgeState = ReadAppSetting("FridgeState").Equals(0); - _defaultLoginMode = ReadAppSetting("FridgeState"); - _defaultAlarmMode = ReadAppSetting("AlarmState"); - _alarmState = ReadAppSetting("AlarmState").Equals(0); + FridgeState = ReadAppSetting("FridgeState").Equals(1); + + AlarmState = ReadAppSetting("AlarmState").Equals(1); GetTemperature(); } @@ -224,7 +223,6 @@ namespace DM_Weight.ViewModels public void OnNavigatedFrom(NavigationContext navigationContext) { - } //获取冰箱温度值,如有更改则保存更改 private async Task GetTemperature() diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index b87ddc5..0874467 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -43,10 +43,10 @@ namespace DM_Weight.ViewModels private string _wd = "恒温冷藏抽屉当前温度2.8(非真实数据)"; public string WD { get => _wd; set => SetProperty(ref _wd, value); } - private SolidColorBrush _alertColor=Brushes.White; + private SolidColorBrush _alertColor = Brushes.White; public SolidColorBrush AlertColor { - get=> _alertColor; + get => _alertColor; set => SetProperty(ref _alertColor, value); } @@ -670,6 +670,14 @@ namespace DM_Weight.ViewModels ////获取录像机的时间 //_chkFunction.HIK_DVR_TIME(); //_chkFunction.HIKStartDVRRecord(); + GetFridgeTemperature(); + + _eventAggregator.GetEvent().Subscribe(GetFridgeTemperature); + } + //获取冰箱温度定时 + private void GetFridgeTemperature() + { + string[] tempRange = TemperatureRange.Split('-'); new PromiseUtil().taskAsyncLoop(10000, 0, async (options, next, stop) => { @@ -696,18 +704,26 @@ namespace DM_Weight.ViewModels //停掉冰箱 await _portUtil.FridgeOff(1); CommonClass.SaveAppSetting("FridgeState", "1"); - AlertMsg alertMsg = new AlertMsg + //AlertMsg alertMsg = new AlertMsg + //{ + // Message = $"冰箱制冷片温度超过65度,已关闭冰箱制冷功能!!!", + // Type = MsgType.ERROR + //}; + //_eventAggregator.GetEvent().Publish(alertMsg); + + System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { - Message = $"冰箱制冷片温度超过65度,已关闭冰箱制冷功能!!!", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("warnMessage", "冰箱制冷片温度超过65度,已关闭冰箱制冷功能!!!"); + DialogServiceExtensions.ShowDialogHost(_dialogService, "WarnDialog", dialogParameters, DoDialogResult, "RootDialog"); + + })); } logger.Info($"制冷片温度超过65度"); Thread.Sleep(100); //给出提示 WD += "冰箱温度异常,已关闭冰箱制冷功能"; - AlertColor=Brushes.Red; + AlertColor = Brushes.Red; FridgeTime = null; stop(); } @@ -741,12 +757,19 @@ namespace DM_Weight.ViewModels AlertColor = Brushes.Red; FridgeState = "1"; CommonClass.SaveAppSetting("FridgeState", "1"); - AlertMsg alertMsg = new AlertMsg + //AlertMsg alertMsg = new AlertMsg + //{ + // Message = $"冰箱温度异常,已关闭冰箱制冷功能!!!", + // Type = MsgType.ERROR + //}; + //_eventAggregator.GetEvent().Publish(alertMsg); + System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { - Message = $"冰箱温度异常,已关闭冰箱制冷功能!!!", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("warnMessage", "冰箱温度异常,已关闭冰箱制冷功能!!!"); + DialogServiceExtensions.ShowDialogHost(_dialogService, "WarnDialog", dialogParameters, DoDialogResult, "RootDialog"); + + })); FridgeTime = null; stop(); } @@ -814,7 +837,6 @@ namespace DM_Weight.ViewModels next(); } }); - } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 @@ -828,6 +850,8 @@ namespace DM_Weight.ViewModels { IsLeave = true; navigationContext.NavigationService.Region.RegionManager.Regions.Remove(PrismManager.SettingViewRegionName); + + _eventAggregator.GetEvent().Unsubscribe(GetFridgeTemperature); } } } diff --git a/DM_Weight/ViewModels/WarnDialogViewModel.cs b/DM_Weight/ViewModels/WarnDialogViewModel.cs new file mode 100644 index 0000000..927bdd9 --- /dev/null +++ b/DM_Weight/ViewModels/WarnDialogViewModel.cs @@ -0,0 +1,50 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class WarnDialogViewModel:BindableBase, IDialogAware, IRegionMemberLifetime + { + private string _warnMessage; + public string WarnMessage + { + get => _warnMessage; + set => SetProperty(ref _warnMessage, value); + } + + public string Title => "警告"; + + public bool KeepAlive => false; + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + } + + public void OnDialogOpened(IDialogParameters parameters) + { + WarnMessage=parameters.GetValue("warnMessage"); + + } + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + } +} diff --git a/DM_Weight/Views/Dialog/WarnDialog.xaml b/DM_Weight/Views/Dialog/WarnDialog.xaml new file mode 100644 index 0000000..f55521b --- /dev/null +++ b/DM_Weight/Views/Dialog/WarnDialog.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + +