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.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DB.Service; using HslControls; using Tool; using Tool.Model; using HslCommunication.LogNet; using Chloe; namespace RfidWeb.Frm { public partial class UserAlarmShow : UserControl { private ICache cache = Cache.Default; private ILogNet logNet = ILogNetFactory.GetLogNet; private TimerX _timer; private readonly HimAlarmManager himAlarmManager = new HimAlarmManager(); readonly PromptAlarmManager promptAlarmManager = new PromptAlarmManager(); readonly AlarmLogService alarmLogService = new AlarmLogService(); public UserAlarmShow() { InitializeComponent(); _timer = new TimerX(TimeState, null, 2000, 1000); _timer.Async = true; } Stopwatch stopwatc=new Stopwatch(); void TimeState(Object state) { if(cache.ContainsKey("UserAlarmShow")) return; cache.Set("UserAlarmShow", DateTime.Now.ToString(), TimeSpan.FromSeconds(20)); stopwatc.Restart(); var stateText = HmiPointInfo.GetStateText(); this.Invoke(() => { btnStatus.Text = stateText; }); FillAlarmGrid(); FillPromptGrid(); FillAlartLed(); FillhslLabelCombo(); stopwatc.Stop(); cache.Remove("UserAlarmShow"); logNet.WriteInfo("运行时间:"+stopwatc.Elapsed.TotalMilliseconds); } /// /// 右下角的gridView /// void FillAlarmGrid() { List lsList = new List(); var list = himAlarmManager.GetList(); alarmLogService.Insert(list,1); foreach (var keyValuePair in list) { lsList.Add(new GridViewData() { AlartTime = keyValuePair.Value.ToString("MM-dd HH:mm:ss"), Msg = keyValuePair.Key }); } this.Invoke(() => { try { int currentFirstVisibleRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex; this.dataGridView1.DataSource = lsList; if (currentFirstVisibleRowIndex >= 0 && currentFirstVisibleRowIndex < dataGridView1.Rows.Count) { dataGridView1.FirstDisplayedScrollingRowIndex = currentFirstVisibleRowIndex; } } catch (Exception e) { Console.WriteLine(e); } }); } void FillPromptGrid() { List lsList = new List(); var list = promptAlarmManager.GetList(); alarmLogService.Insert(list,2); foreach (var keyValuePair in list) { lsList.Add(new GridViewData() { AlartTime = keyValuePair.Value.ToString("MM-dd HH:mm:ss"), Msg = keyValuePair.Key }); } this.Invoke(() => { try { int currentFirstVisibleRowIndex = dataGridView2.FirstDisplayedScrollingRowIndex; this.dataGridView2.DataSource = lsList; if (currentFirstVisibleRowIndex >= 0 && currentFirstVisibleRowIndex < dataGridView2.Rows.Count) { dataGridView2.FirstDisplayedScrollingRowIndex = currentFirstVisibleRowIndex; } } catch (Exception e) { Console.WriteLine(e.Message); } }); } /// /// 异常信息 /// void FillAlartLed() { var plcCh = cache.Get(CacheKeyManager.CH_alarm); var plcCq= cache.Get(CacheKeyManager.CQ_alarm); var plcStop = cache.Get>(CacheKeyManager.estop_temporary_storage); var plcAlarm= cache.Get>(CacheKeyManager.Prompt_alarm); if (plcStop==null || plcCh ==null || plcCq==null ) return; //No0 if (plcStop[4] || plcStop[0] || plcStop[1]) { SetTrueLed(hsl0); } else { SetFaileLed(hsl0); } //No1 if (plcCh.B6 || plcCh.B7) { SetTrueLed(hslA1, hslB1); } else { SetFaileLed(hslA1, hslB1); } //No2 if (plcCh.A1 || plcCh.A2 || plcCh.B3 || plcCh.B4 || plcStop[12]) { SetTrueLed(hslA2,hslB2); } else { SetFaileLed(hslA2, hslB2); } //No3 if (plcCh.A0 || plcCh.B0 || plcCh.B1 || plcStop[10] || plcStop[11]) { SetTrueLed(hslA3,hslB3); } else { SetFaileLed(hslA3, hslB3); } //No4 if (plcCh.B10 || plcCh.B11 || plcCh.B12 || plcCh.B14 || plcCh.B5 || plcCh.B8 || plcStop[14] || plcStop[25]) { SetTrueLed(hslA4); } else { SetFaileLed(hslA4); } //No5 SetLed(plcCh.B9,hslA5,hslB5); //No6 if (plcCh.B13 || plcStop[15]) { SetTrueLed(hslA6); } else { SetFaileLed(hslA6); } //No7 if (plcStop[3] || plcStop[5]) { SetTrueLed(hslA7,hslB7); } else { SetFaileLed(hslA7, hslB7); } //No8 SetLed(plcStop[6],hslA8,hslB8); //No9 if (plcCq.B9 || plcStop[16]) { SetTrueLed(hslA9,hslB9); } else { SetFaileLed(hslA9, hslB9); } //No10 if (plcCq.A0 || plcCq.A1 || plcCq.A2 || plcCq.B0 || plcCq.B1 || plcCq.B3 || plcCq.B4 || plcStop[13] || plcStop[24] || plcAlarm[0] || plcAlarm[1]) { SetTrueLed(hslA10,hslB10); } else { SetFaileLed(hslA10, hslB10); } //No11 if (plcCq.B2 || plcCq.B5 || plcCq.B6 || plcStop[2] || plcStop[7] || plcStop[17] || plcStop[18]) { SetTrueLed(hslA11, hslB11); } else { SetFaileLed(hslA11, hslB11); } //No12 if (plcCq.B7 || plcCq.B8) { SetTrueLed(hslA12); } else { SetFaileLed(hslA12); } //No13 if (plcStop[8] || plcStop[21] || plcStop[22] || plcStop[23] || plcStop[26]) { SetTrueLed(hslB13); } else { SetFaileLed(hslB13); } //No14 if (plcStop[9] || plcStop[19] || plcStop[20]) { SetTrueLed(hslB14); } else { SetFaileLed(hslB14); } } void FillhslLabelCombo() { //HmiPoint this.Invoke(() => { hslLabelCombofeedingMotorSpeed.TextValue = HmiPointInfo.GetFeedingMotorSpeed.ToString(); hslLabelComboLaminated.TextValue = HmiPointInfo.GetLaminatedMotorSpeed.ToString(); hslLabelComboFelt.TextValue = HmiPointInfo.GetFeltBeltMotorSpeed.ToString(); hslLabelComboReceiving.TextValue = HmiPointInfo.GeReceivingMotorSpeed.ToString(); hslLabelComboProduct_counter2.TextValue = HmiPointInfo.GetProduct_counter2.ToString(); hslLabelComboCQ_Chip1_counter.TextValue = HmiPointInfo.GetCQ_Chip1_counter.ToString(); hslLabelComboCQ_Chip2_counter.TextValue = HmiPointInfo.GetCQ_Chip2_counter.ToString(); hslLabelComboQDWD1SS.TextValue = HmiPointInfo.GetQDWD1SS.ToString(); hslLabelComboQDWD2SS.TextValue = HmiPointInfo.GetQDWD2SS.ToString(); double result = HmiPointInfo.GetSWSS / 10.0; hslLabelComboSWSS.TextValue = result.ToString(); }); } private void SetTrueLed(params HslLanternSimple[] simples) { SetLed(true,simples); } private void SetFaileLed(params HslLanternSimple[] simples) { SetLed(false, simples); } private void SetLed( bool b, params HslLanternSimple[] simples) { if (b) { foreach (var simple in simples) { if (simple.LanternBackground != Color.Red) { simple.LanternBackground = Color.Red; } } } else { foreach (var simple in simples) { if (simple.LanternBackground != Color.Chartreuse) { simple.LanternBackground = Color.Chartreuse; } } } } } }