tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using DevExpress.XtraEditors;
using System.Collections.Generic;
 
namespace TProduct.WinFrmUI.TestBench
{
    public partial class WorkBenchInstrumentShunPortAnaCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public WorkBenchInstrumentShunPortAnaCtrl()
        {
            InitializeComponent();
 
 
            this.gridView1.SetNormalEditView();
            this.gridView1.SetGridMianViewColor();
 
            this.repositoryItemImageComboBox1.Items.Clear();
            //this.repositoryItemImageComboBox1.Items.AddEnum(typeof(Model.eAnalogDataType), false);
            this.repositoryItemImageComboBox1.Items.AddRange(
                new DevExpress.XtraEditors.Controls.ImageComboBoxItem[] {
                new DevExpress.XtraEditors.Controls.ImageComboBoxItem("4ma~20ma", Model.eAnalogDataType.I4to20ma, -1),
                new DevExpress.XtraEditors.Controls.ImageComboBoxItem("0ma~20ma", Model.eAnalogDataType.I0to20ma, -1)});
        }
 
        private class CurrentViewModel : Model.WorkBenchInstrumentShunPortAna
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Model.WorkBenchInstrumentShunPortAna rhs) : base(rhs)
            {
            }
 
            public bool IsChecked { get; set; }
            public string PortName { get; set; }
        }
        public static string PortName1 = "1号端口";
        public static string PortName2 = "2号端口";
        public static string PortName3 = "3号端口";
        public static string PortName4 = "4号端口";
 
        private List<CurrentViewModel> _bindList = null;
 
        /// <summary>
        /// 添加
        /// </summary>
        public void SetBindingData(Model.WorkBenchBase paras)
        {
            if (paras == null)
                return;
            _bindList = new List<CurrentViewModel>();
            _bindList.Add(new CurrentViewModel()
            {
                LinkID = 0,
                IsChecked = false,
                PortName = PortName1,
                PortIndex = 1,
                MonitorPointID = 0,
                UseStatus = Model.eUseStatus.Enable,
                AnalogDataType = Model.eAnalogDataType.I4to20ma
            });
 
            _bindList.Add(new CurrentViewModel()
            {
                LinkID = 0,
                IsChecked = false,
                PortName = PortName2,
                PortIndex = 2,
                MonitorPointID = 0,
                UseStatus = Model.eUseStatus.Enable,
                AnalogDataType = Model.eAnalogDataType.I4to20ma
            });
 
            //_bindList.Add(new CurrentViewModel()
            //{
            //    UseStatus = Model.eUseStatus.Enable,
            //    AnalogDataType = Model.eAnalogDataType.I4to20ma,
            //    MeasRangeMaxValue = 0,
            //    MeasRangeMinValue = 0,
            //    PortName = PortAna3
            //});
 
            //_bindList.Add(new CurrentViewModel()
            //{
            //    UseStatus = Model.eUseStatus.Enable,
            //    AnalogDataType = Model.eAnalogDataType.I4to20ma,
            //    MeasRangeMaxValue = 0,
            //    MeasRangeMinValue = 0,
            //    PortName = PortAna4
            //});
            var points = new BLL.WorkBenchMonitorPoint().Get模拟量ByBenchID(paras.ID);
            points?.ForEach(x => this.repositoryItemImageComboBox3.Items.Add(x.Name, x.ID, -1));
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
        }
 
        /// <summary>
        /// 编辑
        /// </summary>
        public void SetBindingData(Model.WorkBenchBase paras,
            Model.WorkBenchInstrumentShun sz02)
        {
            if (sz02 == null)
                return;
            var points = new BLL.WorkBenchMonitorPoint().Get模拟量ByBenchID(paras.ID);
            points?.ForEach(x => this.repositoryItemImageComboBox3.Items.Add(x.Name, x.ID, -1));
            var port_list = new BLL.WorkBenchInstrumentShunPortAna().GetByLinkID(sz02.ID);
            _bindList = new List<CurrentViewModel>();
            //x.PortName == PortAna2);
            var portAna1 = port_list?.Find(x => x.PortIndex == 1);
            if (portAna1 == null)
            {
                _bindList.Add(new CurrentViewModel()
                {
                    LinkID = sz02.ID,
                    IsChecked = false,
                    PortIndex = 1,
                    MonitorPointID = 0,
                    UseStatus = Model.eUseStatus.Enable,
                    AnalogDataType = Model.eAnalogDataType.I4to20ma,
                    PortName = PortName1
                });
            }
            else
            {
                _bindList.Add(new CurrentViewModel(portAna1) { IsChecked = true, PortName = PortName1 });
            }
 
            var portAna2 = port_list?.Find(x => x.PortIndex == 2);
            if (portAna2 == null)
            {
                _bindList.Add(new CurrentViewModel()
                {
                    LinkID = sz02.ID,
                    IsChecked = false,
                    PortIndex = 2,
                    MonitorPointID = 0,
                    UseStatus = Model.eUseStatus.Enable,
                    AnalogDataType = Model.eAnalogDataType.I4to20ma,
                    PortName = PortName2
                });
            }
            else
            {
                _bindList.Add(new CurrentViewModel(portAna2) { IsChecked = true, PortName = PortName2 });
            }
            if (sz02.SZ02Type == Model.eShunSZ02Type.Ana1234RS485)
            {
                var portAna3 = port_list?.Find(x => x.PortIndex == 3);
                if (portAna3 == null)
                {
                    _bindList.Add(new CurrentViewModel()
                    {
                        LinkID = sz02.ID,
                        IsChecked = false,
                        PortIndex = 3,
                        MonitorPointID = 0,
                        UseStatus = Model.eUseStatus.Enable,
                        AnalogDataType = Model.eAnalogDataType.I4to20ma,
                        PortName = PortName3
                    });
                }
                else
                {
                    _bindList.Add(new CurrentViewModel(portAna3) { IsChecked = true, PortName = PortName3 });
                }
                var portAna4 = port_list?.Find(x => x.PortIndex == 4);
                if (portAna4 == null)
                {
                    _bindList.Add(new CurrentViewModel()
                    {
                        LinkID = sz02.ID,
                        IsChecked = false,
                        PortIndex = 4,
                        MonitorPointID = 0,
                        UseStatus = Model.eUseStatus.Enable,
                        AnalogDataType = Model.eAnalogDataType.I4to20ma,
                        PortName = PortName4
                    });
                }
                else
                {
                    _bindList.Add(new CurrentViewModel(portAna4) { IsChecked = true, PortName = PortName4 });
                }
            }
 
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
        }
 
        /// <summary>
        /// 获取数据
        /// </summary>
        public List<Model.WorkBenchInstrumentShunPortAna> GetData()
        {
            if (!Verify())
                return null;
            var list = new List<Model.WorkBenchInstrumentShunPortAna>();
            _bindList.FindAll(x => x.IsChecked).ForEach(x => list.Add(new Model.WorkBenchInstrumentShunPortAna(x)));
            return list;
        }
 
        //验证
        private bool Verify()
        {
            var check_list = _bindList.FindAll(x => x.IsChecked);
            if (check_list != null)
            {
                var model = check_list.Find(x => x.MonitorPointID <= 0);
                if (model != null)
                {
                    XtraMessageBox.Show("请选择测点!");
                    return false;
                }
            }
            return true;
        }
 
    }
}