diff --git a/App.config b/App.config index ae9b93b..4ba9578 100644 --- a/App.config +++ b/App.config @@ -2,24 +2,20 @@ - + - - - - - + - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 2a56d19..51e5b0e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -11,6 +11,7 @@ using HandyControl.Tools; using log4net; using log4net.Config; using SparkClient.Model.Helper; +using SparkClient.Model.Services; using SparkClient.ViewModel; using SparkClient.ViewModel.BaseWindow; using SparkClient.Views.BaseWindow; @@ -142,7 +143,7 @@ public partial class MainWindow } - private void MainWindow_OnClosing(object? sender, CancelEventArgs e) + private async void MainWindow_OnClosing(object? sender, CancelEventArgs e) { var message = MultilingualHelper.getString("ExitAsk"); var title = MultilingualHelper.getString("ExitAskTitle"); @@ -152,6 +153,7 @@ public partial class MainWindow if (result == MessageBoxResult.OK) { + await SOCClientService.Service.OpenPump(false); DataBaseHelper.CloseConnection(); // this.Close(); Environment.Exit(0); diff --git a/Model/Entity/ApiEntity/AlgorithmResultEntity.cs b/Model/Entity/ApiEntity/AlgorithmResultEntity.cs index 6de152b..0de7f97 100644 --- a/Model/Entity/ApiEntity/AlgorithmResultEntity.cs +++ b/Model/Entity/ApiEntity/AlgorithmResultEntity.cs @@ -39,7 +39,9 @@ namespace SparkClient.Model.Entity.ApiEntity /// 面的类型。 /// public int facet_type { get; set; } - + /// + /// 旋转角度 + /// public double theta { get; set; } } diff --git a/Model/Entity/ApiEntity/StatusCodes.cs b/Model/Entity/ApiEntity/StatusCodes.cs index 97948d8..799c661 100644 --- a/Model/Entity/ApiEntity/StatusCodes.cs +++ b/Model/Entity/ApiEntity/StatusCodes.cs @@ -32,6 +32,12 @@ namespace SparkClient.Model.Common // 切工仪舱门未关闭 public const string OpenOfTheHatch = "S007"; + + /// + /// 输出参数错误或者未定义 + /// + public const string OutputParameterNotProvidedOrIncorrect = "S008"; + public const string PreviousTaskIncomplete = "S009"; // 未找到切工仪 public const string DeviceNotFound = "P001"; diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index f9e6142..cecc375 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -77,9 +77,9 @@ namespace SparkClient.Model.Services // 记录日志 Logger.Info($"Response: Status={statusCode}, Body={responseBody}"); var tempEntity = JsonConvert.DeserializeObject(responseBody); - if ("S007".Equals(tempEntity.Status)) + if (StatusCodes.PreviousTaskIncomplete.Equals(tempEntity.Status)) { - Logger.Info($"S007 请求重试"); + Logger.Info($"S009 请求重试"); await Task.Delay(50); return await SendGetRequestAsync(url); } diff --git a/SparkClient.csproj b/SparkClient.csproj index 1319731..21de682 100644 --- a/SparkClient.csproj +++ b/SparkClient.csproj @@ -258,6 +258,11 @@ Wpf Designer + + MSBuild:Compile + Wpf + Designer + diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index e91f229..8376e22 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -165,15 +165,12 @@ public class DiamondSelectVM : BaseViewModel WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); return; } - else if ( res <= -100) + if ( res <= -100) { return; } - else - { - GradingResult(loadingView.Parameter); - loadingView.Dispose(); - } + GradingResult(loadingView.Parameter); + loadingView.Dispose(); } else if ("1".Equals(runModel)) { @@ -191,18 +188,15 @@ public class DiamondSelectVM : BaseViewModel //返回 loadingView.Dispose(); WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); - ; + await SOCClientService.Service.OpenPump(false); return; } - else if ( res <= -100) + if ( res <= -100) { return; } - else - { - GradingResult(loadingView.Parameter); - loadingView.Dispose(); - } + GradingResult(loadingView.Parameter); + loadingView.Dispose(); } else { @@ -221,18 +215,17 @@ public class DiamondSelectVM : BaseViewModel //返回 loadingView.Dispose(); WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); - ; + await SOCClientService.Service.OpenPump(false); return; } - else if ( res <= -100) + if ( res <= -100) { return; } - else - { - GradingResult(loadingView.Parameter); - loadingView.Dispose(); - } + + GradingResult(loadingView.Parameter); + loadingView.Dispose(); + } diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index 0a844e4..389288c 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -191,14 +191,28 @@ public class GradingLoadingVM : BaseViewModel,IDisposable LoadImages(processImage.Result.Images); } + string strImageModeImagePath = string.Empty; if (type == 1) { - List mnFiles = new List(); - for (int i = 0; i < 100; i++) + ImageSelect jsonImport = new ImageSelect(); + bool? a = jsonImport.ShowDialog(); + if (a ?? false) { - mnFiles.Add($"{i}.bmp"); + strImageModeImagePath = jsonImport.FilePath.Text; + string name = jsonImport.FileName.Text; + List mnFiles = new List(); + for (int i = 0; i < 100; i++) + { + mnFiles.Add(name.Replace("%d", i.ToString())); + } + LoadImages(mnFiles); } - LoadImages(mnFiles); + else + { + return -1; + } + + } ImageIsEnable = true; @@ -216,11 +230,18 @@ public class GradingLoadingVM : BaseViewModel,IDisposable var _algorithmConfigVM = new AlgorithmConfigVM(); _algorithmConfigVM.InitAlgorithmData(null); string algo_config = _algorithmConfigVM.AlgorithmConfigJson; - - + + string imageFileBasePath = string.Empty; //图片根目录 - string? image_file_base_path = ConfigurationManager.AppSettings["ImageFileBasePath"]; - if (string.IsNullOrEmpty(image_file_base_path)) + if (type == 1) + { + imageFileBasePath = strImageModeImagePath; + } + else + { + imageFileBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; + } + if (string.IsNullOrEmpty(imageFileBasePath)) { throw new InvalidOperationException("ImageFileBasePath is not configured in AppSettings."); } @@ -235,7 +256,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable JObject jsonData = new JObject( new JProperty("shape", _diamnondType.Split(" ")[0]), new JProperty("shape_mode", _diamnondType.Split(" ")[1]), - new JProperty("image_file_base_path", image_file_base_path), + new JProperty("image_file_base_path", imageFileBasePath), new JProperty("image_files", ImagePaths), new JProperty("half_circle", half_circle), new JProperty("algorithm_log_path", algorithm_log_path), @@ -294,6 +315,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable Progress = (100.00); string strParam = JsonConvert.SerializeObject(detectTask.Result); + //Logger.Info("序列化字符串:" + strParam); AlgorithmResultEntity parameter = JsonConvert.DeserializeObject(strParam); if (parameter == null && _isCancel == false) { @@ -328,6 +350,12 @@ public class GradingLoadingVM : BaseViewModel,IDisposable Parameter = parameter; if (_isCancel == true) return -100; + + if (parameter.status == StatusCodes.Recheck) + { + new MessageBox().Show(MultilingualHelper.getString("Recheck")); + } + return 0; } @@ -366,7 +394,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable { current = Math.Min(current + 1, 100); UpdateProgress(current); - await Task.Delay(stepTime); + await Task.Delay(stepTime/2); } } private void UpdateProgress(int value) diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 15e8807..390387e 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -1977,17 +1977,17 @@ public class GradingResultVM : BaseViewModel [Log] private void ExecuteThermalPrint(object parameter) { - MessageBox messageBox = new MessageBox(); - MessageBoxResult boxResult = messageBox.ShowAsk(MultilingualHelper.getString("YesOrNo")); - if (boxResult != MessageBoxResult.OK) - { - return; - } - - string tempFilePath = string.Empty; Microsoft.Office.Interop.Excel.Application excelApp = null; + string tempFilePath = string.Empty; try { + MessageBox messageBox = new MessageBox(); + MessageBoxResult boxResult = messageBox.ShowAsk(MultilingualHelper.getString("YesOrNo")); + if (boxResult != MessageBoxResult.OK) + { + return; + } + // 步骤2:加载模板并填充数据 tempFilePath = GenerateTempExcelFile(); @@ -1997,13 +1997,14 @@ public class GradingResultVM : BaseViewModel excelApp.DisplayAlerts = false; // 禁用警告提示 Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(tempFilePath); - + + string printName = ConfigurationHelper.ReadConfigValue("PrintName"); string? targetPrinter = System.Drawing.Printing.PrinterSettings.InstalledPrinters .Cast() - .FirstOrDefault(p => p.Contains(ConfigurationHelper.ReadConfigValue("PrintName"))); + .FirstOrDefault(p => p.Contains(printName)); if (targetPrinter == null) { - throw new Exception($"未找到打印机{targetPrinter}"); + throw new Exception($"未找到打印机{printName}"); } // 打印配置 @@ -2335,86 +2336,94 @@ public class GradingResultVM : BaseViewModel private string GenerateTempExcelFile() { - string TemplatePath = @"Resource\ResultReport.xlsx"; - using (FileStream templateStream = new FileStream(TemplatePath, FileMode.Open, FileAccess.Read)) + try { - IWorkbook workbook = new XSSFWorkbook(templateStream); - ISheet sheet = workbook.GetSheetAt(0); - - //Row 1 - SetCellValue(sheet, "A1", $"{MultilingualHelper.getString("Organization")}:{Standard}"); - SetCellValue(sheet, "B1", $"{MultilingualHelper.getString("DiamondResultShape")}:{Shape}"); - SetCellValue(sheet, "C1", $"{MultilingualHelper.getString("Code")}:{DiamondCode}"); - SetCellValue(sheet, "E1", $"{MultilingualHelper.getString("Wight")}:{Wight}ct."); - //Row 2 - SetCellValue(sheet, "A2", $"{MultilingualHelper.getString("Parameters")}"); - SetCellValue(sheet, "B2", $"{MultilingualHelper.getString("DiamondResultGridAvgValue")}"); - SetCellValue(sheet, "C2", $"{MultilingualHelper.getString("Interval")}(Min~Max)"); - SetCellValue(sheet, "D2", $"{MultilingualHelper.getString("DiamondResultGridCutLevel")}"); - SetCellValue(sheet, "E2", $"{MultilingualHelper.getString("DiamondResultSymmetryGrade")}"); - //Row 3 - var row3 = getSelectData("DIAMETER"); - SetCellValue(sheet, "A3", $"{GetName("DIAMETER")}(mm)"); - SetCellValue(sheet, "B3", $"{row3.Avg}"); - SetCellValue(sheet, "C3", $"({row3.Min}~{row3.Max})"); - SetCellValue(sheet, "D3", "--"); - SetCellValue(sheet, "E3", $"{row3.SymLevel}"); - //Row 4 - var row4 = getSelectData("TOTAL_DEPTH"); - SetCellValue(sheet, "A4", $"{GetName("TOTAL_DEPTH")}(%)"); - SetCellValue(sheet, "B4", $"{row4.Avg}"); - SetCellValue(sheet, "C4", "--"); - SetCellValue(sheet, "D4", $"{row4.CutLevel}"); - SetCellValue(sheet, "E4", "--"); - // Row 5 - var row5 = getSelectData("TABLE"); - SetCellValue(sheet, "A5", $"{GetName("TABLE")}(%)"); - SetCellValue(sheet, "B5", $"{row5.Avg}"); - SetCellValue(sheet, "C5", $"({row5.Min}~{row5.Max})"); - SetCellValue(sheet, "D5", $"{row5.CutLevel}"); - SetCellValue(sheet, "E5", "--"); - var row6 = getSelectData("CROWN_ANGLE"); - SetCellValue(sheet, "A6", $"{GetName("CROWN_ANGLE")}(°)"); - SetCellValue(sheet, "B6", $"{row6.Avg}"); - SetCellValue(sheet, "C6", $"({row6.Min}~{row6.Max})"); - SetCellValue(sheet, "D6", $"{row6.CutLevel}"); - SetCellValue(sheet, "E6", $"{row6.SymLevel}"); - var row7 = getSelectData("CROWN_HEIGHT"); - SetCellValue(sheet, "A7", $"{GetName("CROWN_HEIGHT")}(%)"); - SetCellValue(sheet, "B7", $"{row7.Avg}"); - SetCellValue(sheet, "C7", $"({row7.Min}~{row7.Max})"); - SetCellValue(sheet, "D7", $"{row7.CutLevel}"); - SetCellValue(sheet, "E7", $"{row7.SymLevel}"); - var row8 = getSelectData("GIRDLE"); - SetCellValue(sheet, "A8", $"{GetName("GIRDLE")}(%)"); - SetCellValue(sheet, "B8", $"{row8.Avg}"); - SetCellValue(sheet, "C8", $"({row8.Min}~{row8.Max})"); - SetCellValue(sheet, "D8", $"{row8.CutLevel}"); - SetCellValue(sheet, "E8", $"{row8.SymLevel}"); - var row9 = getSelectData("PAV_DEPTH"); - SetCellValue(sheet, "A9", $"{GetName("PAV_DEPTH")}(%)"); - SetCellValue(sheet, "B9", $"{row9.Avg}"); - SetCellValue(sheet, "C9", $"({row9.Min}~{row9.Max})"); - SetCellValue(sheet, "D9", $"{row9.CutLevel}"); - SetCellValue(sheet, "E9", $"{row9.SymLevel}"); - //row 10 - //Row 11 - SetCellValue(sheet, "A11", $"{MultilingualHelper.getString("CuttingGrade")}"); - SetCellValue(sheet, "B11", $"{CutLevelTotal}"); - //Row 12 - SetCellValue(sheet, "A12", $"{MultilingualHelper.getString("SymmetryLevel")}"); - SetCellValue(sheet, "B12", $"{SymLevelTotal}"); - SetCellValue(sheet, "C12", $"{MultilingualHelper.getString("DateOfIssue")}: {DateTime.Now:yyyy/M/d}"); - // 生成临时文件路径 - string tempFile = Path.Combine( - Path.GetTempPath(), - $"DiamondReport_{DateTime.Now:yyyyMMddHHmmss}.xlsx"); - - using (FileStream fs = new FileStream(tempFile, FileMode.Create)) + string TemplatePath = @"Resource\ResultReport.xlsx"; + using (FileStream templateStream = new FileStream(TemplatePath, FileMode.Open, FileAccess.Read)) { - workbook.Write(fs); + IWorkbook workbook = new XSSFWorkbook(templateStream); + ISheet sheet = workbook.GetSheetAt(0); + + //Row 1 + SetCellValue(sheet, "A1", $"{MultilingualHelper.getString("Organization")}:{Standard}"); + SetCellValue(sheet, "B1", $"{MultilingualHelper.getString("DiamondResultShape")}:{Shape}"); + SetCellValue(sheet, "C1", $"{MultilingualHelper.getString("Code")}:{DiamondCode}"); + SetCellValue(sheet, "E1", $"{MultilingualHelper.getString("Wight")}:{Wight}ct."); + //Row 2 + SetCellValue(sheet, "A2", $"{MultilingualHelper.getString("Parameters")}"); + SetCellValue(sheet, "B2", $"{MultilingualHelper.getString("DiamondResultGridAvgValue")}"); + SetCellValue(sheet, "C2", $"{MultilingualHelper.getString("Interval")}(Min~Max)"); + SetCellValue(sheet, "D2", $"{MultilingualHelper.getString("DiamondResultGridCutLevel")}"); + SetCellValue(sheet, "E2", $"{MultilingualHelper.getString("DiamondResultSymmetryGrade")}"); + //Row 3 + var row3 = getSelectData("DIAMETER"); + SetCellValue(sheet, "A3", $"{GetName("DIAMETER")}(mm)"); + SetCellValue(sheet, "B3", $"{row3.Avg}"); + SetCellValue(sheet, "C3", $"({row3.Min}~{row3.Max})"); + SetCellValue(sheet, "D3", "--"); + SetCellValue(sheet, "E3", $"{row3.SymLevel}"); + //Row 4 + var row4 = getSelectData("TOTAL_DEPTH"); + SetCellValue(sheet, "A4", $"{GetName("TOTAL_DEPTH")}(%)"); + SetCellValue(sheet, "B4", $"{row4.Avg}"); + SetCellValue(sheet, "C4", "--"); + SetCellValue(sheet, "D4", $"{row4.CutLevel}"); + SetCellValue(sheet, "E4", "--"); + // Row 5 + var row5 = getSelectData("TABLE"); + SetCellValue(sheet, "A5", $"{GetName("TABLE")}(%)"); + SetCellValue(sheet, "B5", $"{row5.Avg}"); + SetCellValue(sheet, "C5", $"({row5.Min}~{row5.Max})"); + SetCellValue(sheet, "D5", $"{row5.CutLevel}"); + SetCellValue(sheet, "E5", "--"); + var row6 = getSelectData("CROWN_ANGLE"); + SetCellValue(sheet, "A6", $"{GetName("CROWN_ANGLE")}(°)"); + SetCellValue(sheet, "B6", $"{row6.Avg}"); + SetCellValue(sheet, "C6", $"({row6.Min}~{row6.Max})"); + SetCellValue(sheet, "D6", $"{row6.CutLevel}"); + SetCellValue(sheet, "E6", $"{row6.SymLevel}"); + var row7 = getSelectData("CROWN_HEIGHT"); + SetCellValue(sheet, "A7", $"{GetName("CROWN_HEIGHT")}(%)"); + SetCellValue(sheet, "B7", $"{row7.Avg}"); + SetCellValue(sheet, "C7", $"({row7.Min}~{row7.Max})"); + SetCellValue(sheet, "D7", $"{row7.CutLevel}"); + SetCellValue(sheet, "E7", $"{row7.SymLevel}"); + var row8 = getSelectData("GIRDLE"); + SetCellValue(sheet, "A8", $"{GetName("GIRDLE")}(%)"); + SetCellValue(sheet, "B8", $"{row8.Avg}"); + SetCellValue(sheet, "C8", $"({row8.Min}~{row8.Max})"); + SetCellValue(sheet, "D8", $"{row8.CutLevel}"); + SetCellValue(sheet, "E8", $"{row8.SymLevel}"); + var row9 = getSelectData("PAV_DEPTH"); + SetCellValue(sheet, "A9", $"{GetName("PAV_DEPTH")}(%)"); + SetCellValue(sheet, "B9", $"{row9.Avg}"); + SetCellValue(sheet, "C9", $"({row9.Min}~{row9.Max})"); + SetCellValue(sheet, "D9", $"{row9.CutLevel}"); + SetCellValue(sheet, "E9", $"{row9.SymLevel}"); + //row 10 + //Row 11 + SetCellValue(sheet, "A11", $"{MultilingualHelper.getString("CuttingGrade")}"); + SetCellValue(sheet, "B11", $"{CutLevelTotal}"); + //Row 12 + SetCellValue(sheet, "A12", $"{MultilingualHelper.getString("SymmetryLevel")}"); + SetCellValue(sheet, "B12", $"{SymLevelTotal}"); + SetCellValue(sheet, "C12", $"{MultilingualHelper.getString("DateOfIssue")}: {DateTime.Now:yyyy/M/d}"); + // 生成临时文件路径 + string tempFile = Path.Combine( + Path.GetTempPath(), + $"DiamondReport_{DateTime.Now:yyyyMMddHHmmss}.xlsx"); + + using (FileStream fs = new FileStream(tempFile, FileMode.Create)) + { + workbook.Write(fs); + } + + return tempFile; } - return tempFile; + } + catch (Exception e) + { + throw e; } } diff --git a/Views/Dialog/ImageSelect.xaml b/Views/Dialog/ImageSelect.xaml new file mode 100644 index 0000000..ac7fb67 --- /dev/null +++ b/Views/Dialog/ImageSelect.xaml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +