using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelectPumpComboxContentCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
|
public SelectPumpComboxContentCtrl()
|
{
|
InitializeComponent();
|
|
this.layoutControl1.SetupLayoutControl();
|
|
this.gridViewMain.SetNormalView(30);
|
this.gridViewMain.SetGridMianViewColor();
|
this.gridViewMain.RegistCustomDrawRowIndicator();
|
this.gridViewMain.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
|
//this.gridViewMain.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.GridViewMain_CustomDrawRowIndicator);
|
//this.gridViewMain.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridViewMain_CustomUnboundColumnData);
|
//this.gridViewMain.DoubleClick += new System.EventHandler(this.GridViewMain_DoubleClick);
|
//this.gridViewMain.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridViewMain_RowCellClick);
|
|
flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
|
colQ.Caption = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
|
|
}
|
|
|
|
public event Action<Model.ProductMainExPump> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductMainExPump> AddDataChanedEvent = null;
|
public event Action<Model.ProductMainExPump> EditDataChanedEvent = null;
|
|
private List<CurrentViewModel> _bindList = null;
|
private Model.ProductSeries _series = null;
|
|
public class CurrentViewModel : Model.ProductMainExPump
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Eventech.Model.UnitQ flow_unit, Model.ProductMainExPump rhs) : base(rhs)
|
{
|
var pumpparas = Model.RatedParas4Pump.ToModel(rhs.RatedParas);
|
this.Q = pumpparas.Q > 0 ? Math.Round(Eventech.Common.UnitQHelper.fromM3H(
|
flow_unit, pumpparas.Q), 4).ToString() : "";
|
//pumpparas.Q.ToString():"";
|
this.H = pumpparas.H > 0 ? pumpparas.H.ToString() : "";
|
this.N = rhs.Ratedn > 0 ? rhs.Ratedn.ToString() : "";
|
}
|
public string Q { get; set; }
|
public string H { get; set; }
|
public string N { get; set; }
|
}
|
public Model.ProductMainExPump SetBindingData4Series(Model.ProductSeries Series , long ProductID)
|
{
|
if (Series == null)
|
return null;
|
_series = Series;
|
var productPumpList = new BLL.ProductPump().GetExBySeriesID(Series.ID);
|
if (productPumpList == null || productPumpList.Count < 1)
|
{
|
return null;
|
}
|
_bindList = new List<CurrentViewModel>();
|
productPumpList.ForEach(x => _bindList.Add(new CurrentViewModel(flow_unit, x)));
|
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
|
|
Model.ProductMainExPump find = null;
|
if (ProductID > 0)
|
{
|
find = this._bindList.Find(x => x.ID == ProductID);
|
}
|
if (find == null)
|
find = _bindList.First();
|
|
SetFocusedData(find);
|
|
|
|
this.FocusedDataChangedEvent?.Invoke(find);
|
|
|
return find;
|
}
|
|
|
public void SetReadOnly()
|
{
|
this.barButAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
this.barButEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
}
|
|
/// <summary>
|
/// 初始化并设置默认值
|
/// </summary>
|
/// <param name="sel"></param>
|
public bool SetFocusedData(Model.ProductMainExPump sel)
|
{
|
if (sel == null) { return false; }
|
var find_index = this._bindList.FindIndex(x => x.ID == sel.ID);
|
this.gridViewMain.SelectRow(find_index);
|
|
this.gridViewMain.FocusedRowHandle = find_index;
|
return true;
|
}
|
private void barButCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_series == null)
|
return;
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
XtraMessageBox.Show("请选择一行数据!");
|
return;
|
}
|
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductPumpDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_series, row);
|
dlg.ReloadDataEvent += (pump, motor) =>
|
{
|
if (_bindList == null)
|
_bindList = new List<CurrentViewModel>();
|
|
_bindList.Add(new CurrentViewModel(flow_unit, pump));
|
this.bindingSource1.ResetBindings(false);
|
this.AddDataChanedEvent?.Invoke(pump);
|
this.FocusedDataChangedEvent?.Invoke(pump);
|
XtraMessageBox.Show("添加成功!");
|
_isChangeList = true;
|
};
|
dlg.ShowDialog();
|
}
|
private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Add();
|
}
|
|
private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
XtraMessageBox.Show("请选择一行数据!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new EditProductPumpDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(row,0);
|
dlg.ReloadDataEvent += (isChangePart, pump, motor, part) =>
|
{
|
row.Reset(pump);
|
this.bindingSource1.ResetBindings(false);
|
EditDataChanedEvent?.Invoke(pump);
|
XtraMessageBox.Show("修改成功!");
|
_isChangeList = true;
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barButSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.gridViewMain.OptionsFind.AlwaysVisible = this.barCkSelect.Checked;
|
}
|
|
private bool _isChangeList = false;//是否修改了数组成员
|
|
public bool IsChangeList { get => _isChangeList; set => _isChangeList = value; }
|
|
|
|
|
private void Add()
|
{
|
if (_series == null)
|
return;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductPumpDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_series, _bindList?.Count() + 1 ?? 0);
|
dlg.ReloadDataEvent += (pump, motor) =>
|
{
|
if (_bindList == null)
|
_bindList = new List<CurrentViewModel>();
|
|
_bindList.Add(new CurrentViewModel(flow_unit, pump));
|
this.bindingSource1.ResetBindings(false);
|
this.AddDataChanedEvent?.Invoke(pump);
|
this.FocusedDataChangedEvent?.Invoke(pump);
|
XtraMessageBox.Show("添加成功!");
|
_isChangeList = true;
|
};
|
dlg.ShowDialog();
|
}
|
|
private void GridViewMain_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetFocusedRow() as Model.ProductMainExPump;
|
if (row == null)
|
return;
|
this.FocusedDataChangedEvent?.Invoke(row);
|
}
|
|
private void bar1_VisibleChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
|
}
|
}
|