using DevExpress.XtraGrid.Views.Grid;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Analy
|
{
|
public partial class ParallelCurvePage_bak : DocumentPage// DevExpress.XtraEditors.XtraUserControl//
|
{
|
|
public ParallelCurvePage_bak()
|
{
|
InitializeComponent();
|
|
this.PageTitle.Caption = "曲线并联";
|
this.gridView1.SetNormalEditView();
|
this.gridView1.OptionsSelection.MultiSelect = false;//单选
|
this.gridView1.OptionsBehavior.Editable = true;//
|
this.gridView1.BestFitColumns();
|
|
this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanged);
|
this.gridView1.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanging);
|
this.gridView1.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridView_RowCellClick);
|
|
this.pumpCurveTreeList1.ClickAddCurveEvent += (stationName, pump, curve) =>
|
{
|
AddCurve(stationName, pump, curve);
|
CreateConnectCurve();
|
};
|
|
this.mainChart.OnCalcQueryPoint += (id, pt) =>
|
{
|
SetQueryInfo(id, pt);
|
};
|
}
|
|
|
public class CurrentViewModel
|
{
|
public long ID { get; set; }
|
|
public Color DispColor
|
{
|
set { _dispColor = value; }
|
get { return _dispColor; }
|
}
|
private Color _dispColor = Color.Black;
|
public string StationName { get; set; }
|
public string PumpName { get; set; }
|
public string CurveName { get; set; }
|
public string QueryPtQ { get; set; }
|
public string QueryPtH { get; set; }
|
public string QueryPtE { get; set; }
|
public string QueryPtP { get; set; }
|
public bool IsFrequency { get; set; }
|
public double ConnFrequence { get; set; }
|
public double ExtendRatio { get; set; } = 100;
|
|
public Model.CurveExpress CurveOriginQH { get; set; }
|
public Model.CurveExpress CurveOriginQE { get; set; }
|
public Model.CurveExpress CurveOriginQP { get; set; }
|
|
public Model.CurveExpress CurveRunQH { get; set; }
|
public Model.CurveExpress CurveRunQE { get; set; }
|
public Model.CurveExpress CurveRunQP { get; set; }
|
|
public double RunMaxFlowByTest = 0;
|
|
public void CalcRunCurve()
|
{
|
if (ConnFrequence > 50)
|
return;
|
if (ConnFrequence < 20)
|
return;
|
this.CurveRunQH = IStation.Common.CutSimuCalculer.GetSimuPointQH(CurveOriginQH, 2900, 2900 * ConnFrequence / 50);
|
this.CurveRunQE = IStation.Common.CutSimuCalculer.GetSimuPointQE(CurveOriginQE, 2900, 2900 * ConnFrequence / 50);
|
this.CurveRunQP = IStation.Common.CutSimuCalculer.GetSimuPointQP(CurveOriginQP, 2900, 2900 * ConnFrequence / 50);
|
RunMaxFlowByTest = this.CurveRunQH.Max;
|
|
this.CurveRunQH.Max = this.CurveRunQH.Max * ExtendRatio / 100;
|
this.CurveRunQE.Max = this.CurveRunQE.Max * ExtendRatio / 100;
|
this.CurveRunQP.Max = this.CurveRunQP.Max * ExtendRatio / 100;
|
}
|
public List<Model.CurvePoint> PointsQH { get; set; }
|
public List<Model.CurvePoint> PointsQE { get; set; }
|
public List<Model.CurvePoint> PointsQP { get; set; }
|
}
|
|
private BindingList<CurrentViewModel> _allBindingList = null;
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
_allBindingList = new BindingList<CurrentViewModel>();
|
this.bindingSource1.DataSource = _allBindingList;
|
this.pumpCurveTreeList1.SetBindingData();
|
}
|
|
/// <summary>
|
/// 添加曲线
|
/// </summary>
|
/// <param name="stationName"></param>
|
/// <param name="pump"></param>
|
/// <param name="pumpCurve"></param>
|
public void AddCurve(string stationName, Model.Equipment<Model.Pump> pump, Model.PumpCurve pumpCurve)
|
{
|
foreach (var it in _allBindingList)
|
{
|
if (it.ID == pumpCurve.ID)
|
{
|
return;
|
}
|
}
|
if (pumpCurve.CurveInfo == null || pumpCurve.CurveInfo.CurveQH == null)
|
return;
|
var curveInfo = pumpCurve.CurveInfo;
|
if (curveInfo.CurveQH == null)
|
return;
|
|
var vm = new CurrentViewModel();
|
vm.PumpName = pump.Name;
|
vm.CurveName = pumpCurve.CurveCode;
|
vm.ID = pumpCurve.ID;
|
|
|
List<Model.CurvePoint> qhPoints, qePoints = null, qpPoints = null;
|
if (curveInfo.CurveQH.DefinePoints != null)
|
qhPoints = curveInfo.CurveQH.DefinePoints;
|
else
|
qhPoints = curveInfo.CurveQH.GetFitPoints(12);
|
|
if (curveInfo.CurveQE != null)
|
if (curveInfo.CurveQE.DefinePoints != null)
|
qePoints = curveInfo.CurveQE.DefinePoints;
|
else
|
qePoints = curveInfo.CurveQE?.GetFitPoints(12);
|
|
if (curveInfo.CurveQP != null)
|
if (curveInfo.CurveQP?.DefinePoints != null)
|
qpPoints = curveInfo.CurveQP.DefinePoints;
|
else
|
qpPoints = curveInfo.CurveQP?.GetFitPoints(12);
|
|
|
|
vm.PointsQH = qhPoints;
|
vm.PointsQE = qePoints;
|
vm.PointsQP = qpPoints;
|
|
if (qhPoints.Any())
|
{
|
var fitType = curveInfo.CurveQH.FitType;
|
vm.CurveOriginQH = Model.FitCurveHelper.BuildCurveExpress(qhPoints, fitType);
|
}
|
if (qePoints.Any())
|
{
|
var fitType = curveInfo.CurveQE.FitType;
|
vm.CurveOriginQE = Model.FitCurveHelper.BuildCurveExpress(qePoints, fitType);
|
}
|
if (qpPoints.Any())
|
{
|
var fitType = curveInfo.CurveQP.FitType;
|
vm.CurveOriginQP = Model.FitCurveHelper.BuildCurveExpress(qpPoints, fitType);
|
}
|
|
vm.CurveRunQH = vm.CurveOriginQH;
|
vm.CurveRunQE = vm.CurveOriginQE;
|
vm.CurveRunQP = vm.CurveOriginQP;
|
|
vm.RunMaxFlowByTest = vm.CurveOriginQH.Max;
|
|
var color = GetCurveColor();
|
|
vm.DispColor = color;
|
vm.StationName = stationName;
|
vm.IsFrequency = pump.RatedParas == null ? false : pump.RatedParas.IsBp;
|
vm.ConnFrequence = 50;
|
vm.ExtendRatio = 100;
|
|
_allBindingList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
|
|
this.mainChart.AddCurve(vm.ID, $"{stationName}-{pump.Name}", vm.CurveOriginQH, vm.CurveOriginQE, vm.CurveOriginQP, color);
|
}
|
|
/// <summary>
|
/// 创建并联曲线
|
/// </summary>
|
private void CreateConnectCurve()
|
{
|
mainChart.DeleteCurve(-1);
|
if (_allBindingList.Count < 2)
|
{
|
return;
|
}
|
|
var theConnectCurve = new Model.ConnectCurveHelper();
|
// 计算并联后的曲线
|
for (int i = 0; i < _allBindingList.Count; i++)
|
{
|
var vm = _allBindingList[i];
|
theConnectCurve.AddSinglePumpCurve(vm.CurveRunQH, vm.CurveRunQP);
|
}
|
|
if (!theConnectCurve.CalculateParallel(out List<IStation.Model.CurvePoint> connectCurveQH,
|
out List<IStation.Model.CurvePoint> connectCurveQE,
|
out List<IStation.Model.CurvePoint> connectCurveQP))
|
{
|
MessageBox.Show("这些泵不适合并联");
|
return;
|
}
|
|
var curveExpressQH = new Model.CurveExpress(connectCurveQH);
|
var curveExpressQE = new Model.CurveExpress(connectCurveQE);
|
var curveExpressQP = new Model.CurveExpress(connectCurveQP);
|
|
this.mainChart.AddCurve(-1, "并联曲线", curveExpressQH, curveExpressQE, curveExpressQP, System.Drawing.Color.Black);
|
}
|
|
/// <summary>
|
/// 查询点信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="queryPt"></param>
|
private void SetQueryInfo(long id, Model.GroupPoint queryPt)
|
{
|
if (queryPt == null || id < 0)
|
return;
|
var vm = _allBindingList.Where(x => x.ID == id).FirstOrDefault();
|
if (vm == null)
|
return;
|
|
if (queryPt.Q > 0)
|
{
|
vm.QueryPtQ = string.Format("{0} {1}", Math.Round(queryPt.Q, 2), Unit.UnitQHelper.GetEnUnitName(Unit.eUnitQ.M3H));
|
}
|
else
|
{
|
vm.QueryPtQ = string.Empty;
|
}
|
|
if (queryPt.H > 0)
|
{
|
vm.QueryPtH = string.Format("{0} {1}", Math.Round(queryPt.H, 2), Unit.UnitHHelper.GetEnUnitName(Unit.eUnitH.M));
|
}
|
else
|
{
|
vm.QueryPtH = string.Empty;
|
}
|
|
if (queryPt.E > 0)
|
{
|
vm.QueryPtE = string.Format("{0:N1} %", queryPt.E);
|
}
|
else
|
{
|
vm.QueryPtE = string.Empty;
|
}
|
|
|
if (queryPt.P > 0)
|
{
|
vm.QueryPtP = string.Format("{0} {1} ", Math.Round(queryPt.P, 2), Unit.UnitPHelper.GetEnUnitName(Unit.eUnitP.KW));
|
}
|
else
|
{
|
vm.QueryPtP = string.Empty;
|
}
|
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
#region Color
|
|
private List<Color> ColorArray = new List<Color>()
|
{ Color.Red, Color.Blue, Color.Green, Color.DodgerBlue,
|
Color.Fuchsia, Color.MidnightBlue, Color.Maroon,
|
Color.Aquamarine, Color.Bisque, Color.BurlyWood
|
};
|
|
/// <summary>
|
/// 获取曲线颜色
|
/// </summary>
|
/// <returns></returns>
|
private Color GetCurveColor()
|
{
|
|
for (int index = 0; index < 20; index++)
|
{
|
Color color = index < ColorArray.Count ? ColorArray[index] : GetRandomColor();
|
CurrentViewModel vm = null;
|
foreach (var it in _allBindingList)
|
if (it.DispColor == color)
|
{
|
vm = it;
|
break;
|
}
|
if (vm == null)
|
return color;
|
}
|
|
return Color.Black;
|
}
|
|
/// <summary>
|
/// 获取随机颜色
|
/// </summary>
|
/// <returns></returns>
|
private Color GetRandomColor()
|
{
|
Random rdmFirst = new Random((int)DateTime.Now.Ticks);
|
int red = rdmFirst.Next(256);
|
Random rdmSencond = new Random((int)DateTime.Now.Ticks);
|
int green = rdmSencond.Next(256);
|
int blue = rdmSencond.Next(256);
|
return Color.FromArgb(red, green, blue);
|
}
|
#endregion
|
|
#region GridView
|
|
private void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
var index = e.RowHandle;
|
if (index < 0)
|
return;
|
if (e.Value == null)
|
return;
|
if (e.Column == this.colConnFrequence)
|
{
|
var hz = Convert.ToDouble(e.Value);
|
if (hz > 50)
|
return;
|
if (hz < 5)
|
return;
|
var vm = this.gridView1.GetRow(index) as CurrentViewModel;
|
vm.CalcRunCurve();
|
this.mainChart.SetCurve(vm.ID, vm.CurveRunQH, vm.CurveRunQE, vm.CurveRunQP);
|
CreateConnectCurve();
|
|
}
|
if (e.Column == this.colExtendRatio)
|
{
|
var ext = Convert.ToDouble(e.Value);
|
if (ext > 250)
|
return;
|
var vm = this.gridView1.GetRow(index) as CurrentViewModel;
|
vm.CalcRunCurve();
|
this.mainChart.SetCurve(vm.ID, vm.CurveRunQH, vm.CurveRunQE, vm.CurveRunQP);
|
CreateConnectCurve();
|
}
|
|
}
|
|
|
private void GridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
|
if (e.Column == colColor)
|
{
|
var index = e.RowHandle;
|
if (index < 0)
|
return;
|
var vm = _allBindingList[index];
|
vm.DispColor = (Color)e.Value;
|
this.mainChart.SetCurve(vm.ID, vm.DispColor);
|
}
|
|
|
}
|
private void GridView_RowCellClick(object sender, RowCellClickEventArgs e)
|
{
|
if (e.Column == colDelete)
|
{
|
var vm = _allBindingList[e.RowHandle];
|
if (null == vm)
|
{
|
return;
|
}
|
_allBindingList.Remove(vm);
|
this.mainChart.DeleteCurve(vm.ID);
|
CreateConnectCurve();
|
}
|
}
|
|
#endregion GridView
|
|
|
//计算曲线
|
private void barBtnCalcuCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
CreateConnectCurve();
|
}
|
|
//工作点
|
private void barCekSearchCurve_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.mainChart.LineVisible = this.barCekSearchCurve.Checked;
|
}
|
}
|
}
|