冰箱报警由提示改为弹窗,修改冰箱设置页面打开冰箱则调用Home中定时查温度

This commit is contained in:
maqiao 2025-03-13 10:14:36 +08:00
parent 34c6cbb69c
commit 5708dc0675
7 changed files with 184 additions and 29 deletions

View File

@ -276,6 +276,8 @@ namespace DM_Weight
containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>();
containerRegistry.RegisterForNavigation<WarnDialog, WarnDialogViewModel>();
logger.Info("结束APP-RegisterTypes");
}

View File

@ -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<FridgeEvent>().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()

View File

@ -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<FridgeEvent>().Subscribe(GetFridgeTemperature);
}
//获取冰箱温度定时
private void GetFridgeTemperature()
{
string[] tempRange = TemperatureRange.Split('-');
new PromiseUtil<int>().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<SnackbarEvent>().Publish(alertMsg);
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
Message = $"冰箱制冷片温度超过65度已关闭冰箱制冷功能!!!",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().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<SnackbarEvent>().Publish(alertMsg);
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
Message = $"冰箱温度异常,已关闭冰箱制冷功能!!!",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().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<FridgeEvent>().Unsubscribe(GetFridgeTemperature);
}
}
}

View File

@ -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<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
WarnMessage=parameters.GetValue<string>("warnMessage");
}
public DelegateCommand CancleTake
{
get => new DelegateCommand(() =>
{
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
});
}
}
}

View File

@ -0,0 +1,40 @@
<UserControl x:Class="DM_Weight.Views.Dialog.WarnDialog"
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.Dialog"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Background="#FFD32F2F" Grid.ColumnSpan="3">
<TextBlock Text="警告" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="White" Margin="16 4 16 4" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="3" VerticalAlignment="Center"
Margin="16 14 16 4" FontSize="16" FontWeight="Bold"
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="{Binding WarnMessage,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" />
<Button Grid.Row="3" Grid.Column="1"
Margin="6"
Style="{StaticResource MaterialDesignOutlinedLightButton}"
Content="确认"
Command="{Binding CancleTake}" />
</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.Dialog
{
/// <summary>
/// WarnDialog.xaml 的交互逻辑
/// </summary>
public partial class WarnDialog : UserControl
{
public WarnDialog()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,13 @@
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.msg
{
public class FridgeEvent:PubSubEvent
{
}
}