MatrixForm.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using GDNXFD.Data;
  11. using IntelligentControlForsx.Template;
  12. using IntelligentControlForsx.Service;
  13. using IntelligentControlForsx.MyControls;
  14. using EntityDataSet;
  15. using WisdomClient.data;
  16. using WisdomClient;
  17. using log4net;
  18. using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc;
  19. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  20. using CommonMethod = IntelligentControlForsx.Common.CommonMethod;
  21. namespace IntelligentControlForsx.ChildForms
  22. {
  23. public partial class MatrixFormTest : TemplateForm
  24. {
  25. private ILog logger = LogManager.GetLogger("AppInfoLog");
  26. private bool isPageChange = false; //标记矩阵页面是否被切换
  27. #region 构造方法及界面初始化
  28. public MatrixFormTest()
  29. {
  30. //| ControlStyles.UserPaint
  31. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);//开启双缓冲
  32. InitializeComponent();
  33. InitMatrixPanel();
  34. }
  35. private void MatrixForm_Load(object sender, EventArgs e)
  36. {
  37. //stationId = NavService.Instance.StationId;
  38. stationId = "0";
  39. RefreshMatrixPanel();
  40. }
  41. private void InitMatrixPanel()
  42. {
  43. this.pnlStations.Controls.Clear();
  44. this.SuspendLayout();
  45. IList<windpowerstation> lstStation = CacheService.Instance.GetFDCList();
  46. foreach (var st in lstStation)
  47. {
  48. MatrixStation ctrlStation = new MatrixStation();
  49. ctrlStation.StationId = st.ID;
  50. ctrlStation.StationName = st.NAME;
  51. ctrlStation.CntAll = st.QUANTITY.GetValueOrDefault();
  52. ctrlStation.ContextMenuStrip1 = this.cMenuControl;
  53. ctrlStation.InitTablePanel();
  54. ctrlStation.Dock = DockStyle.Top;
  55. ctrlStation.Name = "ctrl" + st.ID;
  56. this.pnlStations.Controls.Add(ctrlStation);
  57. ///////////////////////////////////////////////////
  58. //MatrixStation2 ctrlStation2 = new MatrixStation2();
  59. //ctrlStation2.StationId = st.ID;
  60. //ctrlStation2.StationId = st.ID;
  61. //ctrlStation2.StationName = st.NAME;
  62. //ctrlStation2.CntAll = st.QUANTITY.GetValueOrDefault();
  63. //ctrlStation2.ContextMenuStrip1 = this.cMenuControl;
  64. //ctrlStation2.InitTablePanel();
  65. //ctrlStation2.Dock = DockStyle.Top;
  66. //ctrlStation2.Name = "ctrl2" + st.ID;
  67. //ctrlStation2.Hide();
  68. //this.pnlStations.Controls.Add(ctrlStation2);
  69. ///////////////////////////////////////////////////
  70. }
  71. this.ResumeLayout();
  72. }
  73. #endregion
  74. #region 场站变换
  75. private string stationId;
  76. [Browsable(true), Category("Data")]
  77. public String StationId
  78. {
  79. get
  80. {
  81. return stationId;
  82. }
  83. set
  84. {
  85. stationId = value;
  86. RefreshMatrixPanel();
  87. }
  88. }
  89. private void RefreshMatrixPanel()
  90. {
  91. if (stationId == "all" || stationId == "0" || stationId == "-1")
  92. {
  93. foreach (var ctrl in this.pnlStations.Controls)
  94. {
  95. if (ctrl is MatrixStation)
  96. {
  97. ((MatrixStation)ctrl).Active();
  98. }
  99. }
  100. }
  101. else
  102. {
  103. foreach (var ctrl in this.pnlStations.Controls)
  104. {
  105. if (ctrl is MatrixStation2)
  106. {
  107. if (((MatrixStation2)ctrl).StationId == stationId)
  108. ((MatrixStation2)ctrl).Active();
  109. else
  110. ((MatrixStation2)ctrl).DeActive();
  111. }
  112. else if (ctrl is MatrixStation)
  113. {
  114. ((MatrixStation)ctrl).DeActive();
  115. }
  116. }
  117. }
  118. }
  119. #endregion
  120. private string formMode = "matrix"; //matrix -- 显示矩阵 popup -- 显示弹窗(智慧启停)
  121. public string FormMode
  122. {
  123. get
  124. {
  125. return formMode;
  126. }
  127. set
  128. {
  129. formMode = value;
  130. }
  131. }
  132. public override void Active()
  133. {
  134. //stationId = NavService.Instance.StationId;
  135. if (!isPageChange)
  136. {
  137. if (stationId.Length > 3)
  138. {
  139. this.matrixPopup1.StationId = stationId;
  140. }
  141. if ("matrix".Equals(formMode))
  142. {
  143. this.matrixTop1.Active();
  144. RefreshMatrixPanel();
  145. this.matrixPopup1.DeActive();
  146. }
  147. else
  148. {
  149. this.matrixTop1.DeActive();
  150. foreach (var ctrl in this.pnlStations.Controls)
  151. {
  152. if (ctrl is MatrixStation)
  153. {
  154. ((MatrixStation)ctrl).DeActive();
  155. }
  156. }
  157. this.matrixPopup1.Active();
  158. }
  159. }
  160. else
  161. {
  162. this.matrixTop1.Active();
  163. foreach (var ctrl in this.pnlStations.Controls)
  164. {
  165. if (ctrl is MatrixStation)
  166. {
  167. ((MatrixStation)ctrl).Active();
  168. }
  169. if (ctrl is MatrixStation2)
  170. {
  171. ((MatrixStation2)ctrl).DeActive();
  172. }
  173. }
  174. this.matrixPopup1.Active();
  175. }
  176. this.Show();
  177. }
  178. public override void DeActive()
  179. {
  180. isPageChange = true;
  181. this.Hide();
  182. this.matrixTop1.DeActive();
  183. foreach (var ctrl in this.pnlStations.Controls)
  184. {
  185. if (ctrl is MatrixStation)
  186. {
  187. ((MatrixStation)ctrl).DeActive();
  188. }
  189. if (ctrl is MatrixStation2)
  190. {
  191. ((MatrixStation2)ctrl).DeActive();
  192. }
  193. }
  194. this.matrixPopup1.DeActive();
  195. }
  196. public override void SelectedStationChanged(string stationId)
  197. {
  198. isPageChange = false;
  199. //MessageBox.Show(stationId);
  200. this.stationId = stationId;
  201. Active();
  202. }
  203. private void btnShowPopup_Click(object sender, EventArgs e)
  204. {
  205. this.matrixPopup1.Visible = true;
  206. this.matrixPopup1.BringToFront();
  207. formMode = "popup";
  208. Active();
  209. }
  210. private void cMenuControl_Opening(object sender, CancelEventArgs e)
  211. {
  212. MatrixDevice3 md = (sender as ContextMenuStrip).SourceControl as MatrixDevice3;
  213. if (md != null)
  214. {
  215. this.cMenuControl.Tag = md;
  216. this.cMenuControl.Enabled = true;
  217. string windturbineId = CommonMethod.GetLongWindturbineId(md.DeviceId);
  218. bool isHung = false;
  219. isHung = md.IsLock;
  220. if (!isHung)
  221. {
  222. if (md.StationId.Equals("SBQ_FDC") || md.StationId.Equals("XS_FDC") ||
  223. md.StationId.Equals("NSS_FDC") || md.StationId.Equals("MHS_FDC"))
  224. {
  225. this.menuReset.Enabled = false;
  226. this.menuMaintain.Enabled = false;
  227. this.menuCancelMaintain.Enabled = false;
  228. this.menuStartUp.Enabled = false;
  229. this.menuShutDown.Enabled = false;
  230. this.menuUnLock.Enabled = false;
  231. this.menuLock.Enabled = true;
  232. int st = Convert.ToInt32(md.Status);
  233. switch (st)
  234. {
  235. case 0:
  236. this.menuShutDown.Enabled = false;
  237. this.menuStartUp.Enabled = false;
  238. this.menuMaintain.Enabled = false;
  239. this.menuCancelMaintain.Enabled = false;
  240. this.menuReset.Enabled = false;
  241. break;
  242. case 1:
  243. this.menuShutDown.Enabled = true;
  244. this.menuStartUp.Enabled = false;
  245. this.menuMaintain.Enabled = false;
  246. this.menuCancelMaintain.Enabled = false;
  247. this.menuReset.Enabled = false;
  248. break;
  249. case 2:
  250. this.menuShutDown.Enabled = false;
  251. this.menuStartUp.Enabled = true;
  252. this.menuMaintain.Enabled = true;
  253. this.menuCancelMaintain.Enabled = false;
  254. this.menuReset.Enabled = false;
  255. break;
  256. case 3:
  257. this.menuShutDown.Enabled = true;
  258. this.menuStartUp.Enabled = false;
  259. this.menuMaintain.Enabled = false;
  260. this.menuCancelMaintain.Enabled = false;
  261. this.menuReset.Enabled = false;
  262. break;
  263. case 4:
  264. this.menuShutDown.Enabled = true;
  265. this.menuStartUp.Enabled = false;
  266. this.menuMaintain.Enabled = false;
  267. this.menuCancelMaintain.Enabled = false;
  268. this.menuReset.Enabled = false;
  269. break;
  270. case 5:
  271. this.menuShutDown.Enabled = false;
  272. this.menuStartUp.Enabled = false;
  273. this.menuMaintain.Enabled = false;
  274. this.menuCancelMaintain.Enabled = false;
  275. this.menuReset.Enabled = true;
  276. break;
  277. case 6:
  278. this.menuShutDown.Enabled = false;
  279. this.menuStartUp.Enabled = false;
  280. this.menuMaintain.Enabled = false;
  281. this.menuCancelMaintain.Enabled = true;
  282. this.menuReset.Enabled = false;
  283. break;
  284. case 7:
  285. this.menuShutDown.Enabled = false;
  286. this.menuStartUp.Enabled = false;
  287. this.menuMaintain.Enabled = false;
  288. this.menuCancelMaintain.Enabled = false;
  289. this.menuReset.Enabled = false;
  290. break;
  291. }
  292. if (md.DeviceModel.Equals("UP105-2000-S"))
  293. {
  294. switch (st)
  295. {
  296. case 0:
  297. this.menuShutDown.Enabled = false;
  298. this.menuStartUp.Enabled = false;
  299. this.menuMaintain.Enabled = false;
  300. this.menuCancelMaintain.Enabled = false;
  301. this.menuReset.Enabled = false;
  302. break;
  303. case 1:
  304. this.menuShutDown.Enabled = true;
  305. this.menuStartUp.Enabled = false;
  306. this.menuMaintain.Enabled = false;
  307. this.menuCancelMaintain.Enabled = false;
  308. this.menuReset.Enabled = false;
  309. break;
  310. case 2:
  311. this.menuShutDown.Enabled = false;
  312. this.menuStartUp.Enabled = true;
  313. this.menuMaintain.Enabled = false;
  314. this.menuCancelMaintain.Enabled = false;
  315. this.menuReset.Enabled = false;
  316. break;
  317. case 3:
  318. this.menuShutDown.Enabled = true;
  319. this.menuStartUp.Enabled = false;
  320. this.menuMaintain.Enabled = false;
  321. this.menuCancelMaintain.Enabled = false;
  322. this.menuReset.Enabled = false;
  323. break;
  324. case 4:
  325. this.menuShutDown.Enabled = true;
  326. this.menuStartUp.Enabled = false;
  327. this.menuMaintain.Enabled = false;
  328. this.menuCancelMaintain.Enabled = false;
  329. this.menuReset.Enabled = false;
  330. break;
  331. case 5:
  332. this.menuShutDown.Enabled = false;
  333. this.menuStartUp.Enabled = false;
  334. this.menuMaintain.Enabled = false;
  335. this.menuCancelMaintain.Enabled = false;
  336. this.menuReset.Enabled = true;
  337. break;
  338. case 6:
  339. this.menuShutDown.Enabled = false;
  340. this.menuStartUp.Enabled = false;
  341. this.menuMaintain.Enabled = false;
  342. this.menuCancelMaintain.Enabled = false;
  343. this.menuReset.Enabled = false;
  344. break;
  345. case 7:
  346. this.menuShutDown.Enabled = false;
  347. this.menuStartUp.Enabled = false;
  348. this.menuMaintain.Enabled = false;
  349. this.menuCancelMaintain.Enabled = false;
  350. this.menuReset.Enabled = false;
  351. break;
  352. }
  353. }
  354. }
  355. else
  356. {
  357. this.cMenuControl.Enabled = false;
  358. }
  359. }
  360. else
  361. {
  362. this.menuShutDown.Enabled = false;
  363. this.menuStartUp.Enabled = false;
  364. this.menuMaintain.Enabled = false;
  365. this.menuCancelMaintain.Enabled = false;
  366. this.menuReset.Enabled = false;
  367. this.menuUnLock.Enabled = true;
  368. this.menuLock.Enabled = false;
  369. }
  370. //MessageBox.Show(md.DeviceModel + "," + md.StationId);
  371. //e.Cancel = true;
  372. }
  373. //string whichcontrol_name = (sender as ContextMenuStrip).SourceControl.Name;
  374. }
  375. private void menuStartUp_Click(object sender, EventArgs e)
  376. {
  377. string deviceId = "";
  378. string powerStationId = "";
  379. if (this.cMenuControl.Tag is MatrixDevice3)
  380. {
  381. MatrixDevice3 device2 = (MatrixDevice3)this.cMenuControl.Tag;
  382. deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId);
  383. powerStationId = device2.StationId;
  384. }
  385. bool isBusy = IsBusy(deviceId);
  386. if (isBusy)
  387. {
  388. MessageBox.Show("风机操作过频繁!");
  389. return;
  390. }
  391. try
  392. {
  393. user userData = null;
  394. FingerCheck2 check = new FingerCheck2();
  395. check.ShowDialog();
  396. userData = FingerCheck2.checkSuccessUser;
  397. if (userData != null)
  398. {
  399. if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false)
  400. sendCommand(deviceId, powerStationId, CmdType.Start, userData);
  401. }
  402. }
  403. catch (Exception ex)
  404. {
  405. logger.Error(ex);
  406. }
  407. }
  408. private void menuShutDown_Click(object sender, EventArgs e)
  409. {
  410. string deviceId = "";
  411. string powerStationId = "";
  412. if (this.cMenuControl.Tag is MatrixDevice3)
  413. {
  414. MatrixDevice3 device2 = (MatrixDevice3)this.cMenuControl.Tag;
  415. deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId);
  416. powerStationId = device2.StationId;
  417. }
  418. bool isBusy = IsBusy(deviceId);
  419. if (isBusy)
  420. {
  421. MessageBox.Show("风机操作过频繁!");
  422. return;
  423. }
  424. try
  425. {
  426. user userData = null;
  427. FingerCheck2 check = new FingerCheck2();
  428. check.ShowDialog();
  429. userData = FingerCheck2.checkSuccessUser;
  430. if (userData != null)
  431. {
  432. if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false)
  433. sendCommand(deviceId, powerStationId, CmdType.Stop, userData);
  434. }
  435. }
  436. catch (Exception ex)
  437. {
  438. logger.Error(ex);
  439. }
  440. }
  441. private void menuReset_Click(object sender, EventArgs e)
  442. {
  443. string deviceId = "";
  444. string powerStationId = "";
  445. if (this.cMenuControl.Tag is MatrixDevice3)
  446. {
  447. MatrixDevice3 device2 = (MatrixDevice3)this.cMenuControl.Tag;
  448. deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId);
  449. powerStationId = device2.StationId;
  450. }
  451. bool isBusy = IsBusy(deviceId);
  452. if (isBusy)
  453. {
  454. MessageBox.Show("风机操作过频繁!");
  455. return;
  456. }
  457. try
  458. {
  459. user userData = null;
  460. FingerCheck2 check = new FingerCheck2();
  461. check.ShowDialog();
  462. userData = FingerCheck2.checkSuccessUser;
  463. if (userData != null)
  464. {
  465. if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false)
  466. sendCommand(deviceId, powerStationId, CmdType.Reset, userData);
  467. }
  468. }
  469. catch (Exception ex)
  470. {
  471. logger.Error(ex);
  472. }
  473. }
  474. private void menuMaintain_Click(object sender, EventArgs e)
  475. {
  476. string deviceId = "";
  477. string powerStationId = "";
  478. if (this.cMenuControl.Tag is MatrixDevice3)
  479. {
  480. MatrixDevice3 device2 = (MatrixDevice3)this.cMenuControl.Tag;
  481. deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId);
  482. powerStationId = device2.StationId;
  483. }
  484. bool isBusy = IsBusy(deviceId);
  485. if (isBusy)
  486. {
  487. MessageBox.Show("风机操作过频繁!");
  488. return;
  489. }
  490. try
  491. {
  492. user userData = null;
  493. FingerCheck2 check = new FingerCheck2();
  494. check.ShowDialog();
  495. userData = FingerCheck2.checkSuccessUser;
  496. if (userData != null)
  497. {
  498. if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false)
  499. sendCommand(deviceId, powerStationId, CmdType.Maintain, userData);
  500. }
  501. }
  502. catch (Exception ex)
  503. {
  504. logger.Error(ex);
  505. }
  506. }
  507. private void menuCancelMaintain_Click(object sender, EventArgs e)
  508. {
  509. string deviceId = "";
  510. string powerStationId = "";
  511. if (this.cMenuControl.Tag is MatrixDevice3)
  512. {
  513. MatrixDevice3 device2 = (MatrixDevice3)this.cMenuControl.Tag;
  514. deviceId = CommonMethod.GetLongWindturbineId(device2.DeviceId);
  515. powerStationId = device2.StationId;
  516. }
  517. bool isBusy = IsBusy(deviceId);
  518. if (isBusy)
  519. {
  520. MessageBox.Show("风机操作过频繁!");
  521. return;
  522. }
  523. try
  524. {
  525. user userData = null;
  526. FingerCheck2 check = new FingerCheck2();
  527. check.ShowDialog();
  528. userData = FingerCheck2.checkSuccessUser;
  529. if (userData != null)
  530. {
  531. if (String.IsNullOrWhiteSpace(deviceId) == false && String.IsNullOrWhiteSpace(powerStationId) == false)
  532. sendCommand(deviceId, powerStationId, CmdType.UnMaintain, userData);
  533. }
  534. }
  535. catch (Exception ex)
  536. {
  537. logger.Error(ex);
  538. }
  539. }
  540. private void sendCommand(string wtId, string windPowerStationId, CmdType cmdType, user userData)
  541. {
  542. IList<string> windturbineIdList = new List<string>();
  543. windturbineIdList.Add(wtId);
  544. TaskQueueSvc.QueueAdd(windturbineIdList, windPowerStationId, cmdType, userData);
  545. }
  546. private void menuUnLock_Click(object sender, EventArgs e)
  547. {
  548. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  549. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  550. string powerStationId = device3.StationId;
  551. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  552. {
  553. view_tspoint point =
  554. ctx.view_tspoint.Where(
  555. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  556. .FirstOrDefault();
  557. if (point != null)
  558. {
  559. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.UnLock);
  560. if (isSuccess)
  561. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  562. else
  563. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  564. }
  565. else
  566. {
  567. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  568. }
  569. }
  570. }
  571. /// <summary>
  572. /// 场内受累检修
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void menuStationCheckLock_Click(object sender, EventArgs e)
  577. {
  578. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  579. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  580. string powerStationId = device3.StationId;
  581. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  582. {
  583. view_tspoint point =
  584. ctx.view_tspoint.Where(
  585. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  586. .FirstOrDefault();
  587. if (point != null)
  588. {
  589. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationCheckLock);
  590. if (isSuccess)
  591. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  592. else
  593. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  594. }
  595. else
  596. {
  597. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  598. }
  599. }
  600. }
  601. /// <summary>
  602. /// 场内受累故障
  603. /// </summary>
  604. /// <param name="sender"></param>
  605. /// <param name="e"></param>
  606. private void menuStationFaultLock_Click(object sender, EventArgs e)
  607. {
  608. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  609. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  610. string powerStationId = device3.StationId;
  611. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  612. {
  613. view_tspoint point =
  614. ctx.view_tspoint.Where(
  615. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  616. .FirstOrDefault();
  617. if (point != null)
  618. {
  619. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationFaulLockt);
  620. if (isSuccess)
  621. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  622. else
  623. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  624. }
  625. else
  626. {
  627. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  628. }
  629. }
  630. }
  631. /// <summary>
  632. /// 场外受累电网
  633. /// </summary>
  634. /// <param name="sender"></param>
  635. /// <param name="e"></param>
  636. private void menuStationPowerLineLock_Click(object sender, EventArgs e)
  637. {
  638. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  639. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  640. string powerStationId = device3.StationId;
  641. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  642. {
  643. view_tspoint point =
  644. ctx.view_tspoint.Where(
  645. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  646. .FirstOrDefault();
  647. if (point != null)
  648. {
  649. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationPowerLineLock);
  650. if (isSuccess)
  651. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  652. else
  653. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  654. }
  655. else
  656. {
  657. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  658. }
  659. }
  660. }
  661. /// <summary>
  662. /// 故障维修
  663. /// </summary>
  664. /// <param name="sender"></param>
  665. /// <param name="e"></param>
  666. private void menuFaultLock_Click(object sender, EventArgs e)
  667. {
  668. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  669. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  670. string powerStationId = device3.StationId;
  671. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  672. {
  673. view_tspoint point =
  674. ctx.view_tspoint.Where(
  675. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  676. .FirstOrDefault();
  677. if (point != null)
  678. {
  679. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.FaultLock);
  680. if (isSuccess)
  681. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  682. else
  683. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  684. }
  685. else
  686. {
  687. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  688. }
  689. }
  690. }
  691. /// <summary>
  692. /// 检修
  693. /// </summary>
  694. /// <param name="sender"></param>
  695. /// <param name="e"></param>
  696. private void menuCheckLock_Click(object sender, EventArgs e)
  697. {
  698. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  699. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  700. string powerStationId = device3.StationId;
  701. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  702. {
  703. view_tspoint point =
  704. ctx.view_tspoint.Where(
  705. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  706. .FirstOrDefault();
  707. if (point != null)
  708. {
  709. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.CheckLock);
  710. if (isSuccess)
  711. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  712. else
  713. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  714. }
  715. else
  716. {
  717. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  718. }
  719. }
  720. }
  721. /// <summary>
  722. /// 场外受累天气
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. private void menuStationWeatherLock_Click(object sender, EventArgs e)
  727. {
  728. MatrixDevice3 device3 = (MatrixDevice3)this.cMenuControl.Tag;
  729. string windturbineId = CommonMethod.GetLongWindturbineId(device3.DeviceId);
  730. string powerStationId = device3.StationId;
  731. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  732. {
  733. view_tspoint point =
  734. ctx.view_tspoint.Where(
  735. s => s.thing_id == windturbineId && s.thing_type == "windturbine" && s.uniform_code == "XDSL")
  736. .FirstOrDefault();
  737. if (point != null)
  738. {
  739. bool isSuccess = WindturbineLock(powerStationId, windturbineId, point.id, HungType.StationWeatherLock);
  740. if (isSuccess)
  741. MessageBox.Show("风机:" + windturbineId + "挂牌成功!");
  742. else
  743. MessageBox.Show("风机:" + windturbineId + "挂牌成功失败,请重试!");
  744. }
  745. else
  746. {
  747. MessageBox.Show("未找到相关挂牌点,请联系管理员!");
  748. }
  749. }
  750. }
  751. /// <summary>
  752. /// 挂牌方法
  753. /// </summary>
  754. /// <param name="pStationId">场站Id</param>
  755. /// <param name="windturbineId">风机Id</param>
  756. /// <param name="tagName">挂牌测点</param>
  757. /// <param name="type">挂牌类型</param>
  758. /// <returns></returns>
  759. private bool WindturbineLock(string pStationId, string windturbineId, string tagName, HungType type)
  760. {
  761. bool isSuccess = false;
  762. try
  763. {
  764. user userData = null;
  765. FingerCheck2 check = new FingerCheck2();
  766. check.ShowDialog();
  767. userData = FingerCheck2.checkSuccessUser;
  768. if (userData != null)
  769. {
  770. TsPointData tData = new TsPointData();
  771. tData.tagName = tagName;
  772. TsData t = new TsData();
  773. t.doubleValue = (int)type;
  774. DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  775. TimeSpan sp = DateTime.Now.Subtract(dtStart);
  776. long time = long.Parse(sp.Ticks.ToString().Substring(0, sp.Ticks.ToString().Length - 4));
  777. t.ts = time;
  778. tData.tsData = t;
  779. RestfulClient.writeLatest(tData);
  780. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  781. {
  782. #region 写入操作日志
  783. control_log logData = new control_log();
  784. logData.windturbine_id = windturbineId;
  785. logData.station_id = pStationId;
  786. logData.control_user_id = userData.id;
  787. logData.send_control_time = DateTime.Now;
  788. logData.control_type = (int)CmdType.UnHangLock;
  789. logData.is_send_control_success = true;
  790. ctx.Entry(logData).State = EntityState.Added;
  791. int count = ctx.SaveChanges();
  792. if (count > 0)
  793. isSuccess = true;
  794. #endregion
  795. }
  796. }
  797. }
  798. catch (Exception ex)
  799. {
  800. logger.Error(ex);
  801. }
  802. return isSuccess;
  803. }
  804. private bool IsBusy(string windturbineId)
  805. {
  806. if (TaskQueueSvc.dicTask.ContainsKey(windturbineId))
  807. return true;
  808. else
  809. return false;
  810. }
  811. protected override CreateParams CreateParams
  812. {
  813. get
  814. {
  815. CreateParams cp = base.CreateParams;
  816. cp.ExStyle |= 0x02000000;
  817. return cp;
  818. }
  819. }
  820. }
  821. }