@@ -77,7 +77,7 @@ | |||
HorizontalAlignment="Center" | |||
FontSize="8" | |||
Foreground="#FF00E6F7" | |||
Text="{Binding ListNum}" /> | |||
Text="{Binding ListNum, Mode=TwoWay}" /> | |||
<!-- --> | |||
</Border> | |||
<Image | |||
@@ -93,6 +93,11 @@ | |||
<ControlTemplate.Triggers> | |||
<Trigger Property="IsChecked" Value="true"> | |||
<Setter TargetName="image1" Property="Source" Value="/BPASmartClient.CustomResource;component/Image/告警/严重告警.png" /> | |||
<Setter TargetName="bd1" Property="Visibility" Value="Visible" /> | |||
</Trigger> | |||
<Trigger Property="IsChecked" Value="False"> | |||
<Setter TargetName="image1" Property="Source" Value="/BPASmartClient.CustomResource;component/Image/告警/无告警.png" /> | |||
<Setter TargetName="bd1" Property="Visibility" Value="Collapsed" /> | |||
</Trigger> | |||
<MultiDataTrigger> | |||
<MultiDataTrigger.Conditions> | |||
@@ -99,8 +99,8 @@ namespace BPASmartClient.Device | |||
/// </summary> | |||
private List<IPeripheral> peripherals; | |||
public Action<object> AddErrorAction { get; set; } | |||
public Action<object> DeleteErrorAction { get; set; } | |||
public Action<int,object> AddErrorAction { get; set; } | |||
public Action<int, object> DeleteErrorAction { get; set; } | |||
#endregion | |||
@@ -173,7 +173,7 @@ namespace BPASmartClient.Device | |||
Text = item.Ms | |||
}; | |||
Error.Add(obj); | |||
AddErrorAction?.Invoke(obj); | |||
AddErrorAction?.Invoke(DeviceId,obj); | |||
} | |||
} | |||
else | |||
@@ -182,7 +182,7 @@ namespace BPASmartClient.Device | |||
if (res != null) | |||
{ | |||
Error.Remove(res); | |||
DeleteErrorAction?.Invoke(res); | |||
DeleteErrorAction?.Invoke(DeviceId,res); | |||
} | |||
} | |||
} | |||
@@ -234,7 +234,7 @@ namespace BPASmartClient.Device | |||
Text = res.Info | |||
}; | |||
Error.Add(obj); | |||
AddErrorAction?.Invoke(obj); | |||
AddErrorAction?.Invoke(DeviceId, obj); | |||
} | |||
}); | |||
alarmHelper.RemoveAction = new Action<string>((s) => | |||
@@ -243,7 +243,7 @@ namespace BPASmartClient.Device | |||
if (res != null && Error.Contains(res)) | |||
{ | |||
Error.Remove(res); | |||
DeleteErrorAction?.Invoke(res); | |||
DeleteErrorAction?.Invoke(DeviceId, res); | |||
} | |||
}); | |||
ThreadManage.GetInstance().StartLong(new Action(() => | |||
@@ -82,7 +82,7 @@ namespace BPASmartClient.Device | |||
/// <param name="field"></param> | |||
object GetPropertyValue(object info, string field); | |||
Action<object> AddErrorAction { get; set; } | |||
Action<object> DeleteErrorAction { get; set; } | |||
Action<int, object> AddErrorAction { get; set; } | |||
Action<int, object> DeleteErrorAction { get; set; } | |||
} | |||
} |
@@ -184,7 +184,7 @@ namespace BPASmartClient.IoT | |||
/// 增加告警 | |||
/// </summary> | |||
/// <param name="obj"></param> | |||
private void AddErrorAction(object obj) | |||
private void AddErrorAction(int Devid, object obj) | |||
{ | |||
string id = Guid.NewGuid().ToString(); | |||
HttpAddAlarm(new AlarmTable | |||
@@ -193,16 +193,19 @@ namespace BPASmartClient.IoT | |||
AlarmType = GetPropertyValue(obj, "Type").ToString(), | |||
AlarmMessage = GetPropertyValue(obj, "Text").ToString(), | |||
AlarmVla = "告警", | |||
DeviceId = Devid.ToString(), | |||
KeyID = id, | |||
}); | |||
keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] =id ; | |||
MessageLog.GetInstance.AddDeviceAlarmLogShow(GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(),id); | |||
} | |||
/// <summary> | |||
/// 删除告警 | |||
/// </summary> | |||
/// <param name="obj"></param> | |||
private void DeleteErrorAction(object obj) | |||
private void DeleteErrorAction(int Devid, object obj) | |||
{ | |||
string message = GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(); | |||
if (keyValues.ContainsKey(message)) | |||
@@ -213,9 +216,12 @@ namespace BPASmartClient.IoT | |||
AlarmType = GetPropertyValue(obj, "Type").ToString(), | |||
AlarmMessage = GetPropertyValue(obj, "Text").ToString(), | |||
AlarmVla = "告警", | |||
DeviceId= Devid.ToString(), | |||
KeyID = keyValues[message], | |||
State="n" | |||
}); | |||
MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]); | |||
} | |||
} | |||
@@ -89,6 +89,42 @@ namespace BPASmartClient.Message | |||
} | |||
#endregion | |||
#region 设备告警日志 | |||
/// <summary> | |||
/// 设备告警日志委托 | |||
/// </summary> | |||
public Action<string, string> DeviceAlarmLogNotify { get; set; } | |||
public Action AlarmLogNotify { get; set; } | |||
/// <summary> | |||
/// 设备告警日志委托字典 | |||
/// </summary> | |||
public ConcurrentDictionary<string, string> DPAlarmInfo = new ConcurrentDictionary<string, string>(); | |||
/// <summary> | |||
/// 设备告警日志输出 | |||
/// </summary> | |||
/// <param name="info"></param> | |||
public void AddDeviceAlarmLogShow(string id, string info) | |||
{ | |||
DPAlarmInfo[info] = id; | |||
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); | |||
if (DeviceAlarmLogNotify != null) DeviceAlarmLogNotify(id, info); | |||
if (AlarmLogNotify != null) AlarmLogNotify(); | |||
} | |||
/// <summary> | |||
/// 设备告警日志输出 | |||
/// </summary> | |||
/// <param name="info"></param> | |||
public void DeleteDeviceAlarmLogShow(string id, string info) | |||
{ | |||
if (DPAlarmInfo.ContainsKey(id)) | |||
{ | |||
string mes=string.Empty; | |||
DPAlarmInfo.Remove(id, out mes); | |||
if (AlarmLogNotify != null) AlarmLogNotify(); | |||
} | |||
} | |||
#endregion | |||
#region 查找设备ID | |||
/// <summary> | |||
/// 查询设备ID | |||
@@ -67,6 +67,16 @@ namespace BPASmartClient.ViewModel | |||
})); | |||
}); | |||
//设备告警日志 | |||
MessageLog.GetInstance.DeviceAlarmLogNotify = new Action<string, string>((id, s) => | |||
{ | |||
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => | |||
{ | |||
LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" }); | |||
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); | |||
})); | |||
}); | |||
//错误日志 | |||
MessageLog.GetInstance.ExInfoNotify = new Action<string>((s) => | |||
{ | |||
@@ -1,4 +1,6 @@ | |||
using BPASmartClient.Business; | |||
using BPASmartClient.Helper; | |||
using BPASmartClient.Message; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using System; | |||
@@ -9,6 +11,7 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Input; | |||
using System.Windows.Threading; | |||
namespace BPASmartClient.ViewModel | |||
{ | |||
@@ -17,9 +20,101 @@ namespace BPASmartClient.ViewModel | |||
/// </summary> | |||
public class MainViewModel : ObservableObject | |||
{ | |||
/// <summary> | |||
/// 网络连接状态 | |||
/// </summary> | |||
private bool _NetworkConnectState = true; | |||
public bool NetworkConnectState | |||
{ | |||
get | |||
{ | |||
return _NetworkConnectState; | |||
} | |||
set | |||
{ | |||
if (_NetworkConnectState == value) | |||
return; | |||
_NetworkConnectState = value; | |||
OnPropertyChanged("NetworkConnectState"); | |||
} | |||
} | |||
/// <summary> | |||
/// 是否告警 | |||
/// </summary> | |||
public AlarmModel IsAlarm { get; set; } | |||
public DispatcherTimer dispatcherTimer; | |||
public MainViewModel() | |||
{ | |||
IsAlarm =new AlarmModel(); | |||
OrderStatusViewModel.Init(); | |||
//设备告警日志 | |||
MessageLog.GetInstance.AlarmLogNotify = new Action(() => | |||
{ | |||
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => | |||
{ | |||
IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0; | |||
IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count; | |||
})); | |||
}); | |||
dispatcherTimer = new DispatcherTimer(); | |||
dispatcherTimer.Tick += delegate | |||
{ | |||
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => | |||
{ | |||
NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState(); | |||
})); | |||
}; | |||
dispatcherTimer.Interval = TimeSpan.FromSeconds(1); | |||
dispatcherTimer.Start(); | |||
} | |||
} | |||
public class AlarmModel : ObservableObject | |||
{ | |||
/// <summary> | |||
/// 是否告警 | |||
/// </summary> | |||
private bool _IsCheck = false; | |||
public bool IsCheck | |||
{ | |||
get | |||
{ | |||
return _IsCheck; | |||
} | |||
set | |||
{ | |||
if (_IsCheck == value) | |||
return; | |||
_IsCheck = value; | |||
OnPropertyChanged("IsCheck"); | |||
} | |||
} | |||
/// <summary> | |||
/// 告警数量 | |||
/// </summary> | |||
private int _ListNum = 0; | |||
public int ListNum | |||
{ | |||
get | |||
{ | |||
return _ListNum; | |||
} | |||
set | |||
{ | |||
if (_ListNum == value) | |||
return; | |||
_ListNum = value; | |||
OnPropertyChanged("ListNum"); | |||
} | |||
} | |||
public AlarmModel() | |||
{ | |||
} | |||
} | |||
} |
@@ -177,16 +177,15 @@ | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Cursor="Hand" | |||
DataContext="{Binding GaoJingMessage}" | |||
IsChecked="True" | |||
IsChecked="{Binding NetworkConnectState}" | |||
Style="{DynamicResource StatusBtnStyle网络连接状态}" | |||
ToolTip="网络连接状态" /> | |||
<Border Style="{DynamicResource border竖线}" /> | |||
<ToggleButton | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Cursor="Hand" | |||
DataContext="{Binding GaoJingMessage}" | |||
Cursor="Hand" | |||
DataContext="{Binding IsAlarm}" | |||
Style="{DynamicResource StatusBtnStyle告警}" | |||
ToolTip="告警消息" /> | |||
<Border Style="{DynamicResource border竖线}" /> | |||