using DevExpress.XtraEditors; namespace ISupply.WinFrm.Main { /// /// /// public partial class FacilitiesExTreeListCtrl : XtraUserControl { public FacilitiesExTreeListCtrl() { InitializeComponent(); this.treeList1.InitialDefaultSettings(); this.treeList1.SelectImageList = ImageLib.Lib; this.layoutControl1.SetupLayoutControl(); this.regionTreeListLookUpEdit1.SelectedChangedEvent += RegionTreeListLookUpEdit1_SelectedChangedEvent; } public class CurrentViewModel { public CurrentViewModel() { } public CurrentViewModel(Model.Building rhs) { this.ID = rhs.ID; this.ParentID = rhs.RegionID; this.Name = rhs.Name; this.ObjectType = ISupply.ObjectType.Building; this.ImageIndex = ImageLib.Building; this.IsGroup = true; this.Model = rhs; } public CurrentViewModel(Model.Facilities rhs) { this.ID = rhs.ID; this.ParentID = rhs.BuildingID; this.Name = rhs.Name; this.ObjectType = ISupply.ObjectType.Facilities; this.ImageIndex = ImageLib.Facilities; this.Model = rhs; } public long ID { get; set; } public long ParentID { get; set; } public string Name { get; set; } public string ObjectType { get; set; } public int ImageIndex { get; set; } public bool IsGroup { get; set; } public object Model { get; set; } } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; private BindingList _allBindingList = null;//所有绑定列表 /// /// 绑定数据 /// public void SetBindingData() { this.regionTreeListLookUpEdit1.SetBindingData(); } /// /// 绑定数据 /// public void Clear() { _allBindingList = new BindingList(); this.treeList1.DataSource = _allBindingList; this.FocusedChangedEvent?.Invoke("", null); } //业务区域变换 private void RegionTreeListLookUpEdit1_SelectedChangedEvent(Model.Region obj) { if (obj == null) { // Clear(); return; } SetBindingData(obj.ID); } /// /// 绑定数据 /// private void SetBindingData(long regionId) { WaitFrmHelper.ShowWaitForm("正在加载数据..."); _allBindingList = new BindingList(); var buildings = new BLL.Building().GetByRegionID(regionId); if (buildings != null && buildings.Any()) { foreach (var item in buildings) { var vm = new CurrentViewModel(item); _allBindingList.Add(vm); } var ids = buildings.Select(x => x.ID).ToList(); var facility = new BLL.Facilities().GetByBuildingIds(ids); if (facility != null && facility.Any()) { foreach (var item in facility) { 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; if (vm.IsGroup) { e.CanFocus = false; }*/ } //聚焦改变 private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { var vm = this.treeList1.GetCurrentViewModel(_allBindingList); if (vm == null) return; this.FocusedChangedEvent?.Invoke(vm.ObjectType, vm.Model); } #region 菜单事件 //全部展开 private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.treeList1.ExpandAll(); } //全部折叠 private void barBtnCollpseAll_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 } }