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 执行拍照,返回结果字符串 /// /// 执行拍照,返回结果字符串 /// /// 装载方法属性节点对象 /// 装载方法属性节点对象 /// 0:连接谁;1:仿真 /// 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 ret = new List(); 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 bacteriaCoordinates = new ObservableCollection(); 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; } /// /// 单机运行时,作成 挑菌下发参数.xls /// /// /// /// /// 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 GetBacteriasDataInfo(string jsonData) { List bacteriaCoordinates = new List(); 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 } }