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 lstWs = new List(); 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 wtList; public static List lblList = new List(); [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 WtList { get { return wtList; } set { wtList = value; UpateWtList(); } } public void UpateWtList() { IList lstWs = PredictService.GetWindturbineStatus(wtList, this.stationId); this.tlpDevices.Controls.Clear(); this.dictPopupDevice2.Clear(); UpdateTablePanel(this.tlpDevices, lstWs); } private void UpdateTablePanel(TableLayoutPanel tlp, IList 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(); //if (wtList.Contains(item) == false) // wtList.Add(item); foreach (String tid in lblList) { if (wtList == null) { wtList = new List(); } 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 windturbineIdList = new List(); // 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 dictPopupDevice2 = new Dictionary(); 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 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-"; } } }