using System.Data;
namespace Yw.WinFrmUI
{
public partial class SetHydroCurveCtrl : DevExpress.XtraEditors.XtraUserControl
{
public SetHydroCurveCtrl()
{
InitializeComponent();
this.gridView1.SetBindingLimitEditView(25);
this.gridView1.ShowViewCaption(25);
}
///
/// 保存曲线信息事件
///
public event Action SaveCurveInfoEvent;
private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息
private Yw.Model.HydroCurveInfo _curveInfo = null;//曲线信息
private BindingList _allBindingList = null;
///
///
///
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroCurveInfo curveInfo, string curveType)
{
if (hydroInfo == null)
{
return;
}
_hydroInfo = hydroInfo;
_curveInfo = curveInfo;
if (_curveInfo == null)
{
_curveInfo = new Model.HydroCurveInfo();
_curveInfo.Catalog = Yw.Hydro.ParterCatalog.Curve;
_curveInfo.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", _hydroInfo.GetAllParters().Select(x => x.Code).ToList());
_curveInfo.CurveType = curveType;
}
this.txtCode.EditValue = _curveInfo.Code;
this.txtName.EditValue = _curveInfo.Name;
this.txtDescription.EditValue = _curveInfo.Description;
switch (curveType)
{
case HydroCurve.TankVol:
{
}
break;
case HydroCurve.PumpQH:
{
this.txtCurveType.EditValue = "水泵流量扬程曲线";
this.colX.Caption = "Q(m³/h)";
this.colY.Caption = "H(m)";
this.hydroCurveViewCtrl1.TitleTextX = "流量(m³/h)";
this.hydroCurveViewCtrl1.TitleTextY = "扬程(m)";
}
break;
case HydroCurve.PumpQP:
{
this.txtCurveType.EditValue = "水泵流量功率曲线";
this.colX.Caption = "Q(m³/h)";
this.colY.Caption = "P(kW)";
this.hydroCurveViewCtrl1.TitleTextX = "流量(m³/h)";
this.hydroCurveViewCtrl1.TitleTextY = "功率(kW)";
}
break;
case HydroCurve.PumpQE:
{
this.txtCurveType.EditValue = "水泵流量效率曲线";
this.colX.Caption = "Q(m³/h)";
this.colY.Caption = "E(%)";
this.hydroCurveViewCtrl1.TitleTextX = "流量(m³/h)";
this.hydroCurveViewCtrl1.TitleTextY = "效率(%)";
}
break;
case HydroCurve.ValveQL:
{
this.txtCurveType.EditValue = "阀门水头损失曲线";
this.colX.Caption = "Q(m³/h)";
this.colY.Caption = "H(m)";
this.hydroCurveViewCtrl1.TitleTextX = "流量(m³/h)";
this.hydroCurveViewCtrl1.TitleTextY = "压力(m)";
}
break;
default: break;
}
_allBindingList = new BindingList();
_curveInfo.CurveData?.ForEach(x =>
{
var pt = new HydroCurvePointViewModel(x.X, x.Y);
_allBindingList.Add(pt);
});
this.hydroCurvePointViewModelBindingSource.DataSource = _allBindingList;
this.hydroCurvePointViewModelBindingSource.ResetBindings(false);
this.hydroCurveViewCtrl1.SetBindingData(_allBindingList.ToList());
}
//保存
private void btnSave_Click(object sender, EventArgs e)
{
_curveInfo.Name = this.txtName.Text.Trim();
_curveInfo.Description = this.txtDescription.Text.Trim();
_curveInfo.CurveData = _allBindingList?.Select(x => new Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
this.hydroCurveViewCtrl1.SetBindingData(_allBindingList.ToList());
this.SaveCurveInfoEvent?.Invoke(_curveInfo);
}
//删除
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
if (e.RowHandle < 0)
{
return;
}
if (e.Column == this.colDelete)
{
_allBindingList.RemoveAt(e.RowHandle);
}
}
}
}