252RB日志查询工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.6 KiB

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LogAnalyzer
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private readonly LogParserService _parser;
private DataTable resultTable;
public MainWindow()
{
InitializeComponent();
_parser = new LogParserService();
}
private void BtnLoadLog_Click(object sender, RoutedEventArgs e)
{
// 1. 打开文件选择对话框
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";
openFileDialog.Title = "请选择染整设备日志文件";
if (openFileDialog.ShowDialog() == true)
{
try
{
TxtStatus.Text = "正在解析...";
// 强制UI刷新状态文本
LogDataGrid.UpdateLayout();
// 2. 调用服务解析文件
// 注意:如果文件非常大,建议使用异步 Task.Run 避免界面卡顿
resultTable = _parser.ParseLogFile(openFileDialog.FileName);
//DataTable resultTable1 = _parser.ExtractDatabaseCommandsWithContext(resultTable,1);
// 3. 绑定数据到 DataGrid
// DataTable 的 DefaultView 实现了 IBindingList,适合直接绑定
LogDataGrid.ItemsSource = resultTable.DefaultView;
//LogDataGrid1.ItemsSource = resultTable1.DefaultView;
TxtStatus.Text = $"解析完成,共加载 {resultTable.Rows.Count} 条记录。";
}
catch (Exception ex)
{
MessageBox.Show($"发生错误: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
TxtStatus.Text = "加载失败";
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DataTable resultTable1 = _parser.ExtractDatabaseCommandsWithContext(resultTable, 1);
LogDataGrid1.ItemsSource = resultTable1.DefaultView;
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
DataTable resultTable1 = _parser.ExtractTank1CommandsWithContext(resultTable);
LogDataGrid1.ItemsSource = resultTable1.DefaultView;
}
private void Button_Click2(object sender, RoutedEventArgs e)
{
DataTable resultTable1 = _parser.ExtractTank2CommandsWithContext(resultTable);
LogDataGrid1.ItemsSource = resultTable1.DefaultView;
}
private void Button_Click3(object sender, RoutedEventArgs e)
{
DataTable resultTable1 = _parser.ExtractTank3CommandsWithContext(resultTable);
LogDataGrid1.ItemsSource = resultTable1.DefaultView;
}
private void Button_Click4(object sender, RoutedEventArgs e)
{
DataTable resultTable1 = _parser.ExtractTank4CommandsWithContext(resultTable);
LogDataGrid1.ItemsSource = resultTable1.DefaultView;
}
}
}