using HStation.WinFrmUI.PhartRelation;
|
using SqlSugar;
|
using Yw.WinFrmUI.Phart;
|
|
namespace HStation.WinFrmUI.Xhs
|
{
|
public partial class SinglePumpCalcCtrl : XtraUserControl
|
{
|
public SinglePumpCalcCtrl()
|
{
|
InitializeComponent();
|
InitChart();
|
}
|
|
private List<SinglePumpCalcViewModel> _list = null;
|
|
#region Init
|
|
private void InitChart()
|
{
|
this.pumpVariableSpeedChart1.LineVisible = true;
|
this.pumpVariableSpeedChart1.LineNameShowHz = true;
|
this.pumpVariableSpeedChart1.SetEasyChart();
|
this.pumpVariableSpeedChart1.AddBySpeedEvent += () =>
|
{
|
AddBySpeed();
|
};
|
|
this.pumpVariableSpeedChart1.AddByHzEvent += () =>
|
{
|
AddByHz();
|
};
|
|
this.pumpVariableSpeedChart1.AddByPointEvent += () =>
|
{
|
AddByPoint();
|
};
|
|
}
|
|
|
private void AddBySpeed()
|
{
|
if (_list == null || _list.Count < 1)
|
{
|
return;
|
}
|
var index = _list.Count;
|
var vm_def = _list.First();
|
var dlg = new SetValueDlg();
|
dlg.SetBindingData(vm_def.RatedSpeed);
|
dlg.VerifyValueChanged += (speed) =>
|
{
|
var hz = Math.Round(speed / vm_def.RatedSpeed * 50, 1);
|
if (hz > 50 || hz < 10)
|
{
|
return false;
|
}
|
var vm = new SinglePumpCalcViewModel(vm_def);
|
vm.Id = Guid.NewGuid().ToString();
|
vm.Name = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
|
vm.Color = GetRandomColor(index);
|
vm.CurrentHz = hz;
|
vm.CurrentSpeed = speed;
|
vm.IsDefault = false;
|
vm.Calc();
|
|
this.pumpVariableSpeedChart1.Add(vm.ToInfo());
|
|
return true;
|
};
|
dlg.ShowDialog();
|
}
|
|
private void AddByHz()
|
{
|
if (_list == null || _list.Count < 1)
|
{
|
return;
|
}
|
|
var index = _list.Count;
|
var vm_def = _list.First();
|
var dlg = new SetValueDlg();
|
dlg.VerifyValueChanged += (hz) =>
|
{
|
if (hz > 50 || hz < 10)
|
{
|
return false;
|
}
|
var speed = Math.Round(hz / 50 * vm_def.RatedSpeed);
|
var vm = new SinglePumpCalcViewModel(vm_def);
|
vm.Id = Guid.NewGuid().ToString();
|
vm.Name = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
|
vm.Color = GetRandomColor(index);
|
vm.CurrentHz = hz;
|
vm.CurrentSpeed = speed;
|
vm.IsDefault = false;
|
vm.Calc();
|
|
this.pumpVariableSpeedChart1.Add(vm.ToInfo());
|
|
return true;
|
};
|
dlg.ShowDialog();
|
}
|
|
private void AddByPoint()
|
{
|
if (_list == null || _list.Count < 1)
|
{
|
return;
|
}
|
var index = _list.Count;
|
var vm_def = _list.First();
|
var dlg = new SetPointDlg();
|
dlg.SetBindingData();
|
dlg.VerifyValueChanged += (x, y) =>
|
{
|
var pt = new Yw.Geometry.Point2d(x, y);
|
var speed = PumpCalcHelper.GetSimuValue(vm_def.Qh, pt, vm_def.RatedSpeed);
|
var hz = Math.Round(speed / vm_def.RatedSpeed * 50, 1);
|
if (hz > 50 || hz < 20)
|
{
|
return false;
|
}
|
var vm = new SinglePumpCalcViewModel(vm_def);
|
vm.Id = Guid.NewGuid().ToString();
|
vm.Name = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
|
vm.Color = GetRandomColor(index);
|
vm.CurrentHz = hz;
|
vm.CurrentSpeed = speed;
|
vm.IsDefault = false;
|
vm.Calc();
|
|
this.pumpVariableSpeedChart1.Add(vm.ToInfo());
|
return true;
|
};
|
dlg.ShowDialog();
|
}
|
|
private Color GetRandomColor(int count)
|
{
|
var color_list = new List<Color>()
|
{
|
Color.Red, Color.Blue, Color.Green,Color.DodgerBlue,
|
Color.Fuchsia, Color.MidnightBlue, Color.Maroon, Color.Aquamarine,
|
Color.Bisque,Color.BurlyWood
|
};
|
|
if (count < color_list.Count)
|
{
|
return color_list[count];
|
}
|
|
var _random = new Random();
|
int r = _random.Next(1, 256);
|
int g = _random.Next(1, 256);
|
int b = _random.Next(1, 256);
|
return Color.FromArgb(r, g, b);
|
}
|
|
#endregion
|
|
private PumpMatchingViewModel _vm = null;
|
public void SetBindindData(PumpMatchingViewModel pump_matching)
|
{
|
_vm = pump_matching;
|
SetChart(pump_matching);
|
}
|
|
//设置图表数据
|
private async void SetChart(PumpMatchingViewModel pump_math)
|
{
|
var db_pump_mian_id = pump_math.DbId;
|
var db_curve_id = pump_math.CurveDbId;
|
if (pump_math.MatchingDbId != null)
|
{
|
db_pump_mian_id = pump_math.MatchingDbId;
|
db_curve_id = pump_math.MatchingCurveDbId;
|
}
|
if (!long.TryParse(db_pump_mian_id, out long pump_main_id))
|
{
|
return;
|
}
|
if (!long.TryParse(db_curve_id, out long curve_id))
|
{
|
return;
|
}
|
var pump_main = await new BLL.AssetsPumpMain().GetByID(pump_main_id);
|
if (pump_main == null)
|
{
|
return;
|
}
|
var phart = await new BLL.XhsPumpMainPhartMappingExtensions().GetByID(curve_id);
|
if (phart == null)
|
{
|
return;
|
}
|
var diagram = phart.Diagram;
|
if (diagram == null)
|
{
|
return;
|
}
|
var graph_list = diagram.GraphList;
|
if (graph_list == null || !graph_list.Any())
|
{
|
return;
|
}
|
|
var graph_qh = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
|
var graph_qe = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
|
var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
|
if (graph_qh == null)
|
{
|
return;
|
}
|
|
List<Yw.Geometry.Point2d> points_qh = null, points_qe = null, points_qp = null;
|
points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 12, null);
|
if (graph_qe != null)
|
points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 12, null);
|
if (graph_qp != null)
|
points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 12, null);
|
|
var qh = new Yw.Geometry.CubicSpline2d(points_qh);
|
var qe = new Yw.Geometry.CubicSpline2d(points_qe);
|
var qp = new Yw.Geometry.CubicSpline2d(points_qp);
|
|
|
var def_vm = new SinglePumpCalcViewModel();
|
def_vm.Id = "def";
|
def_vm.Name = "额定曲线";
|
def_vm.RatedSpeed = pump_main.RatedSpeed;
|
def_vm.CurrentSpeed = pump_main.RatedSpeed;
|
def_vm.CurrentHz = 50;
|
def_vm.IsDefault = true;
|
def_vm.Color = Color.Black;
|
def_vm.ExtendRatio = 100;
|
def_vm.Qh = qh;
|
def_vm.Qe = qe;
|
def_vm.Qp = qp;
|
def_vm.Calc();
|
|
var working_vm = new SinglePumpCalcViewModel();
|
working_vm.Id = "working";
|
working_vm.Name = "设定曲线";
|
working_vm.RatedSpeed = pump_main.RatedSpeed;
|
working_vm.CurrentSpeed = Math.Round(pump_math.CurrentHz / 50 * pump_main.RatedSpeed, 1);
|
working_vm.CurrentHz = pump_math.CurrentHz;
|
working_vm.IsDefault = false;
|
working_vm.Color = Color.Red;
|
working_vm.ExtendRatio = 100;
|
working_vm.Qh = qh;
|
working_vm.Qe = qe;
|
working_vm.Qp = qp;
|
working_vm.Calc();
|
|
var calc_flow = pump_math.CalcuQ;
|
var calc_head = pump_math.CalcuH;
|
|
_list = new List<SinglePumpCalcViewModel>() { def_vm, working_vm };
|
var list_yw = _list.Select(x => x.ToInfo()).ToList();
|
|
this.pumpVariableSpeedChart1.Add(list_yw);
|
|
if (calc_flow.HasValue && calc_head.HasValue)
|
{
|
var flow = Math.Round(calc_flow.Value, 1);
|
var head = Math.Round(calc_head.Value, 1);
|
|
this.pumpVariableSpeedChart1.SetDesignPt(flow, head);
|
}
|
|
}
|
|
}
|
}
|