Files
2026-02-27 16:03:49 +08:00

60 lines
2.5 KiB
C#

using MembranePoreTester.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace MembranePoreTester.Report
{
public class Report
{
public static void GenerateBubblePointReport(BubblePointRecord record)
{
FlowDocument doc = new FlowDocument();
doc.PageWidth = 800; // 适应打印
Section header = new Section();
header.Blocks.Add(new Paragraph(new Run("泡点法测试报告"))
{ FontSize = 24, FontWeight = FontWeights.Bold, TextAlignment = TextAlignment.Center });
header.Blocks.Add(new Paragraph(new Run($"测试日期: {record.TestDate:yyyy-MM-dd} 测试者: {record.Tester}"))
{ TextAlignment = TextAlignment.Right });
// 样品信息表格
Table table = new Table();
table.Columns.Add(new TableColumn { Width = new GridLength(150) });
table.Columns.Add(new TableColumn { Width = new GridLength(200) });
table.RowGroups.Add(new TableRowGroup());
AddRow(table, "膜类型", record.SampleType);
AddRow(table, "规格", record.SampleSpec);
AddRow(table, "室温(°C)", record.RoomTemperature.ToString("F1"));
AddRow(table, "浸润时间(h)", record.SoakingTime.ToString("F1"));
AddRow(table, "测试液体", record.Liquid?.Name);
AddRow(table, "液体生产厂家", record.LiquidManufacturer);
AddRow(table, "泡点压力", $"{record.BubblePointPressure} {record.PressureUnit}");
AddRow(table, "最大孔径(μm)", record.MaxPoreSize.ToString("F3"));
doc.Blocks.Add(table);
doc.Blocks.Add(new Paragraph(new Run("本报告依据GB/T 32361-2015生成。")) { FontStyle = FontStyles.Italic });
// 打印预览
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
IDocumentPaginatorSource dps = doc;
printDialog.PrintDocument(dps.DocumentPaginator, "泡点法测试报告");
}
}
private static void AddRow(Table table, string label, string value)
{
TableRow row = new TableRow();
row.Cells.Add(new TableCell(new Paragraph(new Run(label))));
row.Cells.Add(new TableCell(new Paragraph(new Run(value ?? ""))));
table.RowGroups[0].Rows.Add(row);
}
}
}