using EntityDataSet; using GDNXFD.Data; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.ChildForms; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc; using IntelligentControlForsx.Service; namespace IntelligentControlForsx { public partial class FrmAlarm : Form { [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; private bool isLoadding = false; private bool isReady = false; //private AlertServiceClient asc = null; private IList results = null; string station = string.Empty; string rank = string.Empty; string category = string.Empty; string category2 = string.Empty; string filter = string.Empty; private BindingList bindings; private AlertServiceClient asc = null; public FrmAlarm() { InitializeComponent(); 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; //isReady = true; //LoadData(); } #region 事件处理 private void cmbStation_SelectedValueChanged(object sender, EventArgs e) { if ("全部".Equals(cmbStation.SelectedItem) == false) station = cmbStation.SelectedItem.ToString(); else station = string.Empty; LoadData(); } private void cmbRank_SelectedValueChanged(object sender, EventArgs e) { if ("全部".Equals(cmbRank.SelectedItem) == false) { try { IList lst1 = ClientCache.Instance.GetDataDictByCategory("AlertLevel"); rank = lst1.Where(q => q.Name == cmbRank.SelectedItem.ToString()).First().Code; } catch { rank = string.Empty; } } else rank = string.Empty; LoadData(); } private void cmbCategory_SelectedValueChanged(object sender, EventArgs e) { if ("全部".Equals(cmbCategory.SelectedItem) == false) { try { IList lst1 = ClientCache.Instance.GetDataDictByCategory("AlertCategory"); category = lst1.Where(q => q.Name == cmbCategory.SelectedItem.ToString()).First().Code; } catch { category = string.Empty; } } else category = string.Empty; ResetCmbSubCategory(); LoadData(); } private void ResetCmbSubCategory() { this.cmbSubCategory.Items.Clear(); this.cmbSubCategory.Items.Add("全部"); if (!string.IsNullOrWhiteSpace(category)) { try { IList lst = ClientCache.Instance.GetDataDictByCategory(category); if (lst != null) { foreach (DictItem dItem in lst) { this.cmbSubCategory.Items.Add(dItem.Name); } } } catch (Exception ex) { } } this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf("全部"); } private void cmbSubCategory_SelectedValueChanged(object sender, EventArgs e) { if ("全部".Equals(cmbSubCategory.SelectedItem) == false) { try { IList lst1 = ClientCache.Instance.GetDataDictByCategory(category); category2 = lst1.Where(q => q.Name == cmbSubCategory.SelectedItem.ToString()).First().Code; } catch { category2 = string.Empty; } } else category2 = string.Empty; LoadData(); } private void txtKeyWord_TextChanged(object sender, EventArgs e) { filter = txtKeyWord.Text.Trim(); LoadData(); } private void timer1_Tick(object sender, EventArgs e) { LoadData(); } #endregion #region 数据加载和刷新 public void ShowData(string c1, string c2) { isReady = false; station = string.Empty; rank = string.Empty; category = c1; category2 = c2; filter = string.Empty; this.txtKeyWord.Text = string.Empty; this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf("全部"); this.cmbRank.SelectedIndex = cmbStation.Items.IndexOf("全部"); if (string.IsNullOrWhiteSpace(c1)) { this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf("全部"); } else { string c1Name = "全部"; try { IList lst1 = ClientCache.Instance.GetDataDictByCategory("AlertCategory"); c1Name = lst1.Where(q => q.Code == c1).First().Name; } catch { } this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf(c1Name); ResetCmbSubCategory(); if (!string.IsNullOrWhiteSpace(c2)) { string c2Name = "全部"; try { IList lst1 = ClientCache.Instance.GetDataDictByCategory(category); c2Name = lst1.Where(q => q.Code == c2).First().Name; } catch { } this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf(c2Name); } } isReady = true; LoadData(); this.Show(); } public void ShowData(string stationName) { isReady = false; this.txtKeyWord.Text = string.Empty; this.cmbRank.SelectedIndex = cmbStation.Items.IndexOf("全部"); this.cmbCategory.SelectedIndex = cmbCategory.Items.IndexOf("全部"); this.cmbSubCategory.SelectedIndex = cmbSubCategory.Items.IndexOf("全部"); if (string.IsNullOrWhiteSpace(stationName)) { this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf("全部"); station = string.Empty; } else { this.cmbStation.SelectedIndex = cmbStation.Items.IndexOf(stationName); station = stationName == "全部" ? string.Empty : stationName; } //station = string.Empty; rank = string.Empty; category = string.Empty; category2 = string.Empty; filter = string.Empty; isReady = true; LoadData(); this.Show(); } public void ShowData() { isReady = true; LoadData(); this.Show(); } private void LoadData() { if (isLoadding) return; if (isReady == false) return; isLoadding = true; try { LoadAlertSnaps(); } catch (Exception ex) { //logger.Info("读取报警列表数据失败!ex=" + ex.Message); } finally { isLoadding = false; } } private void LoadAlertSnaps() { IList lstSnap = ClientCache.Instance.AlertSnaps; //从客户端缓存中加载数据 if (lstSnap != null && lstSnap.Count > 0) { var r1 = lstSnap.AsQueryable(); if (!string.IsNullOrWhiteSpace(station)) { r1 = r1.Where(q => q.StationName == station); } if (!string.IsNullOrWhiteSpace(rank)) { r1 = r1.Where(q => q.Rank == rank); } if (!string.IsNullOrWhiteSpace(category)) { r1 = r1.Where(q => q.Category1 == category); } if (!string.IsNullOrWhiteSpace(category2)) { r1 = r1.Where(q => q.Category2 == category2); } if (!string.IsNullOrWhiteSpace(filter)) { r1 = r1.Where(q => q.AlertText.Contains(filter) || q.StationName.Contains(filter) || q.ObjectName.Contains(filter)); } if (r1 != null) { results = r1.OrderByDescending(q => q.LastUpdateTime).ToList(); bindings = new BindingList(results); this.dgvAlarm.DataSource = bindings; } } } #endregion private void dgvAlarm_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1) { string windturbineId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString(); string alertSnapIds = dgvAlarm.Rows[e.RowIndex].Cells["Column8"].Value.ToString().Trim(); long alertSnapId; long.TryParse(alertSnapIds, out alertSnapId); if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Confirm" && e.RowIndex >= 0) { //报警信息操作方法 if (asc == null) asc = AlertServiceClientFactory.CreateAlertServiceClient(); if (alertSnapId > 0) asc.ConfirmAlert(alertSnapId); MessageBox.Show("确认操作" + alertSnapId); } if (dgvAlarm.Columns[e.ColumnIndex].Name == "Column_Control" && e.RowIndex >= 0) { if (!string.IsNullOrEmpty(windturbineId)) { if (windturbineId.Contains("SG01_") || windturbineId.Contains("MG01_") || windturbineId.Contains("QG01_") || windturbineId.Contains("XG01_") || windturbineId.Contains("NG01_")) { user userData = null; try { FingerCheck2 check = new FingerCheck2(); check.ShowDialog(); userData = FingerCheck2.checkSuccessUser; } catch (Exception ex) { } if (userData == null) { return; } IList sendList = new List(); sendList.Add("windturbineId"); string controlTypeString = dgvAlarm.Rows[e.RowIndex].Cells["Column_Control"].Value.ToString().Trim(); string stationId = ""; if (windturbineId.Contains("SG01_")) stationId = "SBQ_FDC"; if (windturbineId.Contains("MG01_")) stationId = "MHS_FDC"; if (windturbineId.Contains("NG01_")) stationId = "NSS_FDC"; if (windturbineId.Contains("XG01_")) stationId = "XS_FDC"; if (windturbineId.Contains("QG01_")) stationId = "QS_FDC"; if (controlTypeString == "复位") TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Reset, userData); else if (controlTypeString == "停机") TaskQueueSvc.QueueAdd(sendList, stationId, CmdType.Stop, userData); //报警信息操作方法 if (asc == null) asc = AlertServiceClientFactory.CreateAlertServiceClient(); if (alertSnapId > 0) asc.ConfirmAlert(alertSnapId); MessageBox.Show(controlTypeString + "操作已完成"); } } } } } private void chkAutoRefresh_CheckedChanged(object sender, EventArgs e) { if (this.chkAutoRefresh.Checked) timer1.Start(); else timer1.Stop(); } private void btnClose_Click(object sender, EventArgs e) { this.Hide(); } private void btnMax_Click(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal; else this.WindowState = FormWindowState.Maximized; } private void panel1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } private void dgvAlarm_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { string objectId = dgvAlarm.Rows[e.RowIndex].Cells["Column_WindturbineId"].Value.ToString(); if (objectId.IndexOf("01") > 0) { NavService.Instance.NavForWindturbine("pictureBoxParamters", objectId, getStationId(objectId)); } } catch { } } private string getStationId(string wtId) { if (wtId.StartsWith("MG")) return "MHS_FDC"; if (wtId.StartsWith("NG")) return "NSS_FDC"; if (wtId.StartsWith("SG")) return "SBQ_FDC"; if (wtId.StartsWith("XG")) return "XS_FDC"; if (wtId.StartsWith("QG")) return "QS_FDC"; return "SBQ_FDC"; } } }