123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using EntityDataSet;
- using log4net;
- using IntelligentControlForsx.Service;
- using IntelligentControlForsx.Model;
- using WisdomClient.data;
- using WisdomClient;
- using System.Threading;
- using IntelligentControlForsx.Common;
- namespace IntelligentControlForsx.MyControls
- {
- public partial class MatrixStation2 : UserControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- private string[] deviceArray;
- private Dictionary<string, MatrixBlock> dictMatrixDevice2;
- private ContextMenuStrip contextMenuStrip;
- public MatrixStation2()
- {
- InitializeComponent();
- //this.mpnlCancelMaintain.Recommond();
- //this.mpnlMaintain.Recommond();
- //this.mpnlReset.Recommond();
- //this.mpnlStartup.Recommond();
- //this.mpnlStop.Recommond();
-
- }
- string stationName;
- string stationId;
- int cntAll;
- int cntBW;
- int cntSD;
- int cntTJ;
- int cntDJ;
- int cntGZ;
- int cntWH;
- int cntLX;
- int cntQD;
- #region 基本属性
- [Browsable(true), Category("Data")]
- public string StationName
- {
- get
- {
- return stationName;
- }
- set
- {
- stationName = value;
- lblStationName.Text = value;
- }
- }
- [Browsable(true), Category("Data")]
- public string StationId
- {
- get
- {
- return stationId;
- }
- set
- {
- stationId = value;
- this.mpnlStartup.StationId = value;
- this.mpnlStop.StationId = value;
- this.mpnlReset.StationId = value;
- this.mpnlMaintain.StationId = value;
- this.mpnlCancelMaintain.StationId = value;
- }
- }
- public ContextMenuStrip ContextMenuStrip1
- {
- get
- {
- return contextMenuStrip;
- }
- set
- {
- contextMenuStrip = value;
- }
- }
- #endregion
- #region 状态台数
- [Browsable(true), Category("Data")]
- public int CntAll
- {
- get
- {
- return cntAll;
- }
- set
- {
- cntAll = value;
- lblCntAll.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntBW
- {
- get
- {
- return cntBW;
- }
- set
- {
- cntBW = value;
- lblCntAll.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntSD
- {
- get
- {
- return cntSD;
- }
- set
- {
- cntSD = value;
- lblCntSD.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntTJ
- {
- get
- {
- return cntTJ;
- }
- set
- {
- cntTJ = value;
- lblCntTJ.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntDJ
- {
- get
- {
- return cntDJ;
- }
- set
- {
- cntDJ = value;
- lblCntDJ.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntGZ
- {
- get
- {
- return cntGZ;
- }
- set
- {
- cntGZ = value;
- lblCntGZ.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntWH
- {
- get
- {
- return cntWH;
- }
- set
- {
- cntWH = value;
- lblCntWH.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntLX
- {
- get
- {
- return cntLX;
- }
- set
- {
- cntLX = value;
- lblCntLX.Text = value.ToString();
- }
- }
- [Browsable(true), Category("Data")]
- public int CntQD
- {
- get
- {
- return cntQD;
- }
- set
- {
- cntQD = value;
- lblCntQD.Text = value.ToString();
- }
- }
- #endregion
- public void InitTablePanel()
- {
- if (String.IsNullOrWhiteSpace(stationId))
- return;
- deviceArray = MatrixFormService.GetDeviceIdArrayByStationId(stationId);
- var wtArray = CacheService.Instance.GetWindturbineListByStationId(stationId).ToArray();
- if (wtArray == null || wtArray.Length < 1)
- return;
- dictMatrixDevice2 = new Dictionary<string, MatrixBlock>();
- int col = 20;
- int row = (int)Math.Ceiling((decimal)wtArray.Length / 20);
- int arrIndex = 0;
- pnlTable.Height = row * 42 + 10;
- //this.Height = pnlTable.Height + 33;
- pnlTable.RowCount = row;
- for (int i = 0; i < row; i++)
- {
- pnlTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 42));
- for (int j = 0; j < col; j++)
- {
- if (arrIndex >= wtArray.Length)
- return;
- MatrixBlock device = new MatrixBlock();
- device.ContextMenuStrip = contextMenuStrip;
- device.DeviceId = CommonMethod.GetShortWindturbineId(wtArray[arrIndex].ID);
- device.DeviceModel = wtArray[arrIndex].MODELID;
- device.StationId = wtArray[arrIndex].WINDPOWERSTATIONID;
- device.Status = 7;
- device.Ts = 0;
- device.MyMouseDown += MyMouseDownHandler;
- device.MyMouseUp += MyMouseUpHandler;
- pnlTable.Controls.Add(device);
- if (!dictMatrixDevice2.ContainsKey(device.DeviceId))
- dictMatrixDevice2.Add(device.DeviceId, device);
- pnlTable.SetRow(device, i);
- pnlTable.SetColumn(device, j);
- arrIndex++;
- }
- }
- }
- public void DeActive()
- {
- this.Hide();
- timer1.Stop();
- this.mpnlCancelMaintain.DeActive();
- this.mpnlMaintain.DeActive();
- this.mpnlReset.DeActive();
- this.mpnlStartup.DeActive();
- this.mpnlStop.DeActive();
- }
- public void Active()
- {
- this.Show();
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- timer1.Start();
- this.mpnlCancelMaintain.Active();
- this.mpnlMaintain.Active();
- this.mpnlReset.Active();
- this.mpnlStartup.Active();
- this.mpnlStop.Active();
- }
- #region 异步加载数据
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isLoadding) return;
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- }
- private bool isLoadding = true;
- private void LoadData()
- {
- isLoadding = true;
- try
- {
- UpdateStationStates();
- UpdateWindturbineStates();
- }
- catch (Exception ex)
- {
- logger.Info("读取实时数据失败!ex=" + ex.Message);
- }
- finally
- {
- isLoadding = false;
- }
- }
- private void UpdateStationStates()
- {
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return;
- var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == stationId).ToArray();
- var points = pmms.Select(q => q.PointId).ToArray();
- Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
- lock (this)
- {
- this.BeginInvoke(
- (Action)delegate
- {
- for (int i = 0; i < points.Length; i++)
- {
- if (dictResult.ContainsKey(points[i]) == false)
- continue;
- double value = dictResult[points[i]].doubleValue.Value;
- pmms[i].Value = value;
- switch (pmms[i].UniformCode)
- {
- #region Switch
- case "BWTS8":
- lblCntBW.Text = value.ToString("f0");
- break;
- case "LXTS8":
- lblCntLX.Text = value.ToString("f0");
- break;
- case "DJTS8":
- lblCntDJ.Text = value.ToString("f0");
- break;
- case "WHTS8":
- lblCntWH.Text = value.ToString("f0");
- break;
- case "GZTS8":
- lblCntGZ.Text = value.ToString("f0");
- break;
- case "TJTS8":
- lblCntTJ.Text = value.ToString("f0");
- break;
- case "QDTS8":
- lblCntQD.Text = value.ToString("f0");
- break;
- case "SDTS8":
- lblCntSD.Text = value.ToString("f0");
- break;
- #endregion
- }
- }
- });
- }
- }
- //private void UpdateStationStates() { }
- private void UpdateWindturbineStates()
- {
- if (deviceArray == null || deviceArray.Length < 1)
- return;
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return;
- var pmms = dict.Values.Where(q => q.ThingType == PointType.Windturbine && deviceArray.Contains(q.ThingId)).ToArray();
- var points = pmms.Select(q => q.PointId).ToArray();
- Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
- lock (this)
- {
- this.BeginInvoke(
- (Action)delegate
- {
- for (int i = 0; i < points.Length; i++)
- {
- if (dictResult.ContainsKey(points[i]) == false)
- continue;
- double value = dictResult[points[i]].doubleValue.Value;
- long ts = dictResult[points[i]].ts;
- pmms[i].Value = value;
- var wBlock = dictMatrixDevice2[pmms[i].ThingId];
- if (wBlock == null)
- continue;
- string windturbineId = CommonMethod.GetLongWindturbineId(pmms[i].ThingId);
- switch (pmms[i].UniformCode)
- {
- #region Switch
- //"AI021", //3秒平均风速
- //"AI130", //功率
- //"AI010", //风向角度
- //"FJZT" //风机状态
- case "AI022":
- wBlock.WindSpeed = value;
- break;
- case "AI130":
- wBlock.Power = value;
- break;
- //case "AI010":
- // wBlock.WindAngle = values[i].ToString("f2") + " 度";
- // break;
- case "FJZT8":
- wBlock.Status = value;
- wBlock.Ts = ts;
- break;
- case "XDSL":
- if (value != 0)
- wBlock.IsLock = true;
- else
- wBlock.IsLock = false;
- wBlock.LockValue = value;
- break;
- #endregion
- }
- }
- refreshDevices();
- });
- }
- }
- #endregion
- #region 数据筛选
- private double selectedStatus = 9;
- private bool autoFilter = false;
- private void pnlAll_Click(object sender, EventArgs e)
- {
- selectedStatus = 9;
- refreshDevices();
- }
- private void refreshDevices()
- {
- foreach (var device in dictMatrixDevice2.Values)
- {
- double minSpeed, maxSpeed, minPower, maxPower;
- Double.TryParse(txtMinSpeed.Text, out minSpeed);
- Double.TryParse(txtMaxSpeed.Text, out maxSpeed);
- Double.TryParse(txtMinPower.Text, out minPower);
- Double.TryParse(txtMaxPower.Text, out maxPower);
- if (device.testShow(selectedStatus, autoFilter, minSpeed, maxSpeed, minPower, maxPower))
- {
- device.Show();
- }
- else
- {
- device.Hide();
- }
- }
- }
- //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3
- private void pnlBW_Click(object sender, EventArgs e)
- {
- selectedStatus = 1;
- refreshDevices();
- }
- private void pnlDJ_Click(object sender, EventArgs e)
- {
- selectedStatus = 0;
- refreshDevices();
- }
- private void pnlGZ_Click(object sender, EventArgs e)
- {
- selectedStatus = 2;
- refreshDevices();
- }
- private void pnlWH_Click(object sender, EventArgs e)
- {
- selectedStatus = 4;
- refreshDevices();
- }
- private void pnlLX_Click(object sender, EventArgs e)
- {
- selectedStatus = 3;
- refreshDevices();
- }
- private void pnlQD_Click(object sender, EventArgs e)
- {
- selectedStatus = 11;
- refreshDevices();
- }
- private void pnlTJ_Click(object sender, EventArgs e)
- {
- selectedStatus = 12;
- refreshDevices();
- }
- private void pnlSD_Click(object sender, EventArgs e)
- {
- selectedStatus = 13;
- refreshDevices();
- }
- private void chkAutoFilter_CheckedChanged(object sender, EventArgs e)
- {
- autoFilter = chkAutoFilter.Checked;
- if (autoFilter)
- refreshDevices();
- }
- #endregion
- // public event EventHandler MyMouseDown;
- private void MyMouseDownHandler(object sender, EventArgs e)
- {
- PointGroup obj = (PointGroup)sender;
- if (obj != null)
- {
- // MessageBox.Show(obj.ToString());
- }
-
- }
- private void MyMouseUpHandler(object sender, EventArgs e)
- {
- PointGroup obj = (PointGroup)sender;
- if (obj != null)
- {
- //MessageBox.Show(obj.ToString());
- }
- }
- }
- }
|