From bc0bc0f5521e3101c6dcfca99b1f7205e9349a1b Mon Sep 17 00:00:00 2001 From: sunhonglei Date: Mon, 10 Feb 2025 14:50:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:excel=E5=8D=A0=E7=94=A8=E5=92=8Cvideo?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Language/en_US.xaml | 2 ++ Language/zh_CN.xaml | 1 + ViewModel/Grading/DiamondSelectVM.cs | 28 +++++++++++++++---- ViewModel/Grading/GradingResultVM.cs | 23 ++++++++++++--- .../ViewportData/Helper/VideoHelper.cs | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Language/en_US.xaml b/Language/en_US.xaml index 214f1e5..18937db 100644 --- a/Language/en_US.xaml +++ b/Language/en_US.xaml @@ -153,6 +153,7 @@ Save Successful Save Failed Select Path + Reset grid lines SparkDetectionSystem @@ -205,6 +206,7 @@ MSVC Runtime not installed, program may encounter errors during execution File path does not exist The file format is incorrect + The file is currently being opened DateOfIssue Organization Code diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml index bd7ea8e..f42bc5d 100644 --- a/Language/zh_CN.xaml +++ b/Language/zh_CN.xaml @@ -206,6 +206,7 @@ MSVC Runtime未安装,程序执行中可能会出错 文件路径不存在 文件格式不正确 + 文件正在被打开 签发日期 机构 编码 diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index e2e496d..15b7ad6 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -285,6 +285,11 @@ public class DiamondSelectVM : BaseViewModel { loading.Close(); new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists")); + } + catch (IOException ex) + { + loading.Close(); + new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}"); } finally { @@ -400,6 +405,11 @@ public class DiamondSelectVM : BaseViewModel loading.Close(); new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists")); } + catch (IOException ex) + { + loading.Close(); + new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}"); + } catch (Exception ex) { new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); @@ -501,12 +511,18 @@ public class DiamondSelectVM : BaseViewModel [Log] public void GradingResult(AlgorithmResultEntity param) { - - //WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); - BaseControlVM vm = new BaseControlVM(new GradingResultVM(param), MultilingualHelper.getString("DetectionResult")); - vm.ShowFunctionButton = System.Windows.Visibility.Hidden; - WindowManager.mainViewModel.Content = vm; - WindowManager.openContent.Add(vm); + try + { + //WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); + BaseControlVM vm = new BaseControlVM(new GradingResultVM(param), MultilingualHelper.getString("DetectionResult")); + vm.ShowFunctionButton = System.Windows.Visibility.Hidden; + WindowManager.mainViewModel.Content = vm; + WindowManager.openContent.Add(vm); + } + catch (IOException) + { + throw; + } } } diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index a3a3a7e..7e9f1d2 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -197,6 +197,9 @@ public class GradingResultVM : BaseViewModel } SaveTestResult(SaveStatus.AutoSave); SaveToCsv(); + }catch(IOException) + { + throw; } catch (Exception ex) { @@ -955,8 +958,8 @@ public class GradingResultVM : BaseViewModel [Log] private async void ExportFile(string filePath) { - try { ExportDialog exportDialog = new ExportDialog(); + try { var tcs = new TaskCompletionSource(); var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => { exportDialog.Closed += (s, e) => tcs.SetResult(true); @@ -1010,13 +1013,21 @@ public class GradingResultVM : BaseViewModel // }); }); await Task.Delay(500); - exportDialog.Close(); + + } + catch (IOException ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}"); } catch(Exception ex) { new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); Logger.Error($"全局异常捕获:{ex.Message}", ex); } + finally + { + exportDialog.Close(); + } } [Log] private bool FileSaveEnabled(string Key) @@ -1118,9 +1129,9 @@ public class GradingResultVM : BaseViewModel [Log] private void ExcelFile(string filePath) { + string fileName = filePath + ".xlsx"; try { - string fileName = filePath + ".xlsx"; IWorkbook workbook = new XSSFWorkbook(); ISheet sheet = workbook.CreateSheet("Sheet1"); @@ -1174,10 +1185,14 @@ public class GradingResultVM : BaseViewModel workbook.Write(stream); } } + catch (IOException) + { + throw new IOException($"{fileName}"); + } catch (Exception ex) { - new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); Logger.Error($"全局异常捕获:{ex.Message}", ex); + throw; } } diff --git a/Views/UserControl/ViewportData/Helper/VideoHelper.cs b/Views/UserControl/ViewportData/Helper/VideoHelper.cs index 9696ecd..464d2a6 100644 --- a/Views/UserControl/ViewportData/Helper/VideoHelper.cs +++ b/Views/UserControl/ViewportData/Helper/VideoHelper.cs @@ -107,7 +107,7 @@ public class VideoHelper } string framePattern = Path.Combine(tempDirectory, "frame_%05d.png").Replace("\\", "/"); // Replace backslashes with forward slashes for FFmpeg compatibility - string arguments = $"-framerate 30 -i \"{framePattern}\" -vf \"scale=640:480\" -c:v libx264 -pix_fmt yuv420p \"{outputPath}\""; + string arguments = $"-framerate 30 -i \"{framePattern}\" -vf \"scale=640:480\" -c:v libx264 -pix_fmt yuv420p -y \"{outputPath}\""; var processInfo = new System.Diagnostics.ProcessStartInfo {