This commit is contained in:
21
Helpers/AppDbContext.cs
Normal file
21
Helpers/AppDbContext.cs
Normal 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
54
Helpers/ExportHelper.cs
Normal 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
57
Helpers/ITestRecord.cs
Normal 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; }
|
||||
}
|
||||
Reference in New Issue
Block a user