|
@@ -1,4 +1,5 @@
|
|
|
-using System;
|
|
|
+using MeterVision.model;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data.SQLite;
|
|
|
using System.Linq;
|
|
@@ -54,6 +55,9 @@ namespace MeterVision.db
|
|
|
-- 删除 t_stand 表中与 stand_id 相关的数据
|
|
|
DELETE FROM t_stand WHERE stand_id = @StandId;
|
|
|
|
|
|
+ -- 删除 t_station 表中与 stand_id 相关的数据
|
|
|
+ DELETE FROM t_station WHERE stand_id = @StandId;
|
|
|
+
|
|
|
COMMIT;";
|
|
|
|
|
|
// 创建参数
|
|
@@ -164,8 +168,10 @@ namespace MeterVision.db
|
|
|
{
|
|
|
// 插入SQL语句
|
|
|
string sql = @"
|
|
|
- INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value)
|
|
|
- VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue);";
|
|
|
+ INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value,
|
|
|
+ station_id, device_sn,sample_time, num_count, last_unit)
|
|
|
+ VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue,
|
|
|
+ @StationId, @DeviceSn, @SampleTime, @NumCount, @LastUnit);";
|
|
|
|
|
|
// 定义参数
|
|
|
SQLiteParameter[] parameters = new SQLiteParameter[]
|
|
@@ -174,7 +180,12 @@ namespace MeterVision.db
|
|
|
new SQLiteParameter("@CreateTime", standDetail.CreateTime),
|
|
|
new SQLiteParameter("@StandId", standDetail.StandId),
|
|
|
new SQLiteParameter("@SrcImage", standDetail.SrcImage),
|
|
|
- new SQLiteParameter("@StandValue", standDetail.StandValue)
|
|
|
+ new SQLiteParameter("@StandValue", standDetail.StandValue),
|
|
|
+ new SQLiteParameter("@StationId", standDetail.StationId),
|
|
|
+ new SQLiteParameter("@DeviceSn",standDetail.DeviceSn),
|
|
|
+ new SQLiteParameter("@SampleTime",standDetail.SampleTime),
|
|
|
+ new SQLiteParameter("@NumCount", standDetail.NumCount),
|
|
|
+ new SQLiteParameter("@LastUnit", standDetail.LastUnit)
|
|
|
};
|
|
|
|
|
|
// 执行插入操作
|
|
@@ -195,8 +206,11 @@ namespace MeterVision.db
|
|
|
{
|
|
|
// 插入SQL语句
|
|
|
string sql = @"
|
|
|
- INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value)
|
|
|
- VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue);";
|
|
|
+ INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value,
|
|
|
+ station_id, device_sn, sample_time, num_count, last_unit)
|
|
|
+ VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue,
|
|
|
+ @StationId, ,@DeviceSn, @SampleTime, @NumCount, @LastUnit);";
|
|
|
+
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -215,7 +229,12 @@ namespace MeterVision.db
|
|
|
new SQLiteParameter("@CreateTime", standDetail.CreateTime),
|
|
|
new SQLiteParameter("@StandId", standDetail.StandId),
|
|
|
new SQLiteParameter("@SrcImage", standDetail.SrcImage),
|
|
|
- new SQLiteParameter("@StandValue", standDetail.StandValue)
|
|
|
+ new SQLiteParameter("@StandValue", standDetail.StandValue),
|
|
|
+ new SQLiteParameter("@StationId", standDetail.StationId),
|
|
|
+ new SQLiteParameter("@DeviceSn",standDetail.DeviceSn),
|
|
|
+ new SQLiteParameter("@SampleTime",standDetail.SampleTime),
|
|
|
+ new SQLiteParameter("@NumCount", standDetail.NumCount),
|
|
|
+ new SQLiteParameter("@LastUnit", standDetail.LastUnit)
|
|
|
};
|
|
|
|
|
|
// 执行插入操作
|
|
@@ -264,15 +283,23 @@ namespace MeterVision.db
|
|
|
foreach (var standDetail in standDetails)
|
|
|
{
|
|
|
string detailSql = @"
|
|
|
- INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value)
|
|
|
- VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue);";
|
|
|
+ INSERT OR IGNORE INTO t_stand_detail (stand_detail_id, create_time, stand_id, src_image, stand_value,
|
|
|
+ station_id, device_sn,sample_time, num_count, last_unit)
|
|
|
+ VALUES (@StandDetailId, @CreateTime, @StandId, @SrcImage, @StandValue,
|
|
|
+ @StationId, @DeviceSn ,@SampleTime, @NumCount, @LastUnit);";
|
|
|
+
|
|
|
SQLiteParameter[] detailParams = new SQLiteParameter[]
|
|
|
{
|
|
|
new SQLiteParameter("@StandDetailId", standDetail.StandDetailId),
|
|
|
new SQLiteParameter("@CreateTime", standDetail.CreateTime),
|
|
|
new SQLiteParameter("@StandId", standDetail.StandId),
|
|
|
new SQLiteParameter("@SrcImage", standDetail.SrcImage),
|
|
|
- new SQLiteParameter("@StandValue", standDetail.StandValue)
|
|
|
+ new SQLiteParameter("@StandValue", standDetail.StandValue),
|
|
|
+ new SQLiteParameter("@StationId", standDetail.StationId),
|
|
|
+ new SQLiteParameter("@DeviceSn", standDetail.DeviceSn),
|
|
|
+ new SQLiteParameter("@SampleTime",standDetail.SampleTime),
|
|
|
+ new SQLiteParameter("@NumCount", standDetail.NumCount),
|
|
|
+ new SQLiteParameter("@LastUnit", standDetail.LastUnit),
|
|
|
};
|
|
|
SQLiteHelper.ExecuteNonQuery(detailSql, detailParams, transaction);
|
|
|
}
|
|
@@ -285,8 +312,9 @@ namespace MeterVision.db
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- Console.WriteLine($"插入数据失败:{ex.Message}");
|
|
|
- return false;
|
|
|
+ //Console.WriteLine($"插入数据失败:{ex.Message}");
|
|
|
+ throw new Exception($"插入数据失败:{ex.Message}");
|
|
|
+ //return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -298,7 +326,7 @@ namespace MeterVision.db
|
|
|
|
|
|
// 分页查询SQL
|
|
|
string sql = @"
|
|
|
- SELECT stand_detail_id, create_time, stand_id, src_image, stand_value
|
|
|
+ SELECT stand_detail_id, create_time, stand_id, src_image, stand_value, station_id, device_sn, sample_time, num_count, last_unit
|
|
|
FROM t_stand_detail WHERE stand_id=@StandId
|
|
|
ORDER BY create_time DESC -- 根据需要修改排序字段
|
|
|
LIMIT @PageSize OFFSET @Offset;";
|
|
@@ -324,7 +352,12 @@ namespace MeterVision.db
|
|
|
CreateTime = reader.GetString(reader.GetOrdinal("create_time")),
|
|
|
StandId = reader.GetString(reader.GetOrdinal("stand_id")),
|
|
|
SrcImage = reader.GetString(reader.GetOrdinal("src_image")),
|
|
|
- StandValue = reader.GetString(reader.GetOrdinal("stand_value"))
|
|
|
+ StandValue = reader.GetString(reader.GetOrdinal("stand_value")),
|
|
|
+ StationId = reader.GetString(reader.GetOrdinal("station_id")),
|
|
|
+ DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
|
|
|
+ SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
|
|
|
+ NumCount = reader.GetInt32(reader.GetOrdinal("num_count")),
|
|
|
+ LastUnit = reader.GetInt32(reader.GetOrdinal("last_unit"))
|
|
|
};
|
|
|
standDetails.Add(standDetail);
|
|
|
}
|
|
@@ -348,7 +381,7 @@ namespace MeterVision.db
|
|
|
{
|
|
|
// 分页查询 SQL
|
|
|
string sql = @"
|
|
|
- SELECT stand_detail_id, create_time, stand_id, src_image, stand_value
|
|
|
+ SELECT stand_detail_id, create_time, stand_id, src_image, stand_value, station_id, device_sn, sample_time, num_count, last_unit
|
|
|
FROM t_stand_detail WHERE stand_id = @StandId
|
|
|
ORDER BY create_time DESC";
|
|
|
|
|
@@ -373,7 +406,12 @@ namespace MeterVision.db
|
|
|
CreateTime = reader.GetString(reader.GetOrdinal("create_time")),
|
|
|
StandId = reader.GetString(reader.GetOrdinal("stand_id")),
|
|
|
SrcImage = reader.GetString(reader.GetOrdinal("src_image")),
|
|
|
- StandValue = reader.GetString(reader.GetOrdinal("stand_value"))
|
|
|
+ StandValue = reader.GetString(reader.GetOrdinal("stand_value")),
|
|
|
+ StationId = reader.GetString(reader.GetOrdinal("station_id")),
|
|
|
+ DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
|
|
|
+ SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
|
|
|
+ NumCount = reader.GetInt32(reader.GetOrdinal("num_count")),
|
|
|
+ LastUnit = reader.GetInt32(reader.GetOrdinal("last_unit"))
|
|
|
};
|
|
|
standDetails.Add(standDetail);
|
|
|
}
|
|
@@ -392,7 +430,7 @@ namespace MeterVision.db
|
|
|
{
|
|
|
// 分页查询 SQL
|
|
|
string sql = @"
|
|
|
- SELECT stand_detail_id, create_time, stand_id, src_image, stand_value
|
|
|
+ SELECT stand_detail_id, create_time, stand_id, src_image, stand_value, station_id, device_sn, sample_id, num_count, last_unit
|
|
|
FROM t_stand_detail WHERE stand_id = @StandId
|
|
|
ORDER BY create_time DESC";
|
|
|
|
|
@@ -417,7 +455,12 @@ namespace MeterVision.db
|
|
|
CreateTime = reader.GetString(reader.GetOrdinal("create_time")),
|
|
|
StandId = reader.GetString(reader.GetOrdinal("stand_id")),
|
|
|
SrcImage = reader.GetString(reader.GetOrdinal("src_image")),
|
|
|
- StandValue = reader.GetString(reader.GetOrdinal("stand_value"))
|
|
|
+ StandValue = reader.GetString(reader.GetOrdinal("stand_value")),
|
|
|
+ StationId = reader.GetString(reader.GetOrdinal("station_id")),
|
|
|
+ DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
|
|
|
+ SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
|
|
|
+ NumCount = reader.GetInt32(reader.GetOrdinal("num_count")),
|
|
|
+ LastUnit = reader.GetInt32(reader.GetOrdinal("last_unit"))
|
|
|
};
|
|
|
standDetails.Add(standDetail);
|
|
|
}
|
|
@@ -559,6 +602,57 @@ namespace MeterVision.db
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static List<StationInfo> GetUniqueStationInfo(string standId)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string sql = @"
|
|
|
+ SELECT
|
|
|
+ stand_id,
|
|
|
+ station_id,
|
|
|
+ device_sn,
|
|
|
+ MAX(num_count) AS num_count,
|
|
|
+ MAX(last_unit) AS last_unit
|
|
|
+ FROM
|
|
|
+ t_stand_detail
|
|
|
+ WHERE
|
|
|
+ stand_id = @StandId
|
|
|
+ GROUP BY
|
|
|
+ station_id,device_sn
|
|
|
+ ORDER BY
|
|
|
+ station_id ASC;";
|
|
|
+
|
|
|
+ SQLiteParameter[] parameters = new SQLiteParameter[]
|
|
|
+ {
|
|
|
+ new SQLiteParameter("@StandId", standId)
|
|
|
+ };
|
|
|
+
|
|
|
+ List<StationInfo> result = new List<StationInfo>();
|
|
|
+
|
|
|
+ using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(sql, parameters))
|
|
|
+ {
|
|
|
+ while (reader.Read())
|
|
|
+ {
|
|
|
+ StationInfo station = new StationInfo
|
|
|
+ {
|
|
|
+ StandId = reader.GetString(reader.GetOrdinal("stand_id")),
|
|
|
+ StationId = reader.GetString(reader.GetOrdinal("station_id")),
|
|
|
+ DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
|
|
|
+ NumCount = reader.GetInt32(reader.GetOrdinal("num_count")),
|
|
|
+ LastUnit = reader.GetInt32(reader.GetOrdinal("last_unit"))
|
|
|
+ };
|
|
|
+ result.Add(station);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine($"查询失败:{ex.Message}");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
//----------------------------------------------------------------------
|
|
|
}
|
|
|
}
|