This commit is contained in:
@@ -15,6 +15,8 @@ namespace 材料热传导系数
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int row { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码(保留用于兼容性)
|
||||
/// </summary>
|
||||
@@ -266,15 +268,73 @@ standarderror)
|
||||
}
|
||||
}
|
||||
|
||||
public List<ScanData> GetScanDataBylldh_jh(string lldh, string jh)
|
||||
public List<ScanData> GetScanDataBylldh_jh(string jh)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"SELECT * FROM scandata
|
||||
where lldh=@lldh and jh = @jh
|
||||
where jh = @jh
|
||||
ORDER BY id asc ";
|
||||
return connection.Query<ScanData>(sql, new { @lldh, jh }).ToList();
|
||||
return connection.Query<ScanData>(sql, new { jh }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新扫描数据
|
||||
/// </summary>
|
||||
/// <param name="scanData">要更新的扫描数据</param>
|
||||
public void UpdateScanItem(ScanData scanData)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"UPDATE scandata SET
|
||||
barcode = @barcode,
|
||||
diffpressure = @diffpressure,
|
||||
exit_temperature = @exit_temperature,
|
||||
temperature = @temperature,
|
||||
dwelltime = @dwelltime,
|
||||
TemperatureMode = @TemperatureMode,
|
||||
kzh = @kzh,
|
||||
lldh = @lldh,
|
||||
jh = @jh,
|
||||
quantity = @quantity,
|
||||
pressuresetting = @pressuresetting,
|
||||
standarderror = @standarderror
|
||||
WHERE id = @Id";
|
||||
|
||||
connection.Execute(sql, new
|
||||
{
|
||||
scanData.barcode,
|
||||
scanData.diffpressure,
|
||||
scanData.exit_temperature,
|
||||
scanData.temperature,
|
||||
scanData.dwelltime,
|
||||
scanData.TemperatureMode,
|
||||
scanData.kzh,
|
||||
scanData.lldh,
|
||||
scanData.jh,
|
||||
scanData.quantity,
|
||||
scanData.pressuresetting,
|
||||
scanData.standarderror,
|
||||
scanData.Id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取扫描数据
|
||||
/// </summary>
|
||||
/// <param name="id">数据ID</param>
|
||||
/// <returns>扫描数据对象</returns>
|
||||
public ScanData GetScanDataById(int id)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"SELECT * FROM scandata WHERE id = @id";
|
||||
return connection.QueryFirstOrDefault<ScanData>(sql, new { id });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,5 +353,53 @@ standarderror)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取测试数据
|
||||
/// </summary>
|
||||
public ConductivityTestData GetTestDataById(int id)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"SELECT * FROM normaltemperature WHERE id = @id";
|
||||
return connection.QueryFirstOrDefault<ConductivityTestData>(sql, new { id });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新测试数据
|
||||
/// </summary>
|
||||
public void UpdateTestData(ConductivityTestData testData)
|
||||
{
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"UPDATE normaltemperature SET
|
||||
barcode = @barcode,
|
||||
temperature = @temperature,
|
||||
startpressure = @startpressure,
|
||||
dwelltime = @dwelltime,
|
||||
diffpressure = @diffpressure,
|
||||
endpressure = @endpressure,
|
||||
type = @type,
|
||||
kzh = @kzh,
|
||||
starttime = @starttime,
|
||||
endtime = @endtime,
|
||||
lldh = @lldh,
|
||||
jh = @jh,
|
||||
quantity = @quantity,
|
||||
standarderror = @standarderror,
|
||||
testresult = @testresult
|
||||
WHERE id = @Id";
|
||||
|
||||
connection.Execute(sql, testData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace 全自动水压检测仪
|
||||
{
|
||||
int maxRetries = 3;
|
||||
int retryCount = 0;
|
||||
|
||||
|
||||
while (retryCount < maxRetries)
|
||||
{
|
||||
try
|
||||
@@ -106,7 +106,7 @@ namespace 全自动水压检测仪
|
||||
// 如果读取失败,默认写入true(开启状态)
|
||||
System.Diagnostics.Debug.WriteLine($"[Function] 读取地址{address}失败,使用默认值: {readEx.Message}");
|
||||
}
|
||||
|
||||
|
||||
// 写入相反的状态
|
||||
modbusMaster.WriteSingleCoil(1, address, !currentState);
|
||||
Thread.Sleep(100);
|
||||
@@ -122,7 +122,7 @@ namespace 全自动水压检测仪
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// 操作成功,退出重试循环
|
||||
return;
|
||||
}
|
||||
@@ -130,13 +130,13 @@ namespace 全自动水压检测仪
|
||||
{
|
||||
retryCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"[Function] Modbus从站异常 (尝试 {retryCount}/{maxRetries}): {slaveEx.Message}");
|
||||
|
||||
|
||||
if (retryCount >= maxRetries)
|
||||
{
|
||||
MessageBox.Show($"操作失败!\n\nModbus从站错误: {slaveEx.SlaveExceptionCode}\n{slaveEx.Message}", "错误");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 等待后重试
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
@@ -144,13 +144,13 @@ namespace 全自动水压检测仪
|
||||
{
|
||||
retryCount++;
|
||||
System.Diagnostics.Debug.WriteLine($"[Function] 操作失败 (尝试 {retryCount}/{maxRetries}): {ex.Message}");
|
||||
|
||||
|
||||
if (retryCount >= maxRetries)
|
||||
{
|
||||
MessageBox.Show("操作失败!" + "\n" + "\n" + ex.Message, "错误");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 等待后重试
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ namespace 全自动水压检测仪
|
||||
|
||||
}
|
||||
|
||||
public void WriteToPLCForNew(string inPutValue, ushort address, DataType dataType, bool isok=false,float max=0,float min=0)
|
||||
public void WriteToPLCForNew(string inPutValue, ushort address, DataType dataType, bool isok = false, float max = 0, float min = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -202,7 +202,7 @@ namespace 全自动水压检测仪
|
||||
|
||||
if (UIInputDialog.ShowInputDoubleDialog(ref value, UIStyle.Inherited, desc: "请输入值", showMask: false))
|
||||
{
|
||||
if ( isok&&value > max || value < min)
|
||||
if (isok && value > max || value < min)
|
||||
{
|
||||
MessageBox.Show("数据不正确");
|
||||
return;
|
||||
@@ -212,9 +212,13 @@ namespace 全自动水压检测仪
|
||||
break;
|
||||
case DataType.整形:
|
||||
int value_int = inPutValue.ToInt();
|
||||
|
||||
if (UIInputDialog.ShowInputIntegerDialog(ref value_int, UIStyle.Inherited, desc: "请输入数据:"))
|
||||
{
|
||||
|
||||
if (isok)
|
||||
{
|
||||
value_int = value_int * 10;
|
||||
}
|
||||
modbusMaster.WriteMultipleRegisters(1, address, dc.intToushorts(value_int));
|
||||
//if (isok)
|
||||
//{ modbusMaster.WriteSingleCoil(1, 25, true); }
|
||||
|
||||
Reference in New Issue
Block a user