using DB.Entity; using HZH_Controls.Controls; using HZH_Controls.Forms; using NewLife.Caching; using NewLife.Reflection; using NewLife.Threading; using System; 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; using DB.Service; using Tool; using Tool.Model; namespace RfidWeb.Frm { public partial class UserAlarmShow : UserControl { private TimerX _timer; private HimAlarmManager himAlarmManager = new HimAlarmManager(); public UserAlarmShow() { InitializeComponent(); _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 GetList() { List list = alarmDataService.GetList(); ICache cache = Cache.Default; Dictionary dictionary = cache[CacheKeyManager.AramlList] as Dictionary ?? new Dictionary(); 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; } } } }