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 lightPlates; private AlertServiceClient asc = null; private FrmAlarm frmAlarm; private FrmAlarmHistory frmAlarmHistory; private IList results = null; IList infoList = new List(); private FrmAlarmByObject frmAlarmByObject; private BindingList 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 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(lst); this.dgvAlarm.DataSource = infoListBindings; //IList lstSnap = ClientCache.Instance.AlertSnaps; ////从客户端缓存中加载数据 //if (lstSnap != null && lstSnap.Count > 0) //{ // var r1 = lstSnap.AsQueryable(); // results = r1.OrderByDescending(q => q.LastUpdateTime).ToList(); // IEnumerable> groupResult = results.GroupBy(s => s.ObjectId); // foreach (IGrouping grouping in groupResult) // { // IList 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(infoList); //} } private void initLightPlates() { lightPlates = new List(); 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 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(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 { } } } } }