using DevExpress.Utils.Extensions;
namespace Yw.WinFrmUI
{
public partial class SelectHydroGradingPropTreeCtrl : DevExpress.XtraEditors.XtraUserControl
{
public SelectHydroGradingPropTreeCtrl()
{
InitializeComponent();
this.simpleTreeViewCtrl1.ToolBarVisible = false;
this.simpleTreeViewCtrl1.CloseSearchControl();
this.simpleTreeViewCtrl1.ShowTreeLines = true;
this.simpleTreeViewCtrl1.FocusedChangedEvent += SimpleTreeViewCtrl1_FocusedChangedEvent;
}
///
/// 选择属性改变事件
///
public event Action SelectedPropChangedEvent;
private Yw.Model.HydroModelInfo _hydro = null;//水力信息
private List _allBindingList = null;//所有绑定列表
///
/// 绑定数据
///
public void SetBindingData(Yw.Model.HydroModelInfo hydro)
{
if (hydro == null)
{
return;
}
_hydro = hydro;
_allBindingList = new List();
var catalogDict = HydroGradingCatalogHelper.GetDict(hydro);
catalogDict?.ForEach(x =>
{
_allBindingList.Add(new HydroGradingPropTreeViewModel(x.Key, x.Value));
var propDict = HydroGradingPropHelper.GetNameDict(x.Key);
propDict?.ForEach(t =>
{
_allBindingList.Add(new HydroGradingPropTreeViewModel(x.Key, t.Key, t.Value));
});
});
var allTreeList = new List();
_allBindingList.ForEach(x =>
{
var treeModel = new SimpleTreeViewModel()
{
Id = x.Id,
ParentId = x.ParentId,
Name = x.Name,
Tag = x
};
allTreeList.Add(treeModel);
});
this.simpleTreeViewCtrl1.SetBindingData(allTreeList);
this.simpleTreeViewCtrl1.ExpandAll();
}
//聚焦节点改变
private void SimpleTreeViewCtrl1_FocusedChangedEvent(SimpleTreeViewModel obj)
{
var vm = obj?.Tag as HydroGradingPropTreeViewModel;
this.SelectedPropChangedEvent?.Invoke(vm);
}
}
}