schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XImagingXhandler.XDAL;
using DataEntity.Share;
using DataEntity;
using System.Collections.ObjectModel;
using XHandler.Class.DataEx;
using System.Runtime.Remoting.Channels;
using XCommon.Log;
using XHandler.Controls;
using DataRWDAL;
using HandyControl.Data;
using XCommon.Tip;
using System.Windows.Shell;
 
namespace XHandler.View.MethodProperty
{
    /// <summary>
    /// SwitchLidProperty.xaml 的交互逻辑
    /// </summary>
    public partial class SwitchLidProperty : UserControl,IMethodProperty
    {
        public MethodSwitchLid methodSwitchLid { get; set; }
        public MethodEx method = null;
 
        public MethodSwitchLid currmethodSwitchLid = null;
 
        #region 变量
        string isrun = "";
        string status = "";
        string name = "";
        string label = "";
        string labwareText = "";
        string labwareValue = "";
        string positionText = "";
        string positionValue = "";
        string armText = "";
        string armValue = "";
        string wellarray = "";
        int switchState = 0;
        double numOfCircle = 0;
        double switchSpeed = 0;
        int curArmSelectedIndex = -1;
        private Labware selectedLabware = null;
        int mark = 0;
        #endregion
 
        public SwitchLidProperty()
        {
            InitializeComponent();
        }
 
        public SwitchLidProperty(MethodEx method)
        {
            mark = 0;
            InitializeComponent();
 
            List<DeviceArm> armList = DataModule.getInstance().GetDeviceArm();
            cbArm.ItemsSource = armList;
            if (armList.Count == 2) //只有一个臂的情况下默认选中该臂
            {
                curArmSelectedIndex = 1;
            }
            else if (armList.Count == 5)
            {
                curArmSelectedIndex = 2;
            }
            else
            {
                curArmSelectedIndex = 0;
            }
 
            //加载台面
            List<string> list = new List<string>();
            List<Lattice> lattices = DataModule.getInstance().GetLattices();
            TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb();  //增加台面模板判断
            if (tabletopTemplate == null)
            {
                for (int i = 0; i < Shared.SoftwareInformation.columns; i++)
                {
                    for (int j = 0; j < Shared.SoftwareInformation.rows; j++)
                    {
                        int tmp = i * Shared.SoftwareInformation.rows + j;
                        Lattice latt = lattices[tmp];
                        if (latt.is_trash == 1)
                            continue;
                        list.Add(latt.lattice_num);
                    }
                }
            }
            else
            {
                foreach (Lattice lattice in lattices)
                {
                    if (lattice.is_trash == 1)
                        continue;
                    list.Add(lattice.lattice_num);
                }
            }
            comboboxTablePos.ItemsSource = list;
            comboboxTablePos.SelectedIndex = 0;
 
            
            tbxCommandLabel.Text = method.method_name;
            methodSwitchLid = new MethodSwitchLid();
            methodSwitchLid.name = method.method_name;
            methodSwitchLid.label = method.method_name;
            methodSwitchLid.status = (method.isEnabled == true ? "enable" : "disable");
            methodSwitchLid.strIndex = method.strIndex;
            methodSwitchLid.wellarray = "";
 
            this.method = method;
            if (method.tag != null)
            {
                methodSwitchLid = (MethodSwitchLid)method.tag;
 
                currmethodSwitchLid = methodSwitchLid;
 
                isrun = methodSwitchLid.isrun;
                status = methodSwitchLid.status;
                name = methodSwitchLid.name;
                label = methodSwitchLid.label;
                labwareText = methodSwitchLid.labwareText;
                labwareValue = methodSwitchLid.labwareValue;
                positionText = methodSwitchLid.positionText;
                positionValue = methodSwitchLid.positionValue;
                armText = methodSwitchLid.armText;
                armValue = methodSwitchLid.armValue;
                switchState = methodSwitchLid.switchState;
                numOfCircle=methodSwitchLid.numOfCircle;
                switchSpeed= methodSwitchLid.switchSpeed;
                wellarray = methodSwitchLid.wellarray;
 
                if (this.method != null)
                {
                    this.method.method_Tipcontent = string.Format("执行{0}盖;旋转速度:{1};旋转圈数:{2}", methodSwitchLid.switchState == 1 ? "关" : "开", methodSwitchLid.switchSpeed.ToString(), methodSwitchLid.numOfCircle.ToString());
                }
            }
            this.DataContext = methodSwitchLid;
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mark += 1;
            try
            {
                if (mark > 1)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(armText))
                {
                    tbxCommandName.Text = name;
                    cbArm.SelectedValue = armValue;
                    DeviceArm arm = cbArm.SelectedItem as DeviceArm;
                    comboboxTablePos.SelectedItem = positionText;
                    tbxWellPositionTips.Text = wellarray;
                    //根据板位上的耗材类型,显示耗材孔位示意图
                    Labware labwareA = DataRWDAL.LabwareDB.GetLabware(methodSwitchLid.labwareValue);
 
                    wellPlate.Rows = labwareA.number_row;
                    wellPlate.Columns = labwareA.number_column;
 
                    if (labwareA.labware_type_id.Equals("4"))
                    {
                        labwareA.labwareWellInfoList = DataRWDAL.LabwareDB.GetSpecialLabwareWellInfo(labwareA.labware_id);
                        wellPlate.labwareWellInfoList = labwareA.labwareWellInfoList;
                        wellPlate.LabwareRealWidth = labwareA.labware_length;
                        wellPlate.LabwareRealLength = labwareA.labware_width;
                    }
 
                    wellPlate.Selection = wellarray;
 
                    if(switchState==0)
                    {
                        radioBtnSwitchOpen.IsChecked = true;
                    }
                    else if(switchState==1)
                    {
                        radioBtnSwitchClose.IsChecked = true;
                    }
                }
                else
                {
                    radioBtnSwitchOpen.IsChecked = true;
                    
                    cbArm.SelectedIndex = curArmSelectedIndex;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void radioBtnSwitchOpen_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.switchState = 0;
 
                    if (this.method != null)
                    {
                        this.method.method_Tipcontent = string.Format("执行{0}盖;旋转速度:{1};旋转圈数:{2}","开", methodSwitchLid.switchSpeed.ToString(), methodSwitchLid.numOfCircle.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void radioBtnSwitchClose_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.switchState = 1;
                    if (this.method != null)
                    {
                        this.method.method_Tipcontent = string.Format("执行{0}盖;旋转速度:{1};旋转圈数:{2}", "关", methodSwitchLid.switchSpeed.ToString(), methodSwitchLid.numOfCircle.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxCommandLabel_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
 
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.label = tbxCommandLabel.Text;
                    methodSwitchLid.name = tbxCommandName.Text.ToString();
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
 
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.label = tbxCommandLabel.Text;
                    methodSwitchLid.name = tbxCommandName.Text.ToString();
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                // 臂未选择
                if (cbArm.SelectedIndex < 0 || cbArm.SelectedIndex == 0)
                {
                    return;
                }
 
                string armName = ((DeviceArm)cbArm.SelectedItem).device_arm_name.ToString();
                DeviceArm arm = cbArm.SelectedItem as DeviceArm;
                methodSwitchLid.armText = arm.device_arm_name;
                methodSwitchLid.armValue = arm.device_arm_id.ToString();
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        #region 设置某些属性信息值
        public void SetTableName(string tableName, Labware lb)
        {
            try
            {
                if (lb == null)
                    return;
                if (string.IsNullOrEmpty(lb.labware_id))
                    return;
                selectedLabware = lb;
                wellPlate.Rows = lb.number_row;
                wellPlate.Columns = lb.number_column;
                wellPlate.labwareWellInfoList = lb.labwareWellInfoList;
                wellPlate.LabwareRealWidth = lb.labware_length;
                wellPlate.LabwareRealLength = lb.labware_width;
                wellPlate.DataContext = lb;
 
                List<Lattice> latticeList = DataRWDAL.LatticeDB.GetGripperLatticeNumDataFromdb(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(Shared.DeviceArmList.FirstOrDefault(x=>x.arm_type.Equals(1)).device_arm_id));
                Lattice lattice = latticeList.Find(s => s.lattice_num == tableName);
                if (lattice == null)
                {
                    LoggerHelper.InfoLog("Error: Can't find lattice with lattice_num=" + tableName);
                    return;
                }
                comboboxTablePos.SelectedItem = tableName;
                if (lb.labware_tubeshelf_type.Equals(1))//异形管架耗材
                {
                    tbxWellPositionTips.Text = "";
                    wellPlate.Selection = "";
                }
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.positionText = tableName;
                    methodSwitchLid.positionValue = lattice.lattice_id;  //Id 在运行时不能作为条件去查询板位夹爪的坐标,只能用lattice_num
                    methodSwitchLid.labwareText = lb.labware_name;
                    methodSwitchLid.labwareValue = lb.labware_id;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        private void comboboxTablePos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (comboboxTablePos.SelectedItem == null)
                    return;
                string name = comboboxTablePos.SelectedItem as string;
                SetTableName(name, selectedLabware);
 
                #region 验证台面耗材类型
                if (TestDesign.SelectLabwares.Count() <= 0 || TestDesign.SelectLabwares.FirstOrDefault(m => m.Label.Equals(comboboxTablePos.SelectedValue.ToString())) == null)
                    return;
 
                ControlLabware labware = TestDesign.SelectLabwares.FirstOrDefault(m => m.Label.Equals(comboboxTablePos.SelectedValue.ToString()));
                if ("1,3,5,4".Contains(labware.LabwareType.ToString()))
                {
                    tbkErrorWellPosition.Text = "";
                }
                else
                {
                    tbkErrorWellPosition.Text = $"不能在耗材 [{labware.LabwareName}] 执行吸液";
                }
                #endregion
 
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxNumOfCircleTransfer_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.numOfCircle = Convert.ToDouble(tbxNumOfCircleTransfer.Text);
                    if (this.method != null)
                    {
                        this.method.method_Tipcontent = string.Format("执行{0}盖;旋转速度:{1};旋转圈数:{2}", methodSwitchLid.switchState==1?"关":"开", methodSwitchLid.switchSpeed.ToString(), methodSwitchLid.numOfCircle.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
                return;
            }
        }
 
        private void tbxSpeedOfCircleTransfer_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (methodSwitchLid != null)
                {
                    methodSwitchLid.switchSpeed = Convert.ToDouble(tbxSpeedOfCircleTransfer.Text);
                    if (this.method != null)
                    {
                        this.method.method_Tipcontent = string.Format("执行{0}盖;旋转速度:{1};旋转圈数:{2}", methodSwitchLid.switchState == 1 ? "关" : "开", methodSwitchLid.switchSpeed.ToString(), methodSwitchLid.numOfCircle.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
                return;
            }
        }
 
        private void wellPlate_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                tbxWellPositionTips.Text = wellPlate.Selection;
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("wellPlate_MouseLeftButtonDown ERROR:", ex);
            }
        }
    }
}