FrmAlarm.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. using EntityDataSet;
  2. using GDNXFD.Data;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using IntelligentControlForsx.ChildForms;
  14. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  15. using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc;
  16. using IntelligentControlForsx.Service;
  17. namespace IntelligentControlForsx
  18. {
  19. public partial class FrmAlarm : Form
  20. {
  21. [DllImport("user32.dll")]
  22. public static extern bool ReleaseCapture();
  23. [DllImport("user32.dll")]
  24. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
  25. public const int WM_SYSCOMMAND = 0x0112;
  26. public const int SC_MOVE = 0xF010;
  27. public const int HTCAPTION = 0x0002;
  28. private bool isLoadding = false;
  29. private bool isReady = false;
  30. //private AlertServiceClient asc = null;
  31. private IList<AlertSnap> results = null;
  32. string station = string.Empty;
  33. string rank = string.Empty;
  34. string category = string.Empty;
  35. string category2 = string.Empty;
  36. string filter = string.Empty;
  37. private BindingList<AlertSnap> bindings;
  38. private AlertServiceClient asc = null;
  39. public FrmAlarm()
  40. {
  41. InitializeComponent();
  42. this.dgvAlarm.AutoGenerateColumns = false;
  43. this.dgvAlarm.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  44. DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  45. dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter;
  46. dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  47. this.dgvAlarm.DefaultCellStyle = dataGridViewCellStyle1;
  48. //isReady = true;
  49. //LoadData();
  50. }
  51. #region 事件处理
  52. private void cmbStation_SelectedValueChanged(object sender, EventArgs e)
  53. {
  54. if ("全部".Equals(cmbStation.SelectedItem) == false)
  55. station = cmbStation.SelectedItem.ToString();
  56. else
  57. station = string.Empty;
  58. LoadData();
  59. }
  60. private void cmbRank_SelectedValueChanged(object sender, EventArgs e)
  61. {
  62. if ("全部".Equals(cmbRank.SelectedItem) == false)
  63. {
  64. try
  65. {
  66. IList<DictItem> lst1 = ClientCache.Instance.GetDataDictByCategory("AlertLevel");
  67. rank = lst1.Where(q => q.Name == cmbRank.SelectedItem.ToString()).First().Code;
  68. }
  69. catch
  70. {
  71. rank = string.Empty;
  72. }
  73. }
  74. else
  75. rank = string.Empty;
  76. LoadData();
  77. }
  78. private void cmbCategory_SelectedValueChanged(object sender, EventArgs e)
  79. {
  80. if ("全部".Equals(cmbCategory.SelectedItem) == false)
  81. {
  82. try
  83. {
  84. IList<DictItem> lst1 = ClientCache.Instance.GetDataDictByCategory("AlertCategory");
  85. category = lst1.Where(q => q.Name == cmbCategory.SelectedItem.ToString()).First().Code;
  86. }
  87. catch
  88. {
  89. category = string.Empty;
  90. }
  91. }
  92. else
  93. category = string.Empty;
  94. ResetCmbSubCategory();
  95. LoadData();
  96. }
  97. private void ResetCmbSubCategory()
  98. {
  99. this.cmbSubCategory.Items.Clear();
  100. this.cmbSubCategory.Items.Add("全部");
  101. if (!string.IsNullOrWhiteSpace(category))
  102. {
  103. try
  104. {
  105. IList<DictItem> lst = ClientCache.Instance.GetDataDictByCategory(category);
  106. if (lst != null)
  107. {
  108. foreach (DictItem dItem in lst)
  109. {
  110. this.cmbSubCategory.Items.Add(dItem.Name);
  111. }
  112. }
  113. }
  114. catch (Exception ex) { }
  115. }
  116. this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf("全部");
  117. }
  118. private void cmbSubCategory_SelectedValueChanged(object sender, EventArgs e)
  119. {
  120. if ("全部".Equals(cmbSubCategory.SelectedItem) == false)
  121. {
  122. try
  123. {
  124. IList<DictItem> lst1 = ClientCache.Instance.GetDataDictByCategory(category);
  125. category2 = lst1.Where(q => q.Name == cmbSubCategory.SelectedItem.ToString()).First().Code;
  126. }
  127. catch
  128. {
  129. category2 = string.Empty;
  130. }
  131. }
  132. else
  133. category2 = string.Empty;
  134. LoadData();
  135. }
  136. private void txtKeyWord_TextChanged(object sender, EventArgs e)
  137. {
  138. filter = txtKeyWord.Text.Trim();
  139. LoadData();
  140. }
  141. private void timer1_Tick(object sender, EventArgs e)
  142. {
  143. LoadData();
  144. }
  145. #endregion
  146. #region 数据加载和刷新
  147. public void ShowData(string c1, string c2)
  148. {
  149. isReady = false;
  150. station = string.Empty;
  151. rank = string.Empty;
  152. category = c1;
  153. category2 = c2;
  154. filter = string.Empty;
  155. this.txtKeyWord.Text = string.Empty;
  156. this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf("全部");
  157. this.cmbRank.SelectedIndex = cmbStation.Items.IndexOf("全部");
  158. if (string.IsNullOrWhiteSpace(c1))
  159. {
  160. this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf("全部");
  161. }
  162. else
  163. {
  164. string c1Name = "全部";
  165. try
  166. {
  167. IList<DictItem> lst1 = ClientCache.Instance.GetDataDictByCategory("AlertCategory");
  168. c1Name = lst1.Where(q => q.Code == c1).First().Name;
  169. }
  170. catch
  171. {
  172. }
  173. this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf(c1Name);
  174. ResetCmbSubCategory();
  175. if (!string.IsNullOrWhiteSpace(c2))
  176. {
  177. string c2Name = "全部";
  178. try
  179. {
  180. IList<DictItem> lst1 = ClientCache.Instance.GetDataDictByCategory(category);
  181. c2Name = lst1.Where(q => q.Code == c2).First().Name;
  182. }
  183. catch
  184. {
  185. }
  186. this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf(c2Name);
  187. }
  188. }
  189. isReady = true;
  190. LoadData();
  191. this.Show();
  192. }
  193. public void ShowData(string stationName)
  194. {
  195. isReady = false;
  196. this.txtKeyWord.Text = string.Empty;
  197. this.cmbRank.SelectedIndex = cmbStation.Items.IndexOf("全部");
  198. this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf("全部");
  199. this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf("全部");
  200. if (string.IsNullOrWhiteSpace(stationName))
  201. {
  202. this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf("全部");
  203. station = string.Empty;
  204. }
  205. else
  206. {
  207. this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf(stationName);
  208. station = stationName == "全部" ? string.Empty : stationName;
  209. }
  210. //station = string.Empty;
  211. rank = string.Empty;
  212. category = string.Empty;
  213. category2 = string.Empty;
  214. filter = string.Empty;
  215. isReady = true;
  216. LoadData();
  217. this.Show();
  218. }
  219. public void ShowData()
  220. {
  221. isReady = true;
  222. LoadData();
  223. this.Show();
  224. }
  225. private void LoadData()
  226. {
  227. if (isLoadding) return;
  228. if (isReady == false) return;
  229. isLoadding = true;
  230. try
  231. {
  232. LoadAlertSnaps();
  233. }
  234. catch (Exception ex)
  235. {
  236. //logger.Info("读取报警列表数据失败!ex=" + ex.Message);
  237. }
  238. finally
  239. {
  240. isLoadding = false;
  241. }
  242. }
  243. private void LoadAlertSnaps()
  244. {
  245. IList<AlertSnap> lstSnap = ClientCache.Instance.AlertSnaps;
  246. //从客户端缓存中加载数据
  247. if (lstSnap != null && lstSnap.Count > 0)
  248. {
  249. var r1 = lstSnap.AsQueryable();
  250. if (!string.IsNullOrWhiteSpace(station))
  251. {
  252. r1 = r1.Where(q => q.StationName == station);
  253. }
  254. if (!string.IsNullOrWhiteSpace(rank))
  255. {
  256. r1 = r1.Where(q => q.Rank == rank);
  257. }
  258. if (!string.IsNullOrWhiteSpace(category))
  259. {
  260. r1 = r1.Where(q => q.Category1 == category);
  261. }
  262. if (!string.IsNullOrWhiteSpace(category2))
  263. {
  264. r1 = r1.Where(q => q.Category2 == category2);
  265. }
  266. if (!string.IsNullOrWhiteSpace(filter))
  267. {
  268. r1 = r1.Where(q => q.AlertText.Contains(filter) ||
  269. q.StationName.Contains(filter) ||
  270. q.ObjectName.Contains(filter));
  271. }
  272. if (r1 != null)
  273. {
  274. results = r1.OrderByDescending(q => q.LastUpdateTime).ToList();
  275. bindings = new BindingList<AlertSnap>(results);
  276. this.dgvAlarm.DataSource = bindings;
  277. }
  278. }
  279. }
  280. #endregion
  281. private void dgvAlarm_CellContentClick(object sender, DataGridViewCellEventArgs e)
  282. {
  283. if (e.RowIndex > -1)
  284. {
  285. string windturbineId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  286. string alertSnapIds = dgvAlarm.Rows[e.RowIndex].Cells["Column8"].Value.ToString().Trim();
  287. long alertSnapId;
  288. long.TryParse(alertSnapIds, out alertSnapId);
  289. if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Confirm" && e.RowIndex >= 0)
  290. {
  291. //报警信息操作方法
  292. if (asc == null)
  293. asc = AlertServiceClientFactory.CreateAlertServiceClient();
  294. if (alertSnapId > 0)
  295. asc.ConfirmAlert(alertSnapId);
  296. MessageBox.Show("确认操作" + alertSnapId);
  297. }
  298. if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Control" && e.RowIndex >= 0)
  299. {
  300. if (!string.IsNullOrEmpty(windturbineId))
  301. {
  302. if (windturbineId.Contains("SG01_") || windturbineId.Contains("MG01_") ||
  303. windturbineId.Contains("QG01_") || windturbineId.Contains("XG01_") ||
  304. windturbineId.Contains("NG01_"))
  305. {
  306. user userData = null;
  307. try
  308. {
  309. FingerCheck2 check = new FingerCheck2();
  310. check.ShowDialog();
  311. userData = FingerCheck2.checkSuccessUser;
  312. }
  313. catch (Exception ex)
  314. {
  315. }
  316. if (userData == null)
  317. {
  318. return;
  319. }
  320. IList<string> sendList = new List<string>();
  321. sendList.Add("windturbineId");
  322. string controlTypeString = dgvAlarm.Rows[e.RowIndex].Cells["Column_Control"].Value.ToString().Trim();
  323. string stationId = "";
  324. if (windturbineId.Contains("SG01_"))
  325. stationId = "SBQ_FDC";
  326. if (windturbineId.Contains("MG01_"))
  327. stationId = "MHS_FDC";
  328. if (windturbineId.Contains("NG01_"))
  329. stationId = "NSS_FDC";
  330. if (windturbineId.Contains("XG01_"))
  331. stationId = "XS_FDC";
  332. if (windturbineId.Contains("QG01_"))
  333. stationId = "QS_FDC";
  334. if (controlTypeString == "复位")
  335. TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Reset, userData);
  336. else if (controlTypeString == "停机")
  337. TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Stop, userData);
  338. //报警信息操作方法
  339. if (asc == null)
  340. asc = AlertServiceClientFactory.CreateAlertServiceClient();
  341. if (alertSnapId > 0)
  342. asc.ConfirmAlert(alertSnapId);
  343. MessageBox.Show(controlTypeString + "操作已完成");
  344. }
  345. }
  346. }
  347. }
  348. }
  349. private void chkAutoRefresh_CheckedChanged(object sender, EventArgs e)
  350. {
  351. if (this.chkAutoRefresh.Checked)
  352. timer1.Start();
  353. else
  354. timer1.Stop();
  355. }
  356. private void btnClose_Click(object sender, EventArgs e)
  357. {
  358. this.Hide();
  359. }
  360. private void btnMax_Click(object sender, EventArgs e)
  361. {
  362. if (this.WindowState == FormWindowState.Maximized)
  363. this.WindowState = FormWindowState.Normal;
  364. else
  365. this.WindowState = FormWindowState.Maximized;
  366. }
  367. private void panel1_MouseDown(object sender, MouseEventArgs e)
  368. {
  369. ReleaseCapture();
  370. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  371. }
  372. private void dgvAlarm_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
  373. {
  374. try
  375. {
  376. string objectId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  377. if (objectId.IndexOf("01") > 0)
  378. {
  379. NavService.Instance.NavForWindturbine("pictureBoxParamters", objectId, getStationId(objectId));
  380. }
  381. }
  382. catch { }
  383. }
  384. private string getStationId(string wtId)
  385. {
  386. if (wtId.StartsWith("MG"))
  387. return "MHS_FDC";
  388. if (wtId.StartsWith("NG"))
  389. return "NSS_FDC";
  390. if (wtId.StartsWith("SG"))
  391. return "SBQ_FDC";
  392. if (wtId.StartsWith("XG"))
  393. return "XS_FDC";
  394. if (wtId.StartsWith("QG"))
  395. return "QS_FDC";
  396. return "SBQ_FDC";
  397. }
  398. }
  399. }