using DevExpress.XtraEditors; using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; namespace IStation.WinFrmUI.Basic { /// /// /// public partial class MonitorPointGroupTreeList : XtraUserControl { public MonitorPointGroupTreeList() { InitializeComponent(); this.treeList1.InitialDefaultSettings(); this.treeList1.SelectImageList = ImageLib.Lib; this.layoutControl1.SetupLayoutControl(); } public class CurrentViewModel { public CurrentViewModel() { } public CurrentViewModel(Model.Station rhs) { Reset(rhs); } public CurrentViewModel(Model.MonitorPointGroup rhs) { Reset(rhs); } public void Reset(Model.Station rhs) { this.ID = rhs.ID; this.Name = rhs.Name; this.IsGroup = true; this.SortCode = rhs.SortCode; this.ImageIndex = ImageLib.Station; this.Model = rhs; } public void Reset(Model.MonitorPointGroup rhs) { this.ID = rhs.ID; this.ParentID = rhs.ParentIds == null || !rhs.ParentIds.Any() ? rhs.BelongID : TreeParentIdsHelper.GetLastParentID(rhs.ParentIds); this.Name = rhs.Name; this.IsGroup = false; this.SortCode = rhs.SortCode; this.ImageIndex = ImageLib.Group; this.Model = rhs; } public long ID { get; set; } public long ParentID { get; set; } public string Name { get; set; } public bool IsGroup { get; set; } public int SortCode { get; set; } public int ImageIndex { get; set; } public object Model { get; set; } } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; private BLL.MonitorPointGroup _bll = new BLL.MonitorPointGroup(); private List _allBindingList = null;//所有绑定列表 /// /// 绑定数据 /// public void Clear() { _allBindingList = new List(); this.treeList1.DataSource = _allBindingList; this.FocusedChangedEvent?.Invoke(null); } /// /// 绑定数据 /// public void SetBindingData(string belongType, long belongId) { WaitFrmHelper.ShowWaitForm("正在加载数据..."); _allBindingList = new List(); var monitorPointGroups = _bll.GetByBelongTypeAndBelongID(belongType, belongId); if (monitorPointGroups != null && monitorPointGroups.Any()) { foreach (var item in monitorPointGroups) { var vm = new CurrentViewModel(item); _allBindingList.Add(vm); } } this.bindingSource1.DataSource = _allBindingList; 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 treeList1_BeforeFocusNode(object sender, DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e) { var vm = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel; if (vm == null) return; e.CanFocus = !vm.IsGroup; } //聚焦改变 private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { var vm = this.treeList1.GetCurrentViewModel(_allBindingList); if (vm == null) return; this.FocusedChangedEvent?.Invoke(vm.Model as Model.MonitorPointGroup); } } }