using DevExpress.XtraGrid.Views.Grid;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Analy
|
{
|
public partial class CompareCurvePage_bak : DocumentPage
|
{
|
public CompareCurvePage_bak()
|
{
|
InitializeComponent();
|
this.PageTitle.Caption = "曲线对比";
|
this.gridView1.SetNormalEditView();
|
this.gridView1.OptionsSelection.MultiSelect = false;//单选
|
this.gridView1.OptionsBehavior.Editable = true;//
|
this.gridView1.BestFitColumns();
|
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, item_item) =>
|
{
|
AddCurve(stationName, pump, item_item);
|
};
|
|
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; }
|
}
|
|
private BindingList<CurrentViewModel> _allBindingList = null;
|
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
_allBindingList = new BindingList<CurrentViewModel>();
|
this.bindingSource1.DataSource = _allBindingList;
|
|
|
this.pumpCurveTreeList1.SetBindingData();
|
}
|
|
private void AddCurve(string name, 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 color = GetCurveColor();
|
var vm = new CurrentViewModel();
|
vm.PumpName = pump.Name;
|
vm.ID = pumpCurve.ID;
|
vm.DispColor = color;
|
vm.StationName = name;
|
vm.CurveName = pumpCurve.CurveCode;
|
|
_allBindingList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
|
|
|
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);
|
|
this.mainChart.AddCurve(pumpCurve.ID, $"{name}-{pump.Name}", curveInfo.CurveQH, curveInfo.CurveQE, curveInfo.CurveQP, color, qhPoints, qePoints, qpPoints);
|
}
|
|
|
/// <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
|
|
//工作点
|
private void barCekSearchCurve_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.mainChart.LineVisible = this.barCekSearchCurve.Checked;
|
}
|
|
#region GridView
|
|
//修改颜色
|
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 item = _allBindingList[index];
|
item.DispColor = (Color)e.Value;
|
this.mainChart.SetCurve(item.ID, item.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);
|
}
|
}
|
|
#endregion GridView
|
|
|
|
}
|
}
|