using DevExpress.Utils; using DevExpress.Utils.Design; using DevExpress.Utils.DragDrop; using DevExpress.XtraEditors; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; using HStation.Vmo; using System.ComponentModel; using System.Windows.Media.Imaging; using Yw; using Yw.WinFrmUI; namespace HStation.WinFrmUI { public partial class RoleTreeListCtrl : DevExpress.XtraEditors.XtraUserControl { /// /// /// public RoleTreeListCtrl() { InitializeComponent(); this.treeList1.InitialDefaultSettings(); this.layoutControl1.SetupLayoutControl(); } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; /// /// 所有绑定列表 /// private List _allBindingList = null; /// /// 初始化数据 /// public async void InitialData() { var overlay = this.ShowOverlay(); var allList = await BLLFactory.Instance.GetByCorpID(0); _allBindingList = new List(); allList?.ForEach(x => { var vm = new RoleTreeListViewModel(x); _allBindingList.Add(vm); }); this.treeList1.DataSource = _allBindingList; this.treeList1.ForceInitialize(); this.treeList1.ExpandAll(); overlay.Close(); // SetDragEnable(this.barCkDrag.Checked); } //全部展开 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(); } //检索(menu) private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.layoutControlItem1.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always) this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; else this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } //聚焦节点改变 private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { var vm = this.treeList1.GetDataRecordByNode(e.Node) as RoleTreeListViewModel; if (vm != null) { this.FocusedChangedEvent?.Invoke(vm.Vmo); } } //刷新 private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InitialData(); } //获取当前 public RoleTreeListViewModel GetCurrentViewModel() { if (_allBindingList == null) { TipFormHelper.ShowError("数据初始化错误!"); return null; } if (_allBindingList.Count < 1) { TipFormHelper.ShowInfo("无数据!"); return null; } var vm = this.treeList1.GetCurrentViewModel(_allBindingList); if (vm == null) { TipFormHelper.ShowWarn("请选择数据行!"); return null; } return vm; } } }