123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- 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<AlertSnap> results = null;
- string station = string.Empty;
- string rank = string.Empty;
- string category = string.Empty;
- string category2 = string.Empty;
- string filter = string.Empty;
- private BindingList<AlertSnap> 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<DictItem> 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<DictItem> 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<DictItem> 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<DictItem> 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<DictItem> 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<DictItem> 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<AlertSnap> 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<AlertSnap>(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<string> sendList = new List<string>();
- 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";
- }
- }
- }
|