123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Collections.Generic;
- namespace IntelligentControlForsx
- {
- public partial class BigForm : Form {
-
- private bool isMouseDown = false;
- public bool isMouseEnter = false;
- private bool selectStation = true;
- private bool lockForm = false;
- private System.Drawing.Point mouseOffset;
- private MiniForm miniForm;
- private AlarmItem[] alarmItems;
- private List<LightPlate> lightPlates;
- private AlertServiceClient asc = null;
- private FrmAlarm frmAlarm;
- private FrmAlarmHistory frmAlarmHistory;
- public BigForm(MiniForm miniForm) {
- Control.CheckForIllegalCrossThreadCalls = false;
- InitializeComponent();
- this.miniForm = miniForm;
- }
- #region 初始化光字牌和最新列表
- private void BigForm_Load(object sender, EventArgs e)
- {
- initAlarmItems();
- initLightPlates();
- }
- private void initAlarmItems()
- {
- alarmItem1.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
- alarmItem2.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
- alarmItem3.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
- alarmItem4.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
- alarmItem5.AlarmConfirmClick += new System.EventHandler(this.confrimAlarm_Click);
- alarmItems = new AlarmItem[] { alarmItem1, alarmItem2, alarmItem3, alarmItem4, alarmItem5 };
- }
- private void initLightPlates()
- {
- lightPlates = new List<LightPlate>();
- lpCustom.LID = "custom";
- lpSBQ.LID = "SBQ_FDC";
- lpNSS.LID = "NSS_FDC";
- lpMHS.LID = "MHS_FDC";
- lpXS.LID = "XS_FDC";
- lpQS.LID = "QS_FDC";
- lpBJ.LID = "bj";
- lpPH.LID = "ph";
- lpCLX.LID = "clx";
- lpJC.LID = "jc";
- lpFDJ.LID = "fdj";
- lpYY.LID = "yy";
- lpKZ.LID = "kz";
- lpDW.LID = "dw";
- lpOther.LID = "other";
-
- this.lpSBQ.Click += new System.EventHandler(this.lightPlate1_Click);
- this.lpNSS.Click += new System.EventHandler(this.lightPlate1_Click);
- this.lpMHS.Click += new System.EventHandler(this.lightPlate1_Click);
- this.lpXS.Click += new System.EventHandler(this.lightPlate1_Click);
- this.lpQS.Click += new System.EventHandler(this.lightPlate1_Click);
- this.lpBJ.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpPH.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpCLX.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpJC.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpFDJ.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpYY.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpKZ.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpDW.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpOther.Click += new System.EventHandler(this.lightPlate_Click);
- this.lpCustom.Click += new System.EventHandler(this.lightPlate_Click);
- lightPlates.Add(lpCustom);
- lightPlates.Add(lpSBQ);
- lightPlates.Add(lpNSS);
- lightPlates.Add(lpMHS);
- lightPlates.Add(lpXS);
- lightPlates.Add(lpQS);
- lightPlates.Add(lpBJ);
- lightPlates.Add(lpPH);
- lightPlates.Add(lpCLX);
- lightPlates.Add(lpJC);
- lightPlates.Add(lpFDJ);
- lightPlates.Add(lpYY);
- lightPlates.Add(lpKZ);
- lightPlates.Add(lpDW);
- lightPlates.Add(lpOther);
- }
- #endregion
- #region DetailsPanel和ballControl的鼠标事件
- private void DetailsPanel_MouseLeave(object sender, EventArgs e)
- {
- System.Drawing.Point p = MousePosition;
- if(p.X - 10 <= this.Left || p.X + 10 >= this.Right || p.Y - 10 <= this.Top || p.Y + 10 >= this.Top + this.Height)
- {
- isMouseEnter = false;
- if (lockForm == false)
- hideDetailsFormTimer.Enabled = true;
- }
- }
- private void DetailsPanel_MouseEnter(object sender, EventArgs e)
- {
- isMouseEnter = true;
- //miniForm.TopLevel = this.TopLevel;
- }
- private void DetailsPanel_MouseDown(object sender, MouseEventArgs e)
- {
- if(e.Button == MouseButtons.Left)
- {
- isMouseDown = true;
- mouseOffset = new System.Drawing.Point(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y);
- this.Cursor = Cursors.SizeAll;
- }
- }
- private void DetailsPanel_MouseUp(object sender, MouseEventArgs e)
- {
- isMouseDown = false;
- this.Cursor = Cursors.Default;
- }
- private void DetailsPanel_MouseMove(object sender, MouseEventArgs e)
- {
- // miniForm.isMouseEnter = false;
- if(isMouseDown == true)
- {
- this.Location = getDetailFormMoveLocation();
- miniForm.Location = getMiniBallMoveLocation();
- }
- }
- private void ballControl_MouseEnter(object sender, EventArgs e)
- {
- this.Cursor = Cursors.Hand;
- }
- private void ballControl_MouseLeave(object sender, EventArgs e)
- {
- this.Cursor = Cursors.Default;
- }
- /*隐藏DetailsForm的定时器*/
- private void hideDetailsFormTimer_Tick(object sender, EventArgs e) {
- hideDetailsFormTimer.Enabled = false;
- if(!isMouseEnter && !miniForm.isMouseEnter)
- {
- refreshTimer.Stop();
- this.Hide();
- }
- }
- /*获取小球出现的位置*/
- private System.Drawing.Point getMiniBallMoveLocation() {
- int x = 0, y = 0;
- if(this.Location.Y <= miniForm.Location.Y) {
- if(miniForm.miniFormLocation == MiniForm.MiniFormLocation.bottomRight)
- x = this.Location.X + this.Width - miniForm.miniFormWidth;
- else
- x = this.Location.X;
- y = this.Location.Y + this.Height + miniForm.miniBigFormSpace;
- }
- else {
- if(miniForm.miniFormLocation == MiniForm.MiniFormLocation.topRigh)
- x = this.Location.X + this.Width - miniForm.miniFormWidth;
- else
- x = this.Location.X;
- y = this.Location.Y - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
- }
- return new System.Drawing.Point(x, y);
- }
- /*获取DetailForm出现的位置*/
- private System.Drawing.Point getDetailFormMoveLocation() {
- int x = MousePosition.X - mouseOffset.X;
- int y = MousePosition.Y - mouseOffset.Y;
- if(x < 0) {
- x = 0;
- }
- if(miniForm.Top > this.Top && y < 0) {
- y = 0;
- }
- if(miniForm.Top < this.Top && y < miniForm.miniFormHeight + miniForm.miniBigFormSpace){ //minBall在上面
- y = miniForm.miniFormHeight + miniForm.miniBigFormSpace;
- }
- if(Screen.PrimaryScreen.WorkingArea.Width - x < this.Width) {
- x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
- }
- if(miniForm.Top < this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < this.Height) { //minBall在上面
- y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
- }
- if(miniForm.Top > this.Top && Screen.PrimaryScreen.WorkingArea.Height - y < (this.Height + miniForm.miniFormHeight + miniForm.miniBigFormSpace)) { //minBall在下面
- y = Screen.PrimaryScreen.WorkingArea.Height - this.Height - miniForm.miniFormHeight - miniForm.miniBigFormSpace;
- }
- return new System.Drawing.Point(x, y);
- }
- #endregion
- #region 刷新报警列表和光字牌
- public void refreshThread() {
- refreshTimer.Start();
- }
- private void refreshTimer_Tick(object sender, EventArgs e)
- {
- updateAlarmList();
- updateLightPlate();
- }
- private void updateAlarmList()
- {
- var lst = ClientCache.Instance.AlertSnaps;
- int cnt = 0;
- if (lst != null && lst.Count > 0)
- {
- int len = lst.Count > 5 ? 5 : lst.Count;
- for (int i = 0; i < len; i++)
- {
- alarmItems[i].setAlertSnap(lst[i]);
- cnt++;
- }
- }
- if (cnt < 5)
- {
- for (int i = cnt; i < 5; i++)
- {
- alarmItems[i].setAlertSnap(null);
- }
- }
- }
- private void updateLightPlate()
- {
- var lmap = ClientCache.Instance.LPModels;
- if (lmap == null || lightPlates == null)
- return;
- foreach(LightPlate lp in lightPlates)
- {
- if (lmap.ContainsKey(lp.LID))
- lp.setLightPlateModel(lmap[lp.LID]);
- else
- lp.setLightPlateModel(null);
- }
- }
- #endregion
- #region 事件及子窗体
- /*获取子窗体应该出现的位置*/
- private System.Drawing.Point getChildFormLocation(int frmWidth, int frmHeight)
- {
- int x = 0;
- if (this.Location.X >= frmWidth) //子窗体出现在bigBall左面
- {
- x = this.Location.X - frmWidth;
- }
- else
- {
- x = this.Location.X + this.Width;
- }
- int y = this.Location.Y;
- return new System.Drawing.Point(x, y);
- }
- private void lightPlate1_Click(object sender, EventArgs e)
- {
- LightPlate lp = sender as LightPlate;
- if (lp != null)
- {
- if (frmAlarm == null)
- frmAlarm = new FrmAlarm();
- frmAlarm.StartPosition = FormStartPosition.Manual;
- frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
- frmAlarm.ShowData(lp.LTitle);
- frmAlarm.BringToFront();
- }
- }
- private void lightPlate_Click(object sender, EventArgs e)
- {
- LightPlate lp = sender as LightPlate;
- if (lp != null)
- {
- if (frmAlarm == null)
- frmAlarm = new FrmAlarm();
- frmAlarm.StartPosition = FormStartPosition.Manual;
- frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
- if ("custom".Equals(lp.LID))
- frmAlarm.ShowData("custom", "");
- else
- frmAlarm.ShowData("windturbine", lp.LID);
- frmAlarm.BringToFront();
- }
- }
- private void confrimAlarm_Click(object sender, EventArgs e)
- {
- //MessageBox.Show("rise" + sender.ToString());
- string snapId = sender.ToString();
- //todo: 报警确认功能待定
- }
- private void button1_Click(object sender, EventArgs e)
- {
- lockForm = !lockForm;
- if (lockForm)
- btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin2;
- else
- btnLockForm.Image = global::IntelligentControlForsx.Properties.Resources.pin1;
- }
- private void btnStation_Click(object sender, EventArgs e)
- {
- selectStation = !selectStation;
- showLightPlate();
- }
- private void btnWindturbine_Click(object sender, EventArgs e)
- {
- selectStation = !selectStation;
- showLightPlate();
- }
- private void showLightPlate()
- {
- if (selectStation)
- {
- this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左一;
- this.btnStation.ForeColor = System.Drawing.Color.White;
- this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右二;
- this.btnWindturbine.ForeColor = System.Drawing.Color.DarkGray;
- this.pnlStation.Visible = true;
- this.pnlWindturbine.Visible = false;
- } else
- {
- this.btnStation.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换左二;
- this.btnStation.ForeColor = System.Drawing.Color.DarkGray;
- this.btnWindturbine.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.切换右一;
- this.btnWindturbine.ForeColor = System.Drawing.Color.White;
- this.pnlStation.Visible = false;
- this.pnlWindturbine.Visible = true;
- }
- }
- private void btnViewReal_Click(object sender, EventArgs e)
- {
- if (frmAlarm == null)
- {
- frmAlarm = new FrmAlarm();
- }
- frmAlarm.StartPosition = FormStartPosition.Manual;
- frmAlarm.WindowState = FormWindowState.Normal;
- //frmAlarm.Location = getChildFormLocation(frmAlarm.Width, frmAlarm.Height);
- frmAlarm.Location = new System.Drawing.Point(260, 140);
-
-
- //frmAlarm.TopLevel = true;
- frmAlarm.BringToFront();
- frmAlarm.ShowData();
- }
- private void btnViewHistory_Click(object sender, EventArgs e)
- {
- if (frmAlarmHistory == null)
- {
- frmAlarmHistory = new FrmAlarmHistory();
- }
- frmAlarmHistory.StartPosition = FormStartPosition.Manual;
- frmAlarmHistory.WindowState = FormWindowState.Normal;
- // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
- // frmAlarmHistory.Location = getChildFormLocation(frmAlarmHistory.Width, frmAlarmHistory.Height);
- frmAlarmHistory.Location = new System.Drawing.Point(260, 140); ;
- //frmAlarmHistory.TopLevel = true;
- frmAlarmHistory.BringToFront();
- frmAlarmHistory.Show();
- }
- #endregion
- }
- }
|