lixiaojun
2024-12-11 be1dcb30e552fff6a2cf733d6577b103665edded
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
namespace HStation.WinFrmUI.PhartRelation
{
    /// <summary>
    ///
    /// </summary>
    public partial class XhsValveMainPhartListCtrl : XtraUserControl
    {
        public XhsValveMainPhartListCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.treeList1.SelectImageList = ImageLib.Lib;
            this.layoutControl1.SetupLayoutControl();
        }
 
        public class CurrentViewModel
        {
            public CurrentViewModel()
            { }
 
            public CurrentViewModel(Vmo.XhsValveMainPhartMappingExtensions model)
            {
                this.ID = model.ID;
                this.Name = model.OtherName;
                this.Importance = model.Importance;
                this.SortCode = model.SortCode;
                this.ImageIndex = ImageLib.Question;
                this.Model = model;
            }
 
            public CurrentViewModel(Vmo.AssetsValveCoefficientVmo model)
            {
                this.ID = model.ID;
                // this.Name = model.OtherName;
                //  this.Importance = model.Importance;
                //this.SortCode = model.SortCode;
                this.ImageIndex = ImageLib.Question;
                this.Model = model;
            }
 
            public long ID { get; set; }
            public string Name { get; set; }
            public int Importance { get; set; }
            public int SortCode { get; set; }
            public int ImageIndex { get; set; }
            public object Model { get; set; }
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary>
        public event Action<Vmo.AssetsValveCoefficientVmo> FocusedChangedEvent;
 
        private readonly Lazy<BLL.AssetsValveCoefficient> _bll_ex = new();
        private List<CurrentViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            _allBindingList = new List<CurrentViewModel>();
            this.treeList1.DataSource = _allBindingList;
            this.FocusedChangedEvent?.Invoke(null);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData(long valve_main_id)
        {
            WaitFormHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new List<CurrentViewModel>();
            var list = await _bll_ex.Value.GetByMainID(valve_main_id);
            if (list != null && list.Any())
            {
                //list= list.OrderBy(x => x.Importance).ToList();
                foreach (var item in list)
                {
                    var vm = new CurrentViewModel(item);
                    _allBindingList.Add(vm);
                }
            }
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.ForceInitialize();
            WaitFormHelper.HideWaitForm();
        }
 
        /// <summary>
        /// 添加
        /// </summary>
        public void Add(Vmo.XhsValveMainPhartMappingExtensions vmo)
        {
            if (vmo == null)
                return;
            var vm = new CurrentViewModel(vmo);
            _allBindingList.Add(vm);
            this.treeList1.RefreshDataSource();
        }
 
        /// <summary>
        /// 添加
        /// </summary>
        public void Add(Vmo.AssetsValveCoefficientVmo vmo)
        {
            if (vmo == null)
                return;
            var vm = new CurrentViewModel(vmo);
            _allBindingList.Add(vm);
            this.treeList1.RefreshDataSource();
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        public void Delete(long id)
        {
            _allBindingList.RemoveAll(x => x.ID == id);
            this.treeList1.RefreshDataSource();
        }
 
        /// <summary>
        /// 别名
        /// </summary>
        public void UpdateOtherName(long id, string other_name)
        {
            var vmo = _allBindingList.Find(x => x.ID == id);
            if (vmo != null)
            {
                vmo.Name = other_name;
                (vmo.Model as Vmo.XhsValveMainPhartMappingExtensions).OtherName = other_name;
                this.treeList1.RefreshNode(this.treeList1.FocusedNode);
            }
        }
 
        /// <summary>
        /// 重要度
        /// </summary>
        public void UpdateImportance(long id, int importance)
        {
            var vmo = _allBindingList.Find(x => x.ID == id);
            if (vmo != null)
            {
                vmo.Importance = importance;
                (vmo.Model as Vmo.XhsValveMainPhartMappingExtensions).Importance = importance;
                this.treeList1.RefreshNode(this.treeList1.FocusedNode);
            }
        }
 
        //聚焦改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
 
            var vmo = vm.Model as Vmo.AssetsValveCoefficientVmo;
            this.FocusedChangedEvent?.Invoke(vmo);
        }
    }
}