using IStation.Unit; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; namespace IStation.WinFrmUI.Monitor { public partial class DataComparePage : DocumentPage { public DataComparePage() { InitializeComponent(); this.PageTitle.Caption = "数据比较"; this.monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent; ; this.multiMonitorPointTreeList1.CheckChangedEvent += MultiMonitorPointTreeList1_CheckChangedEvent; } private class CurrentViewModel { public long ID { get; set; } public long SignalID { get; set; } public string Name { get; set; } public string AxisYTitle { get; set; } public Color Color { get; set; } } private Model.MonitorDataSources _dataSource = null; private BLL.MonitorDataSet _bll = new BLL.MonitorDataSet(); private Dictionary _timeViewDict = null; /// /// 初始化数据 /// public override void InitialDataSource() { _timeViewDict = new Dictionary(); this.timeValueSwiftPlotChartView1.ClearSeries(); this.timeValueSwiftPlotChartView1.SetTimeAxisX(DevExpress.XtraCharts.DateTimeMeasureUnit.Minute); this.monitorDataSourcesTreeList.SetBindingData(); this.multiMonitorPointTreeList1.SetBindingData(); } private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj) { SetBindingData(obj); } private void MultiMonitorPointTreeList1_CheckChangedEvent(Model.MonitorPointExSignalWithSignalType monitorPoint, System.Drawing.Color color, bool cek) { SetBindingData(_dataSource, monitorPoint, color, cek); } private void SetBindingData(Model.MonitorDataSources monitorDataSources) { _dataSource = monitorDataSources; if (_dataSource == null) { this.timeValueSwiftPlotChartView1.ClearSeries(); } else { var year = new BLL.MonitorDataSetSummary().GetMaxMinTime(_dataSource.ID,out DateTime min,out DateTime max); if ((max - min).TotalDays < 2) { this.timeValueSwiftPlotChartView1.SetTimeAxisX(DevExpress.XtraCharts.DateTimeMeasureUnit.Second); } else { this.timeValueSwiftPlotChartView1.SetTimeAxisX(DevExpress.XtraCharts.DateTimeMeasureUnit.Minute); } _currentMonitorDataSourcesId = _dataSource.ID; this.timeValueSwiftPlotChartView1.ClearSeries(); foreach (var item in _timeViewDict) { var timeValues = new List(); var packet = _bll.GetSignalRecordPacket(_dataSource.ID, item.Value.ID, item.Value.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, 4))).ToList(); } } this.timeValueSwiftPlotChartView1.AddSwiftPlotSeries(item.Value.ID.ToString(), item.Value.Color, item.Value.Name, item.Value.AxisYTitle, timeValues); } } } private long _currentMonitorDataSourcesId = 0; private void SetBindingData(Model.MonitorDataSources scene, Model.MonitorPointExSignalWithSignalType monitorPoint, System.Drawing.Color color, bool cek) { _dataSource = scene; if (_dataSource == null) { this.timeValueSwiftPlotChartView1.ClearSeries(); } else { if (_currentMonitorDataSourcesId != _dataSource.ID) { SetBindingData(_dataSource); } if (cek) { if (_timeViewDict.ContainsKey(monitorPoint.MonitorPointID)) return; var timeValues = new List(); var packet = _bll.GetSignalRecordPacket(_dataSource.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, 4))).ToList(); } } var axisYTitle = monitorPoint.UnitValue; if (int.TryParse(monitorPoint.UnitValue, out int unitValue)) { var dict = UnitHelper.GetEnUnitDict(monitorPoint.UnitType); if (dict != null) axisYTitle = dict[unitValue]; } _timeViewDict.Add(monitorPoint.MonitorPointID, new CurrentViewModel() { ID = monitorPoint.MonitorPointID, SignalID = monitorPoint.SignalID, Name = monitorPoint.Name, AxisYTitle = axisYTitle, Color = color }); this.timeValueSwiftPlotChartView1.AddSwiftPlotSeries(monitorPoint.MonitorPointID.ToString(), color, monitorPoint.Name, axisYTitle, timeValues); } else { if (!_timeViewDict.ContainsKey(monitorPoint.MonitorPointID)) return; _timeViewDict.Remove(monitorPoint.MonitorPointID); this.timeValueSwiftPlotChartView1.RemoveSeries(monitorPoint.MonitorPointID.ToString()); } } } // 刷新数据 private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialDataSource(); } private void barBtnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var ids = _timeViewDict.Select(x => x.Key).ToList(); ExportTestHelper.Export(_dataSource.ID, ids, 2024, 10); } } }