using Dapper; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 材料热传导系数 { public class ConductivityTestData { public int Id { get; set; } /// /// 条码(保留用于兼容性) /// public string barcode { get; set; } /// /// 联络单号 /// public string ContactNumber { get; set; } /// /// 件号 /// public string ItemNumber { get; set; } /// /// 温度 /// public double temperature { get; set; } /// /// 初始压力 /// public double startpressure { get; set; } /// /// 保压时间 /// public double dwelltime { get; set; } /// /// 压差 /// public double diffpressure { get; set; } /// /// 结束压力 /// public double endpressure { get; set; } public DateTime CreateTime { get; set; } /// /// 普通0高温1 /// public int Type { get; set; } } public class ScanData { public int Id { get; set; } /// /// 条码(保留用于兼容性) /// public string barcode { get; set; } /// /// 联络单号 /// public string ContactNumber { get; set; } /// /// 件号 /// public string ItemNumber { get; set; } /// /// 压力 /// public float diffpressure { get; set; } /// /// 出口温度 /// public float exit_temperature { get; set; } /// /// 温度 /// public float temperature { get; set; } /// /// 保压时间 /// public float dwelltime { get; set; } public DateTime CreateTime { get; set; } /// ///高温模式 1是0否 /// public bool IsHighMode { get; set; } /// ///模式选择 /// public string TemperatureMode { get; set; } } public class ConductivityRepository { public readonly string _connectionString; public ConductivityRepository() { _connectionString = "Server=localhost;Database=fullautowaterpressure;User=root;Password=123456;port=3306;charset=utf8;"; } public void InsertReportItems(ConductivityTestData data) { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); var sql = @"INSERT INTO normaltemperature (barcode, ContactNumber, ItemNumber, temperature, startpressure, dwelltime, diffpressure, endpressure, CreateTime, type) VALUES (@barcode, @ContactNumber, @ItemNumber, @temperature, @startpressure, @dwelltime, @diffpressure, @endpressure, CURRENT_TIMESTAMP, @type)"; connection.Execute(sql, data); } } public void InsertScanItems(ScanData data) { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); var sql = @"INSERT INTO scandata (barcode, ContactNumber, ItemNumber, diffpressure, exit_temperature, temperature, dwelltime, CreateTime, TemperatureMode) VALUES (@barcode, @ContactNumber, @ItemNumber, @diffpressure, @exit_temperature, @temperature, @dwelltime, CURRENT_TIMESTAMP, @TemperatureMode)"; connection.Execute(sql, data); } } public void DeleteScanItems(int id) { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); var sql = @"delete from scandata where id=@id "; connection.Execute(sql, new { id }); } } public List GetScanData() { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); var sql = @"SELECT * FROM scandata ORDER BY id asc "; return connection.Query(sql).ToList(); } } public bool TestConnection() { try { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); return connection.State == ConnectionState.Open; } } catch { return false; } } } }