using DevExpress.XtraEditors;
|
|
namespace ISupply.WinFrm.Main
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class FacilitiesTreeListCtrl : XtraUserControl
|
{
|
public FacilitiesTreeListCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.InitialDefaultSettings();
|
this.treeList1.SelectImageList = ImageLib.Lib;
|
this.layoutControl1.SetupLayoutControl();
|
}
|
|
public class CurrentViewModel : Model.Facilities
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.Facilities rhs) : base(rhs)
|
{
|
this.ImageIndex = ImageLib.Facilities;
|
this.IsGroup = true;
|
}
|
public long ParentID { get; set; }
|
public int ImageIndex { get; set; }
|
public bool IsGroup { get; set; }
|
}
|
|
/// <summary>
|
/// 聚焦改变事件
|
/// </summary>
|
public event Action<Model.Facilities> FocusedChangedEvent;
|
|
private BLL.Facilities _bll = new BLL.Facilities();
|
private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void Clear()
|
{
|
_allBindingList = new BindingList<CurrentViewModel>();
|
this.treeList1.DataSource = _allBindingList;
|
this.FocusedChangedEvent?.Invoke(null);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long buildingId)
|
{
|
WaitFrmHelper.ShowWaitForm("正在加载数据...");
|
_allBindingList = new BindingList<CurrentViewModel>();
|
var facilitiess = _bll.GetByBuildingID(buildingId);
|
if (facilitiess != null && facilitiess.Any())
|
{
|
foreach (var item in facilitiess)
|
{
|
var vm = new CurrentViewModel(item);
|
_allBindingList.Add(vm);
|
}
|
}
|
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.RefreshDataSource();
|
this.treeList1.ExpandAll();
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
|
//聚焦前
|
private void treeList1_BeforeFocusNode(object sender, DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e)
|
{
|
var vm = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
if (vm == null)
|
return;
|
}
|
|
//聚焦改变
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
|
if (vm == null || vm.IsGroup)
|
return;
|
this.FocusedChangedEvent?.Invoke(vm);
|
}
|
|
#region 菜单事件
|
|
//全部展开
|
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();
|
}
|
#endregion
|
|
}
|
}
|