yangyin
2024-08-20 98e49c0dd42840a094837f7acae532bc237a719a
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
using DevExpress.XtraEditors;
using Yw.Basic;
 
namespace HStation.WinFrmUI.Basic
{
    /// <summary>
    ///
    /// </summary>
    public partial class SysTypeListBoxCtrl : XtraUserControl
    {
        public SysTypeListBoxCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary>
        public event Action<long> FocusedChangedEvent;
 
        private List<SysTypeTreeListViewModel> _allBindingList = null;
 
        private Yw.BLL.SysTypeStd _bll = null;
 
        private Yw.BLL.SysModule _Modulebll = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            this.FocusedChangedEvent?.Invoke(default);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData()
        {
            _allBindingList = new List<SysTypeTreeListViewModel>();
            _bll = new Yw.BLL.SysTypeStd();
            var alllist = await _bll.GetLogicalTreeListByExtendType(eExtendType.Catalog);
            if (alllist == null) return;
            foreach (var item in alllist)
            {
                var module = new SysTypeTreeListViewModel(item);
                _allBindingList.Add(module);
                foreach (var child in item.Children)
                {
                    var children = new SysTypeTreeListViewModel(child);
                    _allBindingList.Add(children);
                }
            }
            this.moduleViewModelBindingSource.DataSource = _allBindingList;
            this.moduleViewModelBindingSource.ResetBindings(false);
        }
 
        //聚焦改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var currentVm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (currentVm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            FocusedChangedEvent.Invoke(currentVm.ID);
        }
 
        #region 菜单事件
 
        //检索
        private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barCkSearch.Checked)
                this.treeList1.ShowFindPanel();
            else
                this.treeList1.HideFindPanel();
        }
 
        #endregion 菜单事件
 
        //获取当前选中id
        public long GetCurrentID()
        {
            var currentVm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (currentVm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return default;
            }
            if (currentVm.ParentID == 0)
            {
                MessageBoxHelper.ShowWarning("请选择具体类型!");
                return default;
            }
            return currentVm.ID;
        }
 
        //全部折叠
        private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.CollapseAll();
        }
 
        //全部展开
        private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.ExpandAll();
        }
    }
}