123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Collections.Generic;
- using GDNXFD.Data;
- using IntelligentControlForsx.MyControls.alarm.Domain;
- using IntelligentControlForsx.Service;
- namespace IntelligentControlForsx
- {
- public partial class BigForm2 : 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;
- private IList<AlertSnap> results = null;
- IList<AlertData> infoList = new List<AlertData>();
- private FrmAlarmByObject frmAlarmByObject;
- private BindingList<AlarmGroupModel> infoListBindings = null;
- public BigForm2(MiniForm miniForm)
- {
- Control.CheckForIllegalCrossThreadCalls = false;
- InitializeComponent();
- this.miniForm = miniForm;
- this.dgvAlarm.AutoGenerateColumns = false;
- this.dgvAlarm.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter;
- dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.dgvAlarm.DefaultCellStyle = dataGridViewCellStyle1;
- }
- #region 初始化光字牌和最新列表
- private void BigForm_Load(object sender, EventArgs e)
- {
- initAlarmItems();
- initLightPlates();
- }
- private void initAlarmItems()
- {
- //绑定gridview方法
- Dictionary<string, AlarmGroupModel> agDict = ClientCache.Instance.AlarmGroups;
- if (agDict == null || agDict.Count == 0)
- return;
- var lst = agDict.Values.OrderByDescending(q => q.AgCount).OrderByDescending(q => q.AgTime).ToList();
- infoListBindings = new BindingList<AlarmGroupModel>(lst);
- this.dgvAlarm.DataSource = infoListBindings;
- //IList<AlertSnap> lstSnap = ClientCache.Instance.AlertSnaps;
- ////从客户端缓存中加载数据
- //if (lstSnap != null && lstSnap.Count > 0)
- //{
- // var r1 = lstSnap.AsQueryable();
- // results = r1.OrderByDescending(q => q.LastUpdateTime).ToList();
-
- // IEnumerable<IGrouping<string, AlertSnap>> groupResult = results.GroupBy(s => s.ObjectId);
- // foreach (IGrouping<string, AlertSnap> grouping in groupResult)
- // {
- // IList<AlertSnap> list = grouping.ToList();
- // foreach (var alertSnap in list)
- // {
- // AlertData info = new AlertData();
- // info.ObjectName = alertSnap.ObjectName;
- // info.ObjectId = alertSnap.ObjectId;
- // info.AlertText = alertSnap.AlertText;
- // info.Rank = alertSnap.Rank;
- // info.LastUpdateTimeString = alertSnap.LastUpdateTime.HasValue?alertSnap.LastUpdateTime.Value.ToString("hh:MM:ss"):"-";
- // info.AlertCount = list.Count;
- // infoList.Add(info);
- // }
- // }
- // infoListBindings = new BindingList<AlertData>(infoList);
-
- //}
- }
- 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()
- {
- Dictionary<string, AlarmGroupModel> agDict = ClientCache.Instance.AlarmGroups;
- if (agDict == null || agDict.Count == 0)
- return;
- var lst = agDict.Values.OrderByDescending(q=>q.AgCount).OrderByDescending(q => q.AgTime).ToList();
- infoListBindings = new BindingList<AlarmGroupModel>(lst);
- this.dgvAlarm.DataSource = infoListBindings;
- }
- 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
- private void dgvAlarm_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.RowIndex > -1)
- {
- string objectId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
- if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Control" && e.RowIndex >= 0)
- {
- if (frmAlarmByObject == null)
- {
- frmAlarmByObject = new FrmAlarmByObject(objectId);
- frmAlarmByObject.StartPosition = FormStartPosition.Manual;
- frmAlarmByObject.WindowState = FormWindowState.Normal;
- frmAlarmByObject.Location = new System.Drawing.Point(260, 140);
- }
- else
- {
- frmAlarmByObject.ShowData(objectId);
- }
- }
- }
-
- }
- private void dgvAlarm_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.RowIndex > -1)
- {
- try
- {
- string objectName = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString();
- AlarmGroupModel agModel = ClientCache.Instance.AlarmGroups[objectName];
- string thingId = agModel.SnapList.First().ObjectId;
- string stationId = agModel.SnapList.First().StationId;
- if (objectName.EndsWith("风机"))
- NavService.Instance.NavForWindturbine("pictureBoxParamters", thingId, stationId);
- }
- catch { }
- }
-
-
- }
- }
- }
|