123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- 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<windpowerstation> 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<string> windtrurbineIdList = new List<string>();
- 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<string> windtrurbineIdList = new List<string>();
- 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<string> windtrurbineIdList = new List<string>();
- 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<string> windtrurbineIdList = new List<string>();
- 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<string> windtrurbineIdList = new List<string>();
- 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<string> faultSendList = new List<string>();
- IList<string> deviceList = new List<string>();
- 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);
- }
- }
- }
- }
|