MatrixForm.cs 35 KB

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