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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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 XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
using static XHandler.Controls.MultiComboBox;
using XCore;
using System.Runtime.Remoting.Channels;
using XHandler.Controls;
using XHandler.View.MethodProperty;
using XCommon.Log;
using DataEntity.Share;
 
namespace XHandler.View.BacteriaProperty
{
    /// <summary>
    /// CaptureProperty.xaml 的交互逻辑
    /// </summary>
    public partial class CaptureProperty : UserControl, IMethodProperty
    {
        ObservableCollection<MultiCbxBaseData> bacteriaList = new ObservableCollection<MultiCbxBaseData>();
        BacteriaBll bacteriaBll = new BacteriaBll();
        int mark = 0;
 
        #region 全局变量
        string isrun = "";
        string status = "";
        string name = "";
        string label = "";
        int ismanualconfig = 0;
        string bacteriaids = "";
        string paramfilepath = "";
        string gapValue = "";
        string colorText = "";
        string colorValue = "";
        int choicemode = 0;
        int choiceTimes = 0;
        string coatingLabwareText = "";        // 涂布耗材名称文本
        string coatingLabwareValue = "";       // 涂布耗材名称Id
        private int coatingLabwareGotFocus = 0;
 
        #endregion
 
        public MethodTakePhoto methodTakePhoto { get; set; }
        public MethodTakePhoto currmethodTakePhoto = null;
        public CaptureProperty()
        {
            InitializeComponent();
        }
 
        public CaptureProperty(MethodEx method)
        {
            mark = 0;
            InitializeComponent();
            methodTakePhoto = new MethodTakePhoto();
            methodTakePhoto.name = method.method_name;
            methodTakePhoto.label = method.method_name;
            methodTakePhoto.status = (method.isEnabled == true ? "enable" : "disable");
            methodTakePhoto.strIndex = method.strIndex;
            this.DataContext = methodTakePhoto;
 
            if (methodTakePhoto.ismanualconfig == 1)
                radioBtnManualConfig.IsChecked = true;
            else
                radioBtnAutoConfig.IsChecked = true;
 
            if (methodTakePhoto.identification == 1)
                radioBtnManual.IsChecked = true;
            else
                radioBtnAuto.IsChecked = true;
 
            if (methodTakePhoto.choiceTimes == 1)
                radioBtnTimes1.IsChecked = true;
            else
                radioBtnTimes2.IsChecked = true;
 
            ObservableCollection<Bacteria> bacterias = DataModule.getInstance().GetBacterias();
            foreach (Bacteria b in bacterias)
            {
                MultiCbxBaseData data = new MultiCbxBaseData();
                data.ID = b.bacteria_id;
                data.ViewName = b.bacteria_name;
                data.IsCheck = false;
                bacteriaList.Add(data);
            }
 
            mcbBacteria.ItemsSource = bacteriaList;
 
            ObservableCollection<BacteriaColor> colorList = bacteriaBll.GetBacteriaColorList();
            mcbBacteriaBackColor.ItemsSource = colorList;
            mcbBacteriaBackColor.SelectedIndex = 0;
            methodTakePhoto.bacteriaids = "";
            methodTakePhoto.gapValue = "0";
            methodTakePhoto.colorText = "";
            methodTakePhoto.colorValue = "";
            methodTakePhoto.identification = 0;
 
            if (method.tag != null)
            {
                methodTakePhoto = (MethodTakePhoto)method.tag;
                currmethodTakePhoto = methodTakePhoto;
 
                isrun = methodTakePhoto.isrun;
                status = methodTakePhoto.status;
                name = methodTakePhoto.name;
                label = methodTakePhoto.label;
                ismanualconfig = methodTakePhoto.ismanualconfig;
                bacteriaids = methodTakePhoto.bacteriaids;
                paramfilepath = methodTakePhoto.paramfilepath;
                gapValue = methodTakePhoto.gapValue;
                colorText = methodTakePhoto.colorText;
                colorValue = methodTakePhoto.colorValue;
                choicemode = methodTakePhoto.identification;
                choiceTimes = methodTakePhoto.choiceTimes;
                coatingLabwareText = methodTakePhoto.coatingLabwareText;
                coatingLabwareValue = methodTakePhoto.coatingLabwareValue;
            }
 
            radioBtnManualConfig.IsChecked = true;
            radioBtnAutoConfig.Visibility = Visibility.Hidden;
            imgTips.Visibility = Visibility.Hidden;
            tbxParamFromCentWidthralControl.Visibility = Visibility.Hidden;
 
            radioBtnManual.IsChecked = true;
            //tBoxIdentification.Visibility = Visibility.Collapsed;
            //radioBtnAuto.Visibility = Visibility.Hidden;
        }
 
        private void radioBtnManualConfig_Checked(object sender, RoutedEventArgs e)
        {
            if (methodTakePhoto == null)
                return;
            methodTakePhoto.ismanualconfig = 1;
            gridManual.Visibility = Visibility.Visible;
        }
 
        private void radioBtnAutoConfig_Checked(object sender, RoutedEventArgs e)
        {
            if (methodTakePhoto == null)
                return;
            methodTakePhoto.ismanualconfig = 2;
            gridManual.Visibility = Visibility.Collapsed;
        }
 
        private void radioBtnManual_Checked(object sender, RoutedEventArgs e)
        {
            if (methodTakePhoto == null)
                return;
            methodTakePhoto.identification = 1;
        }
 
        private void radioBtnAuto_Checked(object sender, RoutedEventArgs e)
        {
            if (methodTakePhoto == null)
                return;
            methodTakePhoto.identification = 0;
        }
 
        /// <summary>
        /// 菌落选择只能选择一个
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mcbBacteria_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //string ids = "";
            //foreach(var item in mcbBacteria.ChekedItems)
            //{
            //    if (string.IsNullOrEmpty(ids))
            //        ids = item.ID;
            //    else
            //        ids += "," + item.ID;
            //}
            methodTakePhoto.bacteriaids = mcbBacteria.SelectedValue.ToString();
        }
 
        private void mcbBacteriaBackColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (mark == 1)
                {
                    if (mcbBacteriaBackColor.SelectedItem == null)
                        return;
                    BacteriaColor bacteriaColor = mcbBacteriaBackColor.SelectedItem as BacteriaColor;
                    if (methodTakePhoto != null)
                    {
                        methodTakePhoto.colorText = bacteriaColor.bacteria_color_name;
                        methodTakePhoto.colorValue = bacteriaColor.bacteria_color_id.ToString();
                    }
                }
                else
                {
                    if (mcbBacteriaBackColor.SelectedItem == null)
                        return;
                    BacteriaColor bacteriaColor = mcbBacteriaBackColor.SelectedItem as BacteriaColor;
                    methodTakePhoto.colorText = bacteriaColor.bacteria_color_name;
                    methodTakePhoto.colorValue = bacteriaColor.bacteria_color_id.ToString();
 
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (mark == 1)
                {
                    //methodTakePhoto.name = tbxCommandName.Text;
                }
                else
                {
                    methodTakePhoto.name = tbxCommandName.Text;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void tbxDistanceOfBothBacteria_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (mark == 1)
                {
                    //methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text;
                    if(!string.IsNullOrEmpty(tbxDistanceOfBothBacteria.Text))
                    {
                        if (methodTakePhoto != null)
                        {
                            methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text;
                        }
                    }
 
                }
                else
                {
                    methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        #region 界面加载完成事件
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mark += 1;
            try
            {
                if (mark > 2)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(label))
                {
                    tbxCommandLabel.Text = label;
                    tbxCommandName.Text = name;
                    if (ismanualconfig == 1)
                    {
                        radioBtnManualConfig.IsChecked = true;
 
                        gridManual.Visibility = Visibility.Visible;
 
                        // 设置菌落下拉框默认选中值
                        BindingBacteriaData(methodTakePhoto.bacteriaids);
 
                        tbxDistanceOfBothBacteria.Text = gapValue;
 
                        mcbBacteriaBackColor.SelectedValue = colorValue;
 
                        // 加载涂布耗材数据
                        string[] coatingLabwareValues = coatingLabwareValue.Split(',');
                        string[] coatingLabwareTexts = coatingLabwareText.Split(',');
                        for (int iCoatingLabwareValueIndex = 0; iCoatingLabwareValueIndex < coatingLabwareValues.Length; iCoatingLabwareValueIndex++)
                        {
                            PromptTextBox textBox = iCoatingLabwareValueIndex == 0 ? coatingLabwareA : coatingLabwareB;
                            textBox.Tag = coatingLabwareValues[iCoatingLabwareValueIndex];
                            textBox.Text = coatingLabwareTexts[iCoatingLabwareValueIndex];
                        }
 
                        if (choicemode == 1)
                        {
                            radioBtnManual.IsChecked = true;
                        }
                        else if (choicemode == 0)
                        {
                            radioBtnAuto.IsChecked = true;
                        }
 
                        if (choiceTimes == 1)
                        {
                            radioBtnTimes1.IsChecked = true;
                        }
                        else if (choiceTimes == 2)
                        {
                            radioBtnTimes2.IsChecked = true;
                        }
                    }
                    else if (ismanualconfig == 2)
                    {
                        radioBtnAutoConfig.IsChecked = true;
                        gridManual.Visibility = Visibility.Hidden;
                    }
                }
                else
                {
                    
                    radioBtnAutoConfig.IsChecked = true;
                    gridManual.Visibility = Visibility.Hidden;
                }
 
                radioBtnManualConfig.IsChecked = true;      // 参数配置:手动
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        /// <summary>
        /// 设置菌落下拉框默认选中值
        /// </summary>
        /// <param name="bacteriaids"></param>
        public void BindingBacteriaData(string bacteriaids)
        {
            if (bacteriaids != null)
            {
                // 只会有一个菌种被选择
                //mcbBacteria.ChekedItems.Clear();
                //string[] subBacteria = bacteriaids.Split(',');
 
                mcbBacteria.SelectedValue = bacteriaids;
 
                //ObservableCollection<MultiCbxBaseData> s = (ObservableCollection<MultiCbxBaseData>)mcbBacteria.ItemsSource;
                //for (int i = 0; i < s.Count; i++)
                //{
                //    MultiCbxBaseData bacteria = s[i];
                //    if (string.IsNullOrEmpty(bacteria.ViewName))
                //        continue;
                //    if (subBacteria.Contains(bacteria.ID.ToString()))
                //    {
                //        bacteria.IsCheck = true;
                //    }
                //    else
                //    {
                //        bacteria.IsCheck = false;
                //    }
                //}
                //mcbBacteria.ItemsSource = s;
                //mcbBacteria.OnApplyTemplate();
            }
        }
 
        #region 条形码 删除
        //private void tbxBarCodeBacteria_TextChanged(object sender, TextChangedEventArgs e)
        //{
        //    try
        //    {
        //        //if (mark == 1)
        //        //{
        //        //    //methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text;
        //        //    if (!string.IsNullOrEmpty(tbxBarCodeBacteria.Text))
        //        //    {
        //        //        if (methodTakePhoto != null)
        //        //        {
        //        //            methodTakePhoto.barcode = tbxBarCodeBacteria.Text;
        //        //        }
        //        //    }
 
        //        //}
        //        //else
        //        //{
        //        //    methodTakePhoto.barcode = tbxBarCodeBacteria.Text;
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
 
        //    }
        //}
        #endregion
 
        public void SetTableName(string tableName, Labware lb)
        {
            if (lb == null)
                return;
            if (gridManual.Visibility == Visibility.Visible)
            {
                if (methodTakePhoto != null)
                {
                    //methodTakePhoto.coatingLabwareText = lb.labware_name;
                    //methodTakePhoto.coatingLabwareValue = lb.labware_id;
 
                    if (coatingLabwareGotFocus == 0)
                    {
                        coatingLabwareA.Tag = lb.labware_id;
                        coatingLabwareA.Text = lb.labware_name;
                    }
                    else
                    {
                        coatingLabwareB.Tag = lb.labware_id;
                        coatingLabwareB.Text = lb.labware_name;
                    }
                }
            }
        }
 
        #region 涂布耗材
        /// <summary>
        /// 涂布耗材类型A文字变更事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void coatingLabwareA_TextChanged(object sender, TextChangedEventArgs e)
        {
            PromptTextBox textBox = (PromptTextBox)sender;
            // 涂布耗材类型文字变更共用方法
            CoatingLabwareTextChange(textBox);
        }
 
        /// <summary>
        /// 涂布耗材类型B文字变更事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void coatingLabwareB_TextChanged(object sender, TextChangedEventArgs e)
        {
            PromptTextBox textBox = (PromptTextBox)sender;
            // 涂布耗材类型文字变更共用方法
            CoatingLabwareTextChange(textBox);
        }
 
        /// <summary>
        /// 涂布耗材类型文字变更共用方法
        /// </summary>
        /// <param name="textBox"></param>
        private void CoatingLabwareTextChange(PromptTextBox textBox)
        {
            if (mark == 1)
            {
                if (!string.IsNullOrEmpty(textBox.Text))
                {
                    if (methodTakePhoto != null)
                    {
                        // 设置涂布耗材信息
                        GetCoatingLabwareTextChange();
                    }
                }
            }
            else
            {
                // 设置涂布耗材信息
                GetCoatingLabwareTextChange();
            }
        }
 
        /// <summary>
        /// 设置涂布耗材信息
        /// </summary>
        private void GetCoatingLabwareTextChange()
        {
            methodTakePhoto.coatingLabwareText = string.Format("{0},{1}", coatingLabwareA.Text, coatingLabwareB.Text);
            methodTakePhoto.coatingLabwareValue = string.Format("{0},{1}", coatingLabwareA.Tag.ToString(), coatingLabwareB.Tag.ToString());
        }
 
        private void coatingLabwareA_GotFocus(object sender, RoutedEventArgs e)
        {
            coatingLabwareGotFocus = 0;
        }
 
        private void coatingLabwareB_GotFocus(object sender, RoutedEventArgs e)
        {
            coatingLabwareGotFocus = 1;
        }
        #endregion
 
        #region 涂布接种次数
        private void radioBtnTimes1_Checked(object sender, RoutedEventArgs e)
        {
            // 根据涂布次数表示涂布耗材B
            RadioBtnTimesChange();
        }
 
        private void radioBtnTimes2_Checked(object sender, RoutedEventArgs e)
        {
            // 根据涂布次数表示涂布耗材B
            RadioBtnTimesChange();
        }
 
        /// <summary>
        /// 根据涂布次数表示涂布耗材B
        /// </summary>
        private void RadioBtnTimesChange()
        {
            if (radioBtnTimes1.IsChecked == true)
            {
                coatingLabwareBTitle.Visibility = coatingLabwareB.Visibility = Visibility.Hidden;
                methodTakePhoto.choiceTimes = 1;
            }
            else if(radioBtnTimes2.IsChecked == true)
            {
                coatingLabwareBTitle.Visibility = coatingLabwareB.Visibility = Visibility.Visible;
                methodTakePhoto.choiceTimes = 2;
            }
        }
        #endregion
    }
}