schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
using DataEntity;
using DataEntity.Share;
using DataRWDAL;
using HxEnum;
using HxSocket;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Media;
using System.Xml;
using XCommon;
using XCommon.Log;
using XCore;
using XHandler.Class;
using XHandler.Class.DataEx;
using XHandler.Controls.Run.Com;
using XHandler.View;
using XHandler.View.ManualPick;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
using static HxEnum.OperationTypeEnum;
using XHandler.View.ElectroCutGum;
 
namespace XHandler.Controls
{
    public class TakePhotoControl
    {
        string strCurrentCulture = Shared.SoftwareInformation.currentculture;
        WellCalc wellCalc = new WellCalc();
        LatticeBll latticeBll = new LatticeBll();
        HomeBll homeBll = new HomeBll();
        public RunWnd launchView = null;
        TakePhotoBll takePhotoBll = new TakePhotoBll();
        public HxSocketClient socketTcpClientToRemote = null;
        private BacteriaBll bacteriaBll = new BacteriaBll();
 
        private int countOfAutoanalysis = 0;//成像识别菌落数量
        private int countOfManualchoice = 0;//人工挑选菌落数量
        private int countOfManualdelete = 0;//人工删除菌落数量
        private int countOfoating = 0;//涂布菌落总数
        private DateTime takephotoTime = DateTime.Now;
 
        #region 执行拍照,返回结果字符串
        /// <summary>
        /// 执行拍照,返回结果字符串
        /// </summary>
        /// <param name="xmlEnv">装载方法属性节点对象</param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="isSimulator">0:连接谁;1:仿真</param>
        /// <returns></returns>
        public bool ExecuteTakePhoto(XmlNode xmlEnv, XmlNode methodNode, bool isSimulator)
        {
            bool result = true;
            try
            {
                if (launchView._cancelSource.IsCancellationRequested)
                {
                    result = false;
                    return result;
                }
 
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】start:");
                }
 
                LoggerHelper.InfoLog("[TakePhotoControl][ExecuteTakePhoto]:Start");
 
                #region 数据准备
                string filePath = ConfigurationManager.AppSettings["choiceFilePath"];           // 挑菌下发参数.xls
                DataTable dtChoiceParams = null;
                // 微牧拍照之前机械臂需要先移到特定位置
                string[] tackPhotoPositionXY = ConfigurationManager.AppSettings["tackPhotoPosition"].ToString().Split(',');
                result = ControlCom.Move(float.Parse(tackPhotoPositionXY[0]), float.Parse(tackPhotoPositionXY[1]), isSimulator, launchView, MoveTypeEnum.Chanel);
                if (!result)
                {
                    return result;
                }
 
                string softwareDeviceNumber = Shared.SoftwareInformation.software_device_number;
                List<string> ret = new List<string>();
                PlsToolTipWin cameraRuningDialog = null;
                if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC))
                {
 
                }
                else
                {
                    // 获取挑菌信息
                    string strBacteriaids = methodNode.SelectSingleNode("bacteriaids").InnerText;      // 挑菌的种类
                    Bacteria bacteriaInfo = bacteriaBll.GetABacteria(strBacteriaids);
 
                    if (!launchView.isRemotingOper)
                    {
                        // 单机运行时,更新 挑菌下发参数.xls
                        dtChoiceParams = DoUpdateChoiceMode(methodNode, filePath, bacteriaInfo);
                    }
                    else
                    {
                        dtChoiceParams = ExcelAndCsvHelper.GetDataTableFromExcelFile(filePath, true);
                    }
 
                    takePhotoBll.socketTcpListener = launchView.mainWindow.socketTcpListener;
                    #endregion
 
                    #region 调用执行
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackingPhoto.ToString());
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: The action of camera is executing...");
                    }
 
                    
 
                    launchView.SetWaitOne();//暂停
                    
                    if (!launchView.isRemotingOper)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            string strMsg = string.Empty;
                            if (strCurrentCulture.Equals("zh-CN"))
                            {
                                strMsg = Properties.TackPhotoResource.strTackingPhoto.ToString();
                            }
                            else
                            {
                                strMsg = "The action of camera is executing...";
                            }
 
                            cameraRuningDialog = new PlsToolTipWin(strMsg);
                            cameraRuningDialog.Height = 200;
                            cameraRuningDialog.Width = 520;
 
                            SolidColorBrush mybtn2_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
                            cameraRuningDialog.Background = (System.Windows.Media.Brush)mybtn2_Brush;
                            cameraRuningDialog.btnCancel.Visibility = Visibility.Collapsed;
                            cameraRuningDialog.btnOK.Visibility = Visibility.Collapsed;
                            cameraRuningDialog.btnClose.Visibility = Visibility.Collapsed;
                            cameraRuningDialog.Show();
 
                            if (!isSimulator)
                            {
                                takephotoTime = DateTime.Now;
                                ret = takePhotoBll.ExecuteTakePhoto(methodNode, dtChoiceParams, softwareDeviceNumber, bacteriaInfo, isSimulator);
                            }
                            else
                            {
                                Thread.Sleep(3000);
                            }
 
                            // 推迟关闭拍照运行页面
                            //cameraRuningDialog.Close();
                        }));
                    }
                    else
                    {
                        ret = takePhotoBll.ExecuteTakePhoto(methodNode, dtChoiceParams, softwareDeviceNumber, bacteriaInfo, isSimulator);
                    }
                }
 
                OperateDialog plsConfirmOper = null;
                if (ret.Count == 0 && !isSimulator)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        if (cameraRuningDialog != null)
                        {
                            cameraRuningDialog.Close();
                        }
                    }));
 
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoError.ToString());
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Take photo was failed! No action!");
                    }
 
                    if (launchView.isRemotingOper)
                    {
                        result = false;
                    }
                    else
                    {
                        App.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.TackPhotoResource.strFailWhatToDo : "takePhoto are fail! What do you want to do?");
                            plsConfirmOper.ShowDialog();
                        }));
                    }
 
                    if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)   // 1:终止
                    {
                        result = false;
                    }
                    else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)   // 2:重试
                    {
                        // 本方法
                        result = ExecuteTakePhoto(xmlEnv, methodNode, isSimulator);
                    }
                    else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 3:跳过继续执行
                    {
                        result = true;
                    }
 
                    return result;
                }
                else
                {
                    if (ret.Count == 1)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            if (cameraRuningDialog != null)
                            {
                                cameraRuningDialog.Close();
                            }
                        }));
 
                        if (strCurrentCulture.Equals("zh-CN"))
                        {
                            launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoError.ToString());
                        }
                        else
                        {
                            launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Take photo was failed! Data miss!");
                        }
 
                        if (launchView.isRemotingOper)
                        {
                            result = false;
                        }
                        else
                        {
                            App.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.TackPhotoResource.strFailWhatToDo : "takePhoto are fail! What do you want to do?");
                                plsConfirmOper.ShowDialog();
                            }));
                        }
 
                        if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)   // 1:终止
                        {
                            result = false;
                        }
                        else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)   // 2:重试
                        {
                            // 本方法
                            result = ExecuteTakePhoto(xmlEnv, methodNode, isSimulator);
                        }
                        else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 3:跳过继续执行
                        {
                            result = true;
                        }
                        return result;
                    }
                    else if (ret.Count == 2 || isSimulator)
                    {
                        int iType = 5;
                        int iMethodStatus = 2;
                        JObject jobFinish = null;
 
                        if (!isSimulator)
                        {
                            // 检查Data是否报错
                            string finishSrc = ret[1];
                            string finish = finishSrc.Replace("#!HxSEP!#", "");
                            LoggerHelper.DebugLog(string.Format("[TakePhotoControl][ExecuteTakePhoto]: finishResponse = {0}", finish));
                            jobFinish = JObject.Parse(finish);
                            iType = Convert.ToInt32(jobFinish["message_type"].ToString());
                            iMethodStatus = Convert.ToInt32(jobFinish["method_status"].ToString());
 
                            if (iMethodStatus == 3)    // Failed
                            {
                                LoggerHelper.DebugLog("[TakePhotoControl][ExecuteTakePhoto]: iMethodStatus == 3");
 
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    if (cameraRuningDialog != null)
                                    {
                                        cameraRuningDialog.Close();
                                    }
                                }));
 
                                if (strCurrentCulture.Equals("zh-CN"))
                                {
                                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoError.ToString());
                                }
                                else
                                {
                                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Take photo was failed! Data error!");
                                }
 
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    plsConfirmOper = new OperateDialog(strCurrentCulture.Equals("zh-CN") ? Properties.TackPhotoResource.strFailWhatToDo : "takePhoto are fail! What do you want to do?");
                                    plsConfirmOper.ShowDialog();
                                }));
 
                                if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Cancel)   // 1:终止
                                {
                                    result = false;
                                }
                                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Retry)   // 2:重试
                                {
                                    // 本方法
                                    result = ExecuteTakePhoto(xmlEnv, methodNode, isSimulator);
                                }
                                else if (plsConfirmOper != null && plsConfirmOper.OperMark == NodeOperationTypeEnum.Continue)   // 3:跳过继续执行
                                {
                                    result = true;
                                }
                                return result;
                            }
                        }
 
                        #region 返回的消息数据处理,下载文件到本地路径下
                        if (iType == 5 && iMethodStatus == 2) // Finish ComPleted
                        {
                            string jsonFilePath = ConfigurationManager.AppSettings["captureFilePath"].ToString();
                            string fullImageFileName = string.Empty;
                            string fullJsonFileName = string.Empty;
                            string originalImageFileName = string.Empty;
 
                            fullImageFileName = jsonFilePath + "\\Simulator.jpg";
                            fullJsonFileName = jsonFilePath + "\\Simulator.json";
                            originalImageFileName = jsonFilePath + "\\Simulator_原.jpg";
 
                            #region 模拟运行下不下载,真机运行下载
                            if (!isSimulator)
                            {
                                //拍照命令下发后,执行完成了
                                string jsonURL = jobFinish["data"]["json"].ToString();
                                string imageURL = jobFinish["data"]["image"].ToString();
                                string originalImg = jobFinish["data"]["original"].ToString();
                                launchView.captureData = jobFinish["data"].ToString();
                                LoggerRunHelper.InfoLog(launchView.captureData.ToString());
                                LoggerRunHelper.InfoLog(jsonURL.ToString());
                                LoggerRunHelper.InfoLog(imageURL.ToString());
                                LoggerRunHelper.InfoLog(originalImg.ToString());
                                if (!Directory.Exists(jsonFilePath))
                                {
                                    Directory.CreateDirectory(jsonFilePath);
                                }
                                //获取目录下文件的最大名称值
                                string[] files = Directory.GetFiles(jsonFilePath);
                                int fiMax = 0;
 
                                FileInfo fileInfo = null;
                                foreach (string f in files)
                                {
                                    // 防止文件全路径包含【.】的情况
                                    fileInfo = new FileInfo(f);
                                    string f1 = fileInfo.Name.Split('.')[0];
                                    if (f1.Contains("_原"))
                                    {
                                        continue;
                                    }
                                    try
                                    {
 
                                        int fileNameNum = Convert.ToInt32(f1);
                                        if (fileNameNum > fiMax)
                                        {
                                            fiMax = fileNameNum;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                    }
                                }
 
                                LoggerHelper.DebugLog("[TakePhotoControl][ExecuteTakePhoto]: Download Start");
                                using (WebClient client = new WebClient())
                                {
                                    if (!isSimulator)
                                    {
                                        if (Directory.Exists(jsonFilePath))
                                        {
                                            fullJsonFileName = jsonFilePath + "\\" + (fiMax + 1).ToString() + ".json";
                                            if (File.Exists(fullJsonFileName))
                                            {
                                                File.Delete(fullJsonFileName);
                                            }
                                            client.DownloadFile(jsonURL, fullJsonFileName);
                                        }
                                    }
 
                                    if (!isSimulator)
                                    {
                                        if (Directory.Exists(jsonFilePath))
                                        {
                                            fullImageFileName = jsonFilePath + "\\" + (fiMax + 1).ToString() + ".jpg";
                                            if (File.Exists(fullImageFileName))
                                            {
                                                File.Delete(fullImageFileName);
                                            }
 
                                            client.DownloadFile(imageURL, fullImageFileName);
                                        }
                                    }
 
                                    if (!isSimulator)
                                    {
                                        if (Directory.Exists(jsonFilePath))
                                        {
                                            originalImageFileName = jsonFilePath + "\\" + (fiMax + 1).ToString() + "_原.jpg";
                                            if (File.Exists(originalImageFileName))
                                            {
                                                File.Delete(originalImageFileName);
                                            }
 
                                            client.DownloadFile(originalImg, originalImageFileName);
                                        }
                                    }
                                }
                                LoggerHelper.DebugLog("[TakePhotoControl][ExecuteTakePhoto]: Download End");
 
                            }
                            #endregion
 
                            ObservableCollection<BacteriaCoordinateEx> bacteriaCoordinates = new ObservableCollection<BacteriaCoordinateEx>();
                            if (!launchView.isRemotingOper)
                            {
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    bacteriaCoordinates = DataModule.getInstance().GetBacteriaCoordinateList(fullJsonFileName);
                                }));
                            }
                            else
                            {
                                bacteriaCoordinates = DataModule.getInstance().GetBacteriaCoordinateList(fullJsonFileName);
                            }
 
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                if (cameraRuningDialog != null)
                                {
                                    cameraRuningDialog.Close();
                                }
                            }));
 
                            if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC))
                            {
                                LoggerHelper.DebugLog(string.Format("[TakePhotoControl][ExecuteTakePhoto]: 拍照识别到的切胶点个数 == {0}", bacteriaCoordinates.Count));
                                ManualPickGum manualPickGum = null;
                                if (bacteriaCoordinates.Count == 0)
                                {
                                    if (strCurrentCulture.Equals("zh-CN"))
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoNoDataForCutGum.ToString());
                                    }
                                    else
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Can't get any cut point!Please check the camera system!");
                                    }
 
                                    result = false;
                                    launchView.captureData = string.Empty;
 
                                    if (launchView.isRemotingOper)
                                    {
                                        ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                        model.RunChoiceBacteraId = ComUtility.GetGuid();
                                        model.ExperimentId = Shared.Exp.ExperimentId;
                                        model.SourceBarcode = dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());
                                        string choicemode = dtChoiceParams.Rows[9]["属性值"].ToString();                        // 1:人工挑选菌落;0:成像系统自动挑选菌落
 
                                    }
                                    else
                                    {
                                        // 0件继续做下一个皿
                                        ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                        model.RunChoiceBacteraId = ComUtility.GetGuid();
                                        model.ExperimentId = Shared.Exp.ExperimentId;
                                        model.SourceBarcode = dtChoiceParams==null?"": dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = dtChoiceParams == null ? 1 : Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());        // 识别方法:0:成像系统自动挑选菌落; 1:人工挑选菌落
 
                                        result = true;
                                        // 成像0件 && 单机运行时
                                        // 人工挑:表示挑菌页面;自动挑:不表示挑菌页面
                                        Application.Current.Dispatcher.Invoke(new Action(() =>
                                        {
                                            manualPickGum = new ManualPickGum(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                            SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                            manualPickGum.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                            manualPickGum.isSimulator = isSimulator;
                                            manualPickGum.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                            manualPickGum.launchView = launchView;
                                            manualPickGum.expRunChoiceBactera = model;
                                            manualPickGum.methodNode = methodNode;
                                            manualPickGum.dtChoiceParams = dtChoiceParams;
                                            manualPickGum.Height = Shared.Config.DisplaySizeH;
                                            manualPickGum.Width = Shared.Config.DisplaySizeW;
                                            manualPickGum.ShowDialog();
                                        }));
                                    }
                                }
                                else
                                {
                                    ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                    model.RunChoiceBacteraId = ComUtility.GetGuid();
                                    model.ExperimentId = Shared.Exp.ExperimentId;
 
                                    int choicemode = dtChoiceParams == null ? 1 : Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());   // 1:人工挑选菌落;0:成像系统自动挑选菌落
                                    if (choicemode == EnumManagement.GetEnumValue(IdentificationEnum.Manual))  // 人工挑选菌落
                                    {
                                        model.SourceBarcode = dtChoiceParams == null ? "" : dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = choicemode;
                                        if (!launchView.isRemotingOper)
                                        {
                                            Application.Current.Dispatcher.Invoke(new Action(() =>
                                            {
                                                manualPickGum = new ManualPickGum(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                                SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                                manualPickGum.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                                manualPickGum.isSimulator = isSimulator;
                                                manualPickGum.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                                manualPickGum.launchView = launchView;
                                                manualPickGum.expRunChoiceBactera = model;
                                                manualPickGum.methodNode = methodNode;
                                                manualPickGum.dtChoiceParams = dtChoiceParams;
                                                manualPickGum.Height = Shared.Config.DisplaySizeH;
                                                manualPickGum.Width = Shared.Config.DisplaySizeW;
                                                manualPickGum.ShowDialog();
                                            }));
                                        }
                                        else
                                        {
                                            manualPickGum = new ManualPickGum(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                            manualPickGum.Height = Shared.Config.DisplaySizeH;
                                            manualPickGum.Width = Shared.Config.DisplaySizeW;
                                            manualPickGum.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                            manualPickGum.isSimulator = isSimulator;
                                            manualPickGum.launchView = launchView;
                                            manualPickGum.expRunChoiceBactera = model;
                                            manualPickGum.isRemotingOper = true;
                                            manualPickGum.methodNode = methodNode;
                                            manualPickGum.dtChoiceParams = dtChoiceParams;
                                            SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                            manualPickGum.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                            manualPickGum.ShowDialog();
                                        }
 
                                        if (manualPickGum.cancelFlg)
                                        {
                                            if (strCurrentCulture.Equals("zh-CN"))
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoCancelled.ToString());
                                            }
                                            else
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Process canceled!");
                                            }
 
                                            result = false;
                                            return result;
                                        }
                                    }
                                    else if (choicemode == EnumManagement.GetEnumValue(IdentificationEnum.Auto))     // 成像系统自动挑选菌落
                                    {
                                        // 直接返回所有字符串给中控
                                        // 获取拍照json文件里的数据条数入库
                                        countOfAutoanalysis = bacteriaCoordinates.Count;
                                        if (launchView != null)
                                        {
                                            model.SourceBarcode = dtChoiceParams == null ? "" : dtChoiceParams.Rows[1]["属性值"].ToString();
                                            model.TakePhotoTime = takephotoTime;
                                            model.Identification = choicemode;
                                            model.CountAutoAnalysis = countOfAutoanalysis;
                                            model.CountManualChoice = countOfManualchoice;
                                            model.CountManualDelete = countOfManualdelete;
                                            model.CountCoating = countOfoating;
                                            ExperimentRunChoiceBacteraDB.Add(model);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                LoggerHelper.DebugLog(string.Format("[TakePhotoControl][ExecuteTakePhoto]: 拍照识别到的菌落个数 == {0}", bacteriaCoordinates.Count));
                                ManualPickBacteria manualPickBacteria = null;
                                if (bacteriaCoordinates.Count == 0)
                                {
                                    if (strCurrentCulture.Equals("zh-CN"))
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoNoData.ToString());
                                    }
                                    else
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Can't get any bacteria!Please check the camera system!");
                                    }
 
                                    result = false;
                                    launchView.captureData = string.Empty;
 
                                    if (launchView.isRemotingOper)
                                    {
                                        ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                        model.RunChoiceBacteraId = ComUtility.GetGuid();
                                        model.ExperimentId = Shared.Exp.ExperimentId;
                                        model.SourceBarcode = dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());
                                        string choicemode = dtChoiceParams.Rows[9]["属性值"].ToString();                        // 1:人工挑选菌落;0:成像系统自动挑选菌落
 
                                        #region Del
                                        //if (choicemode == "1" &&
                                        //    Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceChoice)    // 人工挑选菌落
                                        //{
                                        //    manualPickBacteria = new ManualPickBacteria(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                        //    manualPickBacteria.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                                        //    //manualPickBacteria.Topmost = true;
                                        //    SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                        //    manualPickBacteria.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                        //    manualPickBacteria.isSimulator = isSimulator;
                                        //    manualPickBacteria.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                        //    manualPickBacteria.launchView = launchView;
                                        //    manualPickBacteria.experimentRunChoiceBactera = experimentRunChoiceBactera;
                                        //    manualPickBacteria.isRemotingOper = launchView.isRemotingOper;
                                        //    manualPickBacteria.methodNode = methodNode;
                                        //    manualPickBacteria.dtChoiceParams = dtChoiceParams;
                                        //    manualPickBacteria.Height = 1024;
                                        //    manualPickBacteria.Width = 1920;
                                        //    manualPickBacteria.ShowDialog();
                                        //}
                                        //else if (choicemode != "1" &&
                                        //    Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceChoice)  // 自动挑选菌落
                                        //{
                                        //    result = false;
                                        //    launchView.captureData = string.Empty;
                                        //    return result;
                                        //}
                                        #endregion
                                    }
                                    else
                                    {
                                        // 0件继续做下一个皿
                                        ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                        model.RunChoiceBacteraId = ComUtility.GetGuid();
                                        model.ExperimentId = Shared.Exp.ExperimentId;
                                        model.SourceBarcode = dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());        // 识别方法:0:成像系统自动挑选菌落; 1:人工挑选菌落
 
                                        result = true;
                                        // 成像0件 && 单机运行时
                                        // 人工挑:表示挑菌页面;自动挑:不表示挑菌页面
                                        Application.Current.Dispatcher.Invoke(new Action(() =>
                                        {
                                            manualPickBacteria = new ManualPickBacteria(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                            SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                            manualPickBacteria.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                            manualPickBacteria.isSimulator = isSimulator;
                                            manualPickBacteria.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                            manualPickBacteria.launchView = launchView;
                                            manualPickBacteria.expRunChoiceBactera = model;
                                            manualPickBacteria.methodNode = methodNode;
                                            manualPickBacteria.dtChoiceParams = dtChoiceParams;
                                            manualPickBacteria.Height = Shared.Config.DisplaySizeH;
                                            manualPickBacteria.Width = Shared.Config.DisplaySizeW;
                                            manualPickBacteria.ShowDialog();
                                        }));
                                    }
                                }
                                else
                                {
                                    ExperimentRunChoiceBacteraModel model = new ExperimentRunChoiceBacteraModel();
                                    model.RunChoiceBacteraId = ComUtility.GetGuid();
                                    model.ExperimentId = Shared.Exp.ExperimentId;
 
                                    int choicemode = Convert.ToInt32(dtChoiceParams.Rows[9]["属性值"].ToString());   // 1:人工挑选菌落;0:成像系统自动挑选菌落
                                    if (choicemode == EnumManagement.GetEnumValue(IdentificationEnum.Manual))  // 人工挑选菌落
                                    {
                                        model.SourceBarcode = dtChoiceParams.Rows[1]["属性值"].ToString();
                                        model.TakePhotoTime = takephotoTime;
                                        model.Identification = choicemode;
                                        if (!launchView.isRemotingOper)
                                        {
                                            Application.Current.Dispatcher.Invoke(new Action(() =>
                                            {
                                                manualPickBacteria = new ManualPickBacteria(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                                SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                                manualPickBacteria.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                                manualPickBacteria.isSimulator = isSimulator;
                                                manualPickBacteria.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                                manualPickBacteria.launchView = launchView;
                                                manualPickBacteria.expRunChoiceBactera = model;
                                                manualPickBacteria.methodNode = methodNode;
                                                manualPickBacteria.dtChoiceParams = dtChoiceParams;
                                                manualPickBacteria.Height = Shared.Config.DisplaySizeH;
                                                manualPickBacteria.Width = Shared.Config.DisplaySizeW;
                                                manualPickBacteria.ShowDialog();
                                            }));
                                        }
                                        else
                                        {
                                            manualPickBacteria = new ManualPickBacteria(originalImageFileName, fullImageFileName, fullJsonFileName, isSimulator);
                                            manualPickBacteria.Height = Shared.Config.DisplaySizeH;
                                            manualPickBacteria.Width = Shared.Config.DisplaySizeW;
                                            manualPickBacteria.socketTcpListener = launchView.mainWindow.socketTcpListener;
                                            manualPickBacteria.isSimulator = isSimulator;
                                            manualPickBacteria.launchView = launchView;
                                            manualPickBacteria.expRunChoiceBactera = model;
                                            manualPickBacteria.isRemotingOper = true;
                                            manualPickBacteria.methodNode = methodNode;
                                            manualPickBacteria.dtChoiceParams = dtChoiceParams;
                                            SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0));
                                            manualPickBacteria.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                                            manualPickBacteria.ShowDialog();
                                        }
 
                                        if (manualPickBacteria.cancelFlg)
                                        {
                                            if (strCurrentCulture.Equals("zh-CN"))
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.TackPhotoResource.strTackPhotoCancelled.ToString());
                                            }
                                            else
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: Process canceled!");
                                            }
 
                                            result = false;
                                            return result;
                                        }
                                    }
                                    else if (choicemode == EnumManagement.GetEnumValue(IdentificationEnum.Auto))     // 成像系统自动挑选菌落
                                    {
                                        // 直接返回所有字符串给中控
                                        // 获取拍照json文件里的数据条数入库
                                        countOfAutoanalysis = bacteriaCoordinates.Count;
                                        if (launchView != null)
                                        {
                                            model.SourceBarcode = dtChoiceParams.Rows[1]["属性值"].ToString();
                                            model.TakePhotoTime = takephotoTime;
                                            model.Identification = choicemode;
                                            model.CountAutoAnalysis = countOfAutoanalysis;
                                            model.CountManualChoice = countOfManualchoice;
                                            model.CountManualDelete = countOfManualdelete;
                                            model.CountCoating = countOfoating;
                                            ExperimentRunChoiceBacteraDB.Add(model);
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】error:source:" + ex.Source + ";error:" + ex.Message + ";");
                }
 
                result = false;
                return result;
            }
            return result;
        }
 
        /// <summary>
        /// 单机运行时,作成 挑菌下发参数.xls
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="filePath"></param>
        /// <param name="bacteriaInfo"></param>
        /// <returns></returns>
        private DataTable DoUpdateChoiceMode(XmlNode xmlNode, string filePath, Bacteria bacteriaInfo)
        {
            DataTable dtChoiceParams = ExcelAndCsvHelper.GetDataTableFromExcelFile(filePath, true);
            string strValName = "属性值";
 
            #region 数据准备
            // 实验ID
            dtChoiceParams.Rows[0][strValName] = string.Empty;
            // 皿的二维码信息
            dtChoiceParams.Rows[1][strValName] = launchView.choiceBarcode;
            // 菌名称
            dtChoiceParams.Rows[2][strValName] = bacteriaInfo.bacteria_name.ToString();
            // 形状
            dtChoiceParams.Rows[3][strValName] = bacteriaInfo.bacteria_shape.ToString();
            // 边缘
            dtChoiceParams.Rows[4][strValName] = bacteriaInfo.bacteria_edge.ToString();
            // 颜色
            dtChoiceParams.Rows[5][strValName] = bacteriaInfo.bacteria_color.ToString();
            // 最小直径
            dtChoiceParams.Rows[6][strValName] = bacteriaInfo.bacteria_min_size.ToString();
            // 最大直径
            dtChoiceParams.Rows[7][strValName] = bacteriaInfo.bacteria_max_size.ToString();
            // 临近度
            dtChoiceParams.Rows[8][strValName] = xmlNode.SelectSingleNode("gapValue").InnerText;
            // 识别方法:0:成像系统自动挑选菌落;1:人工挑选菌落
            dtChoiceParams.Rows[9][strValName] = xmlNode.SelectSingleNode("identification").InnerText;
            // 挑菌距离底部或菌类形
            dtChoiceParams.Rows[10][strValName] = bacteriaInfo.choice_position.ToString();
            // 挑菌距离底部或菌类距离
            dtChoiceParams.Rows[11][strValName] = bacteriaInfo.choice_position_distance.ToString();
            // 挑菌时x轴偏移量
            dtChoiceParams.Rows[12][strValName] = bacteriaInfo.choice_xaxis_distance.ToString();
            // 挑菌时y轴偏移量
            dtChoiceParams.Rows[13][strValName] = bacteriaInfo.choice_yaxis_distance.ToString();
 
            // 涂布距离底部距离
            dtChoiceParams.Rows[14][strValName] = bacteriaInfo.coating_position_distance.ToString();
            // 涂布时x轴偏移量
            dtChoiceParams.Rows[15][strValName] = bacteriaInfo.coating_xaxis_distance.ToString();
            // 涂布时y轴偏移量
            dtChoiceParams.Rows[16][strValName] = bacteriaInfo.coating_yaxis_distance.ToString();
            //// 涂布方式:在文件涂布节点更新参数
            //dtChoiceParams.Rows[17][strValName] = xmlNode.SelectSingleNode("choiceMode").InnerText;
            // 涂布速度
            dtChoiceParams.Rows[18][strValName] = float.Parse(ConfigurationManager.AppSettings["coatingSpeed"].ToString());
            // 模型类型:1:算法1(微牧酵母);2:算法2(普通酵母);3:算法3(酵母背光01);4:算法4(链霉菌)
            dtChoiceParams.Rows[19][strValName] = bacteriaInfo.model_type.ToString();
            // 合并识别
            dtChoiceParams.Rows[20][strValName] = bacteriaInfo.merge_masks.ToString();
            // 降采样率
            dtChoiceParams.Rows[21][strValName] = bacteriaInfo.ds_ratio.ToString();
            // 平均直径
            dtChoiceParams.Rows[22][strValName] = bacteriaInfo.mean_diam.ToString();
            // 到边缘距离
            dtChoiceParams.Rows[23][strValName] = bacteriaInfo.dist_to_edge.ToString();
            // 菌标记颜色
            dtChoiceParams.Rows[24][strValName] = bacteriaInfo.mark_color.ToString();
            // 菌标记序号
            dtChoiceParams.Rows[25][strValName] = bacteriaInfo.draw_label.ToString();
            // 菌标记字体大小
            dtChoiceParams.Rows[26][strValName] = bacteriaInfo.fontsize.ToString();
            // 顶部背光亮度
            dtChoiceParams.Rows[27][strValName] = bacteriaInfo.top_light.ToString();
            // 底部背光亮度
            dtChoiceParams.Rows[28][strValName] = "0";
            // 挑菌方式
            dtChoiceParams.Rows[29][strValName] = "0";
            // 挑菌时下压距离
            dtChoiceParams.Rows[30][strValName] = bacteriaInfo.press_distance.ToString();
            #endregion
 
            ExcelAndCsvHelper.WriteDataTableToExcelFile(dtChoiceParams, filePath);
 
            return dtChoiceParams;
        }
        #endregion
 
        #region 获取拍照之后的菌坐标数据-本次拍照后获取的所有菌落点位数据
        public List<BacteriaCoordinate> GetBacteriasDataInfo(string jsonData)
        {
            List<BacteriaCoordinate> bacteriaCoordinates = new List<BacteriaCoordinate>();
            try
            {
                //序列化
                JObject job = JObject.Parse(jsonData);
                JArray jArray = (JArray)job["data"]["germList"];
 
 
                foreach (JToken jt in jArray)
                {
                    BacteriaCoordinate bacteriaCoordinate = new BacteriaCoordinate();
                    bacteriaCoordinate.bacteriacoordinate_id = jt["index"].ToString();
                    string coordinate3D = string.Empty;
                    coordinate3D = jt["coordinate3D"]["x"].ToString() + "," + jt["coordinate3D"]["y"].ToString() + "," + jt["coordinate3D"]["z"].ToString();
                    bacteriaCoordinate.coordinate_machine = coordinate3D;
                    string coordinatePixel = string.Empty;
                    coordinatePixel = jt["coordinatePixel"]["x"].ToString() + "," + jt["coordinatePixel"]["y"].ToString();
                    bacteriaCoordinate.coordinate_pixel = coordinatePixel;
                    bacteriaCoordinates.Add(bacteriaCoordinate);
                }
 
                //gdDatalist.DataContext = bacteriaCoordinates;
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
 
            return bacteriaCoordinates;
        }
        #endregion
    }
}