private void ClosePicturePreview_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); Image image = null; Bitmap bitmap = null; ClosePicturePerview(_bridgeDeckListDamageSummary, l1, ref image, ref bitmap); ClosePicturePerview(_superSpaceListDamageSummary, l2, ref image, ref bitmap); ClosePicturePerview(_subSpaceListDamageSummary, l3, ref image, ref bitmap); void ClosePicturePerview(ObservableCollection <DamageSummary> listDamageSummary, List <DamageSummary> lst, ref Image img, ref Bitmap map) { for (int i = 0; i < lst.Count; i++) { listDamageSummary[i].PictureHeight = 15; listDamageSummary[i].PicturePreview1 = null; listDamageSummary[i].PicturePreview2 = null; } } }
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 GridViewModel(BridgePart bridgePart = BridgePart.BridgeDeck) { GridSource = new GridModel(); IKernel kernel = new StandardKernel(new NinjectDependencyResolver()); var dataRepository = kernel.Get <IDataRepository>(); List <DamageSummary> lst; lst = dataRepository.ReadDamageData(bridgePart); if (bridgePart == BridgePart.BridgeDeck) { DamageSummaryServices.InitListDamageSummary(lst); } else if (bridgePart == BridgePart.SuperSpace) { DamageSummaryServices.InitListDamageSummary(lst, 2_000_000, bridgePart); } else { DamageSummaryServices.InitListDamageSummary(lst, 3_000_000, bridgePart); } ObservableCollection <DamageSummary> oc = new ObservableCollection <DamageSummary>(); //List转ObservableCollection lst.ForEach(x => oc.Add(x)); foreach (var k in oc) { GridSource.GridData.Add(k); } }
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(); }
private static void GenerateReport(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(() => { w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Show(); }); //progressBarModel.ProgressValue = 0; //测试数据 var doc = new Document(templateFile); var asposeService = new AsposeWordsServices(ref doc, l1, l2, l3); asposeService.GenerateSummaryTableAndPictureTable(ref progressBarModel, CommentColumnInsertTable, ImageWidth, ImageHeight, CompressImageFlag); //两次更新域,1次更新序号,1次更新序号对应的交叉引用 doc.UpdateFields(); doc.UpdateFields(); doc.Save(outputFile, SaveFormat.Docx); w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Close(); }); w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { MessageBox.Show("成功生成报告!"); }); })); thread.Start(); }
private void GenerateDamageStatisticsTable_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>; try { DamageSummaryServices.GenerateDamageStatisticsTable(_bridgeDeckListDamageSummary, _superSpaceListDamageSummary, _SubSpaceListDamageSummary); MessageBox.Show("成功生成桥梁检测病害统计汇总表!"); } catch (Exception ex) { MessageBox.Show($"保存excel出错,错误信息:{ex.Message}"); } }
public void SetPictureCounts_ShouldSetCorretPictureCounts() { //Arrange var bridgeDeckListDamageSummary = new List <DamageSummary> { new DamageSummary { PictureNo = "855;858;875" } }; //Act DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary); //Assert Assert.Equal(3, bridgeDeckListDamageSummary[0].PictureCounts); }
public void SetComboBox_ShouldSetCorretComponentValue_WhileBridgePartIsSubSpace() { //Arrange var listDamageSummary = new List <DamageSummary> { new DamageSummary { Component = "台身" , Damage = "墩身水平裂缝" , PictureNo = "855;858;875" } }; //Act DamageSummaryServices.InitListDamageSummary(listDamageSummary, 3_000_000, BridgePart.SubSpace); //Assert Assert.Equal(3, listDamageSummary[0].ComponentValue); }
public void SetComboBox_ShouldSetCorretComponentValue() { //Arrange var bridgeDeckListDamageSummary = new List <DamageSummary> { new DamageSummary { Component = "伸缩缝" , Damage = "缝内沉积物阻塞" , PictureNo = "855;858;875" } }; //Act DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary); //Assert Assert.Equal(2, bridgeDeckListDamageSummary[0].ComponentValue); }
public void SetFirstAndLastPictureBookmark_ShouldSetCorretBookmarkName() { //Arrange var bridgeDeckListDamageSummary = new List <DamageSummary> { new DamageSummary { PictureNo = "855;858;875" } }; //Act DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary); //Assert Assert.Equal(1000000, bridgeDeckListDamageSummary[0].FirstPictureBookmarkIndex); Assert.Equal($"_Ref1000000", bridgeDeckListDamageSummary[0].FirstPictureBookmark); Assert.Equal($"_Ref1000002", bridgeDeckListDamageSummary[0].LastPictureBookmark); }
public void SetComboBox_ShouldSetCorrectDamageAndDamageValue_WhileDamageNotFound() { //Arrange var bridgeDeckListDamageSummary = new List <DamageSummary> { new DamageSummary { Component = "伸缩缝" , Damage = "其它病害" , PictureNo = "855;858;875" } }; //Act DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary); //Assert Assert.Equal("螺帽松动", bridgeDeckListDamageSummary[0].DamageComboBox[0].Title); Assert.Equal("缝内沉积物阻塞", bridgeDeckListDamageSummary[0].DamageComboBox[1].Title); Assert.Equal(10, bridgeDeckListDamageSummary[0].DamageValue); }
public void GenerateDamageStatisticsTableShouldSetCorrectStatisticsData() { //Arrange IKernel kernel = new StandardKernel(new NinjectDependencyResolver()); var dataRepository = kernel.Get <IDataRepository>(); string saveFileName = "桥梁检测病害统计汇总表.xlsx"; List <DamageSummary> lst1, lst2, lst3; lst1 = dataRepository.ReadDamageData(BridgePart.BridgeDeck); lst2 = dataRepository.ReadDamageData(BridgePart.SuperSpace); lst3 = dataRepository.ReadDamageData(BridgePart.SubSpace); DamageSummaryServices.InitListDamageSummary(lst1); DamageSummaryServices.InitListDamageSummary(lst2, 2_000_000, BridgePart.SuperSpace); DamageSummaryServices.InitListDamageSummary(lst3, 3_000_000, BridgePart.SubSpace); ObservableCollection <DamageSummary> oc1 = new ObservableCollection <DamageSummary>(); ObservableCollection <DamageSummary> oc2 = new ObservableCollection <DamageSummary>(); ObservableCollection <DamageSummary> oc3 = new ObservableCollection <DamageSummary>(); lst1.ForEach(x => oc1.Add(x)); lst2.ForEach(x => oc2.Add(x)); lst3.ForEach(x => oc3.Add(x)); int expectedUnit1TotalCounts = 3; int acturalUnit1TotalCounts = 0; decimal expectedUnit2TotalCounts = 29.8m; decimal acturalUnit2TotalCounts = 0.0m; //Act DamageSummaryServices.GenerateDamageStatisticsTable(oc1, oc2, oc3); var file = new FileInfo(saveFileName); using (var excelPackage = new ExcelPackage(file)) { // 检查"桥面系"Worksheets var worksheet = excelPackage.Workbook.Worksheets["桥面系病害统计汇总表"]; acturalUnit1TotalCounts = Convert.ToInt32(worksheet.Cells[2, SaveExcelService.FindColumnIndexByName(worksheet, "单位1数量")].Value?.ToString() ?? string.Empty, CultureInfo.InvariantCulture); acturalUnit2TotalCounts = Convert.ToDecimal(worksheet.Cells[2, SaveExcelService.FindColumnIndexByName(worksheet, "单位2数量")].Value?.ToString() ?? string.Empty, CultureInfo.InvariantCulture); } //Assert Assert.Equal(expectedUnit1TotalCounts, acturalUnit1TotalCounts); Assert.Equal(expectedUnit2TotalCounts, acturalUnit2TotalCounts); }
public void SetComboBox_ShouldSetCorretComponentValue_WhileBridgePartIsSuperSpace() { //Arrange var listDamageSummary = new List <DamageSummary> { new DamageSummary { Component = "横向联系" , Damage = "连接件断裂" , PictureNo = "855;858;875" } , new DamageSummary { Component = "横向联系" , Damage = "横隔板网裂" , PictureNo = "900" } }; //Act DamageSummaryServices.InitListDamageSummary(listDamageSummary, 2_000_000, BridgePart.SuperSpace); //Assert Assert.Equal(2, listDamageSummary[0].ComponentValue); }
public void GenerateReportIntegratedTest() { //Arrange const string tempPath = "Temp"; string templateFile = @"TestFiles\外观检查报告模板.docx"; string outputFile = @"TestFiles\外观检查报告.docx"; double ImageWidth = 224.25; double ImageHeight = 168.75; int CompressImageFlag = 80; IKernel kernel = new StandardKernel(new NinjectDependencyResolver()); var dataRepository = kernel.Get<IDataRepository>(); List<DamageSummary> l1, l2, l3; l1 = dataRepository.ReadDamageData(BridgePart.BridgeDeck); DamageSummaryServices.InitListDamageSummary(l1); l2 = dataRepository.ReadDamageData(BridgePart.SuperSpace); DamageSummaryServices.InitListDamageSummary(l2, 2_000_000, BridgePart.SuperSpace); l3 = dataRepository.ReadDamageData(BridgePart.SubSpace); DamageSummaryServices.InitListDamageSummary(l3, 3_000_000, BridgePart.SubSpace); //Act var doc = new Document(templateFile); var asposeService = new AsposeWordsServices(ref doc, l1, l2, l3); asposeService.GenerateSummaryTableAndPictureTable(false,ImageWidth, ImageHeight, CompressImageFlag); doc.UpdateFields(); doc.UpdateFields(); //参考算法 //var bridgeName = string.Empty; //NodeCollection allTables = _doc.GetChildNodes(NodeType.Table, true); //for (int i = 0; i < allTables.Count; i++) //{ // Table table0 = _doc.GetChildNodes(NodeType.Table, true)[i] as Table; // if ((table0.Rows[0].Cells[0].GetText().IndexOf("委托单位") >= 0)) // { // Cell cell = table0.Rows[2].Cells[1]; // bridgeName = cell.GetText().Replace("\a", "").Replace("\r", ""); //用GetText()的方法来获取cell中的值 // break; // } //} Table bridgeDeckDamageSummaryTable = null; Table bridgeDeckDamagePictureTable = null; int bridgeDeckDamageSummaryTableIndex = 0; NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true); for (int i = 0; i < allTables.Count; i++) { bridgeDeckDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[i] as Table; if (bridgeDeckDamageSummaryTable.Rows[0].Cells.Count < 3) //防止越界 { continue; } if (bridgeDeckDamageSummaryTable.Rows[0].Cells[2].GetText().IndexOf("要素", StringComparison.Ordinal) >= 0) //先找到桥面系病害的汇总表 { bridgeDeckDamageSummaryTableIndex = i; bridgeDeckDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[i + 1] as Table; break; } } Table superSpaceDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2] as Table; Table superSpaceDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 + 1] as Table; Table subSpaceDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 * 2] as Table; Table subSpaceDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 * 2 + 1] as Table; doc.UnlinkFields(); //看情况决定是否要解除链接 doc.Save(outputFile, SaveFormat.Docx); //如果需要查看生成的文件,则加上这句 int skipBefore = 22; int skipAfter = 28; //该数据要手动测试出来 List<string> fileNameList = AutoRegularInspection.Repository.AsposeWordsImage.ExportImageFromWordFile(skipBefore, skipAfter,outputFile, @$"{tempPath}\").ToList(); //Assert //测试汇总内容 Assert.Contains("伸缩缝:共3条缝内沉积物阻塞,长度29.8米;共1处接缝处铺装碎边,面积0.6平方米。\r栏杆:共1处丢失残缺。", doc.Range.Text,StringComparison.Ordinal); Assert.Contains("台身:共3处露筋锈蚀,面积0.48平方米", doc.Range.Text, StringComparison.Ordinal); //测试汇总表(桥面系) Assert.Contains("缝内沉积物阻塞", bridgeDeckDamageSummaryTable.Rows[1].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("接缝处铺装碎边", bridgeDeckDamageSummaryTable.Rows[2].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("图 2-3", bridgeDeckDamageSummaryTable.Rows[2].Cells[5].GetText().Trim(), StringComparison.Ordinal); //测试汇总图片表(桥面系) Assert.Contains("图 2-1 左幅0#伸缩缝沉积物阻塞-1", bridgeDeckDamagePictureTable.Rows[1].Cells[0].GetText().Trim(), StringComparison.Ordinal); Assert.Contains("图 2-4 右幅1#伸缩缝沉积物阻塞-1", bridgeDeckDamagePictureTable.Rows[3].Cells[1].GetText().Trim(), StringComparison.Ordinal); //测试图片md5(桥面系) Assert.Equal("589279c71781666ad3adf2c76a71c9e7", GetFileMD5(@$"{tempPath}\{fileNameList[0]}"),true);
public void GenerateReportIntegratedTest() { //Arrange const string tempPath = "Temp"; string templateFile = @"TestFiles\外观检查报告模板.docx"; string outputFile = @"TestFiles\外观检查报告.docx"; double ImageWidth = 224.25; double ImageHeight = 168.75; int CompressImageFlag = 80; IKernel kernel = new StandardKernel(new NinjectDependencyResolver()); var dataRepository = kernel.Get <IDataRepository>(); List <DamageSummary> l1, l2, l3; l1 = dataRepository.ReadDamageData(BridgePart.BridgeDeck); DamageSummaryServices.InitListDamageSummary(l1); l2 = dataRepository.ReadDamageData(BridgePart.SuperSpace); DamageSummaryServices.InitListDamageSummary(l2, 2_000_000, BridgePart.SuperSpace); l3 = dataRepository.ReadDamageData(BridgePart.SubSpace); DamageSummaryServices.InitListDamageSummary(l3, 3_000_000, BridgePart.SubSpace); //Act var doc = new Document(templateFile); GenerateReportSettings generateReportSettings = new GenerateReportSettings { ComboBoxReportTemplates = new ComboBoxReportTemplates { DisplayName = "建研报告模板", Name = "外观检查报告模板.docx", DocStyleOfMainText = "迪南自动报告正文", DocStyleOfTable = "迪南自动报告表格", DocStyleOfPicture = "迪南自动报告图片" } , InspectionString = "检测" , DeletePositionInBridgeDeckCheckBox = false , CustomTableCellWidth = false , BridgeDeckTableCellWidth = new TableCellWidth { No = 1, Position = 1, Component = 1, Damage = 1, DamageDescription = 1, PictureNo = 1, Comment = 1 } , SuperSpaceTableCellWidth = new TableCellWidth { No = 1, Position = 1, Component = 1, Damage = 1, DamageDescription = 1, PictureNo = 1, Comment = 1 } , SubSpaceTableCellWidth = new TableCellWidth { No = 1, Position = 1, Component = 1, Damage = 1, DamageDescription = 1, PictureNo = 1, Comment = 1 } }; var asposeService = new AsposeWordsServices(ref doc, generateReportSettings, l1, l2, l3); //TODO:改方法,加参数 asposeService.GenerateReport(false, ImageWidth, ImageHeight, CompressImageFlag); doc.UpdateFields(); doc.UpdateFields(); //参考算法 //var bridgeName = string.Empty; //NodeCollection allTables = _doc.GetChildNodes(NodeType.Table, true); //for (int i = 0; i < allTables.Count; i++) //{ // Table table0 = _doc.GetChildNodes(NodeType.Table, true)[i] as Table; // if ((table0.Rows[0].Cells[0].GetText().IndexOf("委托单位") >= 0)) // { // Cell cell = table0.Rows[2].Cells[1]; // bridgeName = cell.GetText().Replace("\a", "").Replace("\r", ""); //用GetText()的方法来获取cell中的值 // break; // } //} Table bridgeDeckDamageSummaryTable = null; Table bridgeDeckDamagePictureTable = null; int bridgeDeckDamageSummaryTableIndex = 0; NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true); for (int i = 0; i < allTables.Count; i++) { bridgeDeckDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[i] as Table; if (bridgeDeckDamageSummaryTable.Rows[0].Cells.Count < 3) //防止越界 { continue; } if (bridgeDeckDamageSummaryTable.Rows[0].Cells[2].GetText().IndexOf("要素", StringComparison.Ordinal) >= 0) //先找到桥面系病害的汇总表 { bridgeDeckDamageSummaryTableIndex = i; bridgeDeckDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[i + 1] as Table; break; } } Table superSpaceDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2] as Table; Table superSpaceDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 + 1] as Table; Table subSpaceDamageSummaryTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 * 2] as Table; Table subSpaceDamagePictureTable = doc.GetChildNodes(NodeType.Table, true)[bridgeDeckDamageSummaryTableIndex + 2 * 2 + 1] as Table; doc.UnlinkFields(); //看情况决定是否要解除链接 doc.Save(outputFile, SaveFormat.Docx); //如果需要查看生成的文件,则加上这句 int skipBefore = 22; int skipAfter = 26; //该数据要手动测试出来 List <string> fileNameList = AutoRegularInspection.Repository.AsposeWordsImage.ExportImageFromWordFile(skipBefore, skipAfter, outputFile, $@"{tempPath}\").ToList(); //Assert //测试汇总内容 Assert.Contains("伸缩缝:共3条缝内沉积物阻塞,长度29.8m;共1处接缝处铺装碎边,面积0.6m²。\r栏杆:共1处丢失残缺。", doc.Range.Text, StringComparison.Ordinal); Assert.Contains("台身:共3处露筋锈蚀,面积0.48m²。", doc.Range.Text, StringComparison.Ordinal); //测试汇总表(桥面系) Assert.Contains("缝内沉积物阻塞", bridgeDeckDamageSummaryTable.Rows[1].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("接缝处铺装碎边", bridgeDeckDamageSummaryTable.Rows[2].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("图 2-3", bridgeDeckDamageSummaryTable.Rows[2].Cells[5].GetText().Trim(), StringComparison.Ordinal); //测试汇总图片表(桥面系) Assert.Contains("图 2-1 左幅0#伸缩缝沉积物阻塞-1", bridgeDeckDamagePictureTable.Rows[1].Cells[0].GetText().Trim(), StringComparison.Ordinal); Assert.Contains("图 2-4 右幅1#伸缩缝沉积物阻塞-1", bridgeDeckDamagePictureTable.Rows[3].Cells[1].GetText().Trim(), StringComparison.Ordinal); //测试图片md5(桥面系) Assert.Equal("2169b9d1255df20c32a8f01b739c06ec", GetFileMD5($@"{tempPath}\{fileNameList[0]}"), true); Assert.Equal("8bf87376612ac0545727f299ab61688d", GetFileMD5($@"{tempPath}\{fileNameList[1]}"), true); //测试汇总表(上部结构) Assert.Contains("无", superSpaceDamageSummaryTable.Rows[1].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("图 2-10", superSpaceDamageSummaryTable.Rows[2].Cells[5].GetText().Trim(), StringComparison.Ordinal); //测试汇总图片表(上部结构) Assert.Contains("图 2-9 左幅主梁", superSpaceDamagePictureTable.Rows[1].Cells[0].GetText().Trim(), StringComparison.Ordinal); Assert.Contains("图 2-10 右幅主梁", superSpaceDamagePictureTable.Rows[1].Cells[1].GetText().Trim(), StringComparison.Ordinal); //测试图片md5(上部结构) Assert.Equal("2169b9d1255df20c32a8f01b739c06ec", GetFileMD5($@"{tempPath}\{fileNameList[8]}"), true); Assert.Equal("0adecfa1b4387ccc54022bd98b518a0f", GetFileMD5($@"{tempPath}\{fileNameList[9]}"), true); //测试汇总表(下部结构) Assert.Contains("水蚀", subSpaceDamageSummaryTable.Rows[1].Cells[3].GetText(), StringComparison.Ordinal); Assert.Contains("图 2-12", subSpaceDamageSummaryTable.Rows[2].Cells[5].GetText().Trim(), StringComparison.Ordinal); //测试汇总图片表(下部结构) Assert.Contains("图 2-13 左幅1#台台身露筋锈蚀", subSpaceDamagePictureTable.Rows[1 + 2].Cells[0].GetText().Trim(), StringComparison.Ordinal); Assert.Contains("图 2-14 右幅1#台台身露筋锈蚀", subSpaceDamagePictureTable.Rows[1 + 2].Cells[1].GetText().Trim(), StringComparison.Ordinal); //测试图片md5(下部结构) Assert.Equal("2169b9d1255df20c32a8f01b739c06ec", GetFileMD5($@"{tempPath}\{fileNameList[10]}"), true); Assert.Equal("0adecfa1b4387ccc54022bd98b518a0f", GetFileMD5($@"{tempPath}\{fileNameList[11]}"), true); }
private void PicturePreview_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); Image image = null; Bitmap bitmap = null; ImageClass imageClass = null; string picture1 = string.Empty; string picture2 = string.Empty; OpenPicturePerview(_bridgeDeckListDamageSummary, l1, ref image, ref bitmap); OpenPicturePerview(_superSpaceListDamageSummary, l2, ref image, ref bitmap); OpenPicturePerview(_subSpaceListDamageSummary, l3, ref image, ref bitmap); void OpenPicturePerview(ObservableCollection <DamageSummary> listDamageSummary, List <DamageSummary> lst, ref Image img, ref Bitmap map) { for (int i = 0; i < lst.Count; i++) { if (lst[i].PictureCounts == 0) { continue; } else if (lst[i].PictureCounts == 1) { //已被重构 //imageClass = new ImageClass(Directory.GetFiles(@"Pictures/", $"*{lst[i].PictureNo}*")[0]); try { imageClass = new ImageClass(FileService.GetFileName(@"Pictures", lst[i].PictureNo)); } catch (System.Exception ex) { imageClass = new ImageClass("ErrorPic.jpg"); if (!File.Exists(@"日志.txt")) { _ = File.Create(@"日志.txt"); } var stream = new FileStream(@"日志.txt", FileMode.Append);//fileMode指定是读取还是写入 StreamWriter writer = new StreamWriter(stream); writer.WriteLine($"警告:{lst[i].PictureNo}不存在!错误信息:{ex.Message}"); writer.Close(); stream.Close(); } img = imageClass.GetReducedImage(0.2); //img = Image.FromFile($"{Directory.GetFiles(@"PicturesOut/", $"*{lst[i].PictureNo}*")[0]}"); map = new Bitmap(img); listDamageSummary[i].PictureHeight = 60; listDamageSummary[i].PicturePreview1 = ConvertBitmap(map); } else if (lst[i].PictureCounts >= 2) { var pictures = lst[i].PictureNo.Split(','); //imageClass = new ImageClass(Directory.GetFiles(@"Pictures/", $"*{pictures[0]}*")[0]); imageClass = new ImageClass(FileService.GetFileName(@"Pictures", pictures[0])); img = imageClass.GetReducedImage(0.2); //img = Image.FromFile($"{Directory.GetFiles(@"Pictures/", $"*{pictures[0]}*")[0]}"); map = new Bitmap(img); listDamageSummary[i].PicturePreview1 = ConvertBitmap(map); //imageClass = new ImageClass(Directory.GetFiles(@"Pictures/", $"*{pictures[1]}*")[0]); imageClass = new ImageClass(FileService.GetFileName(@"Pictures", pictures[1])); img = imageClass.GetReducedImage(0.2); //img = Image.FromFile($"{Directory.GetFiles(@"Pictures/", $"*{pictures[1]}*")[0]}"); map = new Bitmap(img); listDamageSummary[i].PicturePreview2 = ConvertBitmap(map); listDamageSummary[i].PictureHeight = 60; } else //异常、负数等情况 { listDamageSummary[i].PicturePreview1 = null; listDamageSummary[i].PicturePreview2 = null; } } } }