using DevExpress.XtraEditors;
using DevExpress.XtraTabbedMdi;
namespace Yw.WinFrmUI
{
public partial class HydroWaterboxBulkSetListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroParterBulkSetListCtrl
{
public HydroWaterboxBulkSetListCtrl()
{
InitializeComponent();
this.gridView1.SetNormalView(30);
this.gridView1.RegistCustomDrawRowIndicator(40);
}
///
/// 水力点击事件
///
public event Action HydroClickEvent;
///
/// 是否拥有水利列表
///
public bool HasHydroList
{
get { return _allBindingList != null && _allBindingList.Count > 0; }
}
//所有列表
private List _allList = null;
//所有绑定列表
private List _allBindingList = null;
///
/// 绑定数据
///
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
{
_allList = new List();
if (hydroInfo != null && hydroInfo.Waterboxs != null && hydroInfo.Waterboxs.Count > 0)
{
foreach (var waterbox in hydroInfo.Waterboxs)
{
var vm = new HydroWaterboxBulkSetViewModel(waterbox);
_allList.Add(vm);
}
}
Search();
}
//查询
private void Search()
{
if (_allList == null || _allList.Count < 1)
{
return;
}
var name = this.txtName.Text.Trim();
var code = this.txtCode.Text.Trim();
var modelType = this.txtModelType.Text.Trim();
_allBindingList = _allList;
if (!string.IsNullOrEmpty(name))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
}
if (!string.IsNullOrEmpty(code))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
}
if (!string.IsNullOrEmpty(modelType))
{
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
}
this.hydroWaterboxBulkSetViewModelBindingSource.DataSource = _allBindingList;
this.hydroWaterboxBulkSetViewModelBindingSource.ResetBindings(false);
}
//重置
private void Reset()
{
this.txtName.EditValue = null;
this.txtCode.EditValue = null;
this.txtModelType.EditValue = null;
Search();
}
//设置
private void Set()
{
Search();
if (_allBindingList == null || _allBindingList.Count < 1)
{
XtraMessageBox.Show("无可设置水箱数据");
return;
}
var dlg = new HydroWaterboxBulkSetDlg();
dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
dlg.ReloadDataEvent += (list) =>
{
_allBindingList.ForEach(x =>
{
x.PoolElev = x.Vmo.PoolElev;
x.InitLevel = x.Vmo.InitLevel;
x.MinLevel = x.Vmo.MinLevel;
x.MaxLevel = x.Vmo.MaxLevel;
x.DN = x.Vmo.DN;
x.OverFlow = x.Vmo.OverFlow;
});
this.hydroWaterboxBulkSetViewModelBindingSource.DataSource = _allBindingList;
this.hydroWaterboxBulkSetViewModelBindingSource.ResetBindings(false);
};
dlg.ShowDialog();
}
//行点击事件
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
var row = this.gridView1.GetRow(e.RowHandle) as HydroTankBulkSetViewModel;
if (row == null)
{
return;
}
this.HydroClickEvent?.Invoke(row.Vmo);
}
//查询
private void btnSearch_Click(object sender, EventArgs e)
{
Search();
}
//重置
private void btnReset_Click(object sender, EventArgs e)
{
Reset();
}
//设置
private void btnSet_Click(object sender, EventArgs e)
{
Set();
}
}
}