From f16828098a7aeecdd009d9df72cd88a499a871b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Tue, 24 May 2022 13:37:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Device/Alarm.cs | 113 +++++++++--------- BPASmartClient.Device/AlarmHelper.cs | 32 ++--- .../BPASmartClient.Device.csproj | 1 + BPASmartClient.Device/BaseDevice.cs | 25 ++-- BPASmartClient.Device/IDevice.cs | 16 +++ BPASmartClient.Helper/Sqlite.cs | 2 +- BPASmartClient.IoT/DataVClient.cs | 24 ++-- BPASmartClient.Message/MessageLog.cs | 5 +- BPASmartClient.MorkS/Alarm.cs | 66 +++++++++- BPASmartClient.MorkS/Control_Morks.cs | 38 ++++-- BPASmartClient.ViewModel/AlarmViewModel.cs | 101 +++++----------- BPASmartClient/App.xaml.cs | 2 + BPASmartClient/Control/AlarmView.xaml | 2 + BPASmartClient/DeviceInfo.xml | 5 +- BPASmartClient/MainWindow.xaml | 6 + 15 files changed, 247 insertions(+), 191 deletions(-) diff --git a/BPASmartClient.Device/Alarm.cs b/BPASmartClient.Device/Alarm.cs index fecb1b9d..82588982 100644 --- a/BPASmartClient.Device/Alarm.cs +++ b/BPASmartClient.Device/Alarm.cs @@ -1,56 +1,57 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.Device -{ - public class Alarm - { - /// - /// ID - /// - [Key] - public int Id { get { return _mId; } set { _mId = value; } } - private int _mId; - - /// - /// 编号ID - /// - public int NumId { get { return _mNumId; } set { _mNumId = value; } } - private int _mNumId; - - - /// - /// 日期 - /// - public string Date { get { return _mDate; } set { _mDate = value; } } - private string _mDate; - - /// - /// 时间 - /// - public string Time { get { return _mTime; } set { _mTime = value; } } - private string _mTime; - - /// - /// 报警信息 - /// - public string Info { get { return _mInfo; } set { _mInfo = value; } } - private string _mInfo; - - /// - /// 报警值 - /// - public string Value { get { return _mValue; } set { _mValue = value; } } - private string _mValue; - - /// - /// 报警等级 - /// - public string Grade { get { return _mGrade; } set { _mGrade = value; } } - private string _mGrade; - } -} +//using System; +//using System.Collections.Generic; +//using System.ComponentModel.DataAnnotations; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; + + +//namespace BPASmartClient.Device +//{ +// public class Alarm +// { +// /// +// /// ID +// /// +// [Key] +// public int Id { get { return _mId; } set { _mId = value; } } +// private int _mId; + +// /// +// /// 编号ID +// /// +// public int NumId { get { return _mNumId; } set { _mNumId = value; } } +// private int _mNumId; + + +// /// +// /// 日期 +// /// +// public string Date { get { return _mDate; } set { _mDate = value; } } +// private string _mDate; + +// /// +// /// 时间 +// /// +// public string Time { get { return _mTime; } set { _mTime = value; } } +// private string _mTime; + +// /// +// /// 报警信息 +// /// +// public string Info { get { return _mInfo; } set { _mInfo = value; } } +// private string _mInfo; + +// /// +// /// 报警值 +// /// +// public string Value { get { return _mValue; } set { _mValue = value; } } +// private string _mValue; + +// /// +// /// 报警等级 +// /// +// public string Grade { get { return _mGrade; } set { _mGrade = value; } } +// private string _mGrade; +// } +//} diff --git a/BPASmartClient.Device/AlarmHelper.cs b/BPASmartClient.Device/AlarmHelper.cs index 7a0fd494..297ea918 100644 --- a/BPASmartClient.Device/AlarmHelper.cs +++ b/BPASmartClient.Device/AlarmHelper.cs @@ -1,4 +1,7 @@ -using System; +using BPASmartClient.Helper; +using BPASmartClient.Message; +using BPASmartClient.Model; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -48,7 +51,7 @@ namespace BPASmartClient.Device { Alarm tempAlarm = new Alarm() { - NumId = Alarms.Count, + NumId = Alarms.Count + 1, Date = DateTime.Now.ToString("yyyy/MM/dd"), Grade = alarmLevel.ToString(), Info = AlarmInfo, @@ -56,22 +59,15 @@ namespace BPASmartClient.Device Time = DateTime.Now.ToString("HH:mm:ss"), }; - //tempAlarm.Id = IotReport.GetInstance.HttpAddAlarm(new BPA.Message.API请求.AlarmTable - //{ - // AlarmTime=DateTime.Now, - // AlarmType= tempAlarm.Grade, - // AlarmMessage= tempAlarm.Info, - // AlarmVla= tempAlarm.Value, - // ClientId= InternetInfo.ClientId.ToString() - //}); - - //Sqlite.GetInstance.Base.Add(tempAlarm); + Sqlite.GetInstance.Base.Add(tempAlarm); if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null) { - Alarms.Add(tempAlarm); - if (AddAction != null) AddAction(AlarmInfo);//添加报警通知 - if (ChangeAction != null) ChangeAction();//更改报警通知 + Alarms.Insert(0, tempAlarm); + for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } + AddAction?.Invoke(AlarmInfo);//添加报警通知 + ChangeAction?.Invoke();//更改报警通知 + MessageLog.GetInstance.AddDeviceAlarmLogShow(tempAlarm.Info, Guid.NewGuid().ToString()); } } @@ -85,11 +81,7 @@ namespace BPASmartClient.Device if (result != null) { Alarms.Remove(result); - //IotReport.GetInstance.HttpDeleteAlarm(result.Id); - for (int i = 0; i < Alarms.Count; i++) - { - Alarms.ElementAt(i).NumId = i + 1; - } + for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } if (RemoveAction != null) RemoveAction(AlarmInfo); if (ChangeAction != null) ChangeAction(); } diff --git a/BPASmartClient.Device/BPASmartClient.Device.csproj b/BPASmartClient.Device/BPASmartClient.Device.csproj index 3f4f0b9f..ce865d26 100644 --- a/BPASmartClient.Device/BPASmartClient.Device.csproj +++ b/BPASmartClient.Device/BPASmartClient.Device.csproj @@ -12,6 +12,7 @@ + diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 44356031..035dd5c2 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -2,6 +2,7 @@ using BPA.Message.Enum; using BPASmartClient.Helper; using BPASmartClient.Message; +using BPASmartClient.Model; using BPASmartClient.Peripheral; using System; using System.Collections.Concurrent; @@ -101,6 +102,9 @@ namespace BPASmartClient.Device public Action AddErrorAction { get; set; } public Action DeleteErrorAction { get; set; } + public List alarms { get; set; } = new List(); + public IAlarm InterfaceAlarm { get; set; } + public AlarmHelper alarmHelper { get; set; } = new AlarmHelper(); #endregion @@ -217,9 +221,10 @@ namespace BPASmartClient.Device } else if (faces.Name == "IAlarm") { - IAlarm alarm = item.GetValue(this) as IAlarm; - AlarmHelper alarmHelper = new AlarmHelper(); - alarmHelper.AddAction = new Action((s) => + InterfaceAlarm = item.GetValue(this) as IAlarm; + //IAlarm alarm = item.GetValue(this) as IAlarm; + //AlarmHelper alarmHelper = new AlarmHelper(); + alarmHelper.AddAction += new Action((s) => { var res = alarmHelper.Alarms.FirstOrDefault(p => p.Info == s); if (res != null) @@ -234,7 +239,7 @@ namespace BPASmartClient.Device AddErrorAction?.Invoke(DeviceId, obj); } }); - alarmHelper.RemoveAction = new Action((s) => + alarmHelper.RemoveAction += new Action((s) => { var res = Error.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == s); if (res != null && Error.Contains(res)) @@ -245,7 +250,7 @@ namespace BPASmartClient.Device }); ThreadManage.GetInstance().StartLong(new Action(() => { - AlarmMonitoring(alarm, alarmHelper); + AlarmMonitoring(); Thread.Sleep(500); }), $"报警检测监控:{DeviceId}"); } @@ -261,17 +266,17 @@ namespace BPASmartClient.Device /// /// /// - private void AlarmMonitoring(IAlarm alarm, AlarmHelper alarmHelper) + private void AlarmMonitoring() { - if (alarm == null) return; - foreach (var item in alarm.GetType().GetProperties()) + if (InterfaceAlarm == null) return; + foreach (var item in InterfaceAlarm.GetType().GetProperties()) { - var res = item.GetValue(alarm); + var res = item.GetValue(InterfaceAlarm); if (res != null && res is bool blen) { if (item.CustomAttributes.Count() > 0 && item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) { - var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value; + var info = item.GetCustomAttribute().AlarmInfo; if (info != null) alarmHelper.EdgeAlarm(blen, info.ToString()); } } diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs index 582215a8..cf5205bb 100644 --- a/BPASmartClient.Device/IDevice.cs +++ b/BPASmartClient.Device/IDevice.cs @@ -1,4 +1,5 @@ using BPA.Message.Enum; +using BPASmartClient.Model; using BPASmartClient.Peripheral; using System; using System.Collections.Concurrent; @@ -43,6 +44,21 @@ namespace BPASmartClient.Device /// List variableMonitors { get; set; } + /// + /// 设备报警信息集合 + /// + List alarms { get; set; } + + /// + /// 接口报警对象 + /// + IAlarm InterfaceAlarm { get; set; } + + /// + /// 报警实体 + /// + AlarmHelper alarmHelper { get; set; } + /// /// 是否忙碌 /// diff --git a/BPASmartClient.Helper/Sqlite.cs b/BPASmartClient.Helper/Sqlite.cs index 4deff21b..ab396a46 100644 --- a/BPASmartClient.Helper/Sqlite.cs +++ b/BPASmartClient.Helper/Sqlite.cs @@ -39,7 +39,7 @@ namespace BPASmartClient.Helper SaveChanges(); } - public object GetData() + public List GetData() { Database.EnsureCreated(); return Base.ToList(); diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index d08a6a24..d9dd7ea5 100644 --- a/BPASmartClient.IoT/DataVClient.cs +++ b/BPASmartClient.IoT/DataVClient.cs @@ -39,7 +39,7 @@ namespace BPASmartClient.IoT ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString(); DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString(); StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString(); - BroadcastPubTopic= System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString(); + BroadcastPubTopic = System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString(); } #endregion @@ -68,7 +68,7 @@ namespace BPASmartClient.IoT /// /// key值 /// - public Dictionary keyValues = new Dictionary(); + public Dictionary keyValues = new Dictionary(); #endregion #region API调用 @@ -105,7 +105,7 @@ namespace BPASmartClient.IoT string id = string.Empty; try { - if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable!=null) + if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null) { logTable.ClientId = ClientId; logTable.devicename = DeviceDataV.deviceTable.devicename; @@ -147,7 +147,7 @@ namespace BPASmartClient.IoT } else { - MessageLog.GetInstance.ShowEx(message); + MessageLog.GetInstance.ShowEx(message); } } else @@ -161,7 +161,7 @@ namespace BPASmartClient.IoT } Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => { - device.AddErrorAction+= AddErrorAction; + device.AddErrorAction += AddErrorAction; device.DeleteErrorAction += DeleteErrorAction; }); } @@ -173,7 +173,7 @@ namespace BPASmartClient.IoT { ThreadManage.GetInstance().StartLong(new Action(() => { - if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null) + if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null) { List dataVNode = new List(); Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => @@ -215,7 +215,7 @@ namespace BPASmartClient.IoT private void AddErrorAction(int Devid, object obj) { string id = Guid.NewGuid().ToString(); - HttpAddAlarm(new AlarmTable + HttpAddAlarm(new AlarmTable { AlarmTime = GetPropertyValue(obj, "Time").ToString(), AlarmType = GetPropertyValue(obj, "Type").ToString(), @@ -224,8 +224,8 @@ namespace BPASmartClient.IoT 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); + 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); } @@ -244,11 +244,11 @@ namespace BPASmartClient.IoT AlarmType = GetPropertyValue(obj, "Type").ToString(), AlarmMessage = GetPropertyValue(obj, "Text").ToString(), AlarmVla = "告警", - DeviceId= Devid.ToString(), + DeviceId = Devid.ToString(), KeyID = keyValues[message], - State="n" + State = "n" }); - MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]); + //MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]); } } diff --git a/BPASmartClient.Message/MessageLog.cs b/BPASmartClient.Message/MessageLog.cs index 58d0d8d7..f10608b0 100644 --- a/BPASmartClient.Message/MessageLog.cs +++ b/BPASmartClient.Message/MessageLog.cs @@ -84,10 +84,7 @@ namespace BPASmartClient.Message else DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}"; Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); - if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id, info); - //Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); - // //ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}"; - // if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id,info); + DeviceProcessLogNotify?.Invoke(id, info); } #endregion diff --git a/BPASmartClient.MorkS/Alarm.cs b/BPASmartClient.MorkS/Alarm.cs index 6222d318..6655f53d 100644 --- a/BPASmartClient.MorkS/Alarm.cs +++ b/BPASmartClient.MorkS/Alarm.cs @@ -89,9 +89,17 @@ namespace BPASmartClient.MorkS [Alarm("机器人通讯异常")] public bool RobotMacCommunicateError { get; set; } + /// + /// 机器人通讯异常 + /// PLC ---> M231.2 + /// ModbusTcp --> 1581 + /// + [Alarm("设备急停")] + public bool DeviceEstop { get; set; } + /// /// 机器人初始化失败 - /// PLC ---> M551.3 + /// PLC ---> M231.3 /// ModbusTcp --> 1583 /// [Alarm("机器人初始化失败")] @@ -99,7 +107,7 @@ namespace BPASmartClient.MorkS /// /// 机器人急停 - /// PLC ---> M551.4 + /// PLC ---> M231.4 /// ModbusTcp --> 1584 /// [Alarm("机器人急停")] @@ -107,7 +115,7 @@ namespace BPASmartClient.MorkS /// /// 机器人不在远程模式 - /// PLC ---> M551.5 + /// PLC ---> M231.5 /// ModbusTcp --> 1585 /// [Alarm("机器人不在远程模式")] @@ -115,7 +123,7 @@ namespace BPASmartClient.MorkS /// /// 机器人伺服未就绪 - /// PLC ---> M551.6 + /// PLC ---> M231.6 /// ModbusTcp --> 1586 /// [Alarm("机器人伺服未就绪")] @@ -123,7 +131,7 @@ namespace BPASmartClient.MorkS /// /// 机器人本体异常 - /// PLC ---> M551.7 + /// PLC ---> M231.7 /// ModbusTcp --> 1587 /// [Alarm("机器人本体异常")] @@ -144,5 +152,53 @@ namespace BPASmartClient.MorkS /// [Alarm("煮面机右侧缺水报警")] public bool RightLackWater { get; set; } + + /// + /// 丝杆初始化失败 + /// PLC ---> M232.2 + /// ModbusTcp --> 1571 + /// + [Alarm("丝杆初始化失败")] + public bool SvrewInitFail { get; set; } + + /// + /// 转盘初始化失败 + /// PLC ---> M232.3 + /// ModbusTcp --> 1571 + /// + [Alarm("转盘初始化失败")] + public bool TurntableInitFail { get; set; } + + /// + /// 机器人初始化失败 + /// PLC ---> M232.4 + /// ModbusTcp --> 1571 + /// + [Alarm("机器人初始化失败")] + public bool RobotInitFail { get; set; } + + /// + /// 煮面机初始化失败 + /// PLC ---> M232.5 + /// ModbusTcp --> 1571 + /// + [Alarm("煮面机初始化失败")] + public bool NoodleCookerInitFail { get; set; } + + /// + /// 推碗1步进推杆初始化失败 + /// PLC ---> M232.6 + /// ModbusTcp --> 1571 + /// + [Alarm("推碗1步进推杆初始化失败")] + public bool PushBowlInitFail1 { get; set; } + + /// + /// 推碗2步进推杆初始化失败 + /// PLC ---> M232.7 + /// ModbusTcp --> 1571 + /// + [Alarm("推碗2步进推杆初始化失败")] + public bool PushBowlInitFail2 { get; set; } } } diff --git a/BPASmartClient.MorkS/Control_Morks.cs b/BPASmartClient.MorkS/Control_Morks.cs index 63095308..08bfe953 100644 --- a/BPASmartClient.MorkS/Control_Morks.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -88,7 +88,11 @@ namespace BPASmartClient.MorkS { if (peripheralStatus.ContainsKey(key)) { - action((bool[])peripheralStatus[key]); + if (peripheralStatus[key] is bool[] bools) + { + action?.Invoke(bools); + } + //action((bool[])peripheralStatus[key]); } } @@ -106,6 +110,7 @@ namespace BPASmartClient.MorkS alarm.NoodleMacCommunicateError = bools[7]; alarm.DosingMacCommunicateError = bools[8]; alarm.RobotMacCommunicateError = bools[9]; + alarm.DeviceEstop = bools[10]; alarm.RobotInitError = bools[11]; alarm.RobotUrgentStop = bools[12]; alarm.RobotNotInRemoteMode = bools[13]; @@ -113,6 +118,12 @@ namespace BPASmartClient.MorkS alarm.RobotSelfInException = bools[15]; alarm.LeftLackWater = bools[16]; alarm.RightLackWater = bools[17]; + alarm.SvrewInitFail = bools[18]; + alarm.TurntableInitFail = bools[19]; + alarm.RobotInitFail = bools[20]; + alarm.NoodleCookerInitFail = bools[21]; + alarm.PushBowlInitFail1 = bools[22]; + alarm.PushBowlInitFail2 = bools[23]; })); GetStatus("M0.3", new Action((bools) => @@ -165,13 +176,13 @@ namespace BPASmartClient.MorkS } })); - EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) => - { - if (o != null && o.Length > 0 && o[0] is ushort value) - { - mORKS.TurntableFeedbackloc = value; - } - }); + //EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) => + //{ + // if (o != null && o.Length > 0 && o[0] is ushort value) + // { + // mORKS.TurntableFeedbackloc = value; + // } + //}); } /// @@ -229,8 +240,8 @@ namespace BPASmartClient.MorkS public override void MainTask() { mORKS.AllowRun = mORKS.InitComplete; - //IsHealth = mORKS.Error && mORKS.InitComplete; - IsHealth = true; + IsHealth = mORKS.Error && mORKS.InitComplete; + //IsHealth = true; if (mORKS.AllowRun) { @@ -382,6 +393,13 @@ namespace BPASmartClient.MorkS } } + //补料中检测 + if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding)) + { + mORKS.AllowTakeNoodle = false; + mORKS.TakeNoodleInterlock = false; + } + //转台到位检测 if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc)) { diff --git a/BPASmartClient.ViewModel/AlarmViewModel.cs b/BPASmartClient.ViewModel/AlarmViewModel.cs index 74f15e23..11cfd13b 100644 --- a/BPASmartClient.ViewModel/AlarmViewModel.cs +++ b/BPASmartClient.ViewModel/AlarmViewModel.cs @@ -11,6 +11,7 @@ using Microsoft.Toolkit.Mvvm.ComponentModel; using BPASmartClient.Device; using BPASmartClient.Helper; using BPASmartClient.Business; +using BPASmartClient.Model; namespace BPASmartClient.ViewModel { @@ -26,7 +27,7 @@ namespace BPASmartClient.ViewModel } if (ControlButText == "开始查询") { - var lists = Sqlite.GetInstance.Base.ToList(); + var lists = Sqlite.GetInstance.GetData(); var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList(); if (res != null) { @@ -63,87 +64,45 @@ namespace BPASmartClient.ViewModel return; } }); - + AlarmMonitoring(); } - public static void AlarmMonitoring() + public void AlarmMonitoring() { + AlarmInfos.Clear(); Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => { - device.AddErrorAction = new Action((id, o) => - { - Application.Current.Dispatcher.Invoke(new Action(() => - { - AlarmInfos.Add(new Alarm() - { - NumId = AlarmInfos.Count, - Date = DateTime.Now.ToString("yyyy/MM/dd"), - Grade = o?.GetType()?.GetProperty("Type")?.GetValue(o)?.ToString(), - Info = o?.GetType()?.GetProperty("Text")?.GetValue(o)?.ToString(), - Time = DateTime.Now.ToString("HH:mm:ss"), - }); - })); - }); - - device.DeleteErrorAction = new Action((id, o) => + device.alarmHelper.Alarms.ForEach((item) => { AlarmInfos.Add(item); }); + device.alarmHelper.AddAction += new Action((s) => { - var info = o?.GetType()?.GetProperty("Text")?.GetValue(o)?.ToString(); - var res = AlarmInfos.FirstOrDefault(p => p.Info == info); - if (res != null) AlarmInfos.Remove(res); + var res = device.alarmHelper.Alarms.FirstOrDefault(p => p.Info == s); + if (res != null) Application.Current.Dispatcher.Invoke(new Action(() => { AlarmInfos.Insert(0, res); })); }); - }); - - - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - // if (SimpleFactory.GetInstance.Alarm != null) - // { - // foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties()) - // { - // var res = item.GetValue(SimpleFactory.GetInstance.Alarm); - // if (res != null) - // { - // if (res is bool blen) - // { - // if (item.CustomAttributes.Count() > 0) - // { - // if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) - // { - // var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value; - // if (info != null) - // { - // App.Current.Dispatcher.Invoke(new Action(() => - // { - // AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString()); - // })); - // } - // } - // } - // } - // } - // } - // } - // Thread.Sleep(500); - //}), "报警检测监控"); + device.alarmHelper.RemoveAction += new Action((s) => + { + var res = AlarmInfos.FirstOrDefault(p => p.Info == s); + if (res != null) Application.Current.Dispatcher.Invoke(new Action(() => { AlarmInfos.Remove(res); })); + }); + }); } private void GetHistoryAlarm() { - //var data = Sqlite.GetInstance.Base.ToList(); - //if (data != null) - //{ - // AlarmHelper.GetInstance.HistoryAlarms.Clear(); - // foreach (var item in data) - // { - // int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days; - // if (day == 0) - // { - // AlarmHelper.GetInstance.HistoryAlarms.Add(item); - // } - // } - //} + var data = Sqlite.GetInstance.GetData(); + if (data != null) + { + HistoryAlarm.Clear(); + foreach (var item in data) + { + int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days; + if (day == 0) + { + HistoryAlarm.Add(item); + } + } + } } public RelayCommand SwitchCommand { get; set; } @@ -191,9 +150,9 @@ namespace BPASmartClient.ViewModel private DateTime _mEndDateTime = DateTime.Now; - public static ObservableCollection AlarmInfos { get; set; } = new ObservableCollection(); + public ObservableCollection AlarmInfos { get; set; } = new ObservableCollection(); - public static ObservableCollection HistoryAlarm { get; set; } = new ObservableCollection(); + public ObservableCollection HistoryAlarm { get; set; } = new ObservableCollection(); } } diff --git a/BPASmartClient/App.xaml.cs b/BPASmartClient/App.xaml.cs index d34fbade..9b13cb85 100644 --- a/BPASmartClient/App.xaml.cs +++ b/BPASmartClient/App.xaml.cs @@ -114,6 +114,7 @@ namespace BPASmartClient private void DataSave() { Json.Save(); + Sqlite.GetInstance.Save(); } /// @@ -122,6 +123,7 @@ namespace BPASmartClient private void DataRead() { Json.Read(); + Task.Run(new Action(() => { Sqlite.GetInstance.GetData(); })); } diff --git a/BPASmartClient/Control/AlarmView.xaml b/BPASmartClient/Control/AlarmView.xaml index 7abff0cd..e90ae336 100644 --- a/BPASmartClient/Control/AlarmView.xaml +++ b/BPASmartClient/Control/AlarmView.xaml @@ -121,6 +121,7 @@