XS_Control.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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 XS_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 = "XS01_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 XS_Control()
  43. {
  44. InitializeComponent();
  45. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  46. {
  47. windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "XS_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. btnMaintain.Enabled = false;
  62. btnUnMaintain.Enabled = false;
  63. btnRest.Enabled = false;
  64. Init(projectId);
  65. }
  66. public void Active()
  67. {
  68. timer1.Enabled = true;
  69. }
  70. public void DeActive()
  71. {
  72. timer1.Enabled = false;
  73. }
  74. private void lblProject1_Click(object sender, EventArgs e)
  75. {
  76. Init("XS01_GC");
  77. projectId = "XS01_GC";
  78. lblProject1.BackColor = Color.FromArgb(15, 141, 106);
  79. lblProject2.BackColor = Color.FromArgb(3, 24, 48);
  80. isCheckWindturbineIdList = new List<string>();
  81. btnMaintain.Enabled = false;
  82. btnUnMaintain.Enabled = false;
  83. btnRest.Enabled = false;
  84. }
  85. private void lblProject2_Click(object sender, EventArgs e)
  86. {
  87. Init("XS02_GC");
  88. projectId = "XS02_GC";
  89. lblProject1.BackColor = Color.FromArgb(3, 24, 48);
  90. lblProject2.BackColor = Color.FromArgb(15, 141, 106);
  91. isCheckWindturbineIdList = new List<string>();
  92. btnMaintain.Enabled = true;
  93. btnUnMaintain.Enabled = true;
  94. btnRest.Enabled = true;
  95. }
  96. private void timer1_Tick(object sender, EventArgs e)
  97. {
  98. if (isUpdateOverData)
  99. {
  100. isUpdateOverData = false;
  101. Thread getDataThread = new Thread(UpdatePointData);//创建数据更新线程
  102. getDataThread.Start();
  103. }
  104. if (isUpdateOverGv)
  105. {
  106. isUpdateOverGv = false;
  107. Thread t = new Thread(BindFormThread);
  108. t.IsBackground = true;
  109. t.Start();
  110. }
  111. }
  112. private delegate void UpdateGridViewDelegate();
  113. private void Init(string projectId)
  114. {
  115. gvWindturbine.DataSource = null;
  116. formDataList = new BindingList<WindturbineFormData>();
  117. IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
  118. IList<string> windturbineIdList =
  119. windturbineList.Where(s => s.PROJECTID == projectId).ToList().Select(s => s.ID).ToList();
  120. for (int i = 0; i < windturbineIdList.Count; i++)
  121. {
  122. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
  123. pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
  124. }
  125. if (pointDataList.Count <= 0)
  126. {
  127. IList<EntityDataSet.windturbine> list = windturbineList.Where(s => s.WINDPOWERSTATIONID == "XS_FDC" && s.PROJECTID == projectId).ToList().OrderBy(s => Convert.ToInt32(Regex.Replace(s.ID, "[a-zA-Z]", "").Replace("_", ""))).ToList();
  128. for (int i = 0; i < list.Count; i++)
  129. {
  130. WindturbineFormData data = new WindturbineFormData(list[i].ID,
  131. "0.0",
  132. "0.0",
  133. "未知",
  134. "未知",
  135. "0.0",
  136. "0.0",
  137. "0.0",
  138. "0.0",
  139. "0.0",
  140. "0.0",
  141. "0.0",
  142. "0.0"
  143. );
  144. formDataList.Add(data);
  145. }
  146. formBindingSource.DataSource = formDataList;
  147. this.gvWindturbine.DataSource = formBindingSource;
  148. }
  149. else
  150. {
  151. IList<WindturbinePointData> orderList = pointDataList.OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineName, "[a-zA-Z]", "").Replace("_", ""))).ToList();
  152. for (int i = 0; i < orderList.Count; i++)
  153. {
  154. string statusString = "";
  155. #region 状态转化字符串
  156. switch (pointDataList[i].Status)
  157. {
  158. case WindturbineStatus.Standby:
  159. statusString = "待机";
  160. break;
  161. case WindturbineStatus.OnPower:
  162. statusString = "上电";
  163. break;
  164. case WindturbineStatus.Maintain:
  165. statusString = "维护";
  166. break;
  167. case WindturbineStatus.Fault:
  168. statusString = "故障";
  169. break;
  170. case WindturbineStatus.Start:
  171. statusString = "启动";
  172. break;
  173. case WindturbineStatus.Online:
  174. statusString = "并网";
  175. break;
  176. case WindturbineStatus.Stop:
  177. statusString = "停机";
  178. break;
  179. case WindturbineStatus.Offline:
  180. statusString = "离线";
  181. break;
  182. }
  183. #endregion
  184. string hungTypeString = "";
  185. switch (pointDataList[i].HungType)
  186. {
  187. case HungType.UnLock:
  188. hungTypeString = "正常";
  189. break;
  190. case HungType.StationCheckLock:
  191. hungTypeString = "场内受累检修";
  192. break;
  193. case HungType.StationFaulLockt:
  194. hungTypeString = "场内受累故障";
  195. break;
  196. case HungType.StationPowerLineLock:
  197. hungTypeString = "场外受累电网";
  198. break;
  199. case HungType.StationWeatherLock:
  200. hungTypeString = "场外受累天气";
  201. break;
  202. case HungType.FaultLock:
  203. hungTypeString = "故障检修";
  204. break;
  205. case HungType.CheckLock:
  206. hungTypeString = "检修";
  207. break;
  208. }
  209. WindturbineFormData data = new WindturbineFormData(orderList[i].WindturbineName,
  210. orderList[i].WindSpeed.ToString("f2"),
  211. orderList[i].Power.ToString("f2"),
  212. statusString,
  213. hungTypeString,
  214. orderList[i].AlternatorSpeed.ToString("f2"),
  215. orderList[i].LaminaSpeed.ToString("f2"),
  216. orderList[i].LimitSpeed.ToString("f2"),
  217. orderList[i].LaminaAngle1.ToString("f2"),
  218. orderList[i].LaminaAngle2.ToString("f2"),
  219. orderList[i].LaminaAngle3.ToString("f2"),
  220. orderList[i].WindAngle.ToString("f2"),
  221. orderList[i].YawPosition.ToString("f2")
  222. );
  223. formDataList.Add(data);
  224. }
  225. formBindingSource.DataSource = formDataList;
  226. this.gvWindturbine.DataSource = formBindingSource;
  227. }
  228. #region 添加勾选列 -首次加载才会添加
  229. if (isNeedInsertCheck)
  230. {
  231. DataGridViewCheckBoxColumn checkColum = new DataGridViewCheckBoxColumn();
  232. checkColum.HeaderText = "";
  233. checkColum.Name = "Select";
  234. checkColum.DataPropertyName = "Select";
  235. checkColum.ReadOnly = false;
  236. checkColum.TrueValue = true;
  237. checkColum.FalseValue = false;
  238. gvWindturbine.Columns.Insert(0, checkColum);
  239. isNeedInsertCheck = false;
  240. }
  241. gvWindturbine.Columns[0].Width = 50;
  242. gvWindturbine.Columns[1].Width = 110;
  243. #endregion
  244. #region 修改表头
  245. gvWindturbine.Columns[1].HeaderText = "风机编号";
  246. gvWindturbine.Columns[2].HeaderText = "风速 m/s";
  247. gvWindturbine.Columns[3].HeaderText = "功率 kw";
  248. gvWindturbine.Columns[4].HeaderText = "状态";
  249. gvWindturbine.Columns[5].HeaderText = "挂牌";
  250. gvWindturbine.Columns[6].HeaderText = "发电机转速";
  251. gvWindturbine.Columns[7].HeaderText = "限速值";
  252. gvWindturbine.Columns[8].HeaderText = "叶轮转速";
  253. gvWindturbine.Columns[9].HeaderText = "桨叶角度1";
  254. gvWindturbine.Columns[10].HeaderText = "桨叶角度2";
  255. gvWindturbine.Columns[11].HeaderText = "桨叶角度3";
  256. gvWindturbine.Columns[12].HeaderText = "对风角度";
  257. gvWindturbine.Columns[13].HeaderText = "偏航位置";
  258. #endregion
  259. }
  260. /// <summary>
  261. /// 后台更新数据
  262. /// </summary>
  263. private void UpdatePointData()
  264. {
  265. IList<string> pList = new List<string>();
  266. pList.Add("XS_FDC");
  267. pList.Add(projectId);
  268. WindturbinePointDataSvc.UpdatePointDataByStationAndProject(pList);
  269. isUpdateOverData = true;
  270. }
  271. public void BindFormThread()
  272. {
  273. UpdateGridViewDelegate del = new UpdateGridViewDelegate(FormDataBind);
  274. if (gvWindturbine.InvokeRequired)
  275. {
  276. gvWindturbine.BeginInvoke(del, new object[] { });
  277. }
  278. else
  279. {
  280. FormDataBind();
  281. }
  282. }
  283. public void FormDataBind()
  284. {
  285. IList<WindturbinePointData> pointDataList = new List<WindturbinePointData>();
  286. BindingList<WindturbineFormData> dataList = this.formBindingSource.DataSource as BindingList<WindturbineFormData>;
  287. IList<string> windturbineIdList = dataList.Select(s => s.WindturbineId).ToList();
  288. for (int i = 0; i < windturbineIdList.Count; i++)
  289. {
  290. if (CacheInfo.CacheWindturbineDataDic.ContainsKey(windturbineIdList[i]))
  291. pointDataList.Add(CacheInfo.CacheWindturbineDataDic[windturbineIdList[i]]);
  292. }
  293. for (int i = 0; i < pointDataList.Count; i++)
  294. {
  295. var data =
  296. dataList.Where(s => s.WindturbineId == pointDataList[i].WindturbineName).FirstOrDefault();
  297. if (data != null)
  298. {
  299. data.WindSpeed = pointDataList[i].WindSpeed.ToString("f2");
  300. data.Power = pointDataList[i].Power.ToString("f2");
  301. switch (pointDataList[i].Status)
  302. {
  303. case WindturbineStatus.Standby:
  304. data.StatusString = "待机";
  305. break;
  306. case WindturbineStatus.OnPower:
  307. data.StatusString = "上电";
  308. break;
  309. case WindturbineStatus.Maintain:
  310. data.StatusString = "维护";
  311. break;
  312. case WindturbineStatus.Fault:
  313. data.StatusString = "故障";
  314. break;
  315. case WindturbineStatus.Start:
  316. data.StatusString = "启动";
  317. break;
  318. case WindturbineStatus.Online:
  319. data.StatusString = "并网";
  320. break;
  321. case WindturbineStatus.Stop:
  322. data.StatusString = "停机";
  323. break;
  324. case WindturbineStatus.Offline:
  325. data.StatusString = "离线";
  326. break;
  327. }
  328. switch (pointDataList[i].HungType)
  329. {
  330. case HungType.UnLock:
  331. data.HungTypeString = "正常";
  332. break;
  333. case HungType.StationCheckLock:
  334. data.HungTypeString = "场内受累检修";
  335. break;
  336. case HungType.StationFaulLockt:
  337. data.HungTypeString = "场内受累故障";
  338. break;
  339. case HungType.StationPowerLineLock:
  340. data.HungTypeString = "场外受累电网";
  341. break;
  342. case HungType.StationWeatherLock:
  343. data.HungTypeString = "场外受累天气";
  344. break;
  345. case HungType.FaultLock:
  346. data.HungTypeString = "故障检修";
  347. break;
  348. case HungType.CheckLock:
  349. data.HungTypeString = "检修";
  350. break;
  351. }
  352. if (pointDataList[i].ModelId != "UP105-2000-S")
  353. data.AlternatorSpeed = pointDataList[i].AlternatorSpeed.ToString("f2");
  354. else
  355. data.AlternatorSpeed = (pointDataList[i].AlternatorSpeed * 9.55).ToString("f2");
  356. data.LaminaSpeed = pointDataList[i].LaminaSpeed.ToString("f2");
  357. data.LimitSpeed = pointDataList[i].LimitSpeed.ToString("f2");
  358. if (pointDataList[i].ModelId == "UP105-2000-S")
  359. {
  360. data.LaminaAngle1 = (pointDataList[i].LaminaAngle1 * 57.3).ToString("f2");
  361. data.LaminaAngle2 = (pointDataList[i].LaminaAngle2 * 57.3).ToString("f2");
  362. data.LaminaAngle3 = (pointDataList[i].LaminaAngle3 * 57.3).ToString("f2");
  363. }
  364. else
  365. {
  366. data.LaminaAngle1 = pointDataList[i].LaminaAngle1.ToString("f2");
  367. data.LaminaAngle2 = pointDataList[i].LaminaAngle2.ToString("f2");
  368. data.LaminaAngle3 = pointDataList[i].LaminaAngle3.ToString("f2");
  369. }
  370. data.WindAngle = pointDataList[i].WindAngle.ToString("f2");
  371. data.YawPosition = pointDataList[i].YawPosition.ToString("f2");
  372. }
  373. }
  374. #region 修改风机状态背景色
  375. for (int i = 0; i < gvWindturbine.RowCount; i++)
  376. {
  377. string statusString = gvWindturbine.Rows[i].Cells[4].Value.ToString();
  378. string windturbineId = gvWindturbine.Rows[i].Cells[1].Value.ToString().Trim();
  379. DataGridViewRow row = gvWindturbine.Rows[i];
  380. switch (statusString)
  381. {
  382. case "待机":
  383. row.Cells[1].Style.BackColor = Color.FromArgb(15, 141, 106);
  384. break;
  385. case "上电":
  386. row.Cells[1].Style.BackColor = Color.FromArgb(177, 14, 126);
  387. break;
  388. case "维护":
  389. row.Cells[1].Style.BackColor = Color.FromArgb(204, 83, 51);
  390. break;
  391. case "故障":
  392. row.Cells[1].Style.BackColor = Color.FromArgb(170, 15, 59);
  393. break;
  394. case "启动":
  395. row.Cells[1].Style.BackColor = Color.FromArgb(14, 72, 91);
  396. break;
  397. case "并网":
  398. row.Cells[1].Style.BackColor = Color.FromArgb(15, 135, 170);
  399. break;
  400. case "停机":
  401. row.Cells[1].Style.BackColor = Color.FromArgb(176, 151, 63);
  402. break;
  403. case "离线":
  404. row.Cells[1].Style.BackColor = Color.FromArgb(134, 150, 165);
  405. break;
  406. }
  407. if (gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "正常" && gvWindturbine.Rows[i].Cells[5].Value.ToString().Trim() != "未知")
  408. {
  409. row.Cells[5].Style.BackColor = Color.FromArgb(255, 255, 0);
  410. row.Cells[5].Style.ForeColor = Color.FromArgb(0, 0, 0);
  411. }
  412. else
  413. {
  414. row.Cells[5].Style.BackColor = row.Cells[6].Style.BackColor;
  415. row.Cells[5].Style.ForeColor = row.Cells[6].Style.ForeColor;
  416. }
  417. }
  418. #endregion
  419. isUpdateOverGv = true;
  420. }
  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 btnLimitPower_Click(object sender, EventArgs e)
  430. {
  431. string limitPower = txtPower.Text.Trim();
  432. if (string.IsNullOrEmpty(limitPower))
  433. {
  434. MessageBox.Show("请输入限定功率");
  435. return;
  436. }
  437. else
  438. {
  439. double power = 0.0;
  440. bool IsNumber = Double.TryParse(limitPower, out power);
  441. if (!IsNumber)
  442. {
  443. MessageBox.Show("输入限定功率不合法");
  444. return;
  445. }
  446. else
  447. {
  448. string cmdDescribe = null;
  449. cmdDescribe = "限定功率";
  450. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  451. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  452. {
  453. WindturbineCmdInfo info = new WindturbineCmdInfo();
  454. info.WindturbineId = isCheckWindturbineIdList[i];
  455. info.StationId = "XS_FDC";
  456. info.CmdType = CmdType.LimitPower;
  457. cmdInfoList.Add(info);
  458. }
  459. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe, power);
  460. confirm.ShowDialog();
  461. }
  462. }
  463. txtPower.Text = "";
  464. isCheckWindturbineIdList = new List<string>();
  465. ClearCheck();
  466. }
  467. private void btnLimitSpeed_Click(object sender, EventArgs e)
  468. {
  469. string limitSpeed = txtSpeed.Text.Trim();
  470. if (string.IsNullOrEmpty(limitSpeed))
  471. {
  472. MessageBox.Show("请输入限定转速");
  473. return;
  474. }
  475. else
  476. {
  477. double speed = 0.0;
  478. bool IsNumber = Double.TryParse(limitSpeed, out speed);
  479. if (!IsNumber)
  480. {
  481. MessageBox.Show("输入限定转速不合法");
  482. return;
  483. }
  484. else
  485. {
  486. string cmdDescribe = null;
  487. cmdDescribe = "限定转速";
  488. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  489. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  490. {
  491. WindturbineCmdInfo info = new WindturbineCmdInfo();
  492. info.WindturbineId = isCheckWindturbineIdList[i];
  493. info.StationId = "XS_FDC";
  494. info.CmdType = CmdType.LimitSpeed;
  495. cmdInfoList.Add(info);
  496. }
  497. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe, speed);
  498. confirm.ShowDialog();
  499. }
  500. }
  501. txtSpeed.Text = "";
  502. isCheckWindturbineIdList = new List<string>();
  503. ClearCheck();
  504. }
  505. private void btnHang_Click(object sender, EventArgs e)
  506. {
  507. string hungInfo = cbHungReason.SelectedValue.ToString().Trim();
  508. if (hungInfo == "-1")
  509. {
  510. MessageBox.Show("请选择挂牌原因!");
  511. return;
  512. }
  513. HungType type = (HungType)Enum.Parse(typeof(HungType), hungInfo);
  514. bool isSuccess = WindturbineLock("XS_FDC", isCheckWindturbineIdList, type);
  515. if (isSuccess)
  516. {
  517. string message = "";
  518. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  519. {
  520. message = message + isCheckWindturbineIdList[i] + ",";
  521. }
  522. message = "已针对" + message + "风机进行挂牌操作";
  523. MessageBox.Show(message);
  524. }
  525. isCheckWindturbineIdList = new List<string>();
  526. ClearCheck();
  527. cbHungReason.SelectedValue = -1;
  528. }
  529. private void btnUnHang_Click(object sender, EventArgs e)
  530. {
  531. bool isSuccess = WindturbineLock("XS_FDC", isCheckWindturbineIdList, HungType.UnLock);
  532. if (isSuccess)
  533. {
  534. string message = "";
  535. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  536. {
  537. message = message + isCheckWindturbineIdList[i] + ",";
  538. }
  539. message = "已针对" + message + "风机进行取消挂牌操作";
  540. MessageBox.Show(message);
  541. }
  542. isCheckWindturbineIdList = new List<string>();
  543. ClearCheck();
  544. }
  545. private void btnStart_Click(object sender, EventArgs e)
  546. {
  547. string cmdDescribe = null;
  548. cmdDescribe = "正常启动";
  549. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  550. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  551. {
  552. WindturbineCmdInfo info = new WindturbineCmdInfo();
  553. info.WindturbineId = isCheckWindturbineIdList[i];
  554. info.StationId = "XS_FDC";
  555. info.CmdType = CmdType.Start;
  556. cmdInfoList.Add(info);
  557. }
  558. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe);
  559. confirm.ShowDialog();
  560. isCheckWindturbineIdList = new List<string>();
  561. ClearCheck();
  562. }
  563. private void btnStop_Click(object sender, EventArgs e)
  564. {
  565. string cmdDescribe = null;
  566. cmdDescribe = "正常停机";
  567. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  568. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  569. {
  570. WindturbineCmdInfo info = new WindturbineCmdInfo();
  571. info.WindturbineId = isCheckWindturbineIdList[i];
  572. info.StationId = "XS_FDC";
  573. info.CmdType = CmdType.Stop;
  574. cmdInfoList.Add(info);
  575. }
  576. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe);
  577. confirm.ShowDialog();
  578. isCheckWindturbineIdList = new List<string>();
  579. ClearCheck();
  580. }
  581. private void btnRest_Click(object sender, EventArgs e)
  582. {
  583. string cmdDescribe = null;
  584. cmdDescribe = "正常复位";
  585. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  586. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  587. {
  588. WindturbineCmdInfo info = new WindturbineCmdInfo();
  589. info.WindturbineId = isCheckWindturbineIdList[i];
  590. info.StationId = "XS_FDC";
  591. info.CmdType = CmdType.Reset;
  592. cmdInfoList.Add(info);
  593. }
  594. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe);
  595. confirm.ShowDialog();
  596. isCheckWindturbineIdList = new List<string>();
  597. ClearCheck();
  598. }
  599. private void btnMaintain_Click(object sender, EventArgs e)
  600. {
  601. string cmdDescribe = null;
  602. cmdDescribe = "正常维护";
  603. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  604. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  605. {
  606. WindturbineCmdInfo info = new WindturbineCmdInfo();
  607. info.WindturbineId = isCheckWindturbineIdList[i];
  608. info.StationId = "XS_FDC";
  609. info.CmdType = CmdType.Maintain;
  610. cmdInfoList.Add(info);
  611. }
  612. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe);
  613. confirm.ShowDialog();
  614. isCheckWindturbineIdList = new List<string>();
  615. ClearCheck();
  616. }
  617. private void btnUnMaintain_Click(object sender, EventArgs e)
  618. {
  619. string cmdDescribe = null;
  620. cmdDescribe = "正常取消维护";
  621. IList<WindturbineCmdInfo> cmdInfoList = new List<WindturbineCmdInfo>();
  622. for (int i = 0; i < isCheckWindturbineIdList.Count; i++)
  623. {
  624. WindturbineCmdInfo info = new WindturbineCmdInfo();
  625. info.WindturbineId = isCheckWindturbineIdList[i];
  626. info.StationId = "XS_FDC";
  627. info.CmdType = CmdType.UnMaintain;
  628. cmdInfoList.Add(info);
  629. }
  630. Confirm confirm = new Confirm("XS_FDC", cmdInfoList, cmdDescribe);
  631. confirm.ShowDialog();
  632. isCheckWindturbineIdList = new List<string>();
  633. ClearCheck();
  634. }
  635. private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  636. {
  637. if (e.RowIndex != -1)
  638. {
  639. if (e.ColumnIndex == 0)
  640. {
  641. string isCheck = gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value == null ? "0" : gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value.ToString();
  642. string windturbineId = this.gvWindturbine.Rows[e.RowIndex].Cells[1].Value.ToString();
  643. if (isCheck == "1")
  644. {
  645. gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 0;
  646. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  647. if (count > 0)
  648. isCheckWindturbineIdList.Remove(windturbineId);
  649. }
  650. else
  651. {
  652. gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 1;
  653. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  654. if (count <= 0)
  655. isCheckWindturbineIdList.Add(windturbineId);
  656. }
  657. }
  658. }
  659. else
  660. {
  661. if (e.ColumnIndex == 0)
  662. {
  663. for (int i = 0; i < gvWindturbine.RowCount; i++)
  664. {
  665. string isCheck = gvWindturbine.Rows[i].Cells["Select"].Value == null
  666. ? "0"
  667. : gvWindturbine.Rows[i].Cells["Select"].Value.ToString();
  668. string windturbineId = this.gvWindturbine.Rows[i].Cells[1].Value.ToString();
  669. if (isCheck == "1")
  670. {
  671. gvWindturbine.Rows[i].Cells["Select"].Value = 0;
  672. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  673. if (count > 0)
  674. isCheckWindturbineIdList.Remove(windturbineId);
  675. }
  676. else
  677. {
  678. gvWindturbine.Rows[i].Cells["Select"].Value = 1;
  679. int count = isCheckWindturbineIdList.Where(s => s == windturbineId).ToList().Count;
  680. if (count <= 0)
  681. isCheckWindturbineIdList.Add(windturbineId);
  682. }
  683. }
  684. }
  685. }
  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. }