123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Threading;
- using GDNXFD.Data;
- namespace IntelligentControlForsx
- {
- public partial class MiniForm : UserControl
- {
- private BigForm2 bigForm = null;
- private Thread monitorAlarmThread = null;
- private System.Drawing.Point mouseOffset;
- private ToolStripMenuItem currentOpacityItem = null;
- public MiniFormLocation miniFormLocation;
- private bool isMouseDown = false;
- public bool isMouseEnter = false;
- public int miniBigFormSpace = 5;
- public int miniFormWidth = 371;
- public int miniFormHeight = 94;
- private int maxRank = 0;
- private int preMaxRank = 0;
- private int totalAlarms = 0;
- /*移动时小球出现在bigForm窗体的位置方向枚举*/
- public enum MiniFormLocation
- {
- topLeft,
- topRigh,
- bottomLeft,
- bottomRight
- }
- public MiniForm()
- {
- // Control.CheckForIllegalCrossThreadCalls = false;
- InitializeComponent();
- StartAlarmMonitor(); //启动报警监视
- }
- #region 报警监视
- /*开始监视报警数据*/
- private void StartAlarmMonitor()
- {
- AlertBackWorker.Instance.Start();
- refreshTimer.Start();
- }
- private void refreshTimer_Tick(object sender, EventArgs e)
- {
- alarmMonitor();
- }
- private void alarmMonitor()
- {
- string thingName = "";
- string alarmText = "";
- DateTime? alarmDate = null;
- Color? color = null;
- int rank = 0;
- int total = 0;
- if (ClientCache.Instance.AlertSnaps != null && ClientCache.Instance.AlertSnaps.Count > 0)
- {
- AlertSnap snap = ClientCache.Instance.AlertSnaps[0];
- thingName = snap.ObjectName;
- alarmText = snap.AlertText;
- alarmDate = snap.LastUpdateTime;
- color = snap.getBackGroundColor();
- int.TryParse(snap.Rank, out rank);
- total = ClientCache.Instance.AlertSnaps.Count;
- }
- string timeString = alarmDate.HasValue ? alarmDate.Value.ToString("HH:mm:ss") : "-";
- lblAlarmTime.Text = timeString;
- lblObjectName.Text = thingName;
- lblAlarmText.Text = alarmText;
- lblAlarmTime.BackColor = color.HasValue ? color.Value : Color.LightBlue;
- lblObjectName.BackColor = color.HasValue ? color.Value : Color.LightBlue;
- lblAlarmText.BackColor = color.HasValue ? color.Value : Color.LightBlue;
- maxRank = rank;
- totalAlarms = total;
- paintMiniBallControl();
- }
- /*刷新报警紧急程度*/
- private void paintMiniBallControl()
- {
- if (totalAlarms < 10)
- {
- // lblAlarmCount.Location = new System.Drawing.Point(33, 29);
- }
- else if (totalAlarms < 100)
- {
- // lblAlarmCount.Location = new System.Drawing.Point(29, 29);
- }
- else if (totalAlarms < 1000)
- {
- //lblAlarmCount.Location = new System.Drawing.Point(24, 29);
- }
- else if (totalAlarms < 10000)
- {
- //lblAlarmCount.Location = new System.Drawing.Point(19, 29);
- }
- // lblAlarmCount.Text = totalAlarms + "";
- if (preMaxRank != maxRank)
- {
- preMaxRank = maxRank;
- //if (maxRank == 5)
- //{
- // this.pnlBall.BackgroundImage = global::AlarmUI.Properties.Resources.红色球;
- //}
- //else if (maxRank == 4)
- //{
- // this.pnlBall.BackgroundImage = global::AlarmUI.Properties.Resources.橙色球;
- //}
- //else
- //{
- // this.pnlBall.BackgroundImage = global::AlarmUI.Properties.Resources.绿色球;
- //}
- }
- }
- #endregion
- #region 小球的鼠标事件
- private void miniBigFormSpace_MouseEnter(object sender, EventArgs e)
- {
- isMouseEnter = true;
- if (bigForm == null || !bigForm.Visible)
- showDetailFormTimer.Enabled = true;
- }
- private void miniBigFormSpace_MouseLeave(object sender, EventArgs e)
- {
- System.Drawing.Point p = MousePosition;
- if (p.X - 10 <= this.Left || p.X + 10 >= this.Left + miniFormWidth || p.Y - 10 <= this.Top || p.Y + 10 >= this.Bottom)
- {
- isMouseEnter = false;
- hideDetailFormTimer.Enabled = true;
- }
- }
- private void miniBigFormSpace_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 miniBigFormSpace_MouseUp(object sender, MouseEventArgs e)
- {
- isMouseDown = false;
- this.Cursor = Cursors.Default;
- }
- private void miniBigFormSpace_MouseMove(object sender, MouseEventArgs e)
- {
- //if (isMouseDown == true)
- //{
- // System.Drawing.Point old = this.Location;
- // this.Location = getMiniBallMoveLocation();
- // if (old.X != this.Location.X || old.Y != this.Location.Y)
- // {
- // if (bigForm != null && bigForm.Visible)
- // hideDetailsForm();
- // }
- // else
- // {
- // if (bigForm != null && !bigForm.Visible)
- // {
- // isMouseEnter = true;
- // showDetailFormTimer.Enabled = true;
- // }
- // }
- //}
- }
- #endregion
- #region 小球和bigForm的位置方法
- /*小球出现的位置*/
- private System.Drawing.Point getMiniBallMoveLocation()
- {
- int x = MousePosition.X - mouseOffset.X;
- int y = MousePosition.Y - mouseOffset.Y;
- if (x < 0)
- {
- x = 0;
- }
- if (y < 0)
- {
- y = 0;
- }
- if (Screen.PrimaryScreen.WorkingArea.Width - x < miniFormWidth)
- {
- x = Screen.PrimaryScreen.WorkingArea.Width - miniFormWidth;
- }
- if (Screen.PrimaryScreen.WorkingArea.Height - y < miniFormHeight)
- {
- y = Screen.PrimaryScreen.WorkingArea.Height - miniFormHeight;
- }
- return new System.Drawing.Point(x, y);
- }
- /*获取bigForm出现的位置*/
- private System.Drawing.Point getDetailsFormLocation()
- {
- int x = 0, y = 0;
- //System.Drawing.Point miniBallLocation = this.Location;
- //if (this.Location.Y >= bigForm.Height) //minBall在bigBall下面
- //{
- // if (Screen.PrimaryScreen.WorkingArea.Width - this.Location.X <= bigForm.Width)
- // {
- // x = this.Location.X + miniFormWidth - bigForm.Width;
- // miniFormLocation = MiniFormLocation.bottomRight;
- // }
- // else
- // {
- // x = this.Location.X;
- // miniFormLocation = MiniFormLocation.bottomLeft;
- // }
- // y = this.Location.Y - bigForm.Height - miniBigFormSpace;
- //}
- //else if (this.Location.Y < bigForm.Height) //minBall在bigBall上面
- //{
- // if (Screen.PrimaryScreen.WorkingArea.Width - this.Location.X > bigForm.Width)
- // {
- // x = this.Location.X;
- // miniFormLocation = MiniFormLocation.topLeft;
- // }
- // else
- // {
- // x = this.Location.X + miniFormWidth - bigForm.Width;
- // miniFormLocation = MiniFormLocation.topRigh;
- // }
- // y = this.Location.Y + miniFormHeight + miniBigFormSpace;
- //}
- x = 1920 - bigForm.Width;
- y = 1038 - bigForm.Height;
- return new System.Drawing.Point(x, y);
- }
- #endregion
- #region 显示和隐藏detailForm的方法和定时器
- /*隐藏bigForm*/
- private void hideDetailsForm()
- {
- if (bigForm != null && bigForm.Visible)
- {
- bigForm.Hide();
- }
- }
- /*显示bigForm*/
- private void showDetailsForm()
- {
- if (bigForm == null)
- {
- bigForm = new BigForm2(this);
- bigForm.Show();
- bigForm.Location = getDetailsFormLocation();
- }
- else if (!bigForm.Visible)
- {
- bigForm.Location = getDetailsFormLocation();
- bigForm.Show();
- }
- bigForm.refreshThread();
- }
- /*显示bigForm的定时器*/
- private void showDetailFormTimer_Tick(object sender, EventArgs e)
- {
- if (isMouseEnter)
- {
- showDetailsForm();
- }
- showDetailFormTimer.Enabled = false;
- }
- /*隐藏bigForm的定时器*/
- private void hideDetailFormTimer_Tick(object sender, EventArgs e)
- {
- hideDetailFormTimer.Enabled = false;
- if (bigForm != null && bigForm.Visible && !bigForm.isMouseEnter && !isMouseEnter)
- {
- hideDetailsForm();
- }
- if (bigForm != null && bigForm.isMouseEnter)
- isMouseEnter = false;
- }
- #endregion
- }
- }
|