添加项目文件。

This commit is contained in:
xyy
2026-05-05 15:31:24 +08:00
parent 196fcc7822
commit 11bf3f4827
27 changed files with 1526 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using TabletTester2025.Models;
using TabletTester2025.Services;
namespace TabletTester2025
{
public partial class HistoryWindow : Window
{
private readonly DatabaseService _dbService;
private List<TestBatch> _allData;
public HistoryWindow()
{
InitializeComponent();
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"]?.ConnectionString
?? "Data Source=TabletTests.db";
_dbService = new DatabaseService(connectionString);
LoadData();
}
private void LoadData()
{
// 获取所有数据默认前1000条
_allData = _dbService.GetBatches(null, 1000);
ApplyFilter();
}
private void ApplyFilter()
{
int? station = null;
if (StationFilter.SelectedIndex == 1) station = 1;
else if (StationFilter.SelectedIndex == 2) station = 2;
else if (StationFilter.SelectedIndex == 3) station = 3;
var filtered = _allData.AsEnumerable();
if (station.HasValue)
filtered = filtered.Where(b => b.StationId == station.Value);
HistoryGrid.ItemsSource = filtered.OrderByDescending(b => b.TestTime).ToList();
StatusText.Text = $"共 {filtered.Count()} 条记录";
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
ApplyFilter();
}
private void ExportButton_Click(object sender, RoutedEventArgs e)
{
var data = HistoryGrid.ItemsSource as IEnumerable<TestBatch>;
if (data == null || !data.Any())
{
MessageBox.Show("没有数据可导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
var excelService = new ExcelExportService();
string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
$"历史记录_{DateTime.Now:yyyyMMddHHmmss}.xlsx");
excelService.ExportToExcel(data, path);
MessageBox.Show($"导出成功: {path}", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}