123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
- using IntelligentControlForsx.Model;
- using IntelligentControlForsx.Service;
- using EntityDataSet;
- using IntelligentControlForsx.ChildForms;
- using System.Threading;
- using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc;
- using WisdomClient.data;
- using WisdomClient;
- namespace IntelligentControlForsx.MyControls
- {
- public partial class MatrixPanel : UserControl
- {
- public MatrixPanel()
- {
- InitializeComponent();
- toolTip1.SetToolTip(this.btnRecomm, "智能推荐");
- }
- private void btnRecomm_Click(object sender, EventArgs e)
- {
- //MessageBox.Show("aldskj" + this.controlType);
- Recommond();
- }
- public void Recommond()
- {
- var sp = PredictService.GetStationPredict(StationId);
- IList<WindturbineStatus> lstWs = new List<WindturbineStatus>();
- if (this.controlType == CmdType.Start)
- lstWs = sp.StartupList;
- else if (this.controlType == CmdType.Stop)
- lstWs = sp.StopList;
- else if (this.controlType == CmdType.Reset)
- lstWs = sp.ResetList;
- else if (this.controlType == CmdType.Maintain)
- lstWs = sp.MaintainList;
- else if (this.controlType == CmdType.UnMaintain)
- lstWs = sp.CancelMaintainList;
- // case 0: //停机状态
- // case 1: //上电状态
- // case 2: //待机状态
- // case 3: //启动状态
- // case 4: //并网状态
- // case 5: //故障状态
- // case 6: //维护状态
- // case 7: //离线状态
-
- this.tlpDevices.Controls.Clear();
- if (lstWs.Count > 0)
- {
- wtList = lstWs.Select(q => q.WindturbineId).ToList();
- UpdateTablePanel(this.tlpDevices, lstWs);
- }
- }
- private void btnRecomm_MouseHover(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 1;
- }
- private void btnRecomm_MouseLeave(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 0;
- }
- #region 属性定义
- string title;
- string stationId;
- CmdType controlType;
- List<String> wtList;
- public static List<string> lblList = new List<string>();
- [Browsable(true), Category("Data")]
- public string Title
- {
- get
- {
- return title;
- }
- set
- {
- title = value;
- lblTitle.Text = title;
- }
- }
- public string StationId
- {
- get
- {
- return stationId;
- }
- set
- {
- stationId = value;
- }
- }
- [Browsable(true), Category("Data")]
- public CmdType ControlType
- {
- get
- {
- return controlType;
- }
- set
- {
- controlType = value;
- }
- }
- public List<string> WtList
- {
- get
- {
- return wtList;
- }
- set
- {
- wtList = value;
- UpateWtList();
- }
- }
- public void UpateWtList()
- {
- IList<WindturbineStatus> lstWs = PredictService.GetWindturbineStatus(wtList, this.stationId);
- this.tlpDevices.Controls.Clear();
- this.dictPopupDevice2.Clear();
- UpdateTablePanel(this.tlpDevices, lstWs);
- }
- private void UpdateTablePanel(TableLayoutPanel tlp, IList<WindturbineStatus> lstWs)
- {
- int col = 4;
- int row = (int)Math.Ceiling((decimal)lstWs.Count / col);
- int arrIndex = 0;
- var arr = lstWs.ToArray();
- tlp.Height = row * 60;
- tlp.RowCount = row;
- for (int i = 0; i < row; i++)
- {
- tlp.RowStyles.Add(new RowStyle(SizeType.Absolute, 60));
- for (int j = 0; j < col; j++)
- {
- if (arrIndex >= lstWs.Count)
- return;
- PopupDevice2 pd = new PopupDevice2();
- WindturbineStatus ws = arr[arrIndex];
- pd.MatrixPanel1 = this;
- pd.DeviceId = ws.WindturbineId;
- int x = 50;
- int.TryParse(pd.DeviceId.Substring(2, 2), out x);
- pd.Rank = RandomRank(110 - x);
- pd.WindSpeed = ws["AI022"].doubleValue == null ? 0 : ws["AI022"].doubleValue.Value;
- pd.Status = ws.GetStatus();
- pd.Power = ws["AI130"].doubleValue == null ? 0 : ws["AI130"].doubleValue.Value;
- tlp.Controls.Add(pd);
- if (!dictPopupDevice2.ContainsKey(pd.DeviceId))
- dictPopupDevice2.Add(pd.DeviceId, pd);
- tlp.SetRow(pd, i);
- tlp.SetColumn(pd, j);
- arrIndex++;
- }
- }
- }
- #endregion
- #region 窗体事件处理
- private void MatrixPanel_DragDrop(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(typeof(System.String)))
- {
- string item = (string)e.Data.GetData(typeof(System.String));
- if (e.Effect == DragDropEffects.Copy ||
- e.Effect == DragDropEffects.Move)
- {
- //if (this.wtList == null)
- // this.wtList = new List<string>();
- //if (wtList.Contains(item) == false)
- // wtList.Add(item);
- foreach (String tid in lblList)
- {
- if (wtList == null)
- {
- wtList = new List<string>();
- }
- if (wtList.Contains(tid) == false)
- wtList.Add(tid);
- }
- UpateWtList();
- //MessageBox.Show(this.title + "," +item.ToString());
- }
- }
- }
- private void MatrixPanel_DragEnter(object sender, DragEventArgs e)
- {
- e.Effect = DragDropEffects.Move;
- }
- private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
- {
- foreach (var ctrl in tlpDevices.Controls)
- {
- PopupDevice2 pd = ctrl as PopupDevice2;
- if (pd != null)
- {
- if (chkSelectAll.Checked)
- {
- pd.Checked1 = true;
- }
- else
- {
- pd.Checked1 = false;
- }
- }
- }
- }
- private void btnCancel_MouseHover(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 1;
- }
- private void btnCancel_MouseLeave(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 0;
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- if (wtList != null && wtList.Count > 0)
- {
- wtList.Clear();
- UpateWtList();
- }
- this.chkSelectAll.Checked = false;
- }
- private void btnConfirm_Click(object sender, EventArgs e)
- {
- //bool ifSend = false;
- //foreach (var ctrl in tlpDevices.Controls)
- //{
- // PopupDevice2 pd = ctrl as PopupDevice2;
- // if (pd != null)
- // {
- // if (pd.Checked1 == true)
- // {
- // ifSend = true;
- // break;
- // }
- // }
- //}
- //if (ifSend == false)
- //{
- // MessageBox.Show("您没有勾选任何风机!");
- // return;
- //}
- //user u = null;
- //FingerCheck fc = new FingerCheck();
- //fc.ShowDialog();
- //u = FingerCheck.checkSuccessUser;
-
- //if (u != null)
- //{
- // //wtList.Clear();
- // IList<string> windturbineIdList = new List<string>();
- // foreach (var ctrl in tlpDevices.Controls)
- // {
- // PopupDevice2 pd = ctrl as PopupDevice2;
- // if (pd != null)
- // {
- // string windturbineId = "SG01_" + pd.DeviceId.Replace("SG", "");
- // windturbineIdList.Add(windturbineId);
- // if (pd.Checked1 == true)
- // {
- // wtList.Remove(pd.DeviceId);
- // }
- // }
- // }
- // UpateWtList();
- // string busyWindturbine = "";
- // for (int i = 0; i < windturbineIdList.Count; i++)
- // {
- // if (TaskQueueSvc.dicTask.ContainsKey(windturbineIdList[i]))
- // busyWindturbine = busyWindturbine + windturbineIdList[i] + ",";
- // }
- // if (!string.IsNullOrEmpty(busyWindturbine))
- // {
- // MessageBox.Show(busyWindturbine + "风机操作过频繁");
- // return;
- // }
- // TaskQueueSvc.QueueAdd(windturbineIdList, "SBQ_FDC", controlType, u);
- // //ExitPopup();
- //}
- wtList.Clear();
- UpateWtList();
- }
- private void btnConfirm_MouseHover(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 1;
- }
- private void btnConfirm_MouseLeave(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.FlatAppearance.BorderSize = 0;
- }
- #endregion
- private Dictionary<string, PopupDevice2> dictPopupDevice2 = new Dictionary<string, PopupDevice2>();
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isLoadding == true)
- return;
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- //timer1.Start();
- }
- public void DeActive()
- {
- timer1.Stop();
- }
- public void Active()
- {
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- timer1.Start();
- }
- private bool isLoadding = false;
- private void LoadData()
- {
- if (isLoadding == true)
- return;
- isLoadding = true;
- try
- {
- UpdateWindturbineStates();
- }
- catch (Exception ex)
- {
- //logger.Info("读取实时数据失败!ex=" + ex.Message);
- }
- finally
- {
- isLoadding = false;
- }
- }
- private void UpdateWindturbineStates()
- {
- if (wtList == null || wtList.Count() < 1)
- return;
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return;
- var pmms = dict.Values.Where(q => q.ThingType == PointType.Windturbine && wtList.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;
- pmms[i].Value = value;
- var wBlock = dictPopupDevice2[pmms[i].ThingId];
- if (wBlock == null)
- continue;
- 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 "FJZT":
- wBlock.Status = value;
- break;
- #endregion
- }
- }
- });
- }
- }
- private string RandomRank(int intRank)
- {
- //Random random = new Random();
- int rank = intRank;// random.Next(0, 100);
- if (rank >= 90)
- return "AA";
- else if (rank > 80)
- return "A";
- else if (rank > 60)
- return "BBB";
- else if (rank > 40)
- return "BB";
- else if (rank > 20)
- return "B";
- else if (rank > 10)
- return "C";
- else
- return "C-";
- }
- }
- }
|