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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
using DataEntity;
using DataEntity.Share;
using DataRWDAL;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using XCommon.Log;
using XCore;
using XHandler.Class.DataEx;
using XHandler.View.Com;
using XImagingXhandler.XDAL;
 
namespace XHandler.View.MethodProperty
{
    /// <summary>
    /// 超声探测子页面
    /// </summary>
    public partial class UltrasonicChildProperty : System.Windows.Controls.UserControl
    {
        #region 变量
        private AspirateBll aspirateBll = new AspirateBll();
        private int mark = 0;
        public MethodUltrasonicChild m_ultrasonicData = null;
        #endregion
 
        #region 构造函数
        public UltrasonicChildProperty(MethodUltrasonicChild ultrasonicData, bool isFromChoice = false)
        {
            mark = 0;
            InitializeComponent();
            m_ultrasonicData = ultrasonicData;
 
            #region 台面位置
            List<string> list = new List<string>();
            List<Lattice> lattices = DataModule.getInstance().GetLattices();
            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);
                }
            }
            list.Insert(0, Properties.Resources.strPleaseSelect);   // 请选择
            comboboxTablePos.ItemsSource = list;
            if (isFromChoice)
            {
                // 挑选转运
                comboboxTablePos.IsEnabled = false;
            }
            #endregion
 
            // 获取耗材类型下拉选择数据
            ObservableCollection<DropdownName> labwareList = GenerateLabwareType();
            comboboxLabwareType.ItemsSource = labwareList;
 
            // 圆形皿多探测点位DataGrid
            dgPointListData.ItemsSource = m_ultrasonicData.pointList;
            this.DataContext = m_ultrasonicData;
        }
        #endregion
 
        #region 页面初始化
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mark += 1;
            try
            {
                if (mark > 1)
                {
                    return;
                }
 
                if (m_ultrasonicData == null)
                {
                    m_ultrasonicData = new MethodUltrasonicChild();
                    return;
                }
 
                // 台面位置
                if (!string.IsNullOrEmpty(m_ultrasonicData.positionValue))
                {
                    comboboxTablePos.SelectedItem = m_ultrasonicData.positionText;
                }
                else
                {
                    comboboxTablePos.SelectedIndex = 0;
                }
 
                // 耗材名称
                comboboxLabwareType.SelectedValue = m_ultrasonicData.labwareValue;
                if (m_ultrasonicData.pointList == null)
                {
                    // 构建圆形皿默认三个坐标
                    m_ultrasonicData.pointList = GenerateDefaultPointList();
                }
 
                tbxXAxis.Text = m_ultrasonicData.xDishAxisVal.ToString();
                tbxYAxis.Text = m_ultrasonicData.yDishAxisVal.ToString();
                tbxRowNum.Text = m_ultrasonicData.rowNum.ToString();
                tbxColumnNum.Text = m_ultrasonicData.columnNum.ToString();
                tbxCloseTop.Text = m_ultrasonicData.closeTopVal.ToString();
                tbxCloseLeft.Text = m_ultrasonicData.closeLeftVal.ToString();
                tbxDistanceOfX.Text = m_ultrasonicData.xAxisVal.ToString();
                tbxDistanceOfY.Text = m_ultrasonicData.yAxisVal.ToString();
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 台面位置选择变更
        private void comboboxTablePos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (comboboxTablePos.SelectedIndex < 0)
                {
                    return;
                }
                else if (comboboxTablePos.SelectedIndex == 0)
                {
                    m_ultrasonicData.positionValue = "";
                    m_ultrasonicData.positionText = "";
                    return;
                }
                else
                {
                    // 根据所选的台面加载圆皿中心坐标
                    Lattice lattice = null;
                    TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb();  //增加台面模板判断
                    if (tabletopTemplate == null)
                    {
                        lattice = LatticeDB.GetLatticeDataByIdFromdb((string)comboboxTablePos.SelectedItem, Convert.ToInt32(Shared.ChanelArmId), Shared.SoftwareInformation.software_device_number);
                    }
                    else
                    {
                        lattice = LatticeDB.GetLatticeDataByLatticeNumAndTempIdFromdb((string)comboboxTablePos.SelectedItem, Convert.ToInt32(Shared.DeviceArmList.SingleOrDefault(x => x.arm_type.Equals(1)).device_arm_id), Shared.SoftwareInformation.software_device_number, tabletopTemplate.tabletopid);
                    }
                    tbxXAxis.Text = ((double)lattice.lattice_X + ((double)lattice.lattice_length / (double)2)).ToString("0.0");
                    tbxYAxis.Text = ((double)lattice.lattice_Y + ((double)lattice.lattice_width / (double)2)).ToString("0.0");
 
                    m_ultrasonicData.positionText = ((string)comboboxTablePos.SelectedItem).ToString();
                    m_ultrasonicData.positionValue = ((string)comboboxTablePos.SelectedItem).ToString();
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 耗材名称选择变更事件
        private void comboboxLabwareType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (comboboxLabwareType.SelectedIndex == 0)
                {
                    bdDish.Visibility = Visibility.Visible;
                    bdLabware.Visibility = Visibility.Collapsed;
                }
                else if (comboboxLabwareType.SelectedIndex == 1)
                {
                    bdDish.Visibility = Visibility.Collapsed;
                    bdLabware.Visibility = Visibility.Visible;
                }
 
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.labwareValue = ((DropdownName)comboboxLabwareType.SelectedItem).dropdown_id.ToString();
                    m_ultrasonicData.labwareText = ((DropdownName)comboboxLabwareType.SelectedItem).dropdown_name.ToString();
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 圆形皿相关
        #region X轴
        private void tbxXAxis_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.xDishAxisVal = Convert.ToDouble(tbxXAxis.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region Y轴
        private void tbxYAxis_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.yDishAxisVal = Convert.ToDouble(tbxYAxis.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 点位设置    新增
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DropdownName dropdownName = new DropdownName();
                dropdownName.index_id = m_ultrasonicData.pointList.Count + 1;
                dropdownName.dropdown_id = "0";
                dropdownName.dropdown_name = "0";
                m_ultrasonicData.pointList.Add(dropdownName);
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 点位设置    删除
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int SelectedRow = dgPointListData.SelectedIndex;//尝试解析出所选行
                if (SelectedRow < 0)
                {
                    return;
                }
                var a = dgPointListData.Columns[0].GetCellContent(dgPointListData.Items[SelectedRow]);
 
                List<System.Windows.Controls.Label> listBtn = ViewCom.GetChildObjects<System.Windows.Controls.Label>((DependencyObject)a, typeof(System.Windows.Controls.Label));
                if (listBtn.Count > 0)
                {
                    int grd = Convert.ToInt32(listBtn[0].Tag);
 
                    m_ultrasonicData.pointList.Remove(m_ultrasonicData.pointList.FirstOrDefault(x => x.index_id == grd));
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 点位设置    单元格编辑
        private void dgPointListData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                // 如果点击了放弃按钮或ESC
                if (e.EditAction == DataGridEditAction.Cancel)
                {
                    return;
                }
                // 获取编辑模式显示的元素,因为使用了模板,因此这里是ContentPresenter类型
                ContentPresenter cp = e.EditingElement as ContentPresenter;
                if (cp != null && VisualTreeHelper.GetChildrenCount(cp) > 0)
                {
                    // 找到编辑框
                    System.Windows.Controls.TextBox textBox = VisualTreeHelper.GetChild(cp, 0) as System.Windows.Controls.TextBox;
                    // 如果找到
                    if (textBox != null)
                    {
                        #region Del
                        //验证输入值
                        //if (!Consumables.ConsumablesValidationRule.IsPositiveNumber(textBox.Text, out string message))
                        //{
                        //    textBox.Text = "0";
                        //    lnError.Text = message;
                        //    return;
                        //}
                        //else if (!Consumables.ConsumablesValidationRule.IsRange(textBox.Text, 0.0, 1000.0, false, out message))
                        //{
                        //    textBox.Text = "0";
                        //    lnError.Text = message;
                        //    return;
                        //}
                        //else
                        //{
                        //    lnError.Text = "";
                        //}
 
                        //if (!verificationTextBox.VerificateTextBox(textBox, 11))
                        //{
                        //    textBox.BorderThickness = new Thickness(2);
                        //    textBox.BorderBrush = Brushes.Red;
                        //    return;
                        //}
                        #endregion
 
                        int id = Convert.ToInt32(textBox.Tag);
                        var pointItem = m_ultrasonicData.pointList.FirstOrDefault(x => x.index_id == id);
 
                        DropdownName dropdown = new DropdownName();
                        dropdown.index_id = id;
                        if (textBox.Name == "tbXoffset")
                        {
                            dropdown.dropdown_id = textBox.Text;
                            pointItem.dropdown_id = textBox.Text;
                        }
                        else
                        {
                            dropdown.dropdown_name = textBox.Text;
                            pointItem.dropdown_name = textBox.Text;
                        }
 
                        var dataGrid = sender as System.Windows.Controls.DataGrid;
                        dataGrid.BeginEdit();
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
        #endregion
 
        #region 非圆皿相关
        #region 行数变更事件
        private void tbxRowNum_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.rowNum = Convert.ToInt32(tbxRowNum.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 列数变更事件
        private void tbxColumnNum_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.columnNum = Convert.ToInt32(tbxColumnNum.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 距顶边变更事件
        private void tbxCloseTop_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.closeTopVal = Convert.ToDouble(tbxCloseTop.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 距左边
        private void tbxCloseLeft_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.closeLeftVal = Convert.ToDouble(tbxCloseLeft.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region X间距
        private void tbxDistanceOfX_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.xAxisVal = Convert.ToDouble(tbxDistanceOfX.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region Y间距
        private void tbxDistanceOfY_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (m_ultrasonicData != null)
                {
                    m_ultrasonicData.yAxisVal = Convert.ToDouble(tbxDistanceOfY.Text);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
        #endregion
 
        #region 私有方法
        #region 构建耗材类型下拉选择数据
        private ObservableCollection<DropdownName> GenerateLabwareType()
        {
            ObservableCollection<DropdownName> dropdownNames = new ObservableCollection<DropdownName>();
            DropdownName dropdownName = new DropdownName();
            dropdownName.dropdown_id = "1";
            dropdownName.dropdown_name = "圆形皿";
            dropdownNames.Add(dropdownName);
            dropdownName = new DropdownName();
            dropdownName.dropdown_id = "2";
            dropdownName.dropdown_name = "非圆形皿";
            dropdownNames.Add(dropdownName);
            return dropdownNames;
        }
        #endregion
 
        #region 构建圆形皿默认三个坐标
        private ObservableCollection<DropdownName> GenerateDefaultPointList()
        {
            ObservableCollection<DropdownName> points = new ObservableCollection<DropdownName>();
 
            DropdownName point1 = new DropdownName();
            point1.dropdown_id = "-10";
            point1.dropdown_name = "0";
            points.Add(point1);
 
            point1 = new DropdownName();
            point1.dropdown_id = "0";
            point1.dropdown_name = "0";
            points.Add(point1);
 
            point1 = new DropdownName();
            point1.dropdown_id = "10";
            point1.dropdown_name = "0";
            points.Add(point1);
 
            return points;
        }
        #endregion
 
        #endregion
    }
}