tangxu
2024-04-24 1c5fa983ae3506c2edaa88c51a959d46685c1ba1
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList;
using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Monitor
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MultiMonitorPointListCtrl : XtraUserControl
    {
        public MultiMonitorPointListCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultMultiSelectSettings();
            this.treeList1.SelectImageList = ImageLib.Lib;
            this.layoutControl1.SetupLayoutControl();
        }
 
 
        public class CurrentViewModel
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Model.MonitorPointGroup rhs)
            {
                this.ID = rhs.ID;
                this.ParentID = TreeParentIdsHelper.GetLastParentID(rhs.ParentIds);
                this.Name = rhs.Name;
                this.ObjectID = rhs.ID;
                this.SortCode = rhs.SortCode;
                this.Description = rhs.Description;
                this.ImageIndex = ImageLib.Group;
                this.IsGroup = true;
                this.Model = rhs;
            }
            public CurrentViewModel(Model.MonitorPointExSignalExSignalType rhs)
            {
                this.ID = rhs.MonitorPointID;
                this.ParentID = rhs.GroupID == 0 ? -1 : rhs.GroupID;
                this.Name = rhs.Name;
                this.ObjectID = rhs.MonitorPointID;
                this.SortCode = rhs.SortCode;
                this.Description = rhs.Description;
                this.ImageIndex = ImageLib.MonitorPoint;
                this.IsGroup = false;
                this.Model = rhs;
            }
 
            public long ID { get; set; }
            public long ParentID { get; set; }
            public string Name { get; set; }
            public long ObjectID { get; set; }
            public int SortCode { get; set; }
            public string Description { get; set; }
            public bool IsGroup { get; set; }
            public int ImageIndex { get; set; }
            public bool? Checked { get; set; } = false;
            public Color Color { get; set; }
            public object Model { get; set; }
        }
 
        /// <summary>
        /// 选择改变事件
        /// </summary>
        public event Action<Model.MonitorPointExSignalExSignalType, System.Drawing.Color, bool> CheckChangedEvent;
 
        private List<CurrentViewModel> _allBindingList = null;//所有绑定列表  
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            var monitorPointGroups = new BLL.MonitorPointGroup().GetAll();
            var monitorPoints = new BLL.MonitorPoint().GetAllExSignalExSignalType();
            this.SetBindingData(monitorPointGroups, monitorPoints);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(List<Model.MonitorPointGroup> monitorPointGroups, List<Model.MonitorPointExSignalExSignalType> monitorPoints)
        {
            _allBindingList = new List<CurrentViewModel>();
            var stationGroup = new Model.MonitorPointGroup();
            stationGroup.ID = -1;
            stationGroup.Name = "总站";
            stationGroup.SortCode = int.MinValue;
            stationGroup.Description = "虚拟分组";
            _allBindingList.Add(new CurrentViewModel(stationGroup));
 
            if (monitorPointGroups != null && monitorPointGroups.Count > 0)
            {
                monitorPointGroups = monitorPointGroups.OrderBy(x => x.SortCode).ToList();
                monitorPointGroups.ForEach(x => _allBindingList.Add(new CurrentViewModel(x)));
            }
 
            if (monitorPoints != null && monitorPoints.Count > 0)
            {
                monitorPoints = monitorPoints.OrderBy(x => x.SortCode).ToList();
                foreach (var point in monitorPoints)
                {
                    _allBindingList.Add(new CurrentViewModel(point));
                }
            }
 
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.ForceInitialize();
        }
 
        //全部展开
        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();
        }
 
        //检索
        private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barCkSearch.Checked)
                this.treeList1.ShowFindPanel();
            else
                this.treeList1.HideFindPanel();
        }
 
        //详细信息
        private void barBtnDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            XtraMessageBox.Show("待补充!");
        }
 
 
        //节点选中前
        private void treeList1_BeforeCheckNode(object sender, CheckNodeEventArgs e)
        {
            var vm = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
            if (vm == null)
                return;
            if (vm.IsGroup)
            {
                e.CanCheck = false;
            }
        }
 
        //节点选中后
        private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
        {
            if (_allBindingList == null)
                return;
            if (_allBindingList.Where(x => !x.IsGroup && x.Checked == true).Count() > 11)
            {
                XtraMessageBox.Show("目前只支持十个测点展示!");
                e.Node.Checked = false;
                return;
            }
 
            var vm = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
            if (vm == null)
                return;
            if (vm.IsGroup)
                return;
            var monitorPoint = vm.Model as Model.MonitorPointExSignalExSignalType;
            if (monitorPoint == null)
                return;
            vm.Color = ColorHelper.GetRandomColor();
            this.CheckChangedEvent?.Invoke(monitorPoint, vm.Color, e.Node.Checked);
        }
 
 
        //绘制单元格
        private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
        {
            /* var node = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
             if (node == null)
                 return;
             if (node.Checked.HasValue && node.Checked.Value)
             {
                 e.Appearance.ForeColor = node.Color;
             }*/
        }
 
        //取消绘制单元格
        private void treeList1_CustomDrawNodeCheckBox(object sender, CustomDrawNodeCheckBoxEventArgs e)
        {
            var node = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
            if (node == null)
                return;
            if (node.IsGroup)
            {
                e.ObjectArgs.State = DevExpress.Utils.Drawing.ObjectState.Disabled;
            }
        }
 
        //清空选中项
        private void barBtnClearChecked_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (var vm in _allBindingList)
            {
                if (vm.Checked == true)
                {
                    vm.Checked = false;
                    if (vm.IsGroup)
                        continue;
                    var monitorPoint = vm.Model as Model.MonitorPointExSignalExSignalType;
                    this.CheckChangedEvent?.Invoke(monitorPoint, vm.Color, false);
                }
            }
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.RefreshDataSource();
        }
 
 
    }
 
}