duheng
2024-03-26 11c7908bcc2ca699e88b7a0a17bc32e45521c349
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
using DevExpress.XtraEditors;
using IStation.Untity;
using System;
using System.ComponentModel;
using System.Linq;
 
namespace IStation.WinFrmUI.Basic
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MonitorPointListMgrCtrl : XtraUserControl
    {
        public MonitorPointListMgrCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialMultiColSettings();
            this.treeList1.SelectImageList = ImageLib.Lib;
            this.layoutControl1.SetupLayoutControl();
        }
 
        public class CurrentViewModel : Model.MonitorPointExSignalExSignalType
        {
            public CurrentViewModel() { }
 
            public CurrentViewModel(Model.MonitorPointExSignalExSignalType rhs) : base(rhs)
            {
                this.FlagsList = FlagsHelper.ToString(rhs.Flags);
                this.ImageIndex = ImageLib.MonitorPoint;
            }
            public string FlagsList { get; set; }
            public int ImageIndex { get; set; }
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary> 
        public event Action<Model.MonitorPointExSignalExSignalType> FocusedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.FocusedChangedEvent?.Invoke(null);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var monitorPointExSignalExSignalTypes = new BLL.MonitorPoint().GetAllExSignalExSignalType();
 
 
            if (monitorPointExSignalExSignalTypes != null && monitorPointExSignalExSignalTypes.Any())
            {
                foreach (var item in monitorPointExSignalExSignalTypes)
                {
                    var vm = new CurrentViewModel(item);
                    _allBindingList.Add(vm);
                }
            }
 
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.treeList1.BestFitColumns();
            this.treeList1.FocusedNode = this.treeList1.Nodes.FirstOrDefault();
            WaitFrmHelper.HideWaitForm();
        }
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(string mappingType, long mappingId)
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var monitorPointExSignalExSignalTypes = new BLL.MonitorPoint().GetExSignalExSignalTypeByMappingTypeAndMappingID(mappingType, mappingId);
            if (monitorPointExSignalExSignalTypes != null && monitorPointExSignalExSignalTypes.Any())
            {
                foreach (var item in monitorPointExSignalExSignalTypes)
                {
                    var vm = new CurrentViewModel(item);
                    _allBindingList.Add(vm);
                }
            }
 
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.treeList1.BestFitColumns();
            this.treeList1.FocusedNode = this.treeList1.Nodes.FirstOrDefault();
            WaitFrmHelper.HideWaitForm();
        }
 
        //聚焦改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
 
            this.FocusedChangedEvent?.Invoke(vm);
        }
 
 
    }
 
}