You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/RfidWeb/Frm/UserAlarmShow.cs

226 lines
7.5 KiB
C#

2 weeks ago
using DB.Entity;
using HZH_Controls.Controls;
using HZH_Controls.Forms;
using NewLife.Caching;
using NewLife.Reflection;
using NewLife.Threading;
using System;
2 weeks ago
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2 weeks ago
using DB.Service;
using Tool;
using Tool.Model;
2 weeks ago
namespace RfidWeb.Frm
{
public partial class UserAlarmShow : UserControl
{
2 weeks ago
private TimerX _timer;
private HimAlarmManager himAlarmManager = new HimAlarmManager();
2 weeks ago
public UserAlarmShow()
{
InitializeComponent();
2 weeks ago
_timer = new TimerX(TimeState, null, 1000, 1200);
}
void TimeState(Object state)
{
var dataTime = DateTime.Now;
List< GridViewData > lsList=new List< GridViewData >();
var list = himAlarmManager.GetList();
foreach (var keyValuePair in list)
{
lsList.Add(new GridViewData()
{
AlartTime = keyValuePair.Value.ToString("MM-dd HH:mm:ss"),
Msg = keyValuePair.Key
});
}
this.Invoke(() =>
{
int currentFirstVisibleRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
this.dataGridView1.DataSource=lsList;
dataGridView1.FirstDisplayedScrollingRowIndex = currentFirstVisibleRowIndex;
});
// ThreadPoolX.QueueUserWorkItem(UpdateLog);
}
public class HimAlarmManager
{
private HmiChAlarm hmiChAlarm = new HmiChAlarm();
private HmiCqAlarm hmiCq = new HmiCqAlarm();
EsStop esStop=new EsStop();
AlarmDataService alarmDataService = new AlarmDataService();
public Dictionary<string, DateTime> GetList()
{
List<AlarmData> list = alarmDataService.GetList();
ICache cache = Cache.Default;
Dictionary<string, DateTime> dictionary = cache[CacheKeyManager.AramlList] as Dictionary<string, DateTime>
?? new Dictionary<string, DateTime>();
var a = hmiChAlarm.GetPlcDb();
var dicCha = list.Where(x => x.PlcAb == "A" && x.Address == "CH_alarm"
&& !string.IsNullOrEmpty(x.Msg))
.ToDictionary(x => x.No, x => x.Msg);
for (int i = 0; i < 31; i++)
{
var obj = a.GetValue("A" + i);
if (obj != null)
{
if (dicCha.TryGetValue(i, out var value))
{
if (Convert.ToBoolean(obj))
{
if (!dictionary.ContainsKey(value))
{
dictionary[value] = DateTime.Now;
}
}
else
{
dictionary.Remove(value);
}
}
}
}
var dicChb = list.Where(x => x.PlcAb == "B" && x.Address == "CH_alarm"
&& !string.IsNullOrEmpty(x.Msg))
.ToDictionary(x => x.No, x => x.Msg);
for (int i = 0; i < 31; i++)
{
var obj = a.GetValue("B" + i);
if (obj != null)
{
if (dicChb.TryGetValue(i, out var value))
{
if (Convert.ToBoolean(obj))
{
if (!dictionary.ContainsKey(value))
{
dictionary[value] = DateTime.Now;
}
}
else
{
dictionary.Remove(value);
}
}
}
}
a = hmiCq.GetPlcDb();
var dicCqA = list.Where(x => x.PlcAb == "A" && x.Address == "CQ_alarm"
&& !string.IsNullOrEmpty(x.Msg))
.ToDictionary(x => x.No, x => x.Msg);
for (int i = 0; i < 31; i++)
{
var obj = a.GetValue("A" + i);
if (obj != null)
{
if (dicCqA.TryGetValue(i, out var value))
{
if (Convert.ToBoolean(obj))
{
if (!dictionary.ContainsKey(value))
{
dictionary[value] = DateTime.Now;
}
}
else
{
dictionary.Remove(value);
}
}
}
}
var dicCqB = list.Where(x => x.PlcAb == "B" && x.Address == "CQ_alarm"
&& !string.IsNullOrEmpty(x.Msg))
.ToDictionary(x => x.No, x => x.Msg);
for (int i = 0; i < 31; i++)
{
var obj = a.GetValue("B" + i);
if (obj != null)
{
if (dicCqB.TryGetValue(i, out var value))
{
if (Convert.ToBoolean(obj))
{
if (!dictionary.ContainsKey(value))
{
dictionary[value] = DateTime.Now;
}
}
else
{
dictionary.Remove(value);
}
}
}
}
var listEs= list.Where(x => x.PlcAb == "" && x.Address == "estop_temporary_storage"
&& !string.IsNullOrEmpty(x.Msg))
.ToDictionary(x => x.No, x => x.Msg);
var bools = esStop.GetDb();
for (int i = 0; i < 31; i++)
{
var obj = bools[i];
if (listEs.TryGetValue(i, out var value))
{
if (Convert.ToBoolean(obj))
{
if (!dictionary.ContainsKey(value))
{
dictionary[value] = DateTime.Now;
}
}
else
{
dictionary.Remove(value);
}
}
}
cache.Set(CacheKeyManager.AramlList, dictionary, TimeSpan.FromMinutes(10));
return dictionary;
}
2 weeks ago
}
}
}