using DevExpress.Xpo.Helpers;
using DevExpress.XtraEditors;
using Yw.Model;
namespace Yw.WinFrmUI
{
public partial class HydroFourlinkListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroParterList
{
public HydroFourlinkListCtrl()
{
InitializeComponent();
this.gridView1.SetNormalView(30);
this.gridView1.RegistCustomDrawRowIndicator(40);
this.layoutControl1.SetupLayoutControl();
}
///
/// 水力点击事件
///
public event Action HydroClickEvent;
///
/// 水力改变事件
///
public event Action> HydroChangedEvent;
///
/// 显示查询面板
///
[Browsable(true)]
[Description("显示查询面板")]
[DefaultValue(true)]
public bool ShowFindPanel
{
get { return this.gridView1.OptionsFind.AlwaysVisible; }
set { this.gridView1.OptionsFind.AlwaysVisible = value; }
}
///
/// 是否拥有水利列表
///
public bool HasHydroList
{
get { return _allList != null && _allList.Count > 0; }
}
//所有列表
private List _allList = null;
//所有绑定列表
private List _allBindingList = null;
///
/// 绑定数据
///
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
{
_allList = new List();
if (hydroInfo != null && hydroInfo.Fourlinks != null && hydroInfo.Fourlinks.Count > 0)
{
foreach (var fourlink in hydroInfo.Fourlinks)
{
var vm = new HydroFourlinkViewModel(fourlink, hydroInfo);
_allList.Add(vm);
}
}
Search();
}
///
/// 绑定数据
///
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List allCalcuResultList)
{
_allList = new List();
if (hydroInfo != null && hydroInfo.Fourlinks != null && hydroInfo.Fourlinks.Count > 0)
{
foreach (var fourlink in hydroInfo.Fourlinks)
{
var vm = new HydroFourlinkViewModel(fourlink, hydroInfo);
var calcuResult = allCalcuResultList?.Find(x => x.Code == fourlink.Code);
if (calcuResult != null)
{
vm.UpdateCalcuProperty(calcuResult);
}
_allList.Add(vm);
}
}
Search();
}
///
/// 更新属性
///
public void UpdateProperty()
{
if (_allList == null || _allList.Count < 1)
{
return;
}
_allList.ForEach(x => x.UpdateProperty());
this.hydroFourlinkViewModelBindingSource.ResetBindings(false);
}
///
/// 更新属性
///
public void UpdateProperty(Yw.Model.HydroParterInfo parter)
{
if (_allList == null || _allList.Count < 1)
{
return;
}
if (parter == null)
{
return;
}
var vm = _allList.Find(x => x.Code == parter.Code);
if (vm == null)
{
return;
}
vm.UpdateProperty();
this.hydroFourlinkViewModelBindingSource.ResetBindings(false);
}
///
/// 更新属性
///
public void UpdateProperty(List parterList)
{
if (_allList == null || _allList.Count < 1)
{
return;
}
if (parterList == null || parterList.Count < 1)
{
return;
}
parterList.ForEach(x =>
{
var vm = _allList.Find(t => x.Code == x.Code);
if (vm != null)
{
vm.UpdateProperty();
}
});
this.hydroFourlinkViewModelBindingSource.ResetBindings(false);
}
///
/// 更新计算属性
///
public void UpdateCalcuProperty(List allCalcuResultList)
{
if (allCalcuResultList != null && allCalcuResultList.Count > 0)
{
if (_allList != null && _allList.Count > 0)
{
foreach (var parter in _allList)
{
var calcuResult = allCalcuResultList.Find(x => x.Code == parter.Code);
if (calcuResult != null)
{
parter.UpdateCalcuProperty(calcuResult);
}
}
this.hydroFourlinkViewModelBindingSource.ResetBindings(false);
}
}
}
//查询
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.hydroFourlinkViewModelBindingSource.DataSource = _allBindingList;
this.hydroFourlinkViewModelBindingSource.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 SetHydroFourlinkDlg();
dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
dlg.ReloadDataEvent += (list) =>
{
_allBindingList.ForEach(x =>
{
x.UpdateProperty();
});
this.hydroFourlinkViewModelBindingSource.ResetBindings(false);
var allParterList = _allBindingList.Select(x => x.Vmo as Yw.Model.HydroParterInfo).ToList();
this.HydroChangedEvent?.Invoke(allParterList);
};
dlg.ShowDialog();
}
///
/// 设置简单显示模式
///
public void SetSimpleView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colCode.Visible = true;
this.colName.Visible = true;
this.colModelType.Visible = true;
this.colMaterial.Visible = true;
this.colCaliber.Visible = true;
this.colElev.Visible = false;
this.colMinorLoss.Visible = false;
this.colCalcuPress.Visible = false;
this.colCalcuHead.Visible = false;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = false;
}
///
/// 设置正常显示模式
///
public void SetNormalView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colCode.Visible = true;
this.colName.Visible = true;
this.colModelType.Visible = true;
this.colMaterial.Visible = true;
this.colCaliber.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuPress.Visible = false;
this.colCalcuHead.Visible = false;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
///
/// 设置计算显示模式
///
public void SetCalcuView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
this.colDbLocked.Visible = true;
this.colCode.Visible = true;
this.colName.Visible = true;
this.colModelType.Visible = true;
this.colMaterial.Visible = true;
this.colCaliber.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuPress.Visible = true;
this.colCalcuHead.Visible = true;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
///
/// 设置批量设置模式
///
public void SetBulkSetView()
{
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
this.colDbLocked.Visible = true;
this.colCode.Visible = true;
this.colName.Visible = true;
this.colModelType.Visible = true;
this.colMaterial.Visible = true;
this.colCaliber.Visible = true;
this.colElev.Visible = true;
this.colMinorLoss.Visible = true;
this.colCalcuPress.Visible = false;
this.colCalcuHead.Visible = false;
this.colHasDb.Visible = true;
this.colFlags.Visible = true;
this.colDescription.Visible = true;
this.colSet.Visible = true;
}
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();
}
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
var row = this.gridView1.GetRow(e.RowHandle) as HydroFourlinkViewModel;
if (row == null)
{
return;
}
if (e.Column == this.colSet)
{
var dlg = new SetHydroFourlinkDlg();
dlg.SetBindingData(row.Vmo);
dlg.ReloadDataEvent += (list) =>
{
row.UpdateProperty();
this.gridView1.RefreshRow(e.RowHandle);
this.HydroChangedEvent?.Invoke(new List() { row.Vmo });
};
dlg.ShowDialog();
}
else
{
this.HydroClickEvent?.Invoke(row.Vmo);
}
}
}
}