Files
FullAutoWaterCheck/全自动水压检测仪/DATA/ConductividyClass.cs

202 lines
5.3 KiB
C#
Raw Normal View History

2026-01-07 13:42:17 +08:00
using Dapper;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
2026-01-26 15:41:42 +08:00
using System.Data.SqlClient;
2026-01-07 13:42:17 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
public class ConductivityTestData
{
public int Id { get; set; }
/// <summary>
2026-02-04 09:58:56 +08:00
/// 条码(保留用于兼容性)
2026-01-07 13:42:17 +08:00
/// </summary>
public string barcode { get; set; }
/// <summary>
2026-02-04 09:58:56 +08:00
/// 联络单号
/// </summary>
public string ContactNumber { get; set; }
/// <summary>
/// 件号
/// </summary>
public string ItemNumber { get; set; }
/// <summary>
/// 温度
2026-01-07 13:42:17 +08:00
/// </summary>
public double temperature { get; set; }
/// <summary>
/// 初始压力
/// </summary>
public double startpressure { get; set; }
/// <summary>
/// 保压时间
/// </summary>
public double dwelltime { get; set; }
/// <summary>
/// 压差
/// </summary>
public double diffpressure { get; set; }
/// <summary>
/// 结束压力
/// </summary>
public double endpressure { get; set; }
public DateTime CreateTime { get; set; }
/// <summary>
/// 普通0高温1
/// </summary>
public int Type { get; set; }
}
2026-01-24 13:49:39 +08:00
public class ScanData
{
public int Id { get; set; }
/// <summary>
2026-02-04 09:46:06 +08:00
/// 条码(保留用于兼容性)
2026-01-24 13:49:39 +08:00
/// </summary>
public string barcode { get; set; }
2026-02-04 09:46:06 +08:00
/// <summary>
/// 联络单号
/// </summary>
public string ContactNumber { get; set; }
/// <summary>
/// 件号
/// </summary>
public string ItemNumber { get; set; }
2026-01-24 13:49:39 +08:00
/// <summary>
/// 压力
/// </summary>
2026-01-24 16:55:48 +08:00
public float diffpressure { get; set; }
2026-01-24 13:49:39 +08:00
2026-01-24 14:20:24 +08:00
/// <summary>
/// 出口温度
/// </summary>
2026-01-24 16:55:48 +08:00
public float exit_temperature { get; set; }
2026-01-24 14:20:24 +08:00
2026-01-24 13:49:39 +08:00
/// <summary>
/// 温度
/// </summary>
2026-01-24 16:55:48 +08:00
public float temperature { get; set; }
2026-01-24 13:49:39 +08:00
/// <summary>
/// 保压时间
/// </summary>
2026-01-24 16:55:48 +08:00
public float dwelltime { get; set; }
2026-01-24 13:49:39 +08:00
public DateTime CreateTime { get; set; }
2026-01-24 13:59:21 +08:00
/// <summary>
///高温模式 1是0否
/// </summary>
public bool IsHighMode { get; set; }
2026-01-24 13:49:39 +08:00
2026-01-26 15:41:42 +08:00
/// <summary>
///模式选择
/// </summary>
public string TemperatureMode { get; set; }
2026-01-24 13:49:39 +08:00
}
2026-01-07 13:42:17 +08:00
public class ConductivityRepository
{
2026-01-26 15:41:42 +08:00
2026-01-24 16:55:48 +08:00
public readonly string _connectionString;
2026-01-07 13:42:17 +08:00
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
2026-02-04 09:58:56 +08:00
(barcode, ContactNumber, ItemNumber, temperature, startpressure, dwelltime,
2026-01-07 13:42:17 +08:00
diffpressure, endpressure, CreateTime, type)
VALUES
2026-02-04 09:58:56 +08:00
(@barcode, @ContactNumber, @ItemNumber, @temperature, @startpressure, @dwelltime, @diffpressure, @endpressure, CURRENT_TIMESTAMP, @type)";
2026-01-07 13:42:17 +08:00
connection.Execute(sql, data);
}
}
2026-01-24 13:49:39 +08:00
public void InsertScanItems(ScanData data)
2026-01-07 13:42:17 +08:00
{
using (var connection = new MySqlConnection(_connectionString))
{
connection.Open();
2026-01-24 13:49:39 +08:00
var sql = @"INSERT INTO scandata
2026-02-04 09:46:06 +08:00
(barcode, ContactNumber, ItemNumber, diffpressure, exit_temperature, temperature, dwelltime, CreateTime, TemperatureMode)
2026-01-07 13:42:17 +08:00
VALUES
2026-02-04 09:46:06 +08:00
(@barcode, @ContactNumber, @ItemNumber, @diffpressure, @exit_temperature, @temperature, @dwelltime, CURRENT_TIMESTAMP, @TemperatureMode)";
2026-01-24 13:49:39 +08:00
connection.Execute(sql, data);
2026-01-07 13:42:17 +08:00
}
}
2026-01-26 15:57:13 +08:00
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 });
}
}
2026-01-24 13:49:39 +08:00
public List<ScanData> GetScanData()
2026-01-07 13:42:17 +08:00
{
using (var connection = new MySqlConnection(_connectionString))
{
connection.Open();
2026-01-24 13:49:39 +08:00
var sql = @"SELECT * FROM scandata
2026-01-26 15:57:13 +08:00
ORDER BY id asc ";
2026-01-24 13:49:39 +08:00
return connection.Query<ScanData>(sql).ToList();
2026-01-07 13:42:17 +08:00
}
}
public bool TestConnection()
{
try
{
using (var connection = new MySqlConnection(_connectionString))
{
connection.Open();
return connection.State == ConnectionState.Open;
}
}
catch
{
return false;
}
}
}
}