using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Code; using IntelligentControlForsx.Service.AGC; using IntelligentControlForsx.Service.AGC.Domain; using WisdomClient.data; namespace IntelligentControlForsx.MyControls.agc { public partial class SunAGC : UserControl { private bool isUpdateDataOver = true; private bool isBindFormOver = true; private bool isUpdateLineDataOver = true; private bool isBindLineFormOver = true; public SunAGC() { InitializeComponent(); } public void DeActive() { timer1.Stop(); timer2.Stop(); } public void Active() { this.Show(); timer1.Start(); timer2.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (isBindFormOver)//绑定form { isBindFormOver = false; Thread bindDataThread = new Thread(BindFormInvoke); bindDataThread.Start(); } if (isUpdateDataOver)//更新数据 { Thread ayscThread = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetLatestAgcDataInfo)); ayscThread.IsBackground = true; ayscThread.Start(false); } } public delegate void UpdateFormInfoDelegate(); public void BindFormInvoke() { UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { FormDataBind(); } } public void FormDataBind() { string path = UserTools.Path; string green_img_path = path + @"\images\green.png"; string red_img_path = path + @"\images\red.png"; #region 石嘴山5 AgcEntity szs5 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "SZS5").FirstOrDefault(); if (szs5 != null) { lblPowerSet_SZS5.LableText = szs5.PowerSetValue.ToString("f2"); lblActualPower_SZS5.LableText = szs5.ActualPowerValue.ToString("f2"); lblAgcUp_SZS5.LableText = szs5.AgcUp .ToString("f2"); lblAgcLower_SZS5.LableText = szs5.AgcLower.ToString("f2"); lblForecastPower_SZS5.LableText = szs5.ForecastPower.ToString("f2"); if (szs5.AgcIn) picAgcOut_SZS5.Image = Image.FromFile(red_img_path); else picAgcOut_SZS5.Image = Image.FromFile(green_img_path); if (szs5.AgcFar) picAgcFar_SZS5.Image = Image.FromFile(red_img_path); else picAgcFar_SZS5.Image = Image.FromFile(green_img_path); } #endregion #region 平罗3 AgcEntity pl3 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "PL3").FirstOrDefault(); if (pl3 != null) { lblPowerSet_PL3.LableText = pl3.PowerSetValue .ToString("f2"); lblActualPower_PL3.LableText = pl3.ActualPowerValue.ToString("f2"); lblAgcUp_PL3.LableText = pl3.AgcUp .ToString("f2"); lblAgcLower_PL3.LableText = pl3.AgcLower .ToString("f2"); lblForecastPower_PL3.LableText = pl3.ForecastPower.ToString("f2"); if (pl3.AgcIn) picAgcOut_PL3.Image = Image.FromFile(red_img_path); else picAgcOut_PL3.Image = Image.FromFile(green_img_path); if (pl3.AgcFar) picAgcFar_PL3.Image = Image.FromFile(red_img_path); else picAgcFar_PL3.Image = Image.FromFile(green_img_path); } #endregion #region 中卫6 AgcEntity zw6 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "ZW6").FirstOrDefault(); if (zw6 != null) { lblPowerSet_ZW6.LableText = zw6.PowerSetValue .ToString("f2"); lblActualPower_ZW6.LableText = zw6.ActualPowerValue.ToString("f2"); lblAgcUp_ZW6.LableText = zw6.AgcUp .ToString("f2"); lblAgcLower_ZW6.LableText = zw6.AgcLower .ToString("f2"); lblForecastPower_ZW6.LableText = zw6.ForecastPower.ToString("f2"); if (zw6.AgcIn) picAgcOut_ZW6.Image = Image.FromFile(red_img_path); else picAgcOut_ZW6.Image = Image.FromFile(green_img_path); if (zw6.AgcFar) picAgcFar_ZW6.Image = Image.FromFile(red_img_path); else picAgcFar_ZW6.Image = Image.FromFile(green_img_path); } #endregion isBindFormOver = true; } private void timer2_Tick(object sender, EventArgs e) { if (isBindLineFormOver)//绑定form { isBindLineFormOver = false; Thread bindDataThread = new Thread(BindFormLineInvoke); bindDataThread.Start(); } if (isUpdateLineDataOver)//更新数据 { Thread ayscThread = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetHistoryLineData)); ayscThread.IsBackground = true; ayscThread.Start(false); } } public void BindFormLineInvoke() { UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormLineDataBind); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { FormLineDataBind(); } } public void FormLineDataBind() { PowerActual powerActual_szs5 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "SZS5").FirstOrDefault(); PowerSet powerSet_szs5 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "SZS5").FirstOrDefault(); if (powerActual_szs5 != null && powerSet_szs5 != null) { IList pstList = new List(); IList actlList = new List(); for (int i = 0; i < powerSet_szs5.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerSet_szs5.TsDataList[i].ts; double tValue = powerSet_szs5.TsDataList[i].doubleValue.HasValue ? powerSet_szs5.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; pstList.Add(tsData); } for (int i = 0; i < powerActual_szs5.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerActual_szs5.TsDataList[i].ts; double tValue = powerActual_szs5.TsDataList[i].doubleValue.HasValue ? powerActual_szs5.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; actlList.Add(tsData); } lineChar_SZS5.DataBind(actlList, pstList); } PowerActual powerActual_pl3 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "PL3").FirstOrDefault(); PowerSet powerSet_pl3 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "PL3").FirstOrDefault(); if (powerActual_pl3 != null && powerSet_pl3 != null) { IList pstList = new List(); IList actlList = new List(); for (int i = 0; i < powerSet_pl3.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerSet_pl3.TsDataList[i].ts; double tValue = powerSet_pl3.TsDataList[i].doubleValue.HasValue ? powerSet_pl3.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; pstList.Add(tsData); } for (int i = 0; i < powerActual_pl3.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerActual_pl3.TsDataList[i].ts; double tValue = powerActual_pl3.TsDataList[i].doubleValue.HasValue ? powerActual_pl3.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; actlList.Add(tsData); } lineChar_PL3.DataBind(actlList, pstList); } PowerActual powerActual_zw6 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "ZW6").FirstOrDefault(); PowerSet powerSet_zw6 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "ZW6").FirstOrDefault(); if (powerActual_zw6 != null && powerSet_zw6 != null) { IList pstList = new List(); IList actlList = new List(); for (int i = 0; i < powerSet_zw6.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerSet_zw6.TsDataList[i].ts; double tValue = powerSet_zw6.TsDataList[i].doubleValue.HasValue ? powerSet_zw6.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; pstList.Add(tsData); } for (int i = 0; i < powerActual_zw6.TsDataList.Count; i++) { TsData tsData = new TsData(); tsData.ts = powerActual_zw6.TsDataList[i].ts; double tValue = powerActual_zw6.TsDataList[i].doubleValue.HasValue ? powerActual_zw6.TsDataList[i].doubleValue.Value : 0.0; tsData.doubleValue = tValue; actlList.Add(tsData); } lineChar_ZW6.DataBind(actlList, pstList); } isBindLineFormOver = true; } private void SunAGC_Load(object sender, EventArgs e) { Thread ayscThread1 = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetLatestAgcDataInfo)); ayscThread1.IsBackground = true; ayscThread1.Start(true); Thread ayscThread2 = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetHistoryLineData)); ayscThread2.IsBackground = true; ayscThread2.Start(true); } } }