NSS_Control.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using IntelligentControlForsx.Service.WindturbineControl.Domain.FormInfo;
  12. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  13. using Gyee_Control.Svc.Cache;
  14. using EntityDataSet;
  15. using IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc;
  16. using System.Text.RegularExpressions;
  17. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  18. using Gyee_Control.View;
  19. using IntelligentControlForsx.ChildForms;
  20. using log4net;
  21. using WisdomClient;
  22. using WisdomClient.data;
  23. namespace IntelligentControlForsx.MyControls.kz
  24. {
  25. public partial class NSS_Control : UserControl
  26. {
  27. private ILog logger = LogManager.GetLogger("AppInfoLog");
  28. private BindingSource formBindingSource = new BindingSource();
  29. private bool isNeedInsertCheck = true;
  30. private string projectId = "NSS01_GC";
  31. IList<EntityDataSet.windturbine> windturbineList = new List<EntityDataSet.windturbine>();
  32. public void FormDataBind()
  33. {
  34. IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
  35. BindingList<WindturbineFormData> dataList = this.formBindingSource.DataSource as BindingList<WindturbineFormData>;
  36. IList<string> windturbineIdList = dataList.Select(s => s.WindturbineId).ToList();
  37. for (int i = 0; i < windturbineIdList.Count; i++)
  38. {
  39. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
  40. pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
  41. }
  42. for (int i = 0; i < pointDataList.Count; i++)
  43. {
  44. var data =
  45. dataList.Where(s => s.WindturbineId == pointDataList[i].WindturbineName).FirstOrDefault();
  46. if (data != null)
  47. {
  48. data.WindSpeed = pointDataList[i].WindSpeed.ToString("f2");
  49. data.Power = pointDataList[i].Power.ToString("f2");
  50. switch (pointDataList[i].Status)
  51. {
  52. case WindturbineStatus.Standby:
  53. data.StatusString = "待机";
  54. break;
  55. case WindturbineStatus.OnPower:
  56. data.StatusString = "上电";
  57. break;
  58. case WindturbineStatus.Maintain:
  59. data.StatusString = "维护";
  60. break;
  61. case WindturbineStatus.Fault:
  62. data.StatusString = "故障";
  63. break;
  64. case WindturbineStatus.Start:
  65. data.StatusString = "启动";
  66. break;
  67. case WindturbineStatus.Online:
  68. data.StatusString = "并网";
  69. break;
  70. case WindturbineStatus.Stop:
  71. data.StatusString = "停机";
  72. break;
  73. case WindturbineStatus.Offline:
  74. data.StatusString = "离线";
  75. break;
  76. }
  77. switch (pointDataList[i].HungType)
  78. {
  79. case HungType.UnLock:
  80. data.HungTypeString = "正常";
  81. break;
  82. case HungType.StationCheckLock:
  83. data.HungTypeString = "场内受累检修";
  84. break;
  85. case HungType.StationFaulLockt:
  86. data.HungTypeString = "场内受累故障";
  87. break;
  88. case HungType.StationPowerLineLock:
  89. data.HungTypeString = "场外受累电网";
  90. break;
  91. case HungType.StationWeatherLock:
  92. data.HungTypeString = "场外受累天气";
  93. break;
  94. case HungType.FaultLock:
  95. data.HungTypeString = "故障检修";
  96. break;
  97. case HungType.CheckLock:
  98. data.HungTypeString = "检修";
  99. break;
  100. }
  101. data.AlternatorSpeed = pointDataList[i].AlternatorSpeed.ToString("f2");
  102. data.LaminaSpeed = pointDataList[i].LaminaSpeed.ToString("f2");
  103. data.LimitSpeed = pointDataList[i].LimitSpeed.ToString("f2");
  104. data.LaminaAngle1 = pointDataList[i].LaminaAngle1.ToString("f2");
  105. data.LaminaAngle2 = pointDataList[i].LaminaAngle2.ToString("f2");
  106. data.LaminaAngle3 = pointDataList[i].LaminaAngle3.ToString("f2");
  107. data.WindAngle = pointDataList[i].WindAngle.ToString("f2");
  108. data.YawPosition = pointDataList[i].YawPosition.ToString("f2");
  109. }
  110. }
  111. #region 修改风机状态背景色
  112. for (int i = 0; i < gvWindturbine.RowCount; i++)
  113. {
  114. string statusString = gvWindturbine.Rows[i].Cells[4].Value.ToString();
  115. string windturbineId = gvWindturbine.Rows[i].Cells[1].Value.ToString().Trim();
  116. DataGridViewRow row = gvWindturbine.Rows[i];
  117. switch (statusString)
  118. {
  119. case "待机":
  120. row.Cells[1].Style.BackColor = Color.FromArgb(15, 141, 106);
  121. break;
  122. case "上电":
  123. row.Cells[1].Style.BackColor = Color.FromArgb(177, 14, 126);
  124. break;
  125. case "维护":
  126. row.Cells[1].Style.BackColor = Color.FromArgb(204, 83, 51);
  127. break;
  128. case "故障":
  129. row.Cells[1].Style.BackColor = Color.FromArgb(170, 15, 59);
  130. break;
  131. case "启动":
  132. row.Cells[1].Style.BackColor = Color.FromArgb(14, 72, 91);
  133. break;
  134. case "并网":
  135. row.Cells[1].Style.BackColor = Color.FromArgb(15, 135, 170);
  136. break;
  137. case "停机":
  138. row.Cells[1].Style.BackColor = Color.FromArgb(176, 151, 63);
  139. break;
  140. case "离线":
  141. row.Cells[1].Style.BackColor = Color.FromArgb(134, 150, 165);
  142. break;
  143. }
  144. if (gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "正常" && gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "未知")
  145. {
  146. row.Cells[5].Style.BackColor = Color.FromArgb(255, 255, 0);
  147. row.Cells[5].Style.ForeColor = Color.FromArgb(0, 0, 0);
  148. }
  149. else
  150. {
  151. row.Cells[5].Style.BackColor = row.Cells[6].Style.BackColor;
  152. row.Cells[5].Style.ForeColor = row.Cells[6].Style.ForeColor;
  153. }
  154. }
  155. #endregion
  156. isUpdateOverGv = true;
  157. }
  158. private delegate void UpdateGridViewDelegate();
  159. private static BindingList<WindturbineFormData> formDataList = new BindingList<WindturbineFormData>();
  160. public void BindFormThread()
  161. {
  162. UpdateGridViewDelegate del = new UpdateGridViewDelegate(FormDataBind);
  163. if (gvWindturbine.InvokeRequired)
  164. {
  165. gvWindturbine.BeginInvoke(del, new object[] { });
  166. }
  167. else
  168. {
  169. FormDataBind();
  170. }
  171. }
  172. //数据是否绑定完毕
  173. private bool isUpdateOverGv = true;
  174. private void Init(string projectId)
  175. {
  176. gvWindturbine.DataSource = null;
  177. formDataList = new BindingList<WindturbineFormData>();
  178. IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
  179. IList<string> windturbineIdList =
  180. windturbineList.Where(s => s.PROJECTID == projectId).ToList().Select(s => s.ID).ToList();
  181. for (int i = 0; i < windturbineIdList.Count; i++)
  182. {
  183. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
  184. pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
  185. }
  186. if (pointDataList.Count <= 0)
  187. {
  188. IList<EntityDataSet.windturbine> list = windturbineList.Where(s => s.WINDPOWERSTATIONID == "NSS_FDC" && s.PROJECTID == projectId).ToList().OrderBy(s => Convert.ToInt32(Regex.Replace(s.ID, "[a-zA-Z]", "").Replace("_", ""))).ToList();
  189. for (int i = 0; i < list.Count; i++)
  190. {
  191. WindturbineFormData data = new WindturbineFormData(list[i].ID,
  192. "0.0",
  193. "0.0",
  194. "未知",
  195. "未知",
  196. "0.0",
  197. "0.0",
  198. "0.0",
  199. "0.0",
  200. "0.0",
  201. "0.0",
  202. "0.0",
  203. "0.0"
  204. );
  205. formDataList.Add(data);
  206. }
  207. formBindingSource.DataSource = formDataList;
  208. this.gvWindturbine.DataSource = formBindingSource;
  209. }
  210. else
  211. {
  212. IList<WindturbinePointData> orderList = pointDataList.OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineName, "[a-zA-Z]", "").Replace("_", ""))).ToList();
  213. for (int i = 0; i < orderList.Count; i++)
  214. {
  215. string statusString = "";
  216. #region 状态转化字符串
  217. switch (pointDataList[i].Status)
  218. {
  219. case WindturbineStatus.Standby:
  220. statusString = "待机";
  221. break;
  222. case WindturbineStatus.OnPower:
  223. statusString = "上电";
  224. break;
  225. case WindturbineStatus.Maintain:
  226. statusString = "维护";
  227. break;
  228. case WindturbineStatus.Fault:
  229. statusString = "故障";
  230. break;
  231. case WindturbineStatus.Start:
  232. statusString = "启动";
  233. break;
  234. case WindturbineStatus.Online:
  235. statusString = "并网";
  236. break;
  237. case WindturbineStatus.Stop:
  238. statusString = "停机";
  239. break;
  240. case WindturbineStatus.Offline:
  241. statusString = "离线";
  242. break;
  243. }
  244. #endregion
  245. string hungTypeString = "";
  246. switch (pointDataList[i].HungType)
  247. {
  248. case HungType.UnLock:
  249. hungTypeString = "正常";
  250. break;
  251. case HungType.StationCheckLock:
  252. hungTypeString = "场内受累检修";
  253. break;
  254. case HungType.StationFaulLockt:
  255. hungTypeString = "场内受累故障";
  256. break;
  257. case HungType.StationPowerLineLock:
  258. hungTypeString = "场外受累电网";
  259. break;
  260. case HungType.StationWeatherLock:
  261. hungTypeString = "场外受累天气";
  262. break;
  263. case HungType.FaultLock:
  264. hungTypeString = "故障检修";
  265. break;
  266. case HungType.CheckLock:
  267. hungTypeString = "检修";
  268. break;
  269. }
  270. WindturbineFormData data = new WindturbineFormData(orderList[i].WindturbineName,
  271. orderList[i].WindSpeed.ToString("f2"),
  272. orderList[i].Power.ToString("f2"),
  273. statusString,
  274. hungTypeString,
  275. orderList[i].AlternatorSpeed.ToString("f2"),
  276. orderList[i].LaminaSpeed.ToString("f2"),
  277. orderList[i].LimitSpeed.ToString("f2"),
  278. orderList[i].LaminaAngle1.ToString("f2"),
  279. orderList[i].LaminaAngle2.ToString("f2"),
  280. orderList[i].LaminaAngle3.ToString("f2"),
  281. orderList[i].WindAngle.ToString("f2"),
  282. orderList[i].YawPosition.ToString("f2")
  283. );
  284. formDataList.Add(data);
  285. }
  286. formBindingSource.DataSource = formDataList;
  287. this.gvWindturbine.DataSource = formBindingSource;
  288. }
  289. #region 添加勾选列 -首次加载才会添加
  290. if (isNeedInsertCheck)
  291. {
  292. DataGridViewCheckBoxColumn checkColum = new DataGridViewCheckBoxColumn();
  293. checkColum.HeaderText = "";
  294. checkColum.Name = "Select";
  295. checkColum.DataPropertyName = "Select";
  296. checkColum.ReadOnly = false;
  297. checkColum.TrueValue = true;
  298. checkColum.FalseValue = false;
  299. gvWindturbine.Columns.Insert(0, checkColum);
  300. isNeedInsertCheck = false;
  301. }
  302. gvWindturbine.Columns[0].Width = 50;
  303. gvWindturbine.Columns[1].Width = 110;
  304. #endregion
  305. #region 修改表头
  306. gvWindturbine.Columns[1].HeaderText = "风机编号";
  307. gvWindturbine.Columns[2].HeaderText = "风速 m/s";
  308. gvWindturbine.Columns[3].HeaderText = "功率 kw";
  309. gvWindturbine.Columns[4].HeaderText = "状态";
  310. gvWindturbine.Columns[5].HeaderText = "挂牌";
  311. gvWindturbine.Columns[6].HeaderText = "发电机转速";
  312. gvWindturbine.Columns[7].HeaderText = "限速值";
  313. gvWindturbine.Columns[8].HeaderText = "叶轮转速";
  314. gvWindturbine.Columns[9].HeaderText = "桨叶角度1";
  315. gvWindturbine.Columns[10].HeaderText = "桨叶角度2";
  316. gvWindturbine.Columns[11].HeaderText = "桨叶角度3";
  317. gvWindturbine.Columns[12].HeaderText = "对风角度";
  318. gvWindturbine.Columns[13].HeaderText = "偏航位置";
  319. #endregion
  320. }
  321. //第一次加载
  322. public bool firstLoad = true;
  323. //数据是否刷新完毕
  324. private bool isUpdateOverData = true;
  325. private void UpdatePointData()
  326. {
  327. IList<string> pList = new List<string>();
  328. pList.Add("NSS_FDC");
  329. pList.Add(projectId);
  330. WindturbinePointDataSvc.UpdatePointDataByStationAndProject(pList);
  331. isUpdateOverData = true;
  332. }
  333. public NSS_Control()
  334. {
  335. InitializeComponent();
  336. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  337. {
  338. windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "NSS_FDC").ToList();
  339. }
  340. IList<HungTypeSelectItemEntity> selectItemList = new List<HungTypeSelectItemEntity>();
  341. selectItemList.Add(new HungTypeSelectItemEntity(-1, "请选择"));
  342. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.CheckLock, "检修"));
  343. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.FaultLock, "故障检修"));
  344. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationCheckLock, "场内受累检修"));
  345. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationFaulLockt, "场内受累故障"));
  346. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationPowerLineLock, "场外受累电网"));
  347. selectItemList.Add(new HungTypeSelectItemEntity((int)HungType.StationWeatherLock, "场外受累天气"));
  348. this.cbHungReason.DataSource = selectItemList;
  349. this.cbHungReason.DisplayMember = "HungName";
  350. this.cbHungReason.ValueMember = "HungType";
  351. this.cbHungReason.SelectedValue = -1;
  352. Init("NSS01_GC");
  353. }
  354. public void Active()
  355. {
  356. timer1.Enabled = true;
  357. }
  358. public void DeActive()
  359. {
  360. timer1.Enabled = false;
  361. }
  362. private void lblProject1_Click(object sender, EventArgs e)
  363. {
  364. projectId = "NSS01_GC";
  365. Init(projectId);
  366. firstLoad = true;
  367. //ThreadInfo();
  368. lblProject1.BackColor = Color.FromArgb(15, 141, 106);
  369. lblProject2.BackColor = Color.FromArgb(3, 24, 48);
  370. lblProject3.BackColor = Color.FromArgb(3, 24, 48);
  371. btnMaintain.Enabled = true;
  372. btnUnMaintain.Enabled = true;
  373. btnRest.Enabled = true;
  374. }
  375. private void lblProject2_Click(object sender, EventArgs e)
  376. {
  377. projectId = "NSS02_GC";
  378. Init(projectId);
  379. firstLoad = true;
  380. //ThreadInfo();
  381. lblProject1.BackColor = Color.FromArgb(3, 24, 48);
  382. lblProject2.BackColor = Color.FromArgb(15, 141, 106);
  383. lblProject3.BackColor = Color.FromArgb(3, 24, 48);
  384. btnMaintain.Enabled = true;
  385. btnUnMaintain.Enabled = true;
  386. btnRest.Enabled = true;
  387. }
  388. private void lblProject3_Click(object sender, EventArgs e)
  389. {
  390. projectId = "NSS03_GC";
  391. Init(projectId);
  392. firstLoad = true;
  393. // ThreadInfo();
  394. lblProject1.BackColor = Color.FromArgb(3, 24, 48);
  395. lblProject2.BackColor = Color.FromArgb(3, 24, 48);
  396. lblProject3.BackColor = Color.FromArgb(15, 141, 106);
  397. btnMaintain.Enabled = true;
  398. btnUnMaintain.Enabled = true;
  399. btnRest.Enabled = true;
  400. }
  401. private void timer1_Tick(object sender, EventArgs e)
  402. {
  403. if (isUpdateOverData)
  404. {
  405. isUpdateOverData = false;
  406. Thread getDataThread = new Thread(UpdatePointData);//创建数据更新线程
  407. getDataThread.Start();
  408. }
  409. if (isUpdateOverGv)
  410. {
  411. isUpdateOverGv = false;
  412. Thread t = new Thread(BindFormThread);
  413. t.IsBackground = true;
  414. t.Start();
  415. }
  416. }
  417. /// <summary>
  418. /// 已经勾选的风机
  419. /// </summary>
  420. private IList<string> isCheckWindturbineIdList = new List<string>();
  421. //清除所有勾选风机
  422. private void ClearCheck()
  423. {
  424. for (int i = 0; i < gvWindturbine.RowCount; i++)
  425. {
  426. gvWindturbine.Rows[i].Cells["Select"].Value = 0;
  427. }
  428. }
  429. private void btnStart_Click(object sender, EventArgs e)
  430. {
  431. string cmdDescribe = null;
  432. cmdDescribe = "正常启动";
  433. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  434. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  435. {
  436. WindturbineCmdInfo info = new WindturbineCmdInfo();
  437. info.WindturbineId = isCheckWindturbineIdList[i];
  438. info.StationId = "NSS_FDC";
  439. info.CmdType = CmdType.Start;
  440. cmdInfoList.Add(info);
  441. }
  442. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
  443. confirm.ShowDialog();
  444. isCheckWindturbineIdList = new List<string>();
  445. ClearCheck();
  446. }
  447. private void btnStop_Click(object sender, EventArgs e)
  448. {
  449. string cmdDescribe = null;
  450. cmdDescribe = "正常停机";
  451. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  452. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  453. {
  454. WindturbineCmdInfo info = new WindturbineCmdInfo();
  455. info.WindturbineId = isCheckWindturbineIdList[i];
  456. info.StationId = "NSS_FDC";
  457. info.CmdType = CmdType.Stop;
  458. cmdInfoList.Add(info);
  459. }
  460. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
  461. confirm.ShowDialog();
  462. isCheckWindturbineIdList = new List<string>();
  463. ClearCheck();
  464. }
  465. private void btnRest_Click(object sender, EventArgs e)
  466. {
  467. string cmdDescribe = null;
  468. cmdDescribe = "正常复位";
  469. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  470. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  471. {
  472. WindturbineCmdInfo info = new WindturbineCmdInfo();
  473. info.WindturbineId = isCheckWindturbineIdList[i];
  474. info.StationId = "NSS_FDC";
  475. info.CmdType = CmdType.Reset;
  476. cmdInfoList.Add(info);
  477. }
  478. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
  479. confirm.ShowDialog();
  480. isCheckWindturbineIdList = new List<string>();
  481. ClearCheck();
  482. }
  483. private void btnMaintain_Click(object sender, EventArgs e)
  484. {
  485. string cmdDescribe = null;
  486. cmdDescribe = "正常维护";
  487. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  488. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  489. {
  490. WindturbineCmdInfo info = new WindturbineCmdInfo();
  491. info.WindturbineId = isCheckWindturbineIdList[i];
  492. info.StationId = "NSS_FDC";
  493. info.CmdType = CmdType.Maintain;
  494. cmdInfoList.Add(info);
  495. }
  496. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
  497. confirm.ShowDialog();
  498. isCheckWindturbineIdList = new List<string>();
  499. ClearCheck();
  500. }
  501. private void btnUnMaintain_Click(object sender, EventArgs e)
  502. {
  503. string cmdDescribe = null;
  504. cmdDescribe = "正常取消维护";
  505. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  506. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  507. {
  508. WindturbineCmdInfo info = new WindturbineCmdInfo();
  509. info.WindturbineId = isCheckWindturbineIdList[i];
  510. info.StationId = "NSS_FDC";
  511. info.CmdType = CmdType.UnMaintain;
  512. cmdInfoList.Add(info);
  513. }
  514. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe);
  515. confirm.ShowDialog();
  516. isCheckWindturbineIdList = new List<string>();
  517. ClearCheck();
  518. }
  519. private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  520. {
  521. if (e.RowIndex != -1)
  522. {
  523. if (e.ColumnIndex == 0)
  524. {
  525. string isCheck = gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value == null ? "0" : gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value.ToString();
  526. string windturbineId = this.gvWindturbine.Rows[e.RowIndex].Cells[1].Value.ToString();
  527. if (isCheck == "1")
  528. {
  529. gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 0;
  530. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  531. if (count > 0)
  532. isCheckWindturbineIdList.Remove(windturbineId);
  533. }
  534. else
  535. {
  536. gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 1;
  537. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  538. if (count <= 0)
  539. isCheckWindturbineIdList.Add(windturbineId);
  540. }
  541. }
  542. }
  543. else
  544. {
  545. if (e.ColumnIndex == 0)
  546. {
  547. for (int i = 0; i < gvWindturbine.RowCount; i++)
  548. {
  549. string isCheck = gvWindturbine.Rows[i].Cells["Select"].Value == null
  550. ? "0"
  551. : gvWindturbine.Rows[i].Cells["Select"].Value.ToString();
  552. string windturbineId = this.gvWindturbine.Rows[i].Cells[1].Value.ToString();
  553. if (isCheck == "1")
  554. {
  555. gvWindturbine.Rows[i].Cells["Select"].Value = 0;
  556. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  557. if (count > 0)
  558. isCheckWindturbineIdList.Remove(windturbineId);
  559. }
  560. else
  561. {
  562. gvWindturbine.Rows[i].Cells["Select"].Value = 1;
  563. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  564. if (count <= 0)
  565. isCheckWindturbineIdList.Add(windturbineId);
  566. }
  567. }
  568. }
  569. }
  570. }
  571. private void btnHang_Click(object sender, EventArgs e)
  572. {
  573. string hungInfo = cbHungReason.SelectedValue.ToString().Trim();
  574. if (hungInfo == "-1")
  575. {
  576. MessageBox.Show("请选择挂牌原因!");
  577. return;
  578. }
  579. HungType type = (HungType)Enum.Parse(typeof(HungType), hungInfo);
  580. bool isSuccess = WindturbineLock("NSS_FDC", isCheckWindturbineIdList, type);
  581. if (isSuccess)
  582. {
  583. string message = "";
  584. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  585. {
  586. message = message + isCheckWindturbineIdList[i] + ",";
  587. }
  588. message = "已针对" + message + "风机进行挂牌操作";
  589. MessageBox.Show(message);
  590. }
  591. isCheckWindturbineIdList = new List<string>();
  592. ClearCheck();
  593. cbHungReason.SelectedValue = -1;
  594. }
  595. private void btnUnHang_Click(object sender, EventArgs e)
  596. {
  597. bool isSuccess = WindturbineLock("NSS_FDC", isCheckWindturbineIdList, HungType.UnLock);
  598. if (isSuccess)
  599. {
  600. string message = "";
  601. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  602. {
  603. message = message + isCheckWindturbineIdList[i] + ",";
  604. }
  605. message = "已针对" + message + "风机进行取消挂牌操作";
  606. MessageBox.Show(message);
  607. }
  608. isCheckWindturbineIdList = new List<string>();
  609. ClearCheck();
  610. }
  611. private void btnLimitPower_Click(object sender, EventArgs e)
  612. {
  613. string limitPower = txtPower.Text.Trim();
  614. if (string.IsNullOrEmpty(limitPower))
  615. {
  616. MessageBox.Show("请输入限定功率");
  617. return;
  618. }
  619. else
  620. {
  621. double power = 0.0;
  622. bool IsNumber = Double.TryParse(limitPower, out power);
  623. if (!IsNumber)
  624. {
  625. MessageBox.Show("输入限定功率不合法");
  626. return;
  627. }
  628. else
  629. {
  630. string cmdDescribe = null;
  631. cmdDescribe = "限定功率";
  632. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  633. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  634. {
  635. WindturbineCmdInfo info = new WindturbineCmdInfo();
  636. info.WindturbineId = isCheckWindturbineIdList[i];
  637. info.StationId = "NSS_FDC";
  638. info.CmdType = CmdType.LimitPower;
  639. cmdInfoList.Add(info);
  640. }
  641. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe, power);
  642. confirm.ShowDialog();
  643. }
  644. }
  645. txtPower.Text = "";
  646. isCheckWindturbineIdList = new List<string>();
  647. ClearCheck();
  648. }
  649. private void btnLimitSpeed_Click(object sender, EventArgs e)
  650. {
  651. string limitSpeed = txtSpeed.Text.Trim();
  652. if (string.IsNullOrEmpty(limitSpeed))
  653. {
  654. MessageBox.Show("请输入限定转速");
  655. return;
  656. }
  657. else
  658. {
  659. double speed = 0.0;
  660. bool IsNumber = Double.TryParse(limitSpeed, out speed);
  661. if (!IsNumber)
  662. {
  663. MessageBox.Show("输入限定转速不合法");
  664. return;
  665. }
  666. else
  667. {
  668. string cmdDescribe = null;
  669. cmdDescribe = "限定转速";
  670. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  671. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  672. {
  673. WindturbineCmdInfo info = new WindturbineCmdInfo();
  674. info.WindturbineId = isCheckWindturbineIdList[i];
  675. info.StationId = "NSS_FDC";
  676. info.CmdType = CmdType.LimitSpeed;
  677. cmdInfoList.Add(info);
  678. }
  679. Confirm confirm = new Confirm("NSS_FDC", cmdInfoList, cmdDescribe, speed);
  680. confirm.ShowDialog();
  681. }
  682. }
  683. txtSpeed.Text = "";
  684. isCheckWindturbineIdList = new List<string>();
  685. ClearCheck();
  686. }
  687. private bool WindturbineLock(string pStationId, IList<string> windturbineIdList, HungType type)
  688. {
  689. bool isSuccess = false;
  690. try
  691. {
  692. user userData = null;
  693. FingerCheck2 check = new FingerCheck2();
  694. check.ShowDialog();
  695. userData = FingerCheck2.checkSuccessUser;
  696. if (userData != null)
  697. {
  698. for (int i = 0; i < windturbineIdList.Count; i++)
  699. {
  700. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  701. {
  702. string wId = windturbineIdList[i];
  703. view_tspoint point = ctx.view_tspoint.Where(s => s.thing_id == wId && s.thing_type == "windturbine" && s.uniform_code == "XDSL").FirstOrDefault();
  704. if (point != null)
  705. {
  706. #region 将挂牌数据写入实时库
  707. TsPointData tData = new TsPointData();
  708. tData.tagName = point.id;
  709. TsData t = new TsData();
  710. t.doubleValue = (int)type;
  711. DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  712. TimeSpan sp = DateTime.Now.Subtract(dtStart);
  713. long time = long.Parse(sp.Ticks.ToString().Substring(0, sp.Ticks.ToString().Length - 4));
  714. t.ts = time;
  715. tData.tsData = t;
  716. RestfulClient.writeLatest(tData);
  717. #endregion
  718. #region 写入操作日志
  719. control_log logData = new control_log();
  720. logData.windturbine_id = windturbineIdList[i];
  721. logData.station_id = pStationId;
  722. logData.control_user_id = userData.id;
  723. logData.send_control_time = DateTime.Now;
  724. logData.control_type = (int)CmdType.UnHangLock;
  725. logData.is_send_control_success = true;
  726. ctx.Entry(logData).State = EntityState.Added;
  727. int count = ctx.SaveChanges();
  728. if (count > 0)
  729. isSuccess = true;
  730. #endregion
  731. }
  732. }
  733. }
  734. }
  735. }
  736. catch (Exception ex)
  737. {
  738. isSuccess = false;
  739. logger.Error(ex);
  740. }
  741. return isSuccess;
  742. }
  743. }
  744. }