using SQLite; using System; using System.IO; namespace 口罩泄露定制款 { public class SQLiteHelper { private readonly SQLiteConnection _db; public SQLiteHelper() { string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data.db"); _db = new SQLiteConnection(dbPath); // 自动创建表(不存在时创建) _db.CreateTable(); } // 插入数据的方法,直接传模型对象 public void InsertExperimentData(Experiment data) { try { _db.Insert(data); } catch (Exception ex) { // 捕获异常,方便调试 throw new InvalidOperationException("插入数据失败: " + ex.Message, ex); } } } } // 对应 Experiments 表,字段和表结构完全一致 public class Experiment { [PrimaryKey, AutoIncrement] public int Id { get; set; } public string Name { get; set; } public string Sex { get; set; } public int? Age { get; set; } // 可空类型 public string IdNumber { get; set; } public string Company { get; set; } public int? CompanyAge { get; set; } // 可空类型 public string Date { get; set; } public string Time { get; set; } public string ExperName { get; set; } //public string ExperNum { get; set; } public string ExperType { get; set; } public string MaskType { get; set; } public string TestStatus { get; set; } public float HuanJingWenDu { get; set; } public float HuanJingShiDu { get; set; } public float BenDiNongDu { get; set; } public float TsiIndoorAgv { get; set; } public float TsiOutdoorAgv { get; set; } public float Xieloulv { get; set; } public float SamplingFlowRate { get; set; } // 采样流量(L/min) public float DryingFlowRate { get; set; } // 干燥气流(L/min) // 测试时长 public int TestDuration { get; set; } // 测试时长(秒) }