MatrixForm2.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 IntelligentControlForsx.Template;
  11. using IntelligentControlForsx.Service;
  12. using IntelligentControlForsx.MyControls;
  13. using EntityDataSet;
  14. using WisdomClient.data;
  15. using WisdomClient;
  16. using log4net;
  17. using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc;
  18. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  19. namespace IntelligentControlForsx.ChildForms
  20. {
  21. public partial class MatrixForm2 : TemplateForm
  22. {
  23. private ILog logger = LogManager.GetLogger("AppInfoLog");
  24. #region 构造方法及界面初始化
  25. public MatrixForm2()
  26. {
  27. InitializeComponent();
  28. stationId = "0";
  29. InitMatrixPanel();
  30. }
  31. private void MatrixForm_Load(object sender, EventArgs e)
  32. {
  33. RefreshMatrixPanel();
  34. }
  35. private void InitMatrixPanel()
  36. {
  37. this.pnlStations.Controls.Clear();
  38. IList<windpowerstation> lstStation = CacheService.Instance.GetFDCList();
  39. foreach (var st in lstStation)
  40. {
  41. MatrixStation2 ctrlStation = new MatrixStation2();
  42. ctrlStation.StationId = st.ID;
  43. ctrlStation.StationName = st.NAME;
  44. ctrlStation.CntAll = st.QUANTITY.GetValueOrDefault();
  45. ctrlStation.ContextMenuStrip1 = this.cMenuControl;
  46. ctrlStation.InitTablePanel();
  47. ctrlStation.Dock = DockStyle.Top;
  48. ctrlStation.Name = "ctrl" + st.ID;
  49. //ctrlStation.Height = 960;
  50. this.pnlStations.Controls.Add(ctrlStation);
  51. }
  52. }
  53. #endregion
  54. #region 场站变换
  55. private string stationId;
  56. [Browsable(true), Category("Data")]
  57. public String StationId
  58. {
  59. get
  60. {
  61. return stationId;
  62. }
  63. set
  64. {
  65. if (value.EndsWith("_FDC"))
  66. stationId = value;
  67. else
  68. stationId = "SBQ_FDC";
  69. }
  70. }
  71. private void RefreshMatrixPanel()
  72. {
  73. foreach (var ctrl in this.pnlStations.Controls)
  74. {
  75. if (ctrl is MatrixStation2)
  76. {
  77. if (((MatrixStation2)ctrl).StationId == stationId)
  78. ((MatrixStation2)ctrl).Active();
  79. else
  80. ((MatrixStation2)ctrl).DeActive();
  81. }
  82. }
  83. }
  84. #endregion
  85. public override void Active()
  86. {
  87. StationId = NavService.Instance.StationId;
  88. RefreshMatrixPanel();
  89. this.Show();
  90. }
  91. public override void DeActive()
  92. {
  93. this.Hide();
  94. foreach (var ctrl in this.pnlStations.Controls)
  95. {
  96. if (ctrl is MatrixStation2)
  97. {
  98. ((MatrixStation2)ctrl).DeActive();
  99. }
  100. }
  101. }
  102. public override void SelectedStationChanged(string stationId)
  103. {
  104. //MessageBox.Show(stationId);
  105. this.StationId = stationId;
  106. Active();
  107. }
  108. private void cMenuControl_Opening(object sender, CancelEventArgs e)
  109. {
  110. MatrixDevice2 md = (sender as ContextMenuStrip).SourceControl as MatrixDevice2;
  111. if (md != null)
  112. {
  113. if (md.StationId.Equals("SBQ_FDC"))
  114. {
  115. this.cMenuControl.Tag = md.DeviceId;
  116. this.cMenuControl.Enabled = true;
  117. this.menuReset.Enabled = false;
  118. this.menuMaintain.Enabled = false;
  119. this.menuCancelMaintain.Enabled = false;
  120. this.menuStartUp.Enabled = false;
  121. this.menuShutDown.Enabled = false;
  122. //风机六种状态: 限电5》运行1》待机0》维护4》故障2》离线3
  123. //风机八种状态: 0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  124. int st = Convert.ToInt32(md.Status);
  125. switch (st)
  126. {
  127. //case 5:
  128. //case 1:
  129. // this.menuShutDown.Enabled = true;
  130. // break;
  131. //case 0:
  132. // this.menuStartUp.Enabled = true;
  133. // this.menuMaintain.Enabled = true;
  134. // break;
  135. //case 4:
  136. // this.menuCancelMaintain.Enabled = true;
  137. // break;
  138. //case 2:
  139. // this.menuReset.Enabled = true;
  140. // this.menuMaintain.Enabled = true;
  141. // break;
  142. //case 3:
  143. //default:
  144. // break;
  145. case 0:
  146. this.menuStartUp.Enabled = true;
  147. this.menuMaintain.Enabled = true;
  148. this.menuReset.Enabled = true;
  149. this.menuCancelMaintain.Enabled = false;
  150. this.menuShutDown.Enabled = false;
  151. break;
  152. case 1:
  153. this.menuStartUp.Enabled = false;
  154. this.menuMaintain.Enabled = false;
  155. this.menuReset.Enabled = false;
  156. this.menuCancelMaintain.Enabled = false;
  157. this.menuShutDown.Enabled = false;
  158. break;
  159. case 2:
  160. this.menuStartUp.Enabled = true;
  161. this.menuMaintain.Enabled = true;
  162. this.menuReset.Enabled = true;
  163. this.menuCancelMaintain.Enabled = false;
  164. this.menuShutDown.Enabled = false;
  165. break;
  166. case 3:
  167. this.menuStartUp.Enabled = false;
  168. this.menuMaintain.Enabled = false;
  169. this.menuReset.Enabled = false;
  170. this.menuCancelMaintain.Enabled = false;
  171. this.menuShutDown.Enabled = false;
  172. break;
  173. case 4:
  174. this.menuStartUp.Enabled = false;
  175. this.menuMaintain.Enabled = false;
  176. this.menuReset.Enabled = false;
  177. this.menuCancelMaintain.Enabled = false;
  178. this.menuShutDown.Enabled = true;
  179. break;
  180. case 5:
  181. this.menuStartUp.Enabled = false;
  182. this.menuMaintain.Enabled = false;
  183. this.menuReset.Enabled = true;
  184. this.menuCancelMaintain.Enabled = false;
  185. this.menuShutDown.Enabled = false;
  186. break;
  187. case 6:
  188. this.menuStartUp.Enabled = false;
  189. this.menuMaintain.Enabled = false;
  190. this.menuReset.Enabled = false;
  191. this.menuCancelMaintain.Enabled = true;
  192. this.menuShutDown.Enabled = false;
  193. break;
  194. case 7:
  195. this.menuStartUp.Enabled = false;
  196. this.menuMaintain.Enabled = false;
  197. this.menuReset.Enabled = false;
  198. this.menuCancelMaintain.Enabled = true;
  199. this.menuShutDown.Enabled = false;
  200. break;
  201. default: break;
  202. }
  203. if (md.DeviceModel.Equals("UP105-2000-S"))
  204. {
  205. this.menuReset.Enabled = false;
  206. this.menuMaintain.Enabled = false;
  207. this.menuCancelMaintain.Enabled = false;
  208. }
  209. }
  210. else
  211. {
  212. this.cMenuControl.Enabled = false;
  213. }
  214. //MessageBox.Show(md.DeviceModel + "," + md.StationId);
  215. //e.Cancel = true;
  216. }
  217. //string whichcontrol_name = (sender as ContextMenuStrip).SourceControl.Name;
  218. }
  219. private void menuStartUp_Click(object sender, EventArgs e)
  220. {
  221. try
  222. {
  223. user userData = null;
  224. FingerCheck check = new FingerCheck();
  225. check.ShowDialog();
  226. userData = FingerCheck.checkSuccessUser;
  227. if (userData != null)
  228. {
  229. //string deviceId = this.cMenuControl.Tag.ToString();
  230. //if (String.IsNullOrWhiteSpace(deviceId) == false)
  231. // sendCommand(deviceId, CmdType.Start, userData);
  232. string deviceId = this.cMenuControl.Tag.ToString();
  233. if (String.IsNullOrWhiteSpace(deviceId) == false)
  234. {
  235. if (TaskQueueSvc.dicTask.ContainsKey(deviceId))
  236. {
  237. MessageBox.Show("风机操作太频繁,请稍后再试!");
  238. return;
  239. }
  240. IList<string> windtrurbineIdList = new List<string>();
  241. windtrurbineIdList.Add(deviceId);
  242. TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Start, userData);
  243. }
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. logger.Error(ex);
  249. }
  250. }
  251. private void menuShutDown_Click(object sender, EventArgs e)
  252. {
  253. try
  254. {
  255. user userData = null;
  256. FingerCheck check = new FingerCheck();
  257. check.ShowDialog();
  258. userData = FingerCheck.checkSuccessUser;
  259. if (userData != null)
  260. {
  261. //string deviceId = this.cMenuControl.Tag.ToString();
  262. //if (String.IsNullOrWhiteSpace(deviceId) == false)
  263. // sendCommand(deviceId, CmdType.Stop, userData);
  264. string deviceId = this.cMenuControl.Tag.ToString();
  265. if (String.IsNullOrWhiteSpace(deviceId) == false)
  266. {
  267. if (TaskQueueSvc.dicTask.ContainsKey(deviceId))
  268. {
  269. MessageBox.Show("风机操作太频繁,请稍后再试!");
  270. return;
  271. }
  272. IList<string> windtrurbineIdList = new List<string>();
  273. string windturbineId = "SG01_"+deviceId.Replace("SG", "");
  274. windtrurbineIdList.Add(windturbineId);
  275. TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Stop, userData);
  276. }
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. logger.Error(ex);
  282. }
  283. }
  284. private void menuReset_Click(object sender, EventArgs e)
  285. {
  286. try
  287. {
  288. user userData = null;
  289. FingerCheck check = new FingerCheck();
  290. check.ShowDialog();
  291. userData = FingerCheck.checkSuccessUser;
  292. if (userData != null)
  293. {
  294. //string deviceId = this.cMenuControl.Tag.ToString();
  295. //if (String.IsNullOrWhiteSpace(deviceId) == false)
  296. // sendCommand(deviceId, CmdType.Reset, userData);
  297. string deviceId = this.cMenuControl.Tag.ToString();
  298. if (String.IsNullOrWhiteSpace(deviceId) == false)
  299. {
  300. if (TaskQueueSvc.dicTask.ContainsKey(deviceId))
  301. {
  302. MessageBox.Show("风机操作太频繁,请稍后再试!");
  303. return;
  304. }
  305. IList<string> windtrurbineIdList = new List<string>();
  306. string windturbineId = "SG01_" + deviceId.Replace("SG", "");
  307. windtrurbineIdList.Add(windturbineId);
  308. TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Reset, userData);
  309. }
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. logger.Error(ex);
  315. }
  316. }
  317. private void menuMaintain_Click(object sender, EventArgs e)
  318. {
  319. try
  320. {
  321. user userData = null;
  322. FingerCheck check = new FingerCheck();
  323. check.ShowDialog();
  324. userData = FingerCheck.checkSuccessUser;
  325. if (userData != null)
  326. {
  327. //string deviceId = this.cMenuControl.Tag.ToString();
  328. //if (String.IsNullOrWhiteSpace(deviceId) == false)
  329. // sendCommand(deviceId, CmdType.Maintain, userData);
  330. string deviceId = this.cMenuControl.Tag.ToString();
  331. if (String.IsNullOrWhiteSpace(deviceId) == false)
  332. {
  333. if (TaskQueueSvc.dicTask.ContainsKey(deviceId))
  334. {
  335. MessageBox.Show("风机操作太频繁,请稍后再试!");
  336. return;
  337. }
  338. IList<string> windtrurbineIdList = new List<string>();
  339. string windturbineId = "SG01_" + deviceId.Replace("SG", "");
  340. windtrurbineIdList.Add(windturbineId);
  341. TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.Maintain, userData);
  342. }
  343. }
  344. }
  345. catch (Exception ex)
  346. {
  347. logger.Error(ex);
  348. }
  349. }
  350. private void menuCancelMaintain_Click(object sender, EventArgs e)
  351. {
  352. try
  353. {
  354. user userData = null;
  355. FingerCheck check = new FingerCheck();
  356. check.ShowDialog();
  357. userData = FingerCheck.checkSuccessUser;
  358. if (userData != null)
  359. {
  360. //string deviceId = this.cMenuControl.Tag.ToString();
  361. //if (String.IsNullOrWhiteSpace(deviceId) == false)
  362. // sendCommand(deviceId, CmdType.UnMaintain, userData);
  363. string deviceId = this.cMenuControl.Tag.ToString();
  364. if (String.IsNullOrWhiteSpace(deviceId) == false)
  365. {
  366. if (TaskQueueSvc.dicTask.ContainsKey(deviceId))
  367. {
  368. MessageBox.Show("风机操作太频繁,请稍后再试!");
  369. return;
  370. }
  371. IList<string> windtrurbineIdList = new List<string>();
  372. string windturbineId = "SG01_" + deviceId.Replace("SG", "");
  373. windtrurbineIdList.Add(windturbineId);
  374. TaskQueueSvc.QueueAdd(windtrurbineIdList, "SBQ_FDC", CmdType.UnMaintain, userData);
  375. }
  376. }
  377. }
  378. catch (Exception ex)
  379. {
  380. logger.Error(ex);
  381. }
  382. }
  383. private void sendCommand(string wtId, CmdType cmdType, user userData)
  384. {
  385. ControlSvc controlSvc = ControlSvc.GetControlSvc();
  386. IList<string> faultSendList = new List<string>();
  387. IList<string> deviceList = new List<string>();
  388. deviceList.Add(wtId);
  389. bool isSend = controlSvc.SendCmdByWindturbineIdList(deviceList, "SBQ_FDC", cmdType, out faultSendList, "", userData);
  390. if (isSend)
  391. {
  392. MessageBox.Show("命令发送成功");
  393. this.Close();
  394. }
  395. else
  396. {
  397. string windturbineIds = "";
  398. for (int i = 0; i < faultSendList.Count; i++)
  399. {
  400. windturbineIds = windturbineIds + faultSendList[i] + ",";
  401. }
  402. MessageBox.Show("命令发送失败的风机有:" + windturbineIds);
  403. }
  404. }
  405. }
  406. }