添加项目文件。
This commit is contained in:
121
全自动水压检测仪/DATA/ConductividyClass.cs
Normal file
121
全自动水压检测仪/DATA/ConductividyClass.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Dapper;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 材料热传导系数
|
||||
{
|
||||
public class ConductivityTestData
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// </summary>
|
||||
public string barcode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// </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; }
|
||||
}
|
||||
|
||||
|
||||
public class ConductivityRepository
|
||||
{
|
||||
private 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, temperature, startpressure, dwelltime,
|
||||
diffpressure, endpressure, CreateTime, type)
|
||||
VALUES
|
||||
(@barcode, @temperature, @startpressure, @dwelltime, @diffpressure,@endpressure,CURRENT_TIMESTAMP,@type)";
|
||||
connection.Execute(sql, data);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertTestDataList(List<ConductivityTestData> dataList)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"INSERT INTO normaltemperature
|
||||
(barcode, temperature, startpressure, dwelltime,
|
||||
diffpressure, endpressure, CreateTime, type)
|
||||
VALUES
|
||||
(@barcode, @temperature, @startpressure, @dwelltime, @diffpressure,@endpressure,CURRENT_TIMESTAMP,@type)";
|
||||
connection.Execute(sql, dataList);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ConductivityTestData> GetTestData(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"SELECT * FROM normaltemperature
|
||||
WHERE TestStartTime BETWEEN @StartDate AND @EndDate
|
||||
ORDER BY CreateTime DESC";
|
||||
return connection.Query<ConductivityTestData>(sql, new { StartDate = startDate, EndDate = endDate }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool TestConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
return connection.State == ConnectionState.Open;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user