Shuxia Ning
2025-01-08 687a3dfd095bc8c099b7fa6e65f0dc699fdc8f1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
    {
        /// <summary>
        ///
        /// </summary>
        public RoleTreeListCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.layoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary>
        public event Action<Yw.Vmo.Role> FocusedChangedEvent;
 
        /// <summary>
        /// 所有绑定列表
        /// </summary>
        private List<RoleTreeListViewModel> _allBindingList = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public async void InitialData()
        {
            var overlay = this.ShowOverlay();
            var allList = await BLLFactory<Yw.BLL.Role>.Instance.GetByCorpID(0);
            _allBindingList = new List<RoleTreeListViewModel>();
            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;
        }
    }
}