private void ValidatePictures_Click(object sender, RoutedEventArgs e) { var _bridgeDeckListDamageSummary = BridgeDeckGrid.ItemsSource as ObservableCollection <DamageSummary>; var _superSpaceListDamageSummary = SuperSpaceGrid.ItemsSource as ObservableCollection <DamageSummary>; var _subSpaceListDamageSummary = SubSpaceGrid.ItemsSource as ObservableCollection <DamageSummary>; List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList(); List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList(); List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList(); DamageSummaryServices.InitListDamageSummary1(l1); DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000); DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000); int totalInvalidPictureCounts = PictureServices.ValidatePictures(l1, l2, l3, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult); try { WriteInvalidPicturesResultToTxt(totalInvalidPictureCounts, bridgeDeckValidationResult, superSpaceValidationResult, subSpaceValidationResult); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } MessageBoxResult k = MessageBox.Show($"照片验证完成!其中无效照片共计{totalInvalidPictureCounts}张,结果详见根目录文件“无效照片列表.txt”"); }
public void ValidatePicturesTest_ShouldReturnCorrectInvalidPictureCounts_And_ValidationResult() { //Arrange var bridgeDeckListDamageSummary = new List <DamageSummary> { new DamageSummary { PictureNo = "855;858;875" } }; var superSpaceListDamageSummary = new List <DamageSummary> { new DamageSummary { PictureNo = "855;858;875x" } }; var subSpaceListDamageSummary = new List <DamageSummary> { new DamageSummary { PictureNo = "855;858y;875z" } }; DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary); DamageSummaryServices.InitListDamageSummary(superSpaceListDamageSummary, 2_000_000, BridgePart.SuperSpace); DamageSummaryServices.InitListDamageSummary(subSpaceListDamageSummary, 3_000_000, BridgePart.SubSpace); //Act int totalInvalidPictureCounts = PictureServices.ValidatePictures(bridgeDeckListDamageSummary, superSpaceListDamageSummary, subSpaceListDamageSummary, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult); //Assert Assert.Equal(3, totalInvalidPictureCounts); Assert.Equal("上部结构,照片875x不存在", superSpaceValidationResult[0]); }
private static void GenerateReport(GenerateReportSettings generateReportSettings, bool CommentColumnInsertTable, double ImageWidth, double ImageHeight, string templateFile, string outputFile, int CompressImageFlag, ObservableCollection <DamageSummary> _bridgeDeckListDamageSummary, ObservableCollection <DamageSummary> _superSpaceListDamageSummary, ObservableCollection <DamageSummary> _subSpaceListDamageSummary) { var w = new ProgressBarWindow(); w.Top = 0.4 * (App.ScreenHeight - w.Height); w.Left = 0.4 * (App.ScreenWidth - w.Width); var progressBarModel = new ProgressBarModel { ProgressValue = 0 }; w.progressBarNumberTextBlock.DataContext = progressBarModel; w.progressBar.DataContext = progressBarModel; w.progressBarContentTextBlock.DataContext = progressBarModel; var progressSleepTime = 500; //进度条停顿时间 List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList(); List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList(); List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList(); DamageSummaryServices.InitListDamageSummary1(l1); DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000); DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000); var thread = new Thread(new ThreadStart(() => { //progressBarModel.ProgressValue = 0; //测试数据 //生成报告前先验证照片的有效性 int totalInvalidPictureCounts = PictureServices.ValidatePictures(l1, l2, l3, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult); if (totalInvalidPictureCounts > 0) { try { WriteInvalidPicturesResultToTxt(totalInvalidPictureCounts, bridgeDeckValidationResult, superSpaceValidationResult, subSpaceValidationResult); MessageBox.Show($"存在无效照片,无法生成报告,共计{totalInvalidPictureCounts}张,详见根目录{App.InvalidPicturesStoreFile}"); return; } catch (Exception ex) { //MessageBox.Show(ex.Message); //throw; } } w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Show(); }); Document doc = new Document(templateFile); var asposeService = new AsposeWordsServices(ref doc, generateReportSettings, l1, l2, l3); asposeService.GenerateReport(ref progressBarModel, CommentColumnInsertTable, ImageWidth, ImageHeight, CompressImageFlag); doc.Save(outputFile, SaveFormat.Docx); w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Close(); }); w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { MessageBox.Show("成功生成报告!"); }); })); thread.Start(); }