using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw.Geometry;
using Yw.Pump;
using Yw.WinFrmUI.Phart;
namespace HStation.WinFrmUI
{
public partial class SimulationPumpFeatCtrl : DevExpress.XtraEditors.XtraUserControl
{
public SimulationPumpFeatCtrl()
{
InitializeComponent();
this.layoutControl1.SetupLayoutControl();
this.hydroPumpListStateEditCtrl1.SelectedChangedEvent += HydroPumpListStateEditCtrl1_SelectedChangedEvent;
}
///
/// 保存事件
///
public event Action> SaveEvent;
///
///
///
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
{
this.hydroPumpListStateEditCtrl1.SetBindingData(hydroInfo);
}
private void HydroPumpListStateEditCtrl1_SelectedChangedEvent(HydroPumpListItemStateViewModel obj)
{
var vm = CreateViewModel(obj);
this.pumpOperationChart1.SetBindingData(vm);
}
//创建
private PumpOperationViewModel CreateViewModel(HydroPumpListItemStateViewModel state)
{
var vm = new PumpOperationViewModel();
vm.Id = state.Code;
vm.Name = state.Name;
vm.RatedQ = state.Vmo.RatedQ.HasValue ? state.Vmo.RatedQ.Value : 0;
vm.RatedH = state.Vmo.RatedH.HasValue ? state.Vmo.RatedH.Value : 0;
vm.RatedP = state.Vmo.RatedP;
vm.RatedN = state.Vmo.RatedN.HasValue ? state.Vmo.RatedN.Value : 0;
vm.RatedHz = state.Vmo.RatedHz;
vm.CurrentHz = state.CurrentHz;
vm.CurrentN = Math.Round(state.CurrentHz / state.Vmo.RatedHz * vm.RatedN, 1);
vm.CurrentStatus = state.LinkStatus == Yw.Hydro.PumpStatus.Open;
var curveqh = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQH);
if (curveqh != null)
{
var qh_pts = curveqh.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qh_pts != null && qh_pts.Count > 3)
{
vm.CurveQH = new CubicSpline2d(qh_pts);
var qh_current_pts = qh_pts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
vm.CurrentCurveQH = new CubicSpline2d(qh_current_pts);
}
}
var curveqp = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQP);
if (curveqp != null)
{
var qppts = curveqp.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qppts != null && qppts.Count > 3)
{
vm.CurveQP = new CubicSpline2d(qppts);
var sqppts = qppts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
vm.CurrentCurveQP = new CubicSpline2d(sqppts);
}
}
var curveqe = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQE);
if (curveqe != null)
{
var qepts = curveqe.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
if (qepts != null && qepts.Count > 3)
{
vm.CurveQE = new CubicSpline2d(qepts);
var sqepts = qepts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
vm.CurrentCurveQE = new CubicSpline2d(sqepts);
}
}
return vm;
}
///
/// 保存
///
public void Save()
{
if (this.hydroPumpListStateEditCtrl1.HasChanged)
{
var result = XtraMessageBox.Show("是否使用现有水泵状态更新模型?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes;
if (result)
{
var allWorkingList = this.hydroPumpListStateEditCtrl1.GetWorkingList();
this.SaveEvent?.Invoke(allWorkingList);
}
}
}
}
}