using DevExpress.XtraCharts; using System; using System.Collections.Generic; using System.Linq; namespace IStation.WinFrmUI.Monitor { public partial class OperationalViewPage : DocumentPage { public OperationalViewPage() { InitializeComponent(); PageTitle.Caption = "运行视图"; stationListCtrl1.FocusedChangedEvent += StationListCtrl1_FocusedChangedEvent; monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent; } public class CurrentViewModel { public string Month { get; set; } public string Hour { get; set; } public int RunCount { get; set; } } private List _allBindingList = null; private Model.MonitorDataSources _monitorDataSources = null; private Model.Station _station = null; private readonly BLL.MonitorDataSet _bll = new BLL.MonitorDataSet(); private readonly BLL.EquipmentMonitorMapping _bllEquipmentMonitorMapping = new BLL.EquipmentMonitorMapping(); private readonly BLL.MonitorPoint _bllMonitorPoint = new BLL.MonitorPoint(); private GanttDiagram _diagram = null; /// /// 初始化数据 /// public override void InitialDataSource() { _diagram = chartControl1.Diagram as GanttDiagram; _diagram.EnableAxisXScrolling = true; _diagram.EnableAxisYScrolling = true; _diagram.EnableAxisXZooming = true; _diagram.EnableAxisYZooming = true; _diagram.AxisX.CrosshairAxisLabelOptions.Visibility = DevExpress.Utils.DefaultBoolean.False; _diagram.AxisX.GridLines.Visible = true; _diagram.AxisY.GridLines.Visible = false; chartControl1.CrosshairOptions.ShowArgumentLine = false; chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker; chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right; stationListCtrl1.SetBindingData(); monitorDataSourcesTreeList.SetBindingData(); } private void StationListCtrl1_FocusedChangedEvent(Model.Station obj) { _station = obj; OperationalAnalysis(_monitorDataSources, _station); } private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj) { _monitorDataSources = obj; OperationalAnalysis(_monitorDataSources, _station); } private void OperationalAnalysis(Model.MonitorDataSources monitorDataSources, Model.Station station) { chartControl1.BeginInit(); chartControl1.Series.Clear(); chartControl1.EndInit(); _allBindingList = new List(); var lays = chartControl1.ShowOverlay(); if (monitorDataSources != null && station != null) { var enginePumps = new BLL.Equipment().GetEnginePumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID); foreach (var item in enginePumps) { CreateSeries(item); } } lays.Close(); } private void CreateSeries(Model.Equipment equipment) { var mappings = _bllEquipmentMonitorMapping.GetByEquipmentID(equipment.ID); var timeValues = new List(); if (mappings != null && mappings.Any()) { var ids = mappings.Select(x => x.MonitorPointID).ToList(); var monitorPoints = _bllMonitorPoint.GetExSignalWithSignalTypeByIds(ids); if (monitorPoints != null && monitorPoints.Any()) { var monitorPoint = monitorPoints.Find(x => x.SignalType == IStation.SignalType.运行状态); if (monitorPoint != null) { var packet = _bll.GetSignalRecordPacket(_monitorDataSources.ID, monitorPoint.MonitorPointID, monitorPoint.SignalID); if (packet != null) { var records = packet.RecordList; if (records != null && records.Any()) { timeValues = records.Where(x => x.Value != IStation.Error.Default && x.Value != IStation.Error.Abnormal). Select(x => new TimeValue(x.Time, Math.Round(x.Value, 1))).ToList(); } } } } } var series = new DevExpress.XtraCharts.Series(); var sideBySideGanttSeriesView = new DevExpress.XtraCharts.OverlappedGanttSeriesView(); series.Name = equipment.ID.ToString(); series.ValueScaleType = DevExpress.XtraCharts.ScaleType.DateTime; series.View = sideBySideGanttSeriesView; series.LegendText = equipment.Name; series.CrosshairLabelPattern = "开:{V1:yy-M-d HH:mm} 关:{V2:yy-M-d HH:mm}"; if (timeValues.Any()) { DateTime? min = null, max = null; for (int i = 0; i < timeValues.Count; i++) { var item = timeValues[i]; if (item.Value == IStation.RunStatus.Run) { if (min == null) min = item.Time; else max = item.Time; } else { if (min != null && max != null) { var runSeriesPoint = new SeriesPoint(equipment.Name, new DateTime[] { min.Value, max.Value }); var timeSpan = (max.Value - min.Value); var timeSpanInfo = $"{timeSpan.TotalHours}H"; var txt = runSeriesPoint.Annotations.AddTextAnnotation(timeSpanInfo); txt.AutoSize = true; txt.Visible = true; series.Points.Add(runSeriesPoint); max = min = null; } } } } chartControl1.Series.Add(series); } private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialDataSource(); } } }