SBQ_Control.cs 40 KB

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