This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using TabletTester2025.Models;
|
||||
using TabletTester2025.Services;
|
||||
|
||||
@@ -15,16 +16,14 @@ namespace TabletTester2025
|
||||
public HistoryWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"]?.ConnectionString
|
||||
?? "Data Source=TabletTests.db";
|
||||
var connectionString = "Data Source=TabletTests.db";
|
||||
_dbService = new DatabaseService(connectionString);
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
// 获取所有数据(默认前1000条)
|
||||
_allData = _dbService.GetBatches(null, 1000);
|
||||
_allData = _dbService.GetBatches(null, 10000);
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
@@ -39,29 +38,79 @@ namespace TabletTester2025
|
||||
if (station.HasValue)
|
||||
filtered = filtered.Where(b => b.StationId == station.Value);
|
||||
|
||||
HistoryGrid.ItemsSource = filtered.OrderByDescending(b => b.TestTime).ToList();
|
||||
StatusText.Text = $"共 {filtered.Count()} 条记录";
|
||||
// 为每个标签页绑定对应测试类型的数据
|
||||
HardnessGrid.ItemsSource = filtered.Where(b => b.TestType == "硬度").OrderByDescending(b => b.TestTime).ToList();
|
||||
FriabilityGrid.ItemsSource = filtered.Where(b => b.TestType == "脆碎度").OrderByDescending(b => b.TestTime).ToList();
|
||||
DisintegrationGrid.ItemsSource = filtered.Where(b => b.TestType == "崩解").OrderByDescending(b => b.TestTime).ToList();
|
||||
DissolutionGrid.ItemsSource = filtered.Where(b => b.TestType == "溶出").OrderByDescending(b => b.TestTime).ToList();
|
||||
}
|
||||
|
||||
private void SearchButton_Click(object sender, RoutedEventArgs e)
|
||||
private void RefreshButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ApplyFilter();
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ExportButton_Click(object sender, RoutedEventArgs e)
|
||||
private void ExportHardness_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var data = HistoryGrid.ItemsSource as IEnumerable<TestBatch>;
|
||||
var data = HardnessGrid.ItemsSource as IEnumerable<TestBatch>;
|
||||
if (data == null || !data.Any())
|
||||
{
|
||||
MessageBox.Show("没有数据可导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
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);
|
||||
$"硬度报表_{DateTime.Now:yyyyMMddHHmmss}.xlsx");
|
||||
excelService.ExportHardnessToExcel(data, path);
|
||||
MessageBox.Show($"导出成功: {path}", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
|
||||
private void ExportFriability_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var data = FriabilityGrid.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.ExportFriabilityToExcel(data, path);
|
||||
MessageBox.Show($"导出成功: {path}", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
private void ExportDisintegration_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
var data = DisintegrationGrid.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.ExportDisintegrationToExcel(data, path);
|
||||
MessageBox.Show($"导出成功: {path}", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
private void ExportDissolution_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var data = DissolutionGrid.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.ExportDissolutionToExcel(data, path);
|
||||
MessageBox.Show($"导出成功: {path}", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user