duheng
2025-03-27 d2ccacb3317aa6310f1b1bb5eb19fbdecba39ff9
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
117
118
119
120
121
122
123
124
125
126
using HStation.WinFrmUI;
using System.ComponentModel;
using MessageBoxHelper = Yw.WinFrmUI.MessageBoxHelper;
 
namespace MFire.WinFrmUI
{
    public partial class SelectCorprationListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectCorprationListCtrl()
        {
            InitializeComponent();
            this.treeListLookUpEdit1TreeList.InitialDefaultSettings(25);
            this.treeListLookUpEdit1TreeList.SelectImageList = svgImageTree;
            this.treeListLookUpEdit1.EditValueChanged += treeListLookUpEdit1_EditValueChanged;
        }
 
        public class CurrentViewModel
        {
            public CurrentViewModel(Yw.Vmo.SysModuleVmo rhs)
            {
                this.ID = rhs.ID;
                this.Name = rhs.Name;
                this.SortCode = rhs.SortCode;
                this.Description = rhs.Description;
            }
 
            public CurrentViewModel(Yw.Vmo.SysTypeVmo rhs)
            {
                this.ID = rhs.ID;
                this.Name = rhs.Name;
                this.SortCode = rhs.SortCode;
                this.Description = rhs.Description;
                this.ParentID = rhs.ModuleID;
            }
 
            /// <summary>
            /// UserID
            /// </summary>
            public long ID { get; set; }
 
            /// <summary>
            /// 父级ID
            /// </summary>
            public long ParentID { get; set; }
 
            /// <summary>
            /// 名称
            /// </summary>
            public string Name { get; set; }
 
            /// <summary>
            /// 排序码
            /// </summary>
            public int SortCode { get; set; }
 
            /// <summary>
            /// 说明
            /// </summary>
            public string Description { get; set; }
        }
 
        /// <summary>
        /// 选择项变换
        /// </summary>
        public event Action<long> SelectedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList { get; set; }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            var alllist = await SysTypeHelper.GetSysTypeTreeList();
            if (alllist == null)
                return;
            foreach (var item in alllist)
            {
                _allBindingList.Add(new CurrentViewModel(item.Module));
                foreach (var child in item.Children)
                {
                    _allBindingList.Add(new CurrentViewModel(child));
                }
            }
            this.treeListLookUpEdit1TreeList.DataSource = _allBindingList;
            this.treeListLookUpEdit1TreeList.ExpandAll();
            if (_allBindingList.Count > 0)
            {
                var vm = _allBindingList.First();
                this.treeListLookUpEdit1.EditValue = vm.ID;
                SelectedChanged(vm);
            }
        }
 
        //选择对象变换
        private void SelectedChanged(CurrentViewModel vm)
        {
            if (SelectedChangedEvent != null)
            {
                SelectedChangedEvent.Invoke(vm.ID);
            }
        }
 
        //值变换
        private void treeListLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            var vm = this.treeListLookUpEdit1TreeList.GetCurrentViewModel(_allBindingList);
            if (vm != null)
            {
                SelectedChanged(vm);
            }
        }
 
        public long GetCurrentTypeID()
        {
            var vm = this.treeListLookUpEdit1TreeList.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return default;
            }
            return vm.ID;
        }
    }
}