using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; 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.ControlLog; using IntelligentControlForsx.Service.ControlLog.Domain; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; namespace IntelligentControlForsx.MyControls.logInfo { public partial class ControlLog : UserControl { public ControlLog() { InitializeComponent(); } public void DeActive() { } public void Active() { dtEndTime.Value = DateTime.Now; } public void BindDataControlInfo() { using (wisdom_cs_entity ctx = new wisdom_cs_entity()) { IList userList = new List(); user u = new user(); u.id = -1; u.name = "请选择"; userList.Add(u); userList = userList.Union(ctx.user.Select(s => s).ToList()).ToList(); this.cbUser.DataSource = userList; this.cbUser.DisplayMember = "name"; this.cbUser.ValueMember = "id"; this.cbUser.SelectedValue = -1; IList windturbinelList = new List(); IList windturbineList = ctx.windturbine.Where(s => s.WINDPOWERSTATIONID == "SBQ_FDC").ToList().OrderBy(s => Convert.ToInt32(Regex.Replace(s.ID, "[a-zA-Z]", "").Replace("_", ""))).ToList(); windturbinelList.Add(new WindturbineSelectEntity("0", "请选择")); for (int i = 0; i < windturbineList.Count; i++) { windturbinelList.Add(new WindturbineSelectEntity(windturbineList[i].ID, windturbineList[i].ID)); } this.cbWindturbine.DataSource = windturbinelList; this.cbWindturbine.DisplayMember = "WindturbineName"; this.cbWindturbine.ValueMember = "WindturbineId"; this.cbWindturbine.SelectedValue = "0"; } IList controlList = new List(); controlList.Add(new ControlTypeEntity(CmdType.LimitPower, "请选择")); controlList.Add(new ControlTypeEntity(CmdType.Start, "启动")); controlList.Add(new ControlTypeEntity(CmdType.Stop, "停止")); controlList.Add(new ControlTypeEntity(CmdType.Reset, "复位")); controlList.Add(new ControlTypeEntity(CmdType.UnMaintain, "取消维护")); controlList.Add(new ControlTypeEntity(CmdType.Maintain, "维护")); this.cbControlType.DataSource = controlList; this.cbControlType.DisplayMember = "ControlName"; this.cbControlType.ValueMember = "ControlType"; this.cbControlType.SelectedValue = CmdType.LimitPower; this.dtStartTime.CustomFormat = "yyyy-MM-dd hh:mm:ss"; this.dtStartTime.Format = DateTimePickerFormat.Custom; this.dtEndTime.CustomFormat = "yyyy-MM-dd hh:mm:ss"; this.dtEndTime.Format = DateTimePickerFormat.Custom; DateTime endTime = DateTime.Now; DateTime startTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); this.dtStartTime.Value = startTime; this.dtEndTime.Value = endTime; IList stationList = new List(); stationList.Add(new StationEntity("123", "请选择")); stationList.Add(new StationEntity("SBQ_FDC", "石板泉风电场")); stationList.Add(new StationEntity("MHS_FDC", "麻黄山风电场")); stationList.Add(new StationEntity("NSS_FDC", "牛首山风电场")); stationList.Add(new StationEntity("QS_FDC", "青山风电场")); stationList.Add(new StationEntity("XS_FDC", "香山风电场")); cbStation.DataSource = stationList; this.cbStation.DisplayMember = "StationName"; this.cbStation.ValueMember = "StationId"; cbStation.SelectedValue = "SBQ_FDC"; cbStation.Enabled = false; } private void ConditionChange() { SearchCondition condition = new SearchCondition(); DateTime? startTime = dtStartTime.Value; DateTime? endTime = dtEndTime.Value; int? userId = null; CmdType? controlType = null; string userIdString = cbUser.SelectedValue.ToString().Trim(); string controlTypeString = cbControlType.SelectedValue == null ? "" : cbControlType.SelectedValue.ToString().Trim(); string windturbineIdString = cbWindturbine.SelectedValue == null ? "" : cbWindturbine.SelectedValue.ToString().Trim(); string stationId = cbStation.SelectedValue == null ? "" : cbStation.SelectedValue.ToString().Trim(); if (!string.IsNullOrEmpty(userIdString) && !userIdString.Contains("user") && userIdString != "-1") userId = Convert.ToInt32(userIdString); if (!string.IsNullOrEmpty(controlTypeString) && !controlTypeString.Contains("ControlTypeEntity") && controlTypeString != "4") controlType = (CmdType)Enum.Parse(typeof(CmdType), controlTypeString); condition.StartTime = startTime; condition.EndTime = endTime; if (userId.HasValue) condition.UserId = userId.Value; if (controlType.HasValue && controlType != CmdType.LimitPower) condition.ControlType = controlType.Value; if (!string.IsNullOrEmpty(windturbineIdString) && windturbineIdString != "0") condition.WindturbineId = windturbineIdString; if (!string.IsNullOrEmpty(stationId)) condition.Station = stationId; gvInfo.DataSource = ControlLogInfoSvc.GetControlInfo(condition); } private void ControlLog_Load(object sender, EventArgs e) { //Thread t = new Thread(BindFormInvoke); //t.Start(); } private void cbUser_SelectedIndexChanged(object sender, EventArgs e) { ConditionChange(); } private void cbControlType_SelectedIndexChanged(object sender, EventArgs e) { ConditionChange(); } private void cbWindturbine_SelectedIndexChanged(object sender, EventArgs e) { ConditionChange(); } private void dtStartTime_ValueChanged(object sender, EventArgs e) { ConditionChange(); } private void dtEndTime_ValueChanged(object sender, EventArgs e) { ConditionChange(); } public delegate void UpdateFormInfoDelegate(); public void BindFormInvoke() { UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(BindDataControlInfo); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { BindDataControlInfo(); } } } }