using DevExpress.XtraCharts; using DevExpress.XtraEditors; using IStation.Model; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; namespace IStation.WinFrmUI.Monitor { public partial class ScadaVerifyPage : DocumentPage { public ScadaVerifyPage() { InitializeComponent(); this.PageTitle.Caption = "工况验证"; this.repDateEdit.ShowToday = false; this.repDateEdit.ShowMonthHeaders = true; this.repDateEdit.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.Vista; this.repDateEdit.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView; this.repDateEdit.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView; this.repDateEdit.Mask.EditMask = "yyyy-MM"; this.repDateEdit.Mask.UseMaskAsDisplayFormat = true; this.barEditDate.EditValue = DateTime.Now.AddYears(-1); this.equipmentExTreeListCtrl1.FocusedChangedEvent += EquipmentExTreeListCtrl1_FocusedChangedEvent; ; this.monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent; InitialChart(); } public class VerifyViewModel : PumpSignalRecord { public VerifyViewModel(Model.PumpSignalRecord rhs) : base(rhs) { } public VerifyViewModel(Model.PumpSignalRecord rhs, DateTime dateTime) : base(rhs) { this.Time = dateTime; } [Display(Name = "时间")] public DateTime Time { get; set; } [Display(Name = "曲线功率")] public double InterPower { get; set; } [Display(Name = "功率差值")] public double PowerDiff { get; set; } [Display(Name = "曲线扬程")] public double InterHead { get; set; } [Display(Name = "扬程差值")] public double HeadDiff { get; set; } } private List _verifyViewModelList = null; private Model.MonitorDataSources _monitorDataSources = null; private Model.Equipment _equipment = 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 XYDiagram _diagram = null; private SecondaryAxisY _secondaryAxisYHead = null; /// /// 初始化图表 /// public void InitialChart() { _diagram = this.chartControl1.Diagram as XYDiagram; _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; _secondaryAxisYHead = _diagram.SecondaryAxesY[0]; this.chartControl1.RuntimeHitTesting = true; this.chartControl1.CrosshairOptions.ShowArgumentLine = false; this.chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; this.chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker; this.chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right; } /// /// 初始化数据 /// public override void InitialDataSource() { this.chartControl1.BeginInit(); this.chartControl1.Series.Clear(); this.chartControl1.EndInit(); this.equipmentExTreeListCtrl1.SetBindingData(); this.monitorDataSourcesTreeList.SetBindingData(); } private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj) { _monitorDataSources = obj; } private void EquipmentExTreeListCtrl1_FocusedChangedEvent(Model.Equipment obj) { _equipment = obj; } //验证 private void barBtnVerify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.barEditDate.EditValue == null) { XtraMessageBox.Show("请选择时间!"); return; } if (_monitorDataSources == null || _equipment == null) return; var lays = this.chartControl1.ShowOverlay(); this.chartControl1.BeginInit(); this.chartControl1.Series.Clear(); this.chartControl1.EndInit(); _verifyViewModelList = new List(); var date = (DateTime)this.barEditDate.EditValue; var packet = new BLL.StationSignalRecordPacket().Get(_monitorDataSources.ID, _equipment.BelongID, date.Year, date.Month); var stationSignalRecords = packet?.StationSignalRecords?.ToList(); if (stationSignalRecords == null || !stationSignalRecords.Any()) { lays.Close(); XtraMessageBox.Show("无数据!"); return; } var pump = new BLL.Equipment().GetByID(_equipment.ID); foreach (var stationSignalRecord in stationSignalRecords) { foreach (var pumpSignalRecord in stationSignalRecord.PumpSignalRecords) { _verifyViewModelList.Add(new VerifyViewModel(pumpSignalRecord, stationSignalRecord.Time)); } } var verifyVMGroup = _verifyViewModelList.GroupBy(x => x.Flag); var bllPumpCurve = new BLL.PumpCurve(); foreach (var item in verifyVMGroup) { var pump = pumps?.Find(x => x.SortCode == item.Key); if (pump == null) continue; var curveInfo = bllPumpCurve.GetDefaultWorkingByPumpID(pump.ID)?.CurveInfo; if (curveInfo == null) continue; var seriesViewPower = new DevExpress.XtraCharts.LineSeriesView(); var seriesPower = new DevExpress.XtraCharts.Series { Name = pump.SortCode + "-功率", View = seriesViewPower, LegendText = pump.SortCode + "-功率" }; var seriesViewHead = new DevExpress.XtraCharts.LineSeriesView(); seriesViewHead.AxisY = _secondaryAxisYHead; var seriesHead = new DevExpress.XtraCharts.Series { Name = pump.SortCode + "-扬程", View = seriesViewHead, LegendText = pump.SortCode + "-扬程" }; foreach (var record in item) { if (record.InstantaneousPower == IStation.Error.Default) { continue; } var rpm = record.Rpm; if (rpm == IStation.Error.Default || rpm < 1) { if (record.Frequency > 0 && record.Frequency != IStation.Error.Default) { rpm = (record.Frequency / 50) * pump.RatedParas.Nr; } else { continue; } } var time = record.Time; var flowRate = record.FlowRate; var curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, pump.RatedParas.Nr, record.Rpm); var curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, pump.RatedParas.Nr, record.Rpm); //if (flowRate < 1) //{ // flowRate = curveQH.GetFitPointY(record.Head); //} record.InterPower = curveQP.GetFitPointY(flowRate); record.PowerDiff = record.InstantaneousPower - record.InterPower; record.PowerDiff = Math.Round(record.PowerDiff, 2); record.InterHead = curveQH.GetFitPointY(flowRate); record.HeadDiff = record.Head - record.InterHead; record.HeadDiff = Math.Round(record.HeadDiff, 2); seriesPower.Points.Add(new SeriesPoint(time, record.PowerDiff)); seriesHead.Points.Add(new SeriesPoint(time, record.HeadDiff)); } if (pump.SortCode != 25) { this.chartControl1.Series.Add(seriesPower); } this.chartControl1.Series.Add(seriesHead); } lays.Close(); } //刷新 private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialDataSource(); } //图表点击 private void chartControl1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (_verifyViewModelList != null && _verifyViewModelList.Any()) { var hitInfo = chartControl1.CalcHitInfo(e.Location); if (hitInfo.InChart) { var diagramCoordinates = _diagram.PointToDiagram(e.Location); var axisValue = diagramCoordinates.GetAxisValue(_diagram.AxisX); if (axisValue == null) return; var pt_dt = axisValue.DateTimeValue; var vm = _verifyViewModelList.Find(x => x.Time == pt_dt); if (vm == null) { vm = _verifyViewModelList.FindLast(x => x.Time > pt_dt); } this.propertyGridControl1.SelectedObject = vm; } } } } } }