CompLogViewer.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using MeterVision.model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace MeterVision.Dlg
  17. {
  18. /// <summary>
  19. /// CompLogViewer.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class CompLogViewer : Window
  22. {
  23. private readonly CompDetailItem DetailItem;
  24. public CompLogViewer(CompDetailItem detailItem)
  25. {
  26. InitializeComponent();
  27. DetailItem = detailItem;
  28. InitLoad(detailItem);
  29. }
  30. private void InitLoad(CompDetailItem detailItem)
  31. {
  32. ucImageSrc.ImageName = "新任务结果图片";
  33. ucImageDst.ImageName = "旧任务结果图片";
  34. if (File.Exists(detailItem.Detail1.DstImage))
  35. {
  36. ucImageSrc.ImageSource = detailItem.Detail1.DstImage;
  37. }
  38. if (File.Exists(detailItem.Detail2.DstImage))
  39. {
  40. ucImageDst.ImageSource = detailItem.Detail2.DstImage;
  41. }
  42. if (File.Exists(detailItem.Detail1.LogPath))
  43. {
  44. LoadLogContent(RichTxtContentBox,detailItem.Detail1.LogPath);
  45. }
  46. if (File.Exists(detailItem.Detail2.LogPath))
  47. {
  48. LoadLogContent(RichTxtContentBox2,detailItem.Detail2.LogPath);
  49. }
  50. }
  51. private void LoadLogContent(RichTextBox richTextBox,string filePath)
  52. {
  53. try
  54. {
  55. if (File.Exists(filePath))
  56. {
  57. string content = File.ReadAllText(filePath);
  58. // 创建段落并将日志内容添加到段落
  59. Paragraph logParagraph = new Paragraph(new Run(content));
  60. // 将日志段落添加到 RichTextBox 的文档中
  61. //RichTxtContentBox.Document.Blocks.Add(logParagraph);
  62. richTextBox.Document.Blocks.Add(logParagraph);
  63. }
  64. else
  65. {
  66. MessageBox.Show("日志文件未找到!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. MessageBox.Show($"加载日志文件时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  72. }
  73. }
  74. private void Window_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  75. {
  76. }
  77. private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
  78. {
  79. if(e.Key == Key.Escape)
  80. {
  81. this.Close();
  82. }
  83. }
  84. private void LogScrollTop_Click(object sender, RoutedEventArgs e)
  85. {
  86. RichTxtContentBox.ScrollToHome();
  87. }
  88. private void LogScrollBottom_Click(object sender, RoutedEventArgs e)
  89. {
  90. RichTxtContentBox.ScrollToEnd();
  91. }
  92. private void AiLogSave_Click(object sender, RoutedEventArgs e)
  93. {
  94. if (DetailItem == null) return;
  95. string logPath = DetailItem.Detail1.LogPath;
  96. if (!string.IsNullOrEmpty(logPath) && File.Exists(logPath))
  97. {
  98. ThisApp.ExportAiLog(logPath);
  99. }
  100. }
  101. private void LogScrollTop2_Click(object sender, RoutedEventArgs e)
  102. {
  103. RichTxtContentBox2.ScrollToHome();
  104. }
  105. private void LogScrollBottom2_Click(object sender, RoutedEventArgs e)
  106. {
  107. RichTxtContentBox2.ScrollToEnd();
  108. }
  109. private void AiLogSave2_Click(object sender, RoutedEventArgs e)
  110. {
  111. if (DetailItem == null) return;
  112. string logPath = DetailItem.Detail2.LogPath;
  113. if (!string.IsNullOrEmpty(logPath) && File.Exists(logPath))
  114. {
  115. ThisApp.ExportAiLog(logPath);
  116. }
  117. }
  118. private void Window_Closed(object sender, EventArgs e)
  119. {
  120. }
  121. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  122. {
  123. }
  124. //---------------------------------------------------------
  125. }
  126. }