BigForm2.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7. using System.Threading;
  8. using System.Collections.Generic;
  9. using GDNXFD.Data;
  10. using IntelligentControlForsx.MyControls.alarm.Domain;
  11. using IntelligentControlForsx.Service;
  12. namespace IntelligentControlForsx
  13. {
  14. public partial class BigForm2 : Form
  15. {
  16. private bool isMouseDown = false;
  17. public bool isMouseEnter = false;
  18. private bool selectStation = true;
  19. private bool lockForm = false;
  20. private System.Drawing.Point mouseOffset;
  21. private MiniForm miniForm;
  22. private AlarmItem[] alarmItems;
  23. private List<LightPlate> lightPlates;
  24. private AlertServiceClient asc = null;
  25. private FrmAlarm frmAlarm;
  26. private FrmAlarmHistory frmAlarmHistory;
  27. private IList<AlertSnap> results = null;
  28. IList<AlertData> infoList = new List<AlertData>();
  29. private FrmAlarmByObject frmAlarmByObject;
  30. private BindingList<AlarmGroupModel> infoListBindings = null;
  31. public BigForm2(MiniForm miniForm)
  32. {
  33. Control.CheckForIllegalCrossThreadCalls = false;
  34. InitializeComponent();
  35. this.miniForm = miniForm;
  36. this.dgvAlarm.AutoGenerateColumns = false;
  37. this.dgvAlarm.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  38. DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  39. dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter;
  40. dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  41. this.dgvAlarm.DefaultCellStyle = dataGridViewCellStyle1;
  42. }
  43. #region 初始化光字牌和最新列表
  44. private void BigForm_Load(object sender, EventArgs e)
  45. {
  46. initAlarmItems();
  47. initLightPlates();
  48. }
  49. private void initAlarmItems()
  50. {
  51. //绑定gridview方法
  52. Dictionary<string, AlarmGroupModel> agDict = ClientCache.Instance.AlarmGroups;
  53. if (agDict == null || agDict.Count == 0)
  54. return;
  55. var lst = agDict.Values.OrderByDescending(q => q.AgCount).OrderByDescending(q => q.AgTime).ToList();
  56. infoListBindings = new BindingList<AlarmGroupModel>(lst);
  57. this.dgvAlarm.DataSource = infoListBindings;
  58. //IList<AlertSnap> lstSnap = ClientCache.Instance.AlertSnaps;
  59. ////从客户端缓存中加载数据
  60. //if (lstSnap != null && lstSnap.Count > 0)
  61. //{
  62. // var r1 = lstSnap.AsQueryable();
  63. // results = r1.OrderByDescending(q => q.LastUpdateTime).ToList();
  64. // IEnumerable<IGrouping<string, AlertSnap>> groupResult = results.GroupBy(s => s.ObjectId);
  65. // foreach (IGrouping<string, AlertSnap> grouping in groupResult)
  66. // {
  67. // IList<AlertSnap> list = grouping.ToList();
  68. // foreach (var alertSnap in list)
  69. // {
  70. // AlertData info = new AlertData();
  71. // info.ObjectName = alertSnap.ObjectName;
  72. // info.ObjectId = alertSnap.ObjectId;
  73. // info.AlertText = alertSnap.AlertText;
  74. // info.Rank = alertSnap.Rank;
  75. // info.LastUpdateTimeString = alertSnap.LastUpdateTime.HasValue?alertSnap.LastUpdateTime.Value.ToString("hh:MM:ss"):"-";
  76. // info.AlertCount = list.Count;
  77. // infoList.Add(info);
  78. // }
  79. // }
  80. // infoListBindings = new BindingList<AlertData>(infoList);
  81. //}
  82. }
  83. private void initLightPlates()
  84. {
  85. lightPlates = new List<LightPlate>();
  86. lpCustom.LID = "custom";
  87. lpSBQ.LID = "SBQ_FDC";
  88. lpNSS.LID = "NSS_FDC";
  89. lpMHS.LID = "MHS_FDC";
  90. lpXS.LID = "XS_FDC";
  91. lpQS.LID = "QS_FDC";
  92. lpBJ.LID = "bj";
  93. lpPH.LID = "ph";
  94. lpCLX.LID = "clx";
  95. lpJC.LID = "jc";
  96. lpFDJ.LID = "fdj";
  97. lpYY.LID = "yy";
  98. lpKZ.LID = "kz";
  99. lpDW.LID = "dw";
  100. lpOther.LID = "other";
  101. this.lpSBQ.Click += new System.EventHandler(this.lightPlate1_Click);
  102. this.lpNSS.Click += new System.EventHandler(this.lightPlate1_Click);
  103. this.lpMHS.Click += new System.EventHandler(this.lightPlate1_Click);
  104. this.lpXS.Click += new System.EventHandler(this.lightPlate1_Click);
  105. this.lpQS.Click += new System.EventHandler(this.lightPlate1_Click);
  106. this.lpBJ.Click += new System.EventHandler(this.lightPlate_Click);
  107. this.lpPH.Click += new System.EventHandler(this.lightPlate_Click);
  108. this.lpCLX.Click += new System.EventHandler(this.lightPlate_Click);
  109. this.lpJC.Click += new System.EventHandler(this.lightPlate_Click);
  110. this.lpFDJ.Click += new System.EventHandler(this.lightPlate_Click);
  111. this.lpYY.Click += new System.EventHandler(this.lightPlate_Click);
  112. this.lpKZ.Click += new System.EventHandler(this.lightPlate_Click);
  113. this.lpDW.Click += new System.EventHandler(this.lightPlate_Click);
  114. this.lpOther.Click += new System.EventHandler(this.lightPlate_Click);
  115. this.lpCustom.Click += new System.EventHandler(this.lightPlate_Click);
  116. lightPlates.Add(lpCustom);
  117. lightPlates.Add(lpSBQ);
  118. lightPlates.Add(lpNSS);
  119. lightPlates.Add(lpMHS);
  120. lightPlates.Add(lpXS);
  121. lightPlates.Add(lpQS);
  122. lightPlates.Add(lpBJ);
  123. lightPlates.Add(lpPH);
  124. lightPlates.Add(lpCLX);
  125. lightPlates.Add(lpJC);
  126. lightPlates.Add(lpFDJ);
  127. lightPlates.Add(lpYY);
  128. lightPlates.Add(lpKZ);
  129. lightPlates.Add(lpDW);
  130. lightPlates.Add(lpOther);
  131. }
  132. #endregion
  133. #region DetailsPanel和ballControl的鼠标事件
  134. private void DetailsPanel_MouseLeave(object sender, EventArgs e)
  135. {
  136. System.Drawing.Point p = MousePosition;
  137. if (p.X - 10 <= this.Left || p.X + 10 >= this.Right || p.Y - 10 <= this.Top || p.Y + 10 >= this.Top + this.Height)
  138. {
  139. isMouseEnter = false;
  140. if (lockForm == false)
  141. hideDetailsFormTimer.Enabled = true;
  142. }
  143. }
  144. private void DetailsPanel_MouseEnter(object sender, EventArgs e)
  145. {
  146. isMouseEnter = true;
  147. //miniForm.TopLevel = this.TopLevel;
  148. }
  149. private void DetailsPanel_MouseDown(object sender, MouseEventArgs e)
  150. {
  151. if (e.Button == MouseButtons.Left)
  152. {
  153. isMouseDown = true;
  154. mouseOffset = new System.Drawing.Point(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y);
  155. this.Cursor = Cursors.SizeAll;
  156. }
  157. }
  158. private void DetailsPanel_MouseUp(object sender, MouseEventArgs e)
  159. {
  160. isMouseDown = false;
  161. this.Cursor = Cursors.Default;
  162. }
  163. private void DetailsPanel_MouseMove(object sender, MouseEventArgs e)
  164. {
  165. // miniForm.isMouseEnter = false;
  166. if (isMouseDown == true)
  167. {
  168. //this.Location = getDetailFormMoveLocation();
  169. //miniForm.Location = getMiniBallMoveLocation();
  170. }
  171. }
  172. private void ballControl_MouseEnter(object sender, EventArgs e)
  173. {
  174. this.Cursor = Cursors.Hand;
  175. }
  176. private void ballControl_MouseLeave(object sender, EventArgs e)
  177. {
  178. this.Cursor = Cursors.Default;
  179. }
  180. /*隐藏DetailsForm的定时器*/
  181. private void hideDetailsFormTimer_Tick(object sender, EventArgs e)
  182. {
  183. hideDetailsFormTimer.Enabled = false;
  184. if (!isMouseEnter && !miniForm.isMouseEnter)
  185. {
  186. refreshTimer.Stop();
  187. this.Hide();
  188. }
  189. }
  190. /*获取小球出现的位置*/
  191. private System.Drawing.Point getMiniBallMoveLocation()
  192. {
  193. int x = 0, y = 0;
  194. if (this.Location.Y <= miniForm.Location.Y)
  195. {
  196. if (miniForm.miniFormLocation == MiniForm.MiniFormLocation.bottomRight)
  197. x = this.Location.X + this.Width - miniForm.miniFormWidth;
  198. else
  199. x = this.Location.X;
  200. y = this.Location.Y + this.Height + miniForm.miniBigFormSpace;
  201. }
  202. else
  203. {
  204. if (miniForm.miniFormLocation == MiniForm.MiniFormLocation.topRigh)
  205. x = this.Location.X + this.Width - miniForm.miniFormWidth;
  206. else
  207. x = this.Location.X;
  208. y = this.Location.Y - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
  209. }
  210. return new System.Drawing.Point(x, y);
  211. }
  212. /*获取DetailForm出现的位置*/
  213. private System.Drawing.Point getDetailFormMoveLocation()
  214. {
  215. int x = MousePosition.X - mouseOffset.X;
  216. int y = MousePosition.Y - mouseOffset.Y;
  217. if (x < 0)
  218. {
  219. x = 0;
  220. }
  221. if (miniForm.Top > this.Top && y < 0)
  222. {
  223. y = 0;
  224. }
  225. if (miniForm.Top < this.Top && y < miniForm.miniFormHeight + miniForm.miniBigFormSpace)
  226. { //minBall在上面
  227. y = miniForm.miniFormHeight + miniForm.miniBigFormSpace;
  228. }
  229. if (Screen.PrimaryScreen.WorkingArea.Width - x < this.Width)
  230. {
  231. x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
  232. }
  233. if (miniForm.Top < this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < this.Height)
  234. { //minBall在上面
  235. y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
  236. }
  237. if (miniForm.Top > this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < (this.Height + miniForm.miniFormHeight + miniForm.miniBigFormSpace))
  238. { //minBall在下面
  239. y = Screen.PrimaryScreen.WorkingArea.Height - this.Height - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
  240. }
  241. return new System.Drawing.Point(x, y);
  242. }
  243. #endregion
  244. #region 刷新报警列表和光字牌
  245. public void refreshThread()
  246. {
  247. refreshTimer.Start();
  248. }
  249. private void refreshTimer_Tick(object sender, EventArgs e)
  250. {
  251. updateAlarmList();
  252. updateLightPlate();
  253. }
  254. private void updateAlarmList()
  255. {
  256. Dictionary<string, AlarmGroupModel> agDict = ClientCache.Instance.AlarmGroups;
  257. if (agDict == null || agDict.Count == 0)
  258. return;
  259. var lst = agDict.Values.OrderByDescending(q=>q.AgCount).OrderByDescending(q => q.AgTime).ToList();
  260. infoListBindings = new BindingList<AlarmGroupModel>(lst);
  261. this.dgvAlarm.DataSource = infoListBindings;
  262. }
  263. private void updateLightPlate()
  264. {
  265. var lmap = ClientCache.Instance.LPModels;
  266. if (lmap == null || lightPlates == null)
  267. return;
  268. foreach (LightPlate lp in lightPlates)
  269. {
  270. if (lmap.ContainsKey(lp.LID))
  271. lp.setLightPlateModel(lmap[lp.LID]);
  272. else
  273. lp.setLightPlateModel(null);
  274. }
  275. }
  276. #endregion
  277. #region 事件及子窗体
  278. /*获取子窗体应该出现的位置*/
  279. private System.Drawing.Point getChildFormLocation(int frmWidth, int frmHeight)
  280. {
  281. int x = 0;
  282. if (this.Location.X >= frmWidth) //子窗体出现在bigBall左面
  283. {
  284. x = this.Location.X - frmWidth;
  285. }
  286. else
  287. {
  288. x = this.Location.X + this.Width;
  289. }
  290. int y = this.Location.Y;
  291. return new System.Drawing.Point(x, y);
  292. }
  293. private void lightPlate1_Click(object sender, EventArgs e)
  294. {
  295. LightPlate lp = sender as LightPlate;
  296. if (lp != null)
  297. {
  298. if (frmAlarm == null)
  299. frmAlarm = new FrmAlarm();
  300. frmAlarm.StartPosition = FormStartPosition.Manual;
  301. frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  302. frmAlarm.ShowData(lp.LTitle);
  303. frmAlarm.BringToFront();
  304. }
  305. }
  306. private void lightPlate_Click(object sender, EventArgs e)
  307. {
  308. LightPlate lp = sender as LightPlate;
  309. if (lp != null)
  310. {
  311. if (frmAlarm == null)
  312. frmAlarm = new FrmAlarm();
  313. frmAlarm.StartPosition = FormStartPosition.Manual;
  314. frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  315. if ("custom".Equals(lp.LID))
  316. frmAlarm.ShowData("custom", "");
  317. else
  318. frmAlarm.ShowData("windturbine", lp.LID);
  319. frmAlarm.BringToFront();
  320. }
  321. }
  322. private void confrimAlarm_Click(object sender, EventArgs e)
  323. {
  324. //MessageBox.Show("rise" + sender.ToString());
  325. string snapId = sender.ToString();
  326. //todo: 报警确认功能待定
  327. }
  328. private void button1_Click(object sender, EventArgs e)
  329. {
  330. lockForm = !lockForm;
  331. if (lockForm)
  332. btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin2;
  333. else
  334. btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin1;
  335. }
  336. private void btnStation_Click(object sender, EventArgs e)
  337. {
  338. selectStation = !selectStation;
  339. showLightPlate();
  340. }
  341. private void btnWindturbine_Click(object sender, EventArgs e)
  342. {
  343. selectStation = !selectStation;
  344. showLightPlate();
  345. }
  346. private void showLightPlate()
  347. {
  348. if (selectStation)
  349. {
  350. this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左一;
  351. this.btnStation.ForeColor = System.Drawing.Color.White;
  352. this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右二;
  353. this.btnWindturbine.ForeColor = System.Drawing.Color.DarkGray;
  354. this.pnlStation.Visible = true;
  355. this.pnlWindturbine.Visible = false;
  356. }
  357. else
  358. {
  359. this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左二;
  360. this.btnStation.ForeColor = System.Drawing.Color.DarkGray;
  361. this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右一;
  362. this.btnWindturbine.ForeColor = System.Drawing.Color.White;
  363. this.pnlStation.Visible = false;
  364. this.pnlWindturbine.Visible = true;
  365. }
  366. }
  367. private void btnViewReal_Click(object sender, EventArgs e)
  368. {
  369. if (frmAlarm == null)
  370. {
  371. frmAlarm = new FrmAlarm();
  372. }
  373. frmAlarm.StartPosition = FormStartPosition.Manual;
  374. frmAlarm.WindowState = FormWindowState.Normal;
  375. //frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  376. frmAlarm.Location = new System.Drawing.Point(260, 140);
  377. //frmAlarm.TopLevel = true;
  378. frmAlarm.BringToFront();
  379. frmAlarm.ShowData();
  380. }
  381. private void btnViewHistory_Click(object sender, EventArgs e)
  382. {
  383. if (frmAlarmHistory == null)
  384. {
  385. frmAlarmHistory = new FrmAlarmHistory();
  386. }
  387. frmAlarmHistory.StartPosition = FormStartPosition.Manual;
  388. frmAlarmHistory.WindowState = FormWindowState.Normal;
  389. // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
  390. // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
  391. frmAlarmHistory.Location = new System.Drawing.Point(260, 140); ;
  392. //frmAlarmHistory.TopLevel = true;
  393. frmAlarmHistory.BringToFront();
  394. frmAlarmHistory.Show();
  395. }
  396. #endregion
  397. private void dgvAlarm_CellContentClick(object sender, DataGridViewCellEventArgs e)
  398. {
  399. if (e.RowIndex > -1)
  400. {
  401. string objectId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  402. if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Control" && e.RowIndex >= 0)
  403. {
  404. if (frmAlarmByObject == null)
  405. {
  406. frmAlarmByObject = new FrmAlarmByObject(objectId);
  407. frmAlarmByObject.StartPosition = FormStartPosition.Manual;
  408. frmAlarmByObject.WindowState = FormWindowState.Normal;
  409. frmAlarmByObject.Location = new System.Drawing.Point(260, 140);
  410. }
  411. else
  412. {
  413. frmAlarmByObject.ShowData(objectId);
  414. }
  415. }
  416. }
  417. }
  418. private void dgvAlarm_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
  419. {
  420. if (e.RowIndex > -1)
  421. {
  422. try
  423. {
  424. string objectName = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
  425. AlarmGroupModel agModel = ClientCache.Instance.AlarmGroups[objectName];
  426. string thingId = agModel.SnapList.First().ObjectId;
  427. string stationId = agModel.SnapList.First().StationId;
  428. if (objectName.EndsWith("风机"))
  429. NavService.Instance.NavForWindturbine("pictureBoxParamters", thingId, stationId);
  430. }
  431. catch { }
  432. }
  433. }
  434. }
  435. }