using DevExpress.XtraEditors;
using System;
using System.ComponentModel;
using System.Linq;
namespace IStation.WinFrmUI.Basic
{
///
///
///
public partial class StationListCtrl : XtraUserControl
{
public StationListCtrl()
{
InitializeComponent();
this.treeList1.InitialDefaultSettings();
this.treeList1.SelectImageList = ImageLib.Lib;
this.layoutControl1.SetupLayoutControl();
}
public class CurrentViewModel : Model.Station
{
public CurrentViewModel() { }
public CurrentViewModel(Model.Station rhs) : base(rhs) { }
public int ImageIndex { get; set; }
}
///
/// 聚焦改变事件
///
public event Action FocusedChangedEvent;
private BindingList _allBindingList = null;//所有绑定列表
///
/// 绑定数据
///
public void Clear()
{
_allBindingList = new BindingList();
this.treeList1.DataSource = _allBindingList;
this.FocusedChangedEvent?.Invoke(null);
}
///
/// 绑定数据
///
public void SetBindingData()
{
WaitFrmHelper.ShowWaitForm("正在加载数据...");
_allBindingList = new BindingList();
var stations = new BLL.Station().GetAll();
if (stations != null && stations.Any())
{
var imgIndex = ImageLib.Station;
foreach (var station in stations)
{
var vm = new CurrentViewModel(station);
vm.ImageIndex = imgIndex;
_allBindingList.Add(vm);
}
}
this.treeList1.DataSource = _allBindingList;
this.treeList1.ForceInitialize();
if (_allBindingList.Any())
{
this.treeList1.FocusedNode = this.treeList1.FindNodeByKeyID(_allBindingList[0].ID);
}
else
{
this.FocusedChangedEvent?.Invoke(null);
}
WaitFrmHelper.HideWaitForm();
}
//全部展开
private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.treeList1.ExpandAll();
}
//全部折叠
private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.treeList1.CollapseAll();
}
//检索
private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (this.barCkSearch.Checked)
this.treeList1.ShowFindPanel();
else
this.treeList1.HideFindPanel();
}
//详细信息
private void barBtnDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
XtraMessageBox.Show("待补充!");
}
//聚焦改变
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
{
var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
if (vm == null)
return;
this.FocusedChangedEvent?.Invoke(vm);
}
}
}