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 GDNXFD.Data; 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; using CommonMethod = IntelligentControlForsx.Common.CommonMethod; /* * matrixForm窗体 的备份 2020/7/3 * *此界面用来做备份.当前并不需要做控制功能 所以先将matrixForm窗体的控制去掉 * * */ namespace IntelligentControlForsx.ChildForms { public partial class MatrixForm_SendCMD_Backup : TemplateForm { private ILog logger = LogManager.GetLogger("AppInfoLog"); private bool isPageChange = false; //标记矩阵页面是否被切换 #region 构造方法及界面初始化 public MatrixForm_SendCMD_Backup() { // ControlStyles.UserPaint | this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);//开启双缓冲 InitializeComponent(); //stationId = NavService.Instance.StationId; this.pnlStations.Controls.Clear(); stationId = "0"; InitMatrixPanel(); } private void MatrixForm_Load(object sender, EventArgs e) { RefreshMatrixPanel(); } private void InitMatrixPanel() { this.SuspendLayout(); this.pnlStations.Controls.Clear(); IList lstStation = CacheService.Instance.GetFDCList(); foreach (var st in lstStation) { MatrixStation ctrlStation = new MatrixStation(); 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; this.pnlStations.Controls.Add(ctrlStation); /////////////////////////////////////////////////// //MatrixStation2 ctrlStation2 = new MatrixStation2(); //ctrlStation2.StationId = st.ID; //ctrlStation2.StationId = st.ID; //ctrlStation2.StationName = st.NAME; //ctrlStation2.CntAll = st.QUANTITY.GetValueOrDefault(); //ctrlStation2.ContextMenuStrip1 = this.cMenuControl; //ctrlStation2.InitTablePanel(); //ctrlStation2.Dock = DockStyle.Top; //ctrlStation2.Name = "ctrl2" + st.ID; //ctrlStation2.Hide(); //this.pnlStations.Controls.Add(ctrlStation2); /////////////////////////////////////////////////// } this.Refresh(); this.ResumeLayout(); } #endregion #region 场站变换 private string stationId="0"; [Browsable(true), Category("Data")] public String StationId { get { return stationId; } set { stationId = value; RefreshMatrixPanel(); } } private void RefreshMatrixPanel() { if (stationId == "all" || stationId == "0" || stationId == "-1") { foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation) { ((MatrixStation)ctrl).Active(); } } } else { foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation2) { if (((MatrixStation2)ctrl).StationId == stationId) ((MatrixStation2)ctrl).Active(); else ((MatrixStation2)ctrl).DeActive(); } else if (ctrl is MatrixStation) { ((MatrixStation)ctrl).DeActive(); } } } } #endregion private string formMode = "matrix"; //matrix -- 显示矩阵 popup -- 显示弹窗(智慧启停) public string FormMode { get { return formMode; } set { formMode = value; } } public override void Active() { stationId = NavService.Instance.StationId; if (!isPageChange) { if (stationId.Length > 3) { this.matrixPopup1.StationId = stationId; } if ("matrix".Equals(formMode)) { this.matrixTop1.Active(); RefreshMatrixPanel(); this.matrixPopup1.DeActive(); } else { this.matrixTop1.DeActive(); foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation) { ((MatrixStation)ctrl).DeActive(); } } this.matrixPopup1.Active(); } } else { this.matrixTop1.Active(); foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation) { ((MatrixStation)ctrl).Active(); } if (ctrl is MatrixStation2) { ((MatrixStation2)ctrl).DeActive(); } } this.matrixPopup1.Active(); } this.Show(); } public override void DeActive() { isPageChange = true; this.Hide(); this.matrixTop1.DeActive(); foreach (var ctrl in this.pnlStations.Controls) { if (ctrl is MatrixStation) { ((MatrixStation)ctrl).DeActive(); } if (ctrl is MatrixStation2) { ((MatrixStation2)ctrl).DeActive(); } } this.matrixPopup1.DeActive(); } public override void SelectedStationChanged(string stationId) { isPageChange = false; //MessageBox.Show(stationId); this.stationId = stationId; Active(); } private void btnShowPopup_Click(object sender, EventArgs e) { this.matrixPopup1.Visible = true; this.matrixPopup1.BringToFront(); formMode = "popup"; Active(); } private void cMenuControl_Opening(object sender, CancelEventArgs e) { MatrixBlock md = (sender as ContextMenuStrip).SourceControl as MatrixBlock; if (md != null) { this.cMenuControl.Tag = md; this.cMenuControl.Enabled = true; string windturbineId = CommonMethod.GetLongWindturbineId(md.DeviceId); bool isHung = false; isHung = md.IsLock; if (!isHung) { if (md.StationId.Equals("SBQ_FDC") || md.StationId.Equals("XS_FDC") || md.StationId.Equals("NSS_FDC") || md.StationId.Equals("MHS_FDC")) { this.menuReset.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuStartUp.Enabled = false; this.menuShutDown.Enabled = false; this.menuUnLock.Enabled = false; this.menuLock.Enabled = true; int st = Convert.ToInt32(md.Status); switch (st) { case 0: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 1: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 2: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = true; this.menuMaintain.Enabled = true; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 3: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 4: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 5: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = true; break; case 6: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = true; this.menuReset.Enabled = false; break; case 7: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; } if (md.DeviceModel.Equals("UP105-2000-S")) { switch (st) { case 0: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 1: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 2: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = true; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 3: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 4: this.menuShutDown.Enabled = true; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 5: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = true; break; case 6: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; case 7: this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; break; } } } else { this.cMenuControl.Enabled = false; } } else { this.menuShutDown.Enabled = false; this.menuStartUp.Enabled = false; this.menuMaintain.Enabled = false; this.menuCancelMaintain.Enabled = false; this.menuReset.Enabled = false; this.menuUnLock.Enabled = true; this.menuLock.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) { string deviceId = ""; string powerStationId = ""; if (this.cMenuControl.Tag is MatrixBlock) { MatrixBlock device2 = (MatrixBlock)this.cMenuControl.Tag; deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId); powerStationId = device2.StationId; } bool isBusy = IsBusy(deviceId); if (isBusy) { MessageBox.Show("风机操作过频繁!"); return; } try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false) sendCommand(deviceId, powerStationId, CmdType.Start, userData); } } catch (Exception ex) { logger.Error(ex); } } private void menuShutDown_Click(object sender, EventArgs e) { string deviceId = ""; string powerStationId = ""; if (this.cMenuControl.Tag is MatrixBlock) { MatrixBlock device2 = (MatrixBlock)this.cMenuControl.Tag; deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId); powerStationId = device2.StationId; } bool isBusy = IsBusy(deviceId); if (isBusy) { MessageBox.Show("风机操作过频繁!"); return; } try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false) sendCommand(deviceId, powerStationId, CmdType.Stop, userData); } } catch (Exception ex) { logger.Error(ex); } } private void menuReset_Click(object sender, EventArgs e) { string deviceId = ""; string powerStationId = ""; if (this.cMenuControl.Tag is MatrixBlock) { MatrixBlock device2 = (MatrixBlock)this.cMenuControl.Tag; deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId); powerStationId = device2.StationId; } bool isBusy = IsBusy(deviceId); if (isBusy) { MessageBox.Show("风机操作过频繁!"); return; } try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false) sendCommand(deviceId, powerStationId, CmdType.Reset, userData); } } catch (Exception ex) { logger.Error(ex); } } private void menuMaintain_Click(object sender, EventArgs e) { string deviceId = ""; string powerStationId = ""; if (this.cMenuControl.Tag is MatrixBlock) { MatrixBlock device2 = (MatrixBlock)this.cMenuControl.Tag; deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId); powerStationId = device2.StationId; } bool isBusy = IsBusy(deviceId); if (isBusy) { MessageBox.Show("风机操作过频繁!"); return; } try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false) sendCommand(deviceId, powerStationId, CmdType.Maintain, userData); } } catch (Exception ex) { logger.Error(ex); } } private void menuCancelMaintain_Click(object sender, EventArgs e) { string deviceId = ""; string powerStationId = ""; if (this.cMenuControl.Tag is MatrixBlock) { MatrixBlock device2 = (MatrixBlock)this.cMenuControl.Tag; deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId); powerStationId = device2.StationId; } bool isBusy = IsBusy(deviceId); if (isBusy) { MessageBox.Show("风机操作过频繁!"); return; } try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false) sendCommand(deviceId, powerStationId, CmdType.UnMaintain, userData); } } catch (Exception ex) { logger.Error(ex); } } private void sendCommand(string wtId, string windPowerStationId, CmdType cmdType, user userData) { IList windturbineIdList = new List(); windturbineIdList.Add(wtId); TaskQueueSvc.QueueAdd(windturbineIdList, windPowerStationId, cmdType, userData); } private void menuUnLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.UnLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 场内受累检修 /// /// /// private void menuStationCheckLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationCheckLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 场内受累故障 /// /// /// private void menuStationFaultLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationFaulLockt); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 场外受累电网 /// /// /// private void menuStationPowerLineLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationPowerLineLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 故障维修 /// /// /// private void menuFaultLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.FaultLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 检修 /// /// /// private void menuCheckLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.CheckLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 场外受累天气 /// /// /// private void menuStationWeatherLock_Click(object sender, EventArgs e) { MatrixBlock device3 = (MatrixBlock)this.cMenuControl.Tag; string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId); string powerStationId = device3.StationId; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { view_tspoint point = ctx.view_tspoint.Where( s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL") .FirstOrDefault(); if (point != null) { bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationWeatherLock); if (isSuccess) MessageBox.Show("风机:" + windturbineId + "挂牌成功!"); else MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!"); } else { MessageBox.Show("未找到相关挂牌点,请联系管理员!"); } } } /// /// 挂牌方法 /// /// 场站Id /// 风机Id /// 挂牌测点 /// 挂牌类型 /// private bool WindturbineLock(string pStationId, string windturbineId, string tagName, HungType type) { bool isSuccess = false; try { user userData = null; FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; if (userData != null) { TsPointData tData = new TsPointData(); tData.tagName = tagName; TsData t = new TsData(); t.doubleValue = (int)type; DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); TimeSpan sp = DateTime.Now.Subtract(dtStart); long time = long.Parse(sp.Ticks.ToString().Substring(0, sp.Ticks.ToString().Length - 4)); t.ts = time; tData.tsData = t; RestfulClient.writeLatest(tData); using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { #region 写入操作日志 control_log logData = new control_log(); logData.windturbine_id = windturbineId; logData.station_id = pStationId; logData.control_user_id = userData.id; logData.send_control_time = DateTime.Now; logData.control_type = (int)CmdType.UnHangLock; logData.is_send_control_success = true; ctx.Entry(logData).State = EntityState.Added; int count = ctx.SaveChanges(); if (count > 0) isSuccess = true; #endregion } } } catch (Exception ex) { logger.Error(ex); } return isSuccess; } private bool IsBusy(string windturbineId) { if (TaskQueueSvc.dicTask.ContainsKey(windturbineId)) return true; else return false; } //protected override CreateParams CreateParams //{ // get // { // CreateParams cp = base.CreateParams; // cp.ExStyle |= 0x02000000; // return cp; // } //} } }