duheng
2024-10-25 59e5e0bf989993c0dce1851e34bcbe4bfb42ed56
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
127
128
129
130
131
132
133
134
135
using DevExpress.Utils.Extensions;
using System.ComponentModel;
using Yw.Dto;
 
namespace HStation.WinFrmUI.Basic
{
    public partial class SysTypeTreeListLookUpEdit : DevExpress.XtraEditors.XtraUserControl
    {
        public SysTypeTreeListLookUpEdit()
        {
            InitializeComponent();
            this.treeListLookUpEdit1.EditValueChanged += treeListLookUpEdit1_EditValueChanged;
            this.treeListLookUpEdit1TreeList.InitialDefaultSettings();
            this.treeListLookUpEdit1TreeList.OptionsView.ShowIndicator = false;
            this.treeListLookUpEdit1.Properties.PopupFormSize = new System.Drawing.Size(200, 400);
        }
 
        public class CurrentViewModel
        {
            public CurrentViewModel(Yw.Vmo.SysTypeLogicalTreeVmo rhs)
            {
                var module = rhs.LogicalModel as Yw.Dto.SysModuleStdDto;
                this.ID = module.ID;
                this.Name = module.Name;
                this.SortCode = module.SortCode;
                this.Description = module.Description;
            }
 
            public CurrentViewModel(SysTypeStdDto rhs)
            {
                this.ID = rhs.ID;
                this.Name = rhs.Name;
                this.SortCode = rhs.SortCode;
                this.Description = rhs.Description;
                this.ParentID = rhs.ModuleID;
            }
 
            /// <summary>
            /// ID
            /// </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; }
        }
 
        private Yw.BLL.SysTypeStd _bll = null;
 
        /// <summary>
        /// 选择项变换
        /// </summary>
        public event Action<long> SelectedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList { get; set; }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData()
        {
            _bll = new Yw.BLL.SysTypeStd();
            var alllist = await _bll.GetExtendLogicalTreeList();
            if (alllist == null)
                return;
            _allBindingList = new BindingList<CurrentViewModel>();
            foreach (var item in alllist)
            {
                _allBindingList.Add(new CurrentViewModel(item));
                foreach (var child in item.Children)
                {
                    var type = child.LogicalModel as Yw.Dto.SysTypeStdDto;
                    if (type != null)
                    {
                        _allBindingList.Add(new CurrentViewModel(type));
                    }
                }
            }
            this.treeListLookUpEdit1TreeList.DataSource = _allBindingList;
            this.treeListLookUpEdit1TreeList.ExpandAll();
            if (_allBindingList.Count > 0)
            {
                var vm = _allBindingList.Where(x => x.ParentID != 0).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;
        }
    }
}