MHS_Control.cs 37 KB

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