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();
|
PageTitle.Caption = "工况验证";
|
|
repDateEdit.ShowToday = false;
|
repDateEdit.ShowMonthHeaders = true;
|
repDateEdit.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.Vista;
|
repDateEdit.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
|
repDateEdit.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;
|
repDateEdit.Mask.EditMask = "yyyy-MM";
|
repDateEdit.Mask.UseMaskAsDisplayFormat = true;
|
barEditDate.EditValue = DateTime.Now.AddMonths(-1); //DateTime.Now.AddYears(-1);
|
|
equipmentExTreeListCtrl1.FocusedChangedEvent += EquipmentExTreeListCtrl1_FocusedChangedEvent; ;
|
monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent;
|
|
gridView1.SetNormalView();
|
|
repositoryItemDateEdit1.SetShowClock();
|
repositoryItemDateEdit2.SetShowClock();
|
barEditStartTime.EditValue = new DateTime(2024, 07, 01, 00, 00, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 08, 1);
|
InitialChart();
|
}
|
|
|
public class VerifyViewModel : PumpSignalRecord
|
{
|
|
public VerifyViewModel(Model.PumpSignalRecord rhs) : base(rhs) { }
|
public VerifyViewModel(Model.PumpSignalRecord rhs, DateTime dateTime) : base(rhs)
|
{
|
Time = dateTime;
|
}
|
|
[Display(Name = "时间", Order = 0)]
|
public DateTime Time { get; set; }
|
|
|
[Display(Name = "曲线功率", Order = 11)]
|
public double InterPower { get; set; }
|
[Display(Name = "功率差值", Order = 12)]
|
public double PowerDiff { get; set; }
|
|
[Display(Name = "曲线扬程", Order = 9)]
|
public double InterHead { get; set; }
|
[Display(Name = "扬程差值", Order = 10)]
|
public double HeadDiff { get; set; }
|
|
[Display(Name = "效率", Order = 8)]
|
public double Eff { get; set; }
|
}
|
|
|
private List<VerifyViewModel> _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;
|
|
|
/// <summary>
|
/// 初始化图表
|
/// </summary>
|
public void InitialChart()
|
{
|
_diagram = 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.Color = System.Drawing.Color.LightCoral;
|
|
_diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Second;
|
_diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Manual;
|
_diagram.AxisX.GridLines.Visible = true;
|
_diagram.AxisY.GridLines.Visible = false;
|
_secondaryAxisYHead = _diagram.SecondaryAxesY[0];
|
|
|
chartControl1.RuntimeHitTesting = true;
|
chartControl1.CrosshairOptions.ShowArgumentLine = false;
|
chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True;
|
chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker;
|
chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
|
}
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
chartControl1.BeginInit();
|
chartControl1.Series.Clear();
|
chartControl1.EndInit();
|
|
equipmentExTreeListCtrl1.SetBindingData();
|
monitorDataSourcesTreeList.SetBindingData();
|
}
|
|
private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj)
|
{
|
_monitorDataSources = obj;
|
}
|
|
private bool _use = false;
|
private void EquipmentExTreeListCtrl1_FocusedChangedEvent(Model.Equipment obj)
|
{
|
_equipment = obj;
|
if (obj == null)
|
return;
|
if (_use)
|
{
|
|
|
switch (obj.SortCode)
|
{ //21#e172 12:47-13:10
|
//22#f173 13:20-13:36
|
//23#d171 12:22-12:32
|
//24#c170 11:56-12:10
|
//25#b169 10:43-10:58
|
//26#a168 9:59-10:31
|
//27#g174 13:54-14:07
|
case 21:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 12, 47, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 13, 10, 00);
|
}
|
break;
|
case 22:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 13, 20, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 13, 36, 00);
|
}
|
break;
|
case 23:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 12, 22, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 12, 32, 00);
|
}
|
break;
|
case 24:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 11, 56, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 12, 10, 00);
|
}
|
break;
|
case 25:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 10, 43, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 10, 58, 00);
|
}
|
break;
|
case 26:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 09, 59, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 10, 31, 00);
|
}
|
break;
|
case 27:
|
{
|
barEditStartTime.EditValue = new DateTime(2024, 05, 14, 13, 54, 00);
|
barEditEndTime.EditValue = new DateTime(2024, 05, 14, 14, 07, 00);
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
}
|
|
//验证
|
private void barBtnVerify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (barEditDate.EditValue == null)
|
{
|
XtraMessageBox.Show("请选择时间!");
|
return;
|
}
|
if (_monitorDataSources == null || _equipment == null)
|
return;
|
var lays = chartControl1.ShowOverlay();
|
chartControl1.BeginInit();
|
chartControl1.Series.Clear();
|
chartControl1.EndInit();
|
_verifyViewModelList = new List<VerifyViewModel>();
|
|
var pump = new BLL.Equipment().GetChildPumpByEnginePumpID(_equipment.ID);
|
|
var date = (DateTime)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;
|
}
|
|
foreach (var stationSignalRecord in stationSignalRecords)
|
{
|
foreach (var pumpSignalRecord in stationSignalRecord.PumpSignalRecords)
|
{
|
if (pumpSignalRecord.Flag != pump.SortCode)
|
continue;
|
var time = stationSignalRecord.Time;
|
var rpm = pumpSignalRecord.Rpm;
|
var fre = pumpSignalRecord.Frequency;
|
|
|
var time_min = Convert.ToDateTime(barEditStartTime.EditValue);
|
var time_max = Convert.ToDateTime(barEditEndTime.EditValue);
|
if (time >= time_min && time <= time_max)
|
{
|
var vm = new VerifyViewModel(pumpSignalRecord, time);
|
_verifyViewModelList.Add(vm);
|
}
|
|
}
|
}
|
|
var curveInfo = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID)?.CurveInfo;
|
if (curveInfo == null)
|
{
|
lays.Close();
|
return;
|
}
|
|
var seriesViewPower = new DevExpress.XtraCharts.LineSeriesView();
|
seriesViewPower.Color = System.Drawing.Color.LightCoral;
|
var seriesPower = new DevExpress.XtraCharts.Series
|
{
|
Name = pump.SortCode + "-功率",
|
View = seriesViewPower,
|
LegendText = pump.SortCode + "-功率"
|
};
|
|
var seriesViewHead = new DevExpress.XtraCharts.LineSeriesView();
|
seriesViewHead.AxisY = _secondaryAxisYHead;
|
seriesViewHead.Color = System.Drawing.Color.DodgerBlue;
|
var seriesHead = new DevExpress.XtraCharts.Series
|
{
|
Name = pump.SortCode + "-扬程",
|
View = seriesViewHead,
|
LegendText = pump.SortCode + "-扬程"
|
};
|
|
foreach (var record in _verifyViewModelList)
|
{
|
if (record.Flag > 18)
|
{
|
if (record.FlowRate < 1)
|
{
|
continue;
|
}
|
}
|
|
if (record.Head == IStation.Error.Default || record.Head == 0)
|
{
|
continue;
|
}
|
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 hz = record.Rpm / pump.RatedParas.Nr * 50;
|
//hz = Math.Round(hz);
|
//if (hz != 45)
|
// continue;
|
|
var time = record.Time;
|
var flowRate = record.FlowRate;
|
|
Model.CurveExpress curveQH, curveQP;
|
//if (record.Frequency==0|| record.Frequency==IStation.Error.Default)
|
//{
|
curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, pump.RatedParas.Nr, record.Rpm);
|
curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, pump.RatedParas.Nr, record.Rpm);
|
//}
|
//else
|
//{
|
// curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, 50, record.Frequency);
|
// curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, 50, record.Frequency);
|
//}
|
if (curveQH == null || curveQP == null)
|
continue;
|
if (flowRate < 1)
|
{
|
var qhPoints = curveQH.GetFitPoints();
|
Model.FitCurveHelper.GetInterPointX(qhPoints, record.Head, out flowRate);
|
}
|
|
record.InterPower = Math.Round(curveQP.GetFitPointY(flowRate), 2);
|
record.PowerDiff = record.InstantaneousPower - record.InterPower;
|
record.PowerDiff = Math.Round(record.PowerDiff, 2);
|
seriesPower.Points.Add(new SeriesPoint(time, record.PowerDiff));
|
|
if (record.Flag > 19)
|
{
|
record.InterHead = Math.Round(curveQH.GetFitPointY(flowRate), 2);
|
record.HeadDiff = record.Head - record.InterHead;
|
record.HeadDiff = Math.Round(record.HeadDiff, 2);
|
seriesHead.Points.Add(new SeriesPoint(time, record.HeadDiff));
|
}
|
|
|
record.Eff = Model.CurveCalcuHelper.CalculateE(flowRate, record.Head, record.InstantaneousPower);
|
}
|
|
chartControl1.Series.Add(seriesPower);
|
if (pump.SortCode > 19)
|
{
|
chartControl1.Series.Add(seriesHead);
|
}
|
|
lays.Close();
|
|
verifyViewModelBindingSource.DataSource = _verifyViewModelList;
|
verifyViewModelBindingSource.ResetBindings(false);
|
}
|
|
//刷新
|
private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
InitialDataSource();
|
}
|
|
//图表点击
|
private void chartControl1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
|
{
|
if (chartControl1.Series.Count < 1)
|
return;
|
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);
|
}
|
propertyGridControl1.Text = "数据";
|
propertyGridControl1.SelectedObject = vm;
|
}
|
}
|
}
|
}
|
|
|
//导出表格
|
private void barBtnExportExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
gridView1.ExportExcel();
|
}
|
|
|
private void barBtnExportWaterDesk_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (barEditDate.EditValue == null)
|
{
|
XtraMessageBox.Show("请选择时间!");
|
return;
|
}
|
if (_monitorDataSources == null || _equipment == null)
|
return;
|
|
var start_date = (DateTime)barEditStartTime.EditValue;
|
var end_date = (DateTime)barEditDate.EditValue;
|
|
var dlg = new SetTimeStepDlg();
|
dlg.SetBindingData(300);
|
dlg.ReloadDataEvent += (timeStep) =>
|
{
|
//Task.Run(() =>
|
//{
|
// this.Invoke(new Action(() =>
|
// {
|
// AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "开始导出!");
|
// }));
|
// ExportWaterDeskHelper.Export(_monitorDataSources.ID,_equipment.BelongID, year,month, timeStep);
|
// this.Invoke(new Action(() =>
|
// {
|
// AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
|
// }));
|
//});
|
|
WaitFrmHelper.ShowWaitForm("正在导出");
|
ExportWaterDeskHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep);
|
WaitFrmHelper.HideWaitForm();
|
AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
|
|
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barBtnExportEapnet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (barEditDate.EditValue == null)
|
{
|
XtraMessageBox.Show("请选择时间!");
|
return;
|
}
|
if (_monitorDataSources == null || _equipment == null)
|
return;
|
|
|
var date = (DateTime)barEditDate.EditValue;
|
var year = date.Year;
|
var month = date.Month;
|
var dlg = new SetTimeStepDlg();
|
dlg.SetBindingData(300);
|
dlg.ReloadDataEvent += (timeStep) =>
|
{
|
WaitFrmHelper.ShowWaitForm("正在导出");
|
//ExportEpanetHelper.ExportByDay(_monitorDataSources.ID, _equipment.BelongID, year, month, timeStep);
|
ExportEpanetHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep);
|
|
WaitFrmHelper.HideWaitForm();
|
AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
|
};
|
dlg.ShowDialog();
|
}
|
}
|
}
|