using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Template; using IntelligentControlForsx.Service; using IntelligentControlForsx.MyControls; using EntityDataSet; using WisdomClient.data; using WisdomClient; using log4net; using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; namespace IntelligentControlForsx.ChildForms { public partial class MatrixForm2 : TemplateForm { private ILog logger = LogManager.GetLogger("AppInfoLog"); #region 构造方法及界面初始化 public MatrixForm2() { InitializeComponent(); stationId = "0"; InitMatrixPanel(); } private void MatrixForm_Load(object sender, EventArgs e) { RefreshMatrixPanel(); } private void InitMatrixPanel() { this.pnlStations.Controls.Clear(); IList lstStation = CacheService.Instance.GetFDCList(); foreach (var st in lstStation) { MatrixStation2 ctrlStation = new MatrixStation2(); ctrlStation.StationId = st.ID; ctrlStation.StationName = st.NAME; ctrlStation.CntAll = st.QUANTITY.GetValueOrDefault(); ctrlStation.ContextMenuStrip1 = this.cMenuControl; ctrlStation.InitTablePanel(); ctrlStation.Dock = DockStyle.Top; ctrlStation.Name = "ctrl" + st.ID; //ctrlStation.Height = 960; this.pnlStations.Controls.Add(ctrlStation); } } #endregion #region 场站变换 private string stationId; [Browsable(true), Category("Data")] public String StationId { get { return stationId; } set { if (value.EndsWith("_FDC")) stationId = value; else stationId = "SBQ_FDC"; } } private void RefreshMatrixPanel() { foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation2) { if (((MatrixStation2)ctrl).StationId == stationId) ((MatrixStation2)ctrl).Active(); else ((MatrixStation2)ctrl).DeActive(); } } } #endregion public override void Active() { StationId = NavService.Instance.StationId; RefreshMatrixPanel(); this.Show(); } public override void DeActive() { this.Hide(); foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation2) { ((MatrixStation2)ctrl).DeActive(); } } } public override void SelectedStationChanged(string stationId) { //MessageBox.Show(stationId); this.StationId = stationId; Active(); } private void cMenuControl_Opening(object sender, CancelEventArgs e) { MatrixDevice2 md = (sender as ContextMenuStrip).SourceControl as MatrixDevice2; if (md != null) { if (md.StationId.Equals("SBQ_FDC")) { this.cMenuControl.Tag = md.DeviceId; this.cMenuControl.Enabled = true; this.menuReset.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuStartUp.Enabled = false; this.menuShutDown.Enabled = false; //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3 //风机八种状态: 0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS int st = Convert.ToInt32(md.Status); switch (st) { //case 5: //case 1: // this.menuShutDown.Enabled = true; // break; //case 0: // this.menuStartUp.Enabled = true; // this.menuMaintain.Enabled = true; // break; //case 4: // this.menuCancelMaintain.Enabled = true; // break; //case 2: // this.menuReset.Enabled = true; // this.menuMaintain.Enabled = true; // break; //case 3: //default: // break; case 0: this.menuStartUp.Enabled = true; this.menuMaintain.Enabled = true; this.menuReset.Enabled = true; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = false; break; case 1: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = false; break; case 2: this.menuStartUp.Enabled = true; this.menuMaintain.Enabled = true; this.menuReset.Enabled = true; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = false; break; case 3: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = false; break; case 4: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = true; break; case 5: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = true; this.menuCancelMaintain.Enabled = false; this.menuShutDown.Enabled = false; break; case 6: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuCancelMaintain.Enabled = true; this.menuShutDown.Enabled = false; break; case 7: this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuCancelMaintain.Enabled = true; this.menuShutDown.Enabled = false; break; default: break; } if (md.DeviceModel.Equals("UP105-2000-S")) { this.menuReset.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; } } else { this.cMenuControl.Enabled = false; } //MessageBox.Show(md.DeviceModel + "," + md.StationId); //e.Cancel = true; } //string whichcontrol_name = (sender as ContextMenuStrip).SourceControl.Name; } private void menuStartUp_Click(object sender, EventArgs e) { try { user userData = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); userData = FingerCheck.checkSuccessUser; if (userData != null) { //string deviceId = this.cMenuControl.Tag.ToString(); //if (String.IsNullOrWhiteSpace(deviceId) == false) // sendCommand(deviceId, CmdType.Start, userData); string deviceId = this.cMenuControl.Tag.ToString(); if (String.IsNullOrWhiteSpace(deviceId) == false) { if (TaskQueueSvc.dicTask.ContainsKey(deviceId)) { MessageBox.Show("风机操作太频繁,请稍后再试!"); return; } IList windtrurbineIdList = new List(); windtrurbineIdList.Add(deviceId); TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Start, userData); } } } catch (Exception ex) { logger.Error(ex); } } private void menuShutDown_Click(object sender, EventArgs e) { try { user userData = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); userData = FingerCheck.checkSuccessUser; if (userData != null) { //string deviceId = this.cMenuControl.Tag.ToString(); //if (String.IsNullOrWhiteSpace(deviceId) == false) // sendCommand(deviceId, CmdType.Stop, userData); string deviceId = this.cMenuControl.Tag.ToString(); if (String.IsNullOrWhiteSpace(deviceId) == false) { if (TaskQueueSvc.dicTask.ContainsKey(deviceId)) { MessageBox.Show("风机操作太频繁,请稍后再试!"); return; } IList windtrurbineIdList = new List(); string windturbineId = "SG01_"+deviceId.Replace("SG", ""); windtrurbineIdList.Add(windturbineId); TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Stop, userData); } } } catch (Exception ex) { logger.Error(ex); } } private void menuReset_Click(object sender, EventArgs e) { try { user userData = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); userData = FingerCheck.checkSuccessUser; if (userData != null) { //string deviceId = this.cMenuControl.Tag.ToString(); //if (String.IsNullOrWhiteSpace(deviceId) == false) // sendCommand(deviceId, CmdType.Reset, userData); string deviceId = this.cMenuControl.Tag.ToString(); if (String.IsNullOrWhiteSpace(deviceId) == false) { if (TaskQueueSvc.dicTask.ContainsKey(deviceId)) { MessageBox.Show("风机操作太频繁,请稍后再试!"); return; } IList windtrurbineIdList = new List(); string windturbineId = "SG01_" + deviceId.Replace("SG", ""); windtrurbineIdList.Add(windturbineId); TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Reset, userData); } } } catch (Exception ex) { logger.Error(ex); } } private void menuMaintain_Click(object sender, EventArgs e) { try { user userData = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); userData = FingerCheck.checkSuccessUser; if (userData != null) { //string deviceId = this.cMenuControl.Tag.ToString(); //if (String.IsNullOrWhiteSpace(deviceId) == false) // sendCommand(deviceId, CmdType.Maintain, userData); string deviceId = this.cMenuControl.Tag.ToString(); if (String.IsNullOrWhiteSpace(deviceId) == false) { if (TaskQueueSvc.dicTask.ContainsKey(deviceId)) { MessageBox.Show("风机操作太频繁,请稍后再试!"); return; } IList windtrurbineIdList = new List(); string windturbineId = "SG01_" + deviceId.Replace("SG", ""); windtrurbineIdList.Add(windturbineId); TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Maintain, userData); } } } catch (Exception ex) { logger.Error(ex); } } private void menuCancelMaintain_Click(object sender, EventArgs e) { try { user userData = null; FingerCheck check = new FingerCheck(); check.ShowDialog(); userData = FingerCheck.checkSuccessUser; if (userData != null) { //string deviceId = this.cMenuControl.Tag.ToString(); //if (String.IsNullOrWhiteSpace(deviceId) == false) // sendCommand(deviceId, CmdType.UnMaintain, userData); string deviceId = this.cMenuControl.Tag.ToString(); if (String.IsNullOrWhiteSpace(deviceId) == false) { if (TaskQueueSvc.dicTask.ContainsKey(deviceId)) { MessageBox.Show("风机操作太频繁,请稍后再试!"); return; } IList windtrurbineIdList = new List(); string windturbineId = "SG01_" + deviceId.Replace("SG", ""); windtrurbineIdList.Add(windturbineId); TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.UnMaintain, userData); } } } catch (Exception ex) { logger.Error(ex); } } private void sendCommand(string wtId, CmdType cmdType, user userData) { ControlSvc controlSvc = ControlSvc.GetControlSvc(); IList faultSendList = new List(); IList deviceList = new List(); deviceList.Add(wtId); bool isSend = controlSvc.SendCmdByWindturbineIdList(deviceList, "SBQ_FDC", cmdType, out faultSendList, "", userData); if (isSend) { MessageBox.Show("命令发送成功"); this.Close(); } else { string windturbineIds = ""; for (int i = 0; i < faultSendList.Count; i++) { windturbineIds = windturbineIds + faultSendList[i] + ","; } MessageBox.Show("命令发送失败的风机有:" + windturbineIds); } } } }