using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class MonitorDataSourcesTreeList : XtraUserControl
|
{
|
public MonitorDataSourcesTreeList()
|
{
|
InitializeComponent();
|
treeList1.InitialDefaultSettings();
|
treeList1.SelectImageList = ImageLib.Lib;
|
layoutControl1.SetupLayoutControl();
|
}
|
|
public class CurrentViewModel : Model.MonitorDataSources
|
{
|
public CurrentViewModel() { }
|
|
public CurrentViewModel(Model.MonitorDataSources rhs) : base(rhs)
|
{
|
ImageIndex = ImageLib.MonitorDataSources;
|
}
|
|
public int ImageIndex { get; set; }
|
}
|
|
/// <summary>
|
/// 聚焦改变事件
|
/// </summary>
|
public event Action<Model.MonitorDataSources> FocusedChangedEvent;
|
|
|
private BLL.MonitorDataSources _bll = new BLL.MonitorDataSources();
|
private List<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void Clear()
|
{
|
_allBindingList = new List<CurrentViewModel>();
|
treeList1.DataSource = _allBindingList;
|
FocusedChangedEvent?.Invoke(null);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
WaitFrmHelper.ShowWaitForm("正在加载数据...");
|
_allBindingList = new List<CurrentViewModel>();
|
var list = _bll.GetAll();
|
if (list != null && list.Any())
|
{
|
list = list.OrderByDescending(x => x.Name).ToList();
|
foreach (var item in list)
|
{
|
var vm = new CurrentViewModel(item);
|
_allBindingList.Add(vm);
|
}
|
}
|
|
|
bindingSource1.DataSource = _allBindingList;
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
//全部展开
|
private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
treeList1.ExpandAll();
|
}
|
|
//全部折叠
|
private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
treeList1.CollapseAll();
|
}
|
|
//检索
|
private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (barCkSearch.Checked)
|
treeList1.ShowFindPanel();
|
else
|
treeList1.HideFindPanel();
|
}
|
|
//聚焦改变
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = treeList1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
FocusedChangedEvent?.Invoke(null);
|
return;
|
}
|
FocusedChangedEvent?.Invoke(vm);
|
}
|
|
}
|
}
|