using DevExpress.XtraEditors;
|
|
namespace Yw.WinFrmUI.Phart
|
{
|
public partial class PumpParallelInfoCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public PumpParallelInfoCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetNormalEditView();
|
this.gridView2.SetNormalView();
|
this.repColor.ColorChanged += RepColor_ColorChanged;
|
this.repColor.ColorAlignment = DevExpress.Utils.HorzAlignment.Center;
|
this.repColor.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
|
this.repColor.ButtonsStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
|
this.colRunStatus.OptionsColumn.AllowEdit = false;
|
this.colRunStatus.OptionsColumn.ReadOnly = false;
|
//this.colExtendRatio.OptionsColumn.ReadOnly = true;
|
//this.colExtendRatio.OptionsColumn.AllowEdit = false;
|
this.gridView1.RowCellClick += GridView1_RowCellClick;
|
|
}
|
|
|
|
/// <summary>
|
/// 设置曲线
|
/// </summary>
|
public event Action<string, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d> SetEvent;
|
|
/// <summary>
|
/// 设置曲线信息
|
/// </summary>
|
public event Action<string, string, Color> SetInfoEvent;
|
|
/// <summary>
|
/// 添加曲线事件
|
/// </summary>
|
public event Action<PumpSerialParallelInfoViewModel> AddEvent;
|
|
/// <summary>
|
/// 删除曲线事件
|
/// </summary>
|
public event Action<string> DeleteEvent;
|
|
/// <summary>
|
/// 设置设计点
|
/// </summary>
|
public event Action<double, double> SetDesignPointEvent;
|
|
|
/// <summary>
|
/// 保存事件
|
/// </summary>
|
public event Action ResetEvent;
|
|
|
/// <summary>
|
/// 保存事件
|
/// </summary>
|
public event Action SaveEvent;
|
|
private List<PumpSerialParallelInfoViewModel> _all_binding_list = null;
|
private List<PumpSerialParallelInfoViewModel> _src_binding_list = null;
|
|
public void SetBindingData(List<PumpSerialParallelInfoViewModel> vm_list, Yw.Geometry.Point2d design_pt = null)
|
{
|
_src_binding_list = new List<PumpSerialParallelInfoViewModel>();
|
_all_binding_list = new List<PumpSerialParallelInfoViewModel>();
|
if (vm_list != null && vm_list.Any())
|
{
|
_src_binding_list = vm_list.Select(x => new PumpSerialParallelInfoViewModel(x)).ToList();
|
_all_binding_list = vm_list.Select(x => new PumpSerialParallelInfoViewModel(x)).ToList();
|
}
|
|
this.txtDesignQ.EditValue = design_pt?.X;
|
this.txtDesignH.EditValue = design_pt?.Y;
|
|
this.pumpSerialParallelInfoViewModelBindingSource.DataSource = _all_binding_list;
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
this.gridView1.BestFitColumns();
|
|
}
|
|
public void SetDesignPoint(double flow, double head)
|
{
|
this.txtDesignQ.EditValue = flow;
|
this.txtDesignH.EditValue = head;
|
}
|
|
|
/// <summary>
|
/// 获取
|
/// </summary>
|
public Yw.Geometry.Point2d GetDesignPoint()
|
{
|
|
if (!double.TryParse(this.txtDesignQ.Text, out double x))
|
{
|
return default;
|
}
|
if (!double.TryParse(this.txtDesignH.Text, out double y))
|
{
|
return default;
|
}
|
return new Geometry.Point2d(x, y);
|
}
|
|
|
#region Color
|
|
private List<Color> _color_array = 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 GetRandomColor(int count)
|
{
|
if (count < _color_array.Count)
|
{
|
return _color_array[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 void RepColor_ColorChanged(object sender, EventArgs e)
|
{
|
if (this.gridView1.GetCurrentViewModel(_all_binding_list) is not PumpSerialParallelInfoViewModel vm)
|
return;
|
vm.Color = (sender as DevExpress.XtraEditors.ColorEdit).Color;
|
this.SetInfoEvent?.Invoke(vm.Id, vm.Name, vm.Color);
|
}
|
|
private void GridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (e.Column == this.colRunStatus)
|
{
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpSerialParallelInfoViewModel;
|
vm.RunStatus = !vm.RunStatus;
|
this.gridView1.RefreshRow(e.RowHandle);
|
if (_all_binding_list != null && _all_binding_list.Any())
|
{
|
foreach (var item in _all_binding_list)
|
{
|
item.QueryH = string.Empty;
|
item.QueryE = string.Empty;
|
item.QueryQ = string.Empty;
|
item.QueryP = string.Empty;
|
}
|
}
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
if (vm.RunStatus)
|
{
|
vm.Calc();
|
this.AddEvent?.Invoke(vm);
|
}
|
else
|
{
|
this.DeleteEvent?.Invoke(vm.Id);
|
}
|
|
}
|
}
|
|
//值变换
|
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
if (e.Column == this.colName)
|
{
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpSerialParallelInfoViewModel;
|
this.SetInfoEvent?.Invoke(vm.Id, vm.Name, vm.Color);
|
}
|
else
|
if (e.Column == this.colCurrentHz)
|
{
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpSerialParallelInfoViewModel;
|
if (vm.CurrentHz < 10 || vm.CurrentHz > 50)
|
{
|
return;
|
}
|
vm.Calc();
|
this.SetEvent?.Invoke(vm.Id, vm.QhCalc, vm.QeCalc, vm.QpCalc);
|
|
}
|
else if (e.Column == this.colExtendRatio)
|
{
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
var vm = this.gridView1.GetRow(e.RowHandle) as PumpSerialParallelInfoViewModel;
|
vm.Calc();
|
this.SetEvent?.Invoke(vm.Id, vm.QhCalc, vm.QeCalc, vm.QpCalc);
|
|
}
|
}
|
|
/// <summary>
|
/// 设置查询信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="query_pt"></param>
|
public void SetQueryInfo(string id, PumpGroupPt query_pt)
|
{
|
if (query_pt == null)
|
return;
|
if (_all_binding_list == null || !_all_binding_list.Any())
|
return;
|
var vm = _all_binding_list.Find(x => x.Id == id);
|
if (vm == null)
|
return;
|
vm.QueryQ = query_pt.Q > 0 ? $"{query_pt.Q:N1}" : string.Empty;
|
vm.QueryH = query_pt.H > 0 ? $"{query_pt.H:N1}" : string.Empty;
|
vm.QueryE = query_pt.E > 0 ? $"{query_pt.E:N1}" : string.Empty;
|
vm.QueryP = query_pt.P > 0 ? $"{query_pt.P:N1}" : string.Empty;
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
}
|
|
//设置设计点
|
private void btnSetDesignPoint_Click(object sender, EventArgs e)
|
{
|
if (!double.TryParse(this.txtDesignQ.Text, out double design_q))
|
return;
|
if (!double.TryParse(this.txtDesignH.Text, out double design_h))
|
return;
|
|
this.SetDesignPointEvent?.Invoke(design_q, design_h);
|
}
|
|
public List<PumpSerialParallelInfoViewModel> GetRunList()
|
{
|
if (_all_binding_list == null || !_all_binding_list.Any())
|
{
|
return default;
|
}
|
return _all_binding_list.Where(x => x.RunStatus).Select(x => new PumpSerialParallelInfoViewModel(x)).ToList();
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
{
|
if (XtraMessageBox.Show("是否保存数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
|
return;
|
this.SaveEvent?.Invoke();
|
}
|
|
private void btnReset_Click(object sender, EventArgs e)
|
{
|
if (XtraMessageBox.Show("是否重置数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
|
return;
|
_all_binding_list = _src_binding_list?.Select(x => new PumpSerialParallelInfoViewModel(x)).ToList();
|
this.pumpSerialParallelInfoViewModelBindingSource.DataSource = _all_binding_list;
|
this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
|
this.gridView1.BestFitColumns();
|
this.ResetEvent?.Invoke();
|
}
|
|
}
|
}
|