This commit is contained in:
xyy
2026-03-02 18:50:30 +08:00
parent 63c81b48a1
commit b42ee7aa07
17 changed files with 663 additions and 5 deletions

View File

@@ -15,6 +15,9 @@ namespace MembranePoreTester
{
base.OnStartup(e);
using var db = new AppDbContext();
db.Database.EnsureCreated(); // 自动建表
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

21
Helpers/AppDbContext.cs Normal file
View File

@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
public DbSet<BubblePointEntity> BubblePointRecords { get; set; }
public DbSet<PoreDistributionEntity> PoreDistributionRecords { get; set; }
public DbSet<DataPointEntity> DataPoints { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite("Data Source=membrane_test.db");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PoreDistributionEntity>()
.HasMany(p => p.DataPoints)
.WithOne(d => d.PoreDistribution)
.HasForeignKey(d => d.PoreDistributionId)
.OnDelete(DeleteBehavior.Cascade);
}
}

54
Helpers/ExportHelper.cs Normal file
View File

@@ -0,0 +1,54 @@
using OfficeOpenXml;
using System.IO;
public static class ExportHelper
{
public static void ExportBubblePoint(BubblePointEntity entity, string filePath)
{
using var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("泡点法测试");
sheet.Cells["A1"].Value = "工位"; sheet.Cells["B1"].Value = entity.StationId;
sheet.Cells["A2"].Value = "测试日期"; sheet.Cells["B2"].Value = entity.TestDate.ToString("yyyy-MM-dd HH:mm:ss");
sheet.Cells["A3"].Value = "测试者"; sheet.Cells["B3"].Value = entity.Tester;
sheet.Cells["A4"].Value = "样品类型"; sheet.Cells["B4"].Value = entity.SampleType;
sheet.Cells["A5"].Value = "规格"; sheet.Cells["B5"].Value = entity.SampleSpec;
sheet.Cells["A6"].Value = "室温(°C)"; sheet.Cells["B6"].Value = entity.RoomTemperature;
sheet.Cells["A7"].Value = "浸润时间(h)"; sheet.Cells["B7"].Value = entity.SoakingTime;
sheet.Cells["A8"].Value = "测试液体"; sheet.Cells["B8"].Value = entity.LiquidName;
sheet.Cells["A9"].Value = "液体生产厂家"; sheet.Cells["B9"].Value = entity.LiquidManufacturer;
sheet.Cells["A10"].Value = "泡点压力"; sheet.Cells["B10"].Value = $"{entity.BubblePointPressure} {entity.PressureUnit}";
sheet.Cells["A11"].Value = "最大孔径(μm)"; sheet.Cells["B11"].Value = entity.MaxPoreSize;
package.SaveAs(new FileInfo(filePath));
}
public static void ExportPoreDistribution(PoreDistributionEntity entity, string filePath)
{
using var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("孔分布测试");
sheet.Cells["A1"].Value = "工位"; sheet.Cells["B1"].Value = entity.StationId;
sheet.Cells["A2"].Value = "测试日期"; sheet.Cells["B2"].Value = entity.TestDate.ToString("yyyy-MM-dd HH:mm:ss");
sheet.Cells["A3"].Value = "测试者"; sheet.Cells["B3"].Value = entity.Tester;
sheet.Cells["A4"].Value = "样品类型"; sheet.Cells["B4"].Value = entity.SampleType;
sheet.Cells["A5"].Value = "规格"; sheet.Cells["B5"].Value = entity.SampleSpec;
sheet.Cells["A6"].Value = "室温(°C)"; sheet.Cells["B6"].Value = entity.RoomTemperature;
sheet.Cells["A7"].Value = "浸润时间(h)"; sheet.Cells["B7"].Value = entity.SoakingTime;
sheet.Cells["A8"].Value = "测试液体"; sheet.Cells["B8"].Value = entity.LiquidName;
sheet.Cells["A9"].Value = "液体生产厂家"; sheet.Cells["B9"].Value = entity.LiquidManufacturer;
sheet.Cells["A10"].Value = "泡点压力"; sheet.Cells["B10"].Value = $"{entity.BubblePointPressure} {entity.PressureUnit}";
sheet.Cells["A11"].Value = "平均孔径(μm)"; sheet.Cells["B11"].Value = entity.AveragePoreSize;
// 数据点表格
sheet.Cells["A13"].Value = "压力"; sheet.Cells["B13"].Value = "湿膜流量(L/min)"; sheet.Cells["C13"].Value = "干膜流量(L/min)";
int row = 14;
foreach (var dp in entity.DataPoints)
{
sheet.Cells[$"A{row}"].Value = dp.Pressure;
sheet.Cells[$"B{row}"].Value = dp.WetFlow;
sheet.Cells[$"C{row}"].Value = dp.DryFlow;
row++;
}
package.SaveAs(new FileInfo(filePath));
}
}

57
Helpers/ITestRecord.cs Normal file
View File

@@ -0,0 +1,57 @@
public interface ITestRecord
{
int Id { get; set; }
int StationId { get; set; }
DateTime TestDate { get; set; }
string Tester { get; set; }
// 公共字段
}
public class BubblePointEntity : ITestRecord
{
public int Id { get; set; }
public int StationId { get; set; }
public DateTime TestDate { get; set; }
public string Tester { get; set; }
public string SampleType { get; set; }
public string SampleSpec { get; set; }
public double RoomTemperature { get; set; }
public double SoakingTime { get; set; }
public string LiquidName { get; set; }
public double LiquidSurfaceTension { get; set; }
public string LiquidManufacturer { get; set; }
public double BubblePointPressure { get; set; }
public string PressureUnit { get; set; }
public double MaxPoreSize { get; set; }
}
public class PoreDistributionEntity : ITestRecord
{
public int Id { get; set; }
public int StationId { get; set; }
public DateTime TestDate { get; set; }
public string Tester { get; set; }
public string SampleType { get; set; }
public string SampleSpec { get; set; }
public double RoomTemperature { get; set; }
public double SoakingTime { get; set; }
public string LiquidName { get; set; }
public double LiquidSurfaceTension { get; set; }
public string LiquidManufacturer { get; set; }
public string PressureUnit { get; set; }
public double BubblePointPressure { get; set; }
public double AveragePoreSize { get; set; }
// 导航属性:数据点
public List<DataPointEntity> DataPoints { get; set; }
}
public class DataPointEntity
{
public int Id { get; set; }
public int PoreDistributionId { get; set; }
public double Pressure { get; set; }
public double WetFlow { get; set; }
public double DryFlow { get; set; }
public PoreDistributionEntity PoreDistribution { get; set; }
}

View File

@@ -1,6 +1,7 @@
using MembranePoreTester.Communication;
using MembranePoreTester.Helpers;
using MembranePoreTester.Models;
using Microsoft.Win32;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
@@ -93,6 +94,8 @@ namespace MembranePoreTester.ViewModels
GenerateReportCommand = new RelayCommand(GenerateReport);
SelectedLiquid = Liquids[0];
ReadPlcCommand = new RelayCommand(async () => await ReadPlcAsync());
SaveCommand = new RelayCommand(SaveToDatabase);
ExportCommand = new RelayCommand(ExportToExcel);
}
@@ -123,5 +126,83 @@ namespace MembranePoreTester.ViewModels
{
ReportGenerator.GenerateBubblePointReport(Record);
}
private int _stationId;
public int StationId
{
get => _stationId;
set => SetProperty(ref _stationId, value);
}
// 保存当前记录到数据库
public void SaveToDatabase()
{
var entity = new BubblePointEntity
{
StationId = StationId,
TestDate = Record.TestDate,
Tester = Record.Tester,
SampleType = Record.SampleType,
SampleSpec = Record.SampleSpec,
RoomTemperature = Record.RoomTemperature,
SoakingTime = Record.SoakingTime,
LiquidName = Record.Liquid?.Name,
LiquidSurfaceTension = Record.Liquid?.SurfaceTension ?? 0,
LiquidManufacturer = Record.LiquidManufacturer,
BubblePointPressure = Record.BubblePointPressure,
PressureUnit = Record.PressureUnit,
MaxPoreSize = Record.MaxPoreSize
};
using var db = new AppDbContext();
db.BubblePointRecords.Add(entity);
db.SaveChanges();
}
public void LoadFromDatabase(int recordId)
{
using var db = new AppDbContext();
var entity = db.BubblePointRecords.Find(recordId);
if (entity == null) return;
Record.SampleType = entity.SampleType;
Record.SampleSpec = entity.SampleSpec;
Record.RoomTemperature = entity.RoomTemperature;
Record.SoakingTime = entity.SoakingTime;
Record.Liquid = TestLiquid.Predefined.FirstOrDefault(l => l.Name == entity.LiquidName)
?? new TestLiquid { Name = entity.LiquidName, SurfaceTension = entity.LiquidSurfaceTension };
Record.LiquidManufacturer = entity.LiquidManufacturer;
Record.BubblePointPressure = entity.BubblePointPressure;
Record.PressureUnit = entity.PressureUnit;
Record.TestDate = entity.TestDate;
Record.Tester = entity.Tester;
OnPropertyChanged(nameof(Record));
OnPropertyChanged(nameof(MaxPoreSize)); // 触发界面更新
}
public ICommand SaveCommand { get; }
public ICommand ExportCommand { get; }
private void ExportToExcel()
{
var saveFileDialog = new SaveFileDialog
{
Filter = "Excel文件|*.xlsx",
FileName = $"泡点法_工位{StationId}_{DateTime.Now:yyyyMMddHHmmss}.xlsx"
};
if (saveFileDialog.ShowDialog() == true)
{
// 转换为Entity后导出
var entity = new BubblePointEntity { /* 从Record复制 */ };
ExportHelper.ExportBubblePoint(entity, saveFileDialog.FileName);
MessageBox.Show("导出成功");
}
}
}
}

View File

@@ -0,0 +1,6 @@
public interface IStationViewModel
{
int StationId { get; set; }
void SaveToDatabase();
void LoadFromDatabase(int recordId); // 加载指定记录
}

View File

@@ -0,0 +1,29 @@
using System.Collections.ObjectModel;
namespace MembranePoreTester.ViewModels
{
public class MainViewModel : ViewModelBase
{
public ObservableCollection<StationItem> Stations { get; } = new();
public MainViewModel()
{
for (int i = 1; i <= 3; i++)
{
Stations.Add(new StationItem
{
Name = $"工位 {i}",
BubblePointVM = new BubblePointViewModel { StationId = i },
PoreDistributionVM = new PoreDistributionViewModel { StationId = i }
});
}
}
}
public class StationItem
{
public string Name { get; set; }
public BubblePointViewModel BubblePointVM { get; set; }
public PoreDistributionViewModel PoreDistributionVM { get; set; }
}
}

View File

@@ -1,6 +1,8 @@
using MembranePoreTester.Communication;
using MembranePoreTester.Helpers;
using MembranePoreTester.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Win32;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@@ -9,7 +11,7 @@ using System.Windows.Input;
namespace MembranePoreTester.ViewModels
{
public class PoreDistributionViewModel : ViewModelBase
public class PoreDistributionViewModel : ViewModelBase, IStationViewModel
{
private PoreDistributionRecord _record = new();
private TestLiquid _selectedLiquid;
@@ -118,6 +120,8 @@ namespace MembranePoreTester.ViewModels
Record.PressureUnit = PressureUnits[0]; // 默认 "Pa"
ReadPlcCommand = new RelayCommand(async () => await ReadPlcAsync());
SaveCommand = new RelayCommand(SaveToDatabase);
ExportCommand = new RelayCommand(ExportToExcel);
}
@@ -203,5 +207,107 @@ namespace MembranePoreTester.ViewModels
{
ReportGenerator.GeneratePoreDistributionReport(Record);
}
private int _stationId;
public int StationId
{
get => _stationId;
set => SetProperty(ref _stationId, value);
}
public void SaveToDatabase()
{
var entity = new PoreDistributionEntity
{
StationId = this.StationId,
TestDate = Record.TestDate,
Tester = Record.Tester,
SampleType = Record.SampleType,
SampleSpec = Record.SampleSpec,
RoomTemperature = Record.RoomTemperature,
SoakingTime = Record.SoakingTime,
LiquidName = Record.Liquid?.Name,
LiquidSurfaceTension = Record.Liquid?.SurfaceTension ?? 0,
LiquidManufacturer = Record.LiquidManufacturer,
PressureUnit = Record.PressureUnit,
BubblePointPressure = Record.BubblePointPressure,
AveragePoreSize = AveragePoreSize, // 使用计算后的属性
DataPoints = Record.DataPoints.Select(dp => new DataPointEntity
{
Pressure = dp.Pressure,
WetFlow = dp.WetFlow,
DryFlow = dp.DryFlow
}).ToList()
};
using var db = new AppDbContext();
db.PoreDistributionRecords.Add(entity);
db.SaveChanges();
MessageBox.Show("保存成功!", "提示");
}
public void LoadFromDatabase(int recordId)
{
using var db = new AppDbContext();
var entity = db.PoreDistributionRecords
.Include(p => p.DataPoints)
.FirstOrDefault(p => p.Id == recordId);
if (entity == null) return;
Record.SampleType = entity.SampleType;
Record.SampleSpec = entity.SampleSpec;
Record.RoomTemperature = entity.RoomTemperature;
Record.SoakingTime = entity.SoakingTime;
Record.Liquid = TestLiquid.Predefined.FirstOrDefault(l => l.Name == entity.LiquidName)
?? new TestLiquid { Name = entity.LiquidName, SurfaceTension = entity.LiquidSurfaceTension };
Record.LiquidManufacturer = entity.LiquidManufacturer;
Record.PressureUnit = entity.PressureUnit;
Record.BubblePointPressure = entity.BubblePointPressure;
Record.TestDate = entity.TestDate;
Record.Tester = entity.Tester;
Record.DataPoints.Clear();
foreach (var dp in entity.DataPoints)
{
Record.DataPoints.Add(new DataPoint
{
Pressure = dp.Pressure,
WetFlow = dp.WetFlow,
DryFlow = dp.DryFlow
});
}
// 重新计算平均孔径和分布(触发计算命令)
Calculate();
}
public ICommand SaveCommand { get; }
public ICommand ExportCommand { get; }
private void ExportToExcel()
{
var saveFileDialog = new SaveFileDialog
{
Filter = "Excel文件|*.xlsx",
FileName = $"泡点法_工位{StationId}_{DateTime.Now:yyyyMMddHHmmss}.xlsx"
};
if (saveFileDialog.ShowDialog() == true)
{
// 转换为Entity后导出
var entity = new BubblePointEntity { /* 从Record复制 */ };
ExportHelper.ExportBubblePoint(entity, saveFileDialog.FileName);
MessageBox.Show("导出成功");
}
}
}
}

View File

@@ -78,7 +78,11 @@
<!-- 底部按钮 -->
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="保存到历史" Command="{Binding SaveCommand}" Padding="15,8" Margin="5"/>
<Button Content="生成报告" Command="{Binding GenerateReportCommand}" Padding="15,8" Margin="5"/>
<Button Content="导出Excel" Command="{Binding ExportCommand}" Padding="15,8" Margin="5"/>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -7,7 +7,7 @@ namespace MembranePoreTester.Views
public BubblePointView()
{
InitializeComponent();
DataContext = new ViewModels.BubblePointViewModel();
//DataContext = new ViewModels.BubblePointViewModel();
}
}
}

57
Views/HistoryWindow.xaml Normal file
View File

@@ -0,0 +1,57 @@
<Window x:Class="MembranePoreTester.Views.HistoryWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="历史记录" Height="600" Width="900"
WindowStartupLocation="CenterOwner">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 过滤条件 -->
<StackPanel Orientation="Horizontal" Grid.Row="0" Margin="0,0,0,10">
<Label Content="工位:"/>
<ComboBox x:Name="cmbStation" SelectedIndex="0" Width="80" Margin="5,0">
<ComboBoxItem Content="全部"/>
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="3"/>
</ComboBox>
<Label Content="测试类型:"/>
<ComboBox x:Name="cmbType" SelectedIndex="0" Width="120" Margin="5,0">
<ComboBoxItem Content="全部"/>
<ComboBoxItem Content="泡点法"/>
<ComboBoxItem Content="孔分布"/>
</ComboBox>
<Label Content="日期范围:"/>
<DatePicker x:Name="dpStart" Width="120"/>
<Label Content="-" Margin="2"/>
<DatePicker x:Name="dpEnd" Width="120"/>
<Button Content="查询" Click="Query_Click" Padding="15,5" Margin="10,0"/>
<Button Content="导出选中" Click="ExportSelected_Click" Padding="15,5"/>
</StackPanel>
<!-- 历史记录列表 -->
<DataGrid x:Name="dgHistory" Grid.Row="1" AutoGenerateColumns="False"
IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Id}" Width="50"/>
<DataGridTextColumn Header="工位" Binding="{Binding StationId}" Width="50"/>
<DataGridTextColumn Header="类型" Binding="{Binding Type}" Width="80"/>
<DataGridTextColumn Header="测试日期" Binding="{Binding TestDate}" Width="150"/>
<DataGridTextColumn Header="样品类型" Binding="{Binding SampleType}" Width="100"/>
<DataGridTextColumn Header="规格" Binding="{Binding SampleSpec}" Width="100"/>
<DataGridTextColumn Header="测试者" Binding="{Binding Tester}" Width="100"/>
<DataGridTextColumn Header="结果" Binding="{Binding Result}" Width="150"/>
</DataGrid.Columns>
</DataGrid>
<!-- 底部按钮 -->
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<Button Content="加载到当前工位" Click="LoadToCurrentStation_Click" Padding="15,5" Margin="5"/>
<Button Content="关闭" Click="Close_Click" Padding="15,5"/>
</StackPanel>
</Grid>
</Window>

156
Views/HistoryWindow.xaml.cs Normal file
View File

@@ -0,0 +1,156 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MembranePoreTester.Views
{
public partial class HistoryWindow : Window
{
public int? SelectedStation { get; set; } // 传入当前工位ID
public HistoryWindow()
{
InitializeComponent();
}
private void Query_Click(object sender, RoutedEventArgs e)
{
using var db = new AppDbContext();
var query = new List<object>();
// 获取泡点法记录
var bubblePoints = db.BubblePointRecords
.Select(b => new
{
b.Id,
b.StationId,
Type = "泡点法",
b.TestDate,
b.SampleType,
b.SampleSpec,
b.Tester,
Result = $"最大孔径: {b.MaxPoreSize:F3} μm"
});
query.AddRange(bubblePoints);
// 获取孔分布记录
var poreDistributions = db.PoreDistributionRecords
.Select(p => new
{
p.Id,
p.StationId,
Type = "孔分布",
p.TestDate,
p.SampleType,
p.SampleSpec,
p.Tester,
Result = $"平均孔径: {p.AveragePoreSize:F3} μm"
});
query.AddRange(poreDistributions);
// 过滤工位
if (cmbStation.SelectedIndex > 0)
{
int station = cmbStation.SelectedIndex;
query = query.Where(x => ((dynamic)x).StationId == station).ToList();
}
// 过滤类型
if (cmbType.SelectedIndex == 1)
query = query.Where(x => ((dynamic)x).Type == "泡点法").ToList();
else if (cmbType.SelectedIndex == 2)
query = query.Where(x => ((dynamic)x).Type == "孔分布").ToList();
// 过滤日期范围
if (dpStart.SelectedDate != null)
query = query.Where(x => ((dynamic)x).TestDate >= dpStart.SelectedDate).ToList();
if (dpEnd.SelectedDate != null)
query = query.Where(x => ((dynamic)x).TestDate <= dpEnd.SelectedDate.Value.AddDays(1)).ToList();
dgHistory.ItemsSource = query.OrderByDescending(x => ((dynamic)x).TestDate).ToList();
}
private void ExportSelected_Click(object sender, RoutedEventArgs e)
{
if (dgHistory.SelectedItem == null)
{
MessageBox.Show("请先选中一条记录");
return;
}
dynamic selected = dgHistory.SelectedItem;
int id = selected.Id;
string type = selected.Type;
var saveFileDialog = new SaveFileDialog
{
Filter = "Excel文件|*.xlsx",
FileName = $"{type}_{id}.xlsx"
};
if (saveFileDialog.ShowDialog() == true)
{
if (type == "泡点法")
{
using var db = new AppDbContext();
var entity = db.BubblePointRecords.Find(id);
if (entity != null)
{
ExportHelper.ExportBubblePoint(entity, saveFileDialog.FileName);
}
}
else
{
using var db = new AppDbContext();
var entity = db.PoreDistributionRecords
.Include(p => p.DataPoints)
.FirstOrDefault(p => p.Id == id);
if (entity != null)
{
ExportHelper.ExportPoreDistribution(entity, saveFileDialog.FileName);
}
}
}
}
private void LoadToCurrentStation_Click(object sender, RoutedEventArgs e)
{
if (dgHistory.SelectedItem == null) return;
if (SelectedStation == null)
{
MessageBox.Show("未指定当前工位");
return;
}
dynamic selected = dgHistory.SelectedItem;
int id = selected.Id;
string type = selected.Type;
// 通过事件或回调将记录加载到当前工位
// 这里需要与主窗口交互,简单起见,我们使用静态事件
LoadRecordEvent?.Invoke(this, new LoadRecordEventArgs
{
RecordId = id,
Type = type,
TargetStation = SelectedStation.Value
});
DialogResult = true;
Close();
}
private void Close_Click(object sender, RoutedEventArgs e) => Close();
public static event EventHandler<LoadRecordEventArgs> LoadRecordEvent;
}
public class LoadRecordEventArgs : EventArgs
{
public int RecordId { get; set; }
public string Type { get; set; }
public int TargetStation { get; set; }
}
}

View File

@@ -1,4 +1,48 @@
<Window x:Class="MembranePoreTester.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MembranePoreTester.Views"
xmlns:viewModels="clr-namespace:MembranePoreTester.ViewModels"
Title="膜孔径测试系统 (GB/T 32361-2015)"
Width="1024" Height="768"
WindowStartupLocation="CenterScreen">
<Window.DataContext>
<viewModels:MainViewModel />
</Window.DataContext>
<DockPanel LastChildFill="True">
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="5">
<Button Content="历史记录" Click="OpenHistory_Click" Padding="10,5" Margin="5"/>
</StackPanel>
<TabControl ItemsSource="{Binding Stations}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<!-- 每个工位内部再嵌套一个TabControl切换测试类型 -->
<TabControl>
<TabItem Header="泡点法测试最大孔径">
<local:BubblePointView DataContext="{Binding BubblePointVM}"/>
</TabItem>
<TabItem Header="孔分布测试">
<local:PoreDistributionView DataContext="{Binding PoreDistributionVM}"/>
</TabItem>
</TabControl>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</DockPanel>
</Window>
<!--<Window x:Class="MembranePoreTester.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MembranePoreTester.Views"
@@ -14,4 +58,8 @@
<local:PoreDistributionView/>
</TabItem>
</TabControl>
</Window>
</Window>-->

View File

@@ -1,4 +1,5 @@
using System.Windows;
using MembranePoreTester.ViewModels;
using System.Windows;
namespace MembranePoreTester.Views
{
@@ -7,6 +8,37 @@ namespace MembranePoreTester.Views
public MainWindow()
{
InitializeComponent();
HistoryWindow.LoadRecordEvent += OnLoadRecord;
}
private void OnLoadRecord(object sender, LoadRecordEventArgs e)
{
var mainVM = DataContext as MainViewModel;
if (mainVM == null) return;
// 根据工位和类型找到对应的 ViewModel
if (e.Type == "泡点法")
{
var targetVM = mainVM.Stations[e.TargetStation - 1].BubblePointVM;
targetVM.LoadFromDatabase(e.RecordId);
}
else
{
var targetVM = mainVM.Stations[e.TargetStation - 1].PoreDistributionVM;
targetVM.LoadFromDatabase(e.RecordId);
}
}
private void OpenHistory_Click(object sender, RoutedEventArgs e)
{
var mainVM = DataContext as MainViewModel;
if (mainVM == null) return;
// 获取当前选中的工位(可选)
int currentStation = 1; // 可获取当前Tab索引+1
var historyWin = new HistoryWindow { SelectedStation = currentStation };
historyWin.ShowDialog();
}
}
}

View File

@@ -117,6 +117,8 @@
</StackPanel>
</GroupBox>
<Button Content="生成报告" Command="{Binding GenerateReportCommand}" Padding="15,8" Margin="5"/>
<Button Content="保存到历史" Command="{Binding SaveCommand}" Padding="15,8" Margin="5"/>
<Button Content="导出Excel" Command="{Binding ExportCommand}" Padding="15,8" Margin="5"/>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -7,7 +7,7 @@ namespace MembranePoreTester.Views
public PoreDistributionView()
{
InitializeComponent();
DataContext = new ViewModels.PoreDistributionViewModel();
//DataContext = new ViewModels.PoreDistributionViewModel();
}
}
}

View File

@@ -10,6 +10,8 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="EPPlus" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.3" />