using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using EntityDataSet; using IntelligentControlForsx.Service.Control.FormInfo; using IntelligentControlForsx.Service.WindturbineControl.Domain; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; using IntelligentControlForsx.Service.WindturbineControl.Domain.FormInfo; using IntelligentControlForsx.Service.WindturbineControl.FormInfoSvc; using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc; using IntelligentControlForsx.Template; using Gyee_Control.Svc.Cache; using Gyee_Control.View; using log4net; using log4net.Util; namespace IntelligentControlForsx.ChildForms { public partial class ControlForm : TemplateForm { private ILog logger = LogManager.GetLogger("AppInfoLog"); public bool firstLoad = true;//第一次加载 public bool IsNeedCheckColumn = true; public static bool isUpdateOverData = true; private static bool isUpdateOverGv = true; private static bool isUpdateOverSuccessCheck = true; private int selectRow = 0; GridViewDataSvc gvSvc = null; private WindturbinePointDataSvc pointSvc = null; private string stationCode = "SBQ_FDC"; //期次 private string project = "SBQ01_GC"; private static BindingList formDataList = new BindingList(); private BindingSource formBindingSource = new BindingSource(); private Dictionary statusDic = new Dictionary(); private string changeStatusWindturbineId = ""; private Color backColor; public ControlForm() { InitializeComponent(); WindturbinePointDataSvc.UpdatePointData(stationCode); } public override void Active() { this.Show(); timer1.Enabled = true; WindturbinePointDataSvc.UpdatePointData(stationCode); Console.WriteLine("数据访问完毕"); //InfoRefresh(); Console.WriteLine("数据绑定完毕"); } public override void DeActive() { this.Hide(); timer1.Enabled = false; } private delegate void UpdateGridViewDelegate(); private void btnStart_Click(object sender, EventArgs e) { string cmdDescribe = null; cmdDescribe = "正常启动"; IList cmdInfoList = new List(); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { if (CacheInfo.CacheWindturbineDataList[i].IsCheck) { WindturbineCmdInfo info = new WindturbineCmdInfo(); info.WindturbineId = CacheInfo.CacheWindturbineDataList[i].WindturbineName; info.CmdType = CmdType.Start; cmdInfoList.Add(info); } } Confirm confirm = new Confirm(stationCode, cmdInfoList, cmdDescribe); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { CacheInfo.CacheWindturbineDataList[i].IsCheck = false; } confirm.ShowDialog(); ClearCheck(); } private void btnStop_Click(object sender, EventArgs e) { string cmdDescribe = null; try { cmdDescribe = "正常停机"; IList cmdInfoList = new List(); IList list = CacheInfo.CacheWindturbineDataList; for (int i = 0; i < list.Count; i++) { if (list[i].IsCheck) { WindturbineCmdInfo info = new WindturbineCmdInfo(); info.WindturbineId = list[i].WindturbineName; info.CmdType = CmdType.Stop; cmdInfoList.Add(info); } } Confirm confirm = new Confirm(stationCode, cmdInfoList, cmdDescribe); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { CacheInfo.CacheWindturbineDataList[i].IsCheck = false; } confirm.ShowDialog(); ClearCheck(); } catch (Exception ex) { } } private void btnRest_Click(object sender, EventArgs e) { string cmdDescribe = null; cmdDescribe = "复位"; IList cmdInfoList = new List(); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { if (CacheInfo.CacheWindturbineDataList[i].IsCheck) { WindturbineCmdInfo info = new WindturbineCmdInfo(); info.WindturbineId = CacheInfo.CacheWindturbineDataList[i].WindturbineName; info.CmdType = CmdType.Reset; cmdInfoList.Add(info); } } Confirm confirm = new Confirm(stationCode, cmdInfoList, cmdDescribe); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { CacheInfo.CacheWindturbineDataList[i].IsCheck = false; } confirm.ShowDialog(); ClearCheck(); } private void gvWindturbine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex != -1) { if (e.ColumnIndex == 0) { string isCheck = gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value == null ? "0" : gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value.ToString(); if (isCheck == "1") gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 0; else gvWindturbine.Rows[e.RowIndex].Cells["Select"].Value = 1; string windturbineId = this.gvWindturbine.Rows[e.RowIndex].Cells[1].Value.ToString(); int nullCount = CacheInfo.CacheWindturbineDataList.Where(s => s == null).ToList().Count; if (nullCount == 0) { var data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == windturbineId).FirstOrDefault(); if (data != null) { var newData = data; if (data.IsCheck) newData.IsCheck = false; else newData.IsCheck = true; CacheInfo.CacheWindturbineDataList.Remove(data); CacheInfo.CacheWindturbineDataList.Add(newData); } } } selectRow = e.RowIndex; string[] SBQ_UP105 = { "SG01_67", "SG01_68", "SG01_69", "SG01_70", "SG01_71", "SG01_72", "SG01_73", "SG01_74", "SG01_75", "SG01_76", "SG01_77", "SG01_78", "SG01_79", "SG01_80", "SG01_81", "SG01_82", "SG01_83", "SG01_84", "SG01_85", "SG01_86", "SG01_87", "SG01_88", "SG01_89", "SG01_90", "SG01_91", "SG01_100", "SG01_101", "SG01_102", "SG01_103", "SG01_104", "SG01_105", "SG01_106", "SG01_107", "SG01_108", "SG01_109", "SG01_110", "SG01_111", "SG01_112", "SG01_113", "SG01_114", "SG01_115", "SG01_116", "SG01_92", "SG01_93", "SG01_94", "SG01_95", "SG01_96", "SG01_97", "SG01_98", "SG01_99" }; IList enbleMaintainList = SBQ_UP105.ToList(); IList cacheWindturbineIdList = CacheInfo.CacheWindturbineDataList.Where(k => k.IsCheck == true).Select(s => s.WindturbineName).ToList(); if (enbleMaintainList.Intersect(cacheWindturbineIdList).ToList().Count > 0) { btnMaintain.Enabled = false; btnRegister.Enabled = false; btnUnMaintain.Enabled = false; } else { btnMaintain.Enabled = true; btnRegister.Enabled = true; btnUnMaintain.Enabled = true; } } else { if (e.ColumnIndex == 0) { for (int i = 0; i < gvWindturbine.RowCount; i++) { string isCheck = gvWindturbine.Rows[i].Cells["Select"].Value == null ? "0" : gvWindturbine.Rows[i].Cells["Select"].Value.ToString(); if (isCheck == "1") gvWindturbine.Rows[i].Cells["Select"].Value = 0; else gvWindturbine.Rows[i].Cells["Select"].Value = 1; string windturbineId = this.gvWindturbine.Rows[i].Cells[1].Value.ToString(); var data = CacheInfo.CacheWindturbineDataList.Where(s => s.WindturbineName == windturbineId) .FirstOrDefault(); if (data != null) { var newData = data; if (data.IsCheck) newData.IsCheck = false; else newData.IsCheck = true; CacheInfo.CacheWindturbineDataList.Remove(data); CacheInfo.CacheWindturbineDataList.Add(newData); } } } } } private void ControlForm_Load(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { if (firstLoad) { firstLoad = false; using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "SBQ_FDC" && s.PROJECTID == project).ToList(); formDataList = new BindingList(); IList list = CacheInfo.CacheWindturbineDataList.Where(s => s.StationId == stationCode && s.ProjectId == project).ToList().OrderBy(s => Convert.ToInt32(Regex.Replace(s.WindturbineName, "[a-zA-Z]", "").Replace("_", ""))).ToList(); ; statusDic.Clear(); for (int i = 0; i < list.Count; i++) { string statusString = ""; #region 状态转化字符串 switch (list[i].Status) { case WindturbineStatus.Standby: statusString = "待机"; break; case WindturbineStatus.OnPower: statusString = "上电"; break; case WindturbineStatus.Maintain: statusString = "维护"; break; case WindturbineStatus.Fault: statusString = "故障"; break; case WindturbineStatus.Start: statusString = "启动"; break; case WindturbineStatus.Online: statusString = "并网"; break; case WindturbineStatus.Stop: statusString = "停机"; break; case WindturbineStatus.Offline: statusString = "离线"; break; } #endregion string hungTypeString = ""; switch (list[i].HungType) { case HungType.UnLock: hungTypeString = "正常"; break; case HungType.StationCheckLock: hungTypeString = "场内受累检修"; break; case HungType.StationFaulLockt: hungTypeString = "场内受累故障"; break; case HungType.StationPowerLineLock: hungTypeString = "场外受累电网"; break; case HungType.StationWeatherLock: hungTypeString = "场外受累天气"; break; case HungType.FaultLock: hungTypeString = "故障检修"; break; case HungType.CheckLock: hungTypeString = "检修"; break; } WindturbineFormData data = new WindturbineFormData(list[i].WindturbineName, list[i].WindSpeed.ToString("f2"), list[i].Power.ToString("f2"), statusString, hungTypeString, list[i].AlternatorSpeed.ToString("f2"), list[i].LaminaSpeed.ToString("f2"), list[i].LimitSpeed.ToString("f2"), list[i].LaminaAngle1.ToString("f2"), list[i].LaminaAngle2.ToString("f2"), list[i].LaminaAngle3.ToString("f2"), list[i].WindAngle.ToString("f2"), list[i].YawPosition.ToString("f2") ); formDataList.Add(data); if (!statusDic.ContainsKey(windturbineList[i].ID)) statusDic.Add(windturbineList[i].ID, list[i].Status); } formBindingSource.DataSource = formDataList; this.gvWindturbine.DataSource = formBindingSource; if (IsNeedCheckColumn) { DataGridViewCheckBoxColumn checkColum = new DataGridViewCheckBoxColumn(); checkColum.HeaderText = ""; checkColum.Name = "Select"; checkColum.DataPropertyName = "Select"; checkColum.ReadOnly = false; checkColum.TrueValue = true; checkColum.FalseValue = false; gvWindturbine.Columns.Insert(0, checkColum); IsNeedCheckColumn = false; } gvWindturbine.Columns[0].Width = 50; gvWindturbine.Columns[1].Width = 110; } #region 修改风机状态背景色 for (int i = 0; i < gvWindturbine.RowCount; i++) { string statusString = gvWindturbine.Rows[i].Cells[4].Value.ToString(); DataGridViewRow row = gvWindturbine.Rows[i]; switch (statusString) { case "待机": row.Cells[1].Style.BackColor = Color.FromArgb(15, 141, 106); break; case "上电": row.Cells[1].Style.BackColor = Color.FromArgb(177, 14, 126); break; case "维护": row.Cells[1].Style.BackColor = Color.FromArgb(204, 83, 51); break; case "故障": row.Cells[1].Style.BackColor = Color.FromArgb(170, 15, 59); break; case "启动": row.Cells[1].Style.BackColor = Color.FromArgb(14, 72, 91); break; case "并网": row.Cells[1].Style.BackColor = Color.FromArgb(15, 135, 170); break; case "停机": row.Cells[1].Style.BackColor = Color.FromArgb(176, 151, 63); break; case "离线": row.Cells[1].Style.BackColor = Color.FromArgb(134, 150, 165); break; } } #endregion #region 修改表头 gvWindturbine.Columns[1].HeaderText = "风机编号"; gvWindturbine.Columns[2].HeaderText = "风速 m/s"; gvWindturbine.Columns[3].HeaderText = "功率 kwh"; gvWindturbine.Columns[4].HeaderText = "状态"; gvWindturbine.Columns[5].HeaderText = "发电机转速"; gvWindturbine.Columns[6].HeaderText = "限速值"; gvWindturbine.Columns[7].HeaderText = "叶轮转速"; gvWindturbine.Columns[8].HeaderText = "桨叶角度1"; gvWindturbine.Columns[9].HeaderText = "桨叶角度2"; gvWindturbine.Columns[10].HeaderText = "桨叶角度3"; gvWindturbine.Columns[11].HeaderText = "对风角度"; gvWindturbine.Columns[12].HeaderText = "偏航位置"; #endregion } if (isUpdateOverData) { isUpdateOverData = false; Thread getDataThread = new Thread(new ParameterizedThreadStart(WindturbinePointDataSvc.UpdatePointData));//创建数据更新线程 getDataThread.Start(stationCode); } if (isUpdateOverGv) { isUpdateOverGv = false; Thread t = new Thread(ThreadInfo); t.IsBackground = true; t.Start(); } } public void ThreadInfo() { UpdateGridViewDelegate del = new UpdateGridViewDelegate(FormDataBind); if (gvWindturbine.InvokeRequired) { gvWindturbine.BeginInvoke(del, new object[] { }); } else { FormDataBind(); } } public void FormDataBind() { IList pointDataList = CacheInfo.CacheWindturbineDataList.Where(s => s.StationId == stationCode && s.ProjectId == project).ToList().OrderBy(k => k.WindturbineName).ToList(); BindingList dataList = this.formBindingSource.DataSource as BindingList; DateTime stime = DateTime.Now; for (int i = 0; i < pointDataList.Count; i++) { var data = dataList.Where(s => s.WindturbineId == pointDataList[i].WindturbineName).FirstOrDefault(); if (data != null) { data.WindSpeed = pointDataList[i].WindSpeed.ToString("f2"); data.Power = pointDataList[i].Power.ToString("f2"); switch (pointDataList[i].Status) { case WindturbineStatus.Standby: data.StatusString = "待机"; break; case WindturbineStatus.OnPower: data.StatusString = "上电"; break; case WindturbineStatus.Maintain: data.StatusString = "维护"; break; case WindturbineStatus.Fault: data.StatusString = "故障"; break; case WindturbineStatus.Start: data.StatusString = "启动"; break; case WindturbineStatus.Online: data.StatusString = "并网"; break; case WindturbineStatus.Stop: data.StatusString = "停机"; break; case WindturbineStatus.Offline: data.StatusString = "离线"; break; } data.AlternatorSpeed = pointDataList[i].AlternatorSpeed.ToString("f2"); data.LaminaSpeed = pointDataList[i].LaminaSpeed.ToString("f2"); data.LimitSpeed = pointDataList[i].LimitSpeed.ToString("f2"); data.LaminaAngle1 = pointDataList[i].LaminaAngle1.ToString("f2"); data.LaminaAngle2 = pointDataList[i].LaminaAngle2.ToString("f2"); data.LaminaAngle3 = pointDataList[i].LaminaAngle3.ToString("f2"); data.WindAngle = pointDataList[i].WindAngle.ToString("f2"); data.YawPosition = pointDataList[i].YawPosition.ToString("f2"); StatusStyleThread(data.WindturbineId, pointDataList[i].Status); } } UpdateStatInfo("SBQ_FDC"); isUpdateOverGv = true; DateTime etime = DateTime.Now; TimeSpan span = etime - stime; Console.WriteLine("绑定页面时间:" + span.TotalMilliseconds); } private void btnRegister_Click(object sender, EventArgs e) { MessageBox.Show("管理员验证指纹"); FingerCheck check = new FingerCheck(); check.ShowDialog(); user adminUser = FingerCheck.checkSuccessUser; if (adminUser != null && adminUser.user_name == "admin") { Register register = new Register(); register.ShowDialog(); } else { MessageBox.Show("管理员验证失败"); } } private void btnMaintain_Click(object sender, EventArgs e) { string cmdDescribe = null; cmdDescribe = "正常维护"; IList cmdInfoList = new List(); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { if (CacheInfo.CacheWindturbineDataList[i].IsCheck) { WindturbineCmdInfo info = new WindturbineCmdInfo(); info.WindturbineId = CacheInfo.CacheWindturbineDataList[i].WindturbineName; info.CmdType = CmdType.Maintain; cmdInfoList.Add(info); } } Confirm confirm = new Confirm(stationCode, cmdInfoList, cmdDescribe); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { CacheInfo.CacheWindturbineDataList[i].IsCheck = false; } confirm.ShowDialog(); ClearCheck(); } private void btnUnMaintain_Click(object sender, EventArgs e) { string cmdDescribe = null; cmdDescribe = "正常取消维护"; IList cmdInfoList = new List(); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { if (CacheInfo.CacheWindturbineDataList[i].IsCheck) { WindturbineCmdInfo info = new WindturbineCmdInfo(); info.WindturbineId = CacheInfo.CacheWindturbineDataList[i].WindturbineName; info.CmdType = CmdType.UnMaintain; cmdInfoList.Add(info); } } Confirm confirm = new Confirm(stationCode, cmdInfoList, cmdDescribe); for (int i = 0; i < CacheInfo.CacheWindturbineDataList.Count; i++) { CacheInfo.CacheWindturbineDataList[i].IsCheck = false; } confirm.ShowDialog(); ClearCheck(); } private void lblProject1_Click(object sender, EventArgs e) { project = "SBQ01_GC"; firstLoad = true; ThreadInfo(); lblProject1.BackColor = Color.FromArgb(15, 141, 106); lblProject2.BackColor = Color.FromArgb(3, 24, 48); lblProject3.BackColor = Color.FromArgb(3, 24, 48); lblProject4.BackColor = Color.FromArgb(3, 24, 48); btnMaintain.Enabled = true; btnUnMaintain.Enabled = true; btnRest.Enabled = true; } private void lblProject2_Click(object sender, EventArgs e) { project = "SBQ02_GC"; firstLoad = true; ThreadInfo(); lblProject1.BackColor = Color.FromArgb(3, 24, 48); lblProject2.BackColor = Color.FromArgb(15, 141, 106); lblProject3.BackColor = Color.FromArgb(3, 24, 48); lblProject4.BackColor = Color.FromArgb(3, 24, 48); btnMaintain.Enabled = true; btnUnMaintain.Enabled = true; btnRest.Enabled = true; } private void lblProject3_Click(object sender, EventArgs e) { project = "SBQ03_GC"; firstLoad = true; ThreadInfo(); lblProject1.BackColor = Color.FromArgb(3, 24, 48); lblProject2.BackColor = Color.FromArgb(3, 24, 48); lblProject3.BackColor = Color.FromArgb(15, 141, 106); lblProject4.BackColor = Color.FromArgb(3, 24, 48); btnMaintain.Enabled = false; btnUnMaintain.Enabled = false; btnRest.Enabled = false; } private void lblProject4_Click(object sender, EventArgs e) { project = "SBQ04_GC"; firstLoad = true; ThreadInfo(); lblProject1.BackColor = Color.FromArgb(3, 24, 48); lblProject2.BackColor = Color.FromArgb(3, 24, 48); lblProject3.BackColor = Color.FromArgb(3, 24, 48); lblProject4.BackColor = Color.FromArgb(15, 141, 106); btnMaintain.Enabled = false; btnUnMaintain.Enabled = false; btnRest.Enabled = false; } private void StatusStyleThread(string windturbineId, WindturbineStatus status) { WindturbineStatus oldStatus = statusDic[windturbineId]; if (oldStatus != status) { statusDic[windturbineId] = status; switch (status) { case WindturbineStatus.Offline: backColor = Color.FromArgb(134, 150, 165); break; case WindturbineStatus.Start: backColor = Color.FromArgb(14, 72, 91); break; case WindturbineStatus.Fault: backColor = Color.FromArgb(170, 15, 59); break; case WindturbineStatus.Maintain: backColor = Color.FromArgb(204, 83, 51); break; case WindturbineStatus.Stop: backColor = Color.FromArgb(176, 151, 63); break; case WindturbineStatus.Online: backColor = Color.FromArgb(15, 135, 170); break; case WindturbineStatus.OnPower: backColor = Color.FromArgb(177, 14, 126); break; case WindturbineStatus.Standby: backColor = Color.FromArgb(15, 141, 106); break; default: break; } changeStatusWindturbineId = windturbineId; UpdateStatus(); } } public void UpdateStatus() { UpdateGridViewDelegate del = new UpdateGridViewDelegate(BackStyleColor); if (gvWindturbine.InvokeRequired) { gvWindturbine.BeginInvoke(del, new object[] { }); } else { BackStyleColor(); } } private void BackStyleColor() { for (int i = 0; i < gvWindturbine.RowCount; i++) { if (gvWindturbine.Rows[i].Cells[1].Value == changeStatusWindturbineId) { gvWindturbine.Rows[i].Cells[1].Style.BackColor = backColor; } } } private void ClearCheck() { for (int i = 0; i < gvWindturbine.RowCount; i++) { gvWindturbine.Rows[i].Cells["Select"].Value = 0; } } /// /// 更新统计类信息 /// private void UpdateStatInfo(string station) { if (station == "") station = "SBQ_FDC"; StatInfo info1 = StatInfoSvc.Instance.GetStatInfoByStation(station); StatInfo info2 = StatInfoSvc.Instance.GeStatInfo(); controlFormTop.BindStationInfo(info1); controlFormTop.BindAllStationInfo(info2); } public override void SelectedStationChanged(string stationId) { MessageBox.Show("风场切换"); } } }