BigForm.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Runtime.InteropServices;
  5. using System.Threading;
  6. using System.Collections.Generic;
  7. namespace IntelligentControlForsx
  8. {
  9. public partial class BigForm : Form {
  10. private bool isMouseDown = false;
  11. public bool isMouseEnter = false;
  12. private bool selectStation = true;
  13. private bool lockForm = false;
  14. private System.Drawing.Point mouseOffset;
  15. private MiniForm miniForm;
  16. private AlarmItem[] alarmItems;
  17. private List<LightPlate> lightPlates;
  18. private AlertServiceClient asc = null;
  19. private FrmAlarm frmAlarm;
  20. private FrmAlarmHistory frmAlarmHistory;
  21. public BigForm(MiniForm miniForm) {
  22. Control.CheckForIllegalCrossThreadCalls = false;
  23. InitializeComponent();
  24. this.miniForm = miniForm;
  25. }
  26. #region 初始化光字牌和最新列表
  27. private void BigForm_Load(object sender, EventArgs e)
  28. {
  29. initAlarmItems();
  30. initLightPlates();
  31. }
  32. private void initAlarmItems()
  33. {
  34. alarmItem1.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
  35. alarmItem2.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
  36. alarmItem3.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
  37. alarmItem4.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
  38. alarmItem5.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
  39. alarmItems = new AlarmItem[] { alarmItem1, alarmItem2, alarmItem3, alarmItem4, alarmItem5 };
  40. }
  41. private void initLightPlates()
  42. {
  43. lightPlates = new List<LightPlate>();
  44. lpCustom.LID = "custom";
  45. lpSBQ.LID = "SBQ_FDC";
  46. lpNSS.LID = "NSS_FDC";
  47. lpMHS.LID = "MHS_FDC";
  48. lpXS.LID = "XS_FDC";
  49. lpQS.LID = "QS_FDC";
  50. lpBJ.LID = "bj";
  51. lpPH.LID = "ph";
  52. lpCLX.LID = "clx";
  53. lpJC.LID = "jc";
  54. lpFDJ.LID = "fdj";
  55. lpYY.LID = "yy";
  56. lpKZ.LID = "kz";
  57. lpDW.LID = "dw";
  58. lpOther.LID = "other";
  59. this.lpSBQ.Click += new System.EventHandler(this.lightPlate1_Click);
  60. this.lpNSS.Click += new System.EventHandler(this.lightPlate1_Click);
  61. this.lpMHS.Click += new System.EventHandler(this.lightPlate1_Click);
  62. this.lpXS.Click += new System.EventHandler(this.lightPlate1_Click);
  63. this.lpQS.Click += new System.EventHandler(this.lightPlate1_Click);
  64. this.lpBJ.Click += new System.EventHandler(this.lightPlate_Click);
  65. this.lpPH.Click += new System.EventHandler(this.lightPlate_Click);
  66. this.lpCLX.Click += new System.EventHandler(this.lightPlate_Click);
  67. this.lpJC.Click += new System.EventHandler(this.lightPlate_Click);
  68. this.lpFDJ.Click += new System.EventHandler(this.lightPlate_Click);
  69. this.lpYY.Click += new System.EventHandler(this.lightPlate_Click);
  70. this.lpKZ.Click += new System.EventHandler(this.lightPlate_Click);
  71. this.lpDW.Click += new System.EventHandler(this.lightPlate_Click);
  72. this.lpOther.Click += new System.EventHandler(this.lightPlate_Click);
  73. this.lpCustom.Click += new System.EventHandler(this.lightPlate_Click);
  74. lightPlates.Add(lpCustom);
  75. lightPlates.Add(lpSBQ);
  76. lightPlates.Add(lpNSS);
  77. lightPlates.Add(lpMHS);
  78. lightPlates.Add(lpXS);
  79. lightPlates.Add(lpQS);
  80. lightPlates.Add(lpBJ);
  81. lightPlates.Add(lpPH);
  82. lightPlates.Add(lpCLX);
  83. lightPlates.Add(lpJC);
  84. lightPlates.Add(lpFDJ);
  85. lightPlates.Add(lpYY);
  86. lightPlates.Add(lpKZ);
  87. lightPlates.Add(lpDW);
  88. lightPlates.Add(lpOther);
  89. }
  90. #endregion
  91. #region DetailsPanel和ballControl的鼠标事件
  92. private void DetailsPanel_MouseLeave(object sender, EventArgs e)
  93. {
  94. System.Drawing.Point p = MousePosition;
  95. if(p.X - 10 <= this.Left || p.X + 10 >= this.Right || p.Y - 10 <= this.Top || p.Y + 10 >= this.Top + this.Height)
  96. {
  97. isMouseEnter = false;
  98. if (lockForm == false)
  99. hideDetailsFormTimer.Enabled = true;
  100. }
  101. }
  102. private void DetailsPanel_MouseEnter(object sender, EventArgs e)
  103. {
  104. isMouseEnter = true;
  105. //miniForm.TopLevel = this.TopLevel;
  106. }
  107. private void DetailsPanel_MouseDown(object sender, MouseEventArgs e)
  108. {
  109. if(e.Button == MouseButtons.Left)
  110. {
  111. isMouseDown = true;
  112. mouseOffset = new System.Drawing.Point(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y);
  113. this.Cursor = Cursors.SizeAll;
  114. }
  115. }
  116. private void DetailsPanel_MouseUp(object sender, MouseEventArgs e)
  117. {
  118. isMouseDown = false;
  119. this.Cursor = Cursors.Default;
  120. }
  121. private void DetailsPanel_MouseMove(object sender, MouseEventArgs e)
  122. {
  123. // miniForm.isMouseEnter = false;
  124. if(isMouseDown == true)
  125. {
  126. this.Location = getDetailFormMoveLocation();
  127. miniForm.Location = getMiniBallMoveLocation();
  128. }
  129. }
  130. private void ballControl_MouseEnter(object sender, EventArgs e)
  131. {
  132. this.Cursor = Cursors.Hand;
  133. }
  134. private void ballControl_MouseLeave(object sender, EventArgs e)
  135. {
  136. this.Cursor = Cursors.Default;
  137. }
  138. /*隐藏DetailsForm的定时器*/
  139. private void hideDetailsFormTimer_Tick(object sender, EventArgs e) {
  140. hideDetailsFormTimer.Enabled = false;
  141. if(!isMouseEnter && !miniForm.isMouseEnter)
  142. {
  143. refreshTimer.Stop();
  144. this.Hide();
  145. }
  146. }
  147. /*获取小球出现的位置*/
  148. private System.Drawing.Point getMiniBallMoveLocation() {
  149. int x = 0, y = 0;
  150. if(this.Location.Y <= miniForm.Location.Y) {
  151. if(miniForm.miniFormLocation == MiniForm.MiniFormLocation.bottomRight)
  152. x = this.Location.X + this.Width - miniForm.miniFormWidth;
  153. else
  154. x = this.Location.X;
  155. y = this.Location.Y + this.Height + miniForm.miniBigFormSpace;
  156. }
  157. else {
  158. if(miniForm.miniFormLocation == MiniForm.MiniFormLocation.topRigh)
  159. x = this.Location.X + this.Width - miniForm.miniFormWidth;
  160. else
  161. x = this.Location.X;
  162. y = this.Location.Y - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
  163. }
  164. return new System.Drawing.Point(x, y);
  165. }
  166. /*获取DetailForm出现的位置*/
  167. private System.Drawing.Point getDetailFormMoveLocation() {
  168. int x = MousePosition.X - mouseOffset.X;
  169. int y = MousePosition.Y - mouseOffset.Y;
  170. if(x < 0) {
  171. x = 0;
  172. }
  173. if(miniForm.Top > this.Top && y < 0) {
  174. y = 0;
  175. }
  176. if(miniForm.Top < this.Top && y < miniForm.miniFormHeight + miniForm.miniBigFormSpace){ //minBall在上面
  177. y = miniForm.miniFormHeight + miniForm.miniBigFormSpace;
  178. }
  179. if(Screen.PrimaryScreen.WorkingArea.Width - x < this.Width) {
  180. x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
  181. }
  182. if(miniForm.Top < this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < this.Height) { //minBall在上面
  183. y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
  184. }
  185. if(miniForm.Top > this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < (this.Height + miniForm.miniFormHeight + miniForm.miniBigFormSpace)) { //minBall在下面
  186. y = Screen.PrimaryScreen.WorkingArea.Height - this.Height - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
  187. }
  188. return new System.Drawing.Point(x, y);
  189. }
  190. #endregion
  191. #region 刷新报警列表和光字牌
  192. public void refreshThread() {
  193. refreshTimer.Start();
  194. }
  195. private void refreshTimer_Tick(object sender, EventArgs e)
  196. {
  197. updateAlarmList();
  198. updateLightPlate();
  199. }
  200. private void updateAlarmList()
  201. {
  202. var lst = ClientCache.Instance.AlertSnaps;
  203. int cnt = 0;
  204. if (lst != null && lst.Count > 0)
  205. {
  206. int len = lst.Count > 5 ? 5 : lst.Count;
  207. for (int i = 0; i < len; i++)
  208. {
  209. alarmItems[i].setAlertSnap(lst[i]);
  210. cnt++;
  211. }
  212. }
  213. if (cnt < 5)
  214. {
  215. for (int i = cnt; i < 5; i++)
  216. {
  217. alarmItems[i].setAlertSnap(null);
  218. }
  219. }
  220. }
  221. private void updateLightPlate()
  222. {
  223. var lmap = ClientCache.Instance.LPModels;
  224. if (lmap == null || lightPlates == null)
  225. return;
  226. foreach(LightPlate lp in lightPlates)
  227. {
  228. if (lmap.ContainsKey(lp.LID))
  229. lp.setLightPlateModel(lmap[lp.LID]);
  230. else
  231. lp.setLightPlateModel(null);
  232. }
  233. }
  234. #endregion
  235. #region 事件及子窗体
  236. /*获取子窗体应该出现的位置*/
  237. private System.Drawing.Point getChildFormLocation(int frmWidth, int frmHeight)
  238. {
  239. int x = 0;
  240. if (this.Location.X >= frmWidth) //子窗体出现在bigBall左面
  241. {
  242. x = this.Location.X - frmWidth;
  243. }
  244. else
  245. {
  246. x = this.Location.X + this.Width;
  247. }
  248. int y = this.Location.Y;
  249. return new System.Drawing.Point(x, y);
  250. }
  251. private void lightPlate1_Click(object sender, EventArgs e)
  252. {
  253. LightPlate lp = sender as LightPlate;
  254. if (lp != null)
  255. {
  256. if (frmAlarm == null)
  257. frmAlarm = new FrmAlarm();
  258. frmAlarm.StartPosition = FormStartPosition.Manual;
  259. frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  260. frmAlarm.ShowData(lp.LTitle);
  261. frmAlarm.BringToFront();
  262. }
  263. }
  264. private void lightPlate_Click(object sender, EventArgs e)
  265. {
  266. LightPlate lp = sender as LightPlate;
  267. if (lp != null)
  268. {
  269. if (frmAlarm == null)
  270. frmAlarm = new FrmAlarm();
  271. frmAlarm.StartPosition = FormStartPosition.Manual;
  272. frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  273. if ("custom".Equals(lp.LID))
  274. frmAlarm.ShowData("custom", "");
  275. else
  276. frmAlarm.ShowData("windturbine", lp.LID);
  277. frmAlarm.BringToFront();
  278. }
  279. }
  280. private void confrimAlarm_Click(object sender, EventArgs e)
  281. {
  282. //MessageBox.Show("rise" + sender.ToString());
  283. string snapId = sender.ToString();
  284. //todo: 报警确认功能待定
  285. }
  286. private void button1_Click(object sender, EventArgs e)
  287. {
  288. lockForm = !lockForm;
  289. if (lockForm)
  290. btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin2;
  291. else
  292. btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin1;
  293. }
  294. private void btnStation_Click(object sender, EventArgs e)
  295. {
  296. selectStation = !selectStation;
  297. showLightPlate();
  298. }
  299. private void btnWindturbine_Click(object sender, EventArgs e)
  300. {
  301. selectStation = !selectStation;
  302. showLightPlate();
  303. }
  304. private void showLightPlate()
  305. {
  306. if (selectStation)
  307. {
  308. this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左一;
  309. this.btnStation.ForeColor = System.Drawing.Color.White;
  310. this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右二;
  311. this.btnWindturbine.ForeColor = System.Drawing.Color.DarkGray;
  312. this.pnlStation.Visible = true;
  313. this.pnlWindturbine.Visible = false;
  314. } else
  315. {
  316. this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左二;
  317. this.btnStation.ForeColor = System.Drawing.Color.DarkGray;
  318. this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右一;
  319. this.btnWindturbine.ForeColor = System.Drawing.Color.White;
  320. this.pnlStation.Visible = false;
  321. this.pnlWindturbine.Visible = true;
  322. }
  323. }
  324. private void btnViewReal_Click(object sender, EventArgs e)
  325. {
  326. if (frmAlarm == null)
  327. {
  328. frmAlarm = new FrmAlarm();
  329. }
  330. frmAlarm.StartPosition = FormStartPosition.Manual;
  331. frmAlarm.WindowState = FormWindowState.Normal;
  332. //frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
  333. frmAlarm.Location = new System.Drawing.Point(260, 140);
  334. //frmAlarm.TopLevel = true;
  335. frmAlarm.BringToFront();
  336. frmAlarm.ShowData();
  337. }
  338. private void btnViewHistory_Click(object sender, EventArgs e)
  339. {
  340. if (frmAlarmHistory == null)
  341. {
  342. frmAlarmHistory = new FrmAlarmHistory();
  343. }
  344. frmAlarmHistory.StartPosition = FormStartPosition.Manual;
  345. frmAlarmHistory.WindowState = FormWindowState.Normal;
  346. // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
  347. // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
  348. frmAlarmHistory.Location = new System.Drawing.Point(260, 140); ;
  349. //frmAlarmHistory.TopLevel = true;
  350. frmAlarmHistory.BringToFront();
  351. frmAlarmHistory.Show();
  352. }
  353. #endregion
  354. }
  355. }