Bläddra i källkod

站点和模板绑定

djs 5 månader sedan
förälder
incheckning
3bd44032ea

+ 5 - 1
MeterVision/Dlg/EditStandValueDlg.xaml.cs

@@ -42,7 +42,11 @@ namespace MeterVision.Dlg
 
             mStandValueModel = standValueModel;
             InitUIValue(standValueModel);
-            CurImagePath = mStandValueModel.SrcImage;   //让界面线显示结果图片
+            CurImagePath = "";
+            if (standValueModel.ModelType == 2)
+            {
+                CurImagePath = mStandValueModel.SrcImage;   //让界面线显示结果图片
+            }            
             LoadImage();
         }
 

+ 0 - 2
MeterVision/Dlg/EditStationDlg2.xaml.cs

@@ -135,7 +135,6 @@ namespace MeterVision.Dlg
                 return false;
             }
 
-
             //double lastNumUnit;
             //trySuccess = double.TryParse(txtLastNumUnit.Text.Trim(), out lastNumUnit);
             //if((meterType == 1 || meterType == 3) && lastNumUnit == 0)
@@ -144,7 +143,6 @@ namespace MeterVision.Dlg
             //    return false;
             //}
 
-
             //double lastIndUnit;
             //trySuccess = double.TryParse(txtLastIndUnit.Text.Trim(), out lastIndUnit);
             //if(meterType == 2 && lastIndUnit == 0)

+ 1 - 0
MeterVision/MeterVision.csproj

@@ -210,6 +210,7 @@
     <Compile Include="model\CompFindModel.cs" />
     <Compile Include="model\CompItem.cs" />
     <Compile Include="model\PatchFindModel.cs" />
+    <Compile Include="model\StationInfo.cs" />
     <Compile Include="model\StationItem.cs" />
     <Compile Include="Patch\AddCompDlg.xaml.cs">
       <DependentUpon>AddCompDlg.xaml</DependentUpon>

+ 11 - 1
MeterVision/Stand/AddStandDialog.xaml.cs

@@ -137,6 +137,11 @@ namespace MeterVision.Stand
                     if (stand.StandType == 2)
                     {
                         blInsert = DBStand.InsertStandAndDetails(stand, standDetails);
+                        if (blInsert) {
+                            //获取不重复的站点
+                            List<StationInfo> stationInfos = DBStand.GetUniqueStationInfo(stand.StandId);
+                            blInsert = DBStation.InsertTStations(stationInfos);
+                        }
                     }
                     else
                     {
@@ -228,7 +233,12 @@ namespace MeterVision.Stand
                         // 读取图像路径(假设图像路径在A列)
                         SrcImage = worksheet.Cells[row, 1].Text.Trim(),
                         // 读取标准答案(假设标准答案在B列)
-                        StandValue = worksheet.Cells[row, 2].Text.Trim()
+                        StandValue = worksheet.Cells[row, 2].Text.Trim(),
+                        DeviceSn = worksheet.Cells[row, 3].Text.Trim(),
+                        StationId = worksheet.Cells[row, 4].Text.Trim(),
+                        SampleTime = worksheet.Cells[row, 5].Text.Trim(),
+                        NumCount = ThisApp.ConvertToInt(worksheet.Cells[row, 6].Text.Trim()),
+                        LastUnit = ThisApp.ConvertToInt(worksheet.Cells[row, 7].Text.Trim())
                     };
                     // 添加到结果列表
                     mStandDetailList.Add(standDetail);

+ 40 - 0
MeterVision/Stand/UCStandGrid.xaml

@@ -130,6 +130,46 @@
                     </DataGridTemplateColumn.CellTemplate>
                 </DataGridTemplateColumn>
 
+                <DataGridTemplateColumn Header="站点ID" Width="100">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding StationId}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
+                <DataGridTemplateColumn Header="设备SN" Width="100">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding DeviceSn}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
+                <DataGridTemplateColumn Header="采样时间" Width="180">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding SampleTime}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
+                <DataGridTemplateColumn Header="数字个数" Width="100">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding NumCount}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
+                <DataGridTemplateColumn Header="尾数单位" Width="100">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding LastUnitName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
                 <DataGridTemplateColumn Width="*">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>

+ 14 - 0
MeterVision/ThisApp.cs

@@ -211,6 +211,20 @@ namespace MeterVision
                 MessageBox.Show($"导出失败: {ex.Message}");
             }
         }
+
+
+        public static int ConvertToInt(string input)
+        {
+            if (int.TryParse(input, out int result))
+            {
+                return result; // 如果转换成功,返回结果
+            }
+            else
+            {
+                return 0;
+                //throw new FormatException("The input string is not a valid integer.");
+            }
+        }
         //////////////////////////////////////////////////////
 
     }

+ 112 - 18
MeterVision/db/DBStand.cs

@@ -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;
+            }
+        }
         //----------------------------------------------------------------------
     }
 }

+ 87 - 13
MeterVision/db/DBStation.cs

@@ -1,4 +1,5 @@
-using System;
+using MeterVision.model;
+using System;
 using System.Collections.Generic;
 using System.Data.SQLite;
 using System.Linq;
@@ -13,18 +14,20 @@ namespace MeterVision.db
         public static bool InsertTStation(TStation tStation)
         {
             // 构建插入的 SQL 语句
-            string sql = "INSERT INTO t_station (station_id, station_name, meter_type, bright_val, flow_rate, " +
+            string sql = "INSERT INTO t_station (id,station_id, station_name, device_sn,meter_type, bright_val, flow_rate, " +
                          "dial_region, num_count, ind_count, num_region, ht_region, last_num_unit, last_ind_unit, " +
-                         "last_value, last_time, create_time) " +
-                         "VALUES (@StationId, @StationName, @MeterType, @BrightVal, @FlowRate, " +
+                         "last_value, last_time, create_time, stand_id) " +
+                         "VALUES (@StationId, @StationName, @DeviceSn, @MeterType, @BrightVal, @FlowRate, " +
                          "@DialRegion, @NumCount, @IndCount, @NumRegion, @HtRegion, @LastNumUnit, @LastIndUnit, " +
-                         "@LastValue, @LastTime, @CreateTime)";
+                         "@LastValue, @LastTime, @CreateTime, @StandId)";
 
             // 创建参数数组
             SQLiteParameter[] parameters = new SQLiteParameter[]
             {
+                new SQLiteParameter("@Id", tStation.Id),
                 new SQLiteParameter("@StationId", tStation.StationId),
                 new SQLiteParameter("@StationName", tStation.StationName),
+                new SQLiteParameter("@DeviceSn", tStation.DeviceSn),
                 new SQLiteParameter("@MeterType", tStation.MeterType),
                 new SQLiteParameter("@BrightVal", tStation.BrightVal),
                 new SQLiteParameter("@FlowRate", tStation.FlowRate),
@@ -38,6 +41,7 @@ namespace MeterVision.db
                 new SQLiteParameter("@LastValue", tStation.LastValue),
                 new SQLiteParameter("@LastTime", tStation.LastTime),
                 new SQLiteParameter("@CreateTime", tStation.CreateTime),
+                new SQLiteParameter("@StandId", tStation.StandId),
             };
 
             try
@@ -56,6 +60,52 @@ namespace MeterVision.db
             }
         }
 
+        public static bool InsertTStations(List<StationInfo> stationInfos)
+        {
+            string sql = @"
+                INSERT INTO t_station (id, stand_id,create_time, station_id, device_sn, num_count, last_num_unit)
+                VALUES (@Id, @StandId, @CreateTime, @StationId, @DeviceSn, @NumCount, @LastNumUnit);";
+
+            try
+            {
+                // 开始事务
+                using (SQLiteConnection connection = SQLiteHelper.GetConnection())
+                {
+                    connection.Open();
+                    using (SQLiteTransaction transaction = connection.BeginTransaction())
+                    {
+                        // 遍历列表插入每一条数据
+                        foreach (var stationInfo in stationInfos)
+                        {
+                            SQLiteParameter[] parameters = new SQLiteParameter[]
+                            {
+                                new SQLiteParameter("@Id", Guid.NewGuid().ToString()),
+                                new SQLiteParameter("@StandId", stationInfo.StandId),
+                                new SQLiteParameter("@CreateTime", ThisApp.GetNowTime_yyyyMMddHHmmss()),
+                                new SQLiteParameter("@StationId", stationInfo.StationId),
+                                new SQLiteParameter("@DeviceSn", stationInfo.DeviceSn),
+                                new SQLiteParameter("@NumCount", stationInfo.NumCount),
+                                new SQLiteParameter("@LastNumUnit", stationInfo.LastUnit2)
+                            };
+
+                            // 执行插入操作
+                            SQLiteHelper.ExecuteNonQuery(sql, parameters, transaction);
+                        }
+
+                        // 提交事务
+                        transaction.Commit();
+                    }
+                }
+                return true;
+
+            }
+            catch(Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+                return false;
+            }
+        }
+
         public static Tuple<int, int, List<TStation>> GetPagedTStations(int pageNumber, int pageSize,string stationId)
         {
             // 计算 OFFSET 值
@@ -64,9 +114,9 @@ namespace MeterVision.db
             // 定义 SQL 查询语句,带有分页
             // 定义 SQL 查询语句的基础部分
             string sql = @"
-                SELECT station_id, station_name, meter_type, bright_val, flow_rate, dial_region,
+                SELECT id,station_id, station_name, device_sn,meter_type, bright_val, flow_rate, dial_region,
                        num_count, ind_count, num_region, ht_region, last_num_unit, last_ind_unit,
-                       last_value, last_time, create_time
+                       last_value, last_time, create_time,stand_id
                 FROM t_station ";
 
             // 如果传入的 stationId 不为空,增加过滤条件
@@ -107,8 +157,10 @@ namespace MeterVision.db
                     // 将查询结果映射到 TStation 对象
                     TStation station = new TStation
                     {
+                        Id = reader.GetString(reader.GetOrdinal("id")),
                         StationId = reader.GetString(reader.GetOrdinal("station_id")),
                         StationName = reader.GetString(reader.GetOrdinal("station_name")),
+                        DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
                         MeterType = reader.GetInt32(reader.GetOrdinal("meter_type")),
                         BrightVal = reader.GetDouble(reader.GetOrdinal("bright_val")),
                         FlowRate = reader.GetInt32(reader.GetOrdinal("flow_rate")),
@@ -121,7 +173,26 @@ namespace MeterVision.db
                         LastIndUnit = reader.GetDouble(reader.GetOrdinal("last_ind_unit")),
                         LastValue = reader.GetDouble(reader.GetOrdinal("last_value")),
                         LastTime = reader.GetString(reader.GetOrdinal("last_time")),
-                        //CreateTime = reader.GetString(reader.GetOrdinal("create_time"))
+                        CreateTime = reader.GetString(reader.GetOrdinal("create_time")),
+                        StandId = reader.GetString(reader.GetOrdinal("stand_id"))
+                        //Id = reader.IsDBNull(reader.GetOrdinal("id")) ? null : reader.GetString(reader.GetOrdinal("id")),
+                        //StationId = reader.IsDBNull(reader.GetOrdinal("station_id")) ? null : reader.GetString(reader.GetOrdinal("station_id")),
+                        //StationName = reader.IsDBNull(reader.GetOrdinal("station_name")) ? null : reader.GetString(reader.GetOrdinal("station_name")),
+                        //DeviceSn = reader.IsDBNull(reader.GetOrdinal("device_sn")) ? null : reader.GetString(reader.GetOrdinal("device_sn")),
+                        //MeterType = reader.IsDBNull(reader.GetOrdinal("meter_type")) ? 0 : reader.GetInt32(reader.GetOrdinal("meter_type")),
+                        //BrightVal = reader.IsDBNull(reader.GetOrdinal("bright_val")) ? 0.0 : reader.GetDouble(reader.GetOrdinal("bright_val")),
+                        //FlowRate = reader.IsDBNull(reader.GetOrdinal("flow_rate")) ? 0 : reader.GetInt32(reader.GetOrdinal("flow_rate")),
+                        //DialRegion = reader.IsDBNull(reader.GetOrdinal("dial_region")) ? null : reader.GetString(reader.GetOrdinal("dial_region")),
+                        //NumCount = reader.IsDBNull(reader.GetOrdinal("num_count")) ? 0 : reader.GetInt32(reader.GetOrdinal("num_count")),
+                        //IndCount = reader.IsDBNull(reader.GetOrdinal("ind_count")) ? 0 : reader.GetInt32(reader.GetOrdinal("ind_count")),
+                        //NumRegion = reader.IsDBNull(reader.GetOrdinal("num_region")) ? null : reader.GetString(reader.GetOrdinal("num_region")),
+                        //HtRegion = reader.IsDBNull(reader.GetOrdinal("ht_region")) ? null : reader.GetString(reader.GetOrdinal("ht_region")),
+                        //LastNumUnit = reader.IsDBNull(reader.GetOrdinal("last_num_unit")) ? 0.0 : reader.GetDouble(reader.GetOrdinal("last_num_unit")),
+                        //LastIndUnit = reader.IsDBNull(reader.GetOrdinal("last_ind_unit")) ? 0.0 : reader.GetDouble(reader.GetOrdinal("last_ind_unit")),
+                        //LastValue = reader.IsDBNull(reader.GetOrdinal("last_value")) ? 0.0 : reader.GetDouble(reader.GetOrdinal("last_value")),
+                        //LastTime = reader.IsDBNull(reader.GetOrdinal("last_time")) ? null : reader.GetString(reader.GetOrdinal("last_time")),
+                        //CreateTime = reader.IsDBNull(reader.GetOrdinal("create_time")) ? null : reader.GetString(reader.GetOrdinal("create_time")),
+                        //StandId = reader.IsDBNull(reader.GetOrdinal("stand_id")) ? null : reader.GetString(reader.GetOrdinal("stand_id"))
                     };
                     stations.Add(station);
                 }
@@ -138,15 +209,15 @@ namespace MeterVision.db
             return Tuple.Create(totalRecords, totalPages, stations);
         }
 
-        public static bool DeleteTStation(string stationId)
+        public static bool DeleteTStation(string id)
         {
             // 定义删除的 SQL 语句
-            string sql = "DELETE FROM t_station WHERE station_id = @StationId";
+            string sql = "DELETE FROM t_station WHERE id = @Id";
 
             // 创建 SQL 参数
             SQLiteParameter[] parameters = new SQLiteParameter[]
             {
-                new SQLiteParameter("@StationId", stationId)
+                new SQLiteParameter("@Id", id)
             };
 
             try
@@ -184,12 +255,13 @@ namespace MeterVision.db
                     last_ind_unit = @LastIndUnit,
                     last_value = @LastValue,
                     last_time = @LastTime
-                WHERE station_id = @StationId";
+                WHERE id = @Id";
 
             // 创建 SQL 参数
             SQLiteParameter[] parameters = new SQLiteParameter[]
             {
-                new SQLiteParameter("@StationId", tStation.StationId),
+                //new SQLiteParameter("@StationId", tStation.StationId),
+                new SQLiteParameter("@Id",tStation.Id),
                 new SQLiteParameter("@StationName", tStation.StationName),
                 new SQLiteParameter("@MeterType", tStation.MeterType),
                 new SQLiteParameter("@BrightVal", tStation.BrightVal),
@@ -242,6 +314,8 @@ namespace MeterVision.db
             }
         }
 
+
+
         //-----------------------------------------------------
 
     }

+ 11 - 0
MeterVision/db/TStandDetail.cs

@@ -14,6 +14,12 @@ namespace MeterVision.db
         public string SrcImage { get; set; }
         public string StandValue { get; set; }
 
+        public string StationId { get; set; }
+        public string DeviceSn { get; set; }
+        public string SampleTime { get; set; }
+        public int NumCount { get; set; }
+        public int LastUnit { get; set; }
+
         public TStandDetail()
         {
             StandDetailId = string.Empty;
@@ -21,6 +27,11 @@ namespace MeterVision.db
             StandId = string.Empty;
             SrcImage = string.Empty;
             StandValue = string.Empty;
+            StationId = string.Empty;
+            DeviceSn = string.Empty;
+            SampleTime = string.Empty;
+            NumCount = 0;
+            LastUnit = 0;
         }
     }
 }

+ 5 - 0
MeterVision/db/TStation.cs

@@ -11,8 +11,11 @@ namespace MeterVision.db
     //站点表实体对象
     public class TStation
     {
+        public string Id { get; set; }
         public string StationId { get; set; }
         public string StationName { get; set; }
+        public string DeviceSn { get; set; }
+        public string StandId { get; set; }
         public int MeterType { get; set; }
         public double BrightVal { get; set; }
         public int FlowRate { get; set; }
@@ -33,6 +36,7 @@ namespace MeterVision.db
         {
             StationId = string.Empty;
             StationName = string.Empty;
+            DeviceSn = string.Empty;
             MeterType = 0;
             BrightVal = 1.2;
             FlowRate = 0;
@@ -46,6 +50,7 @@ namespace MeterVision.db
             LastValue = 0.0;
             LastTime = string.Empty;
             CreateTime = string.Empty;
+            StandId = string.Empty;
         }
 
         public TStation(StationItem item)

+ 1 - 1
MeterVision/model/ResultModel.cs

@@ -9,7 +9,7 @@ namespace MeterVision.model
     public class ResultModel
     {
         private static double divisor = 10000;
-        private static Dictionary<uint,int> decimalPlaceMapping = new Dictionary<uint, int>
+        public static Dictionary<uint,int> decimalPlaceMapping = new Dictionary<uint, int>
         {
             { 10000000, -3 },  // 100000 表示负 1 位小数,10000立方
             { 1000000, -2 },  // 100000 表示负 1 位小数,100立方

+ 103 - 2
MeterVision/model/StandDetailItem.cs

@@ -13,6 +13,19 @@ namespace MeterVision.model
     {
         public event PropertyChangedEventHandler PropertyChanged;
 
+        public static Dictionary<int, double> LastUnitMapping = new Dictionary<int, double>
+        {
+            {0,0.0001 },
+            {1,0.001 },
+            {2,0.01 },
+            {3,0.1 },
+            {4,1 },
+            {5,10 },
+            {6,100 },
+            {7,1000 },
+            {8,10000 }
+        };
+
         // 触发属性变更通知
         protected virtual void OnPropertyChanged(string propertyName)
         {
@@ -33,7 +46,6 @@ namespace MeterVision.model
             }
         }
 
-
         public string StandId { get; set; }
 
         public string StandDetailId { get; set; }
@@ -53,7 +65,92 @@ namespace MeterVision.model
                 }
             }
         }
-   
+
+        private string _stationId;
+        public string StationId
+        {
+            get => _stationId;
+            set
+            {
+                if(_stationId != value)
+                {
+                    _stationId = value;
+                    OnPropertyChanged(nameof(StationId));
+                }
+            }
+        }
+
+        private string _deviceSn;
+        public string DeviceSn
+        {
+            get => _deviceSn;
+            set
+            {
+                if(_deviceSn != value)
+                {
+                    _deviceSn = value;
+                    OnPropertyChanged(nameof(DeviceSn));
+                }
+            }
+        }
+
+
+        private string _sampleTime;
+        public string SampleTime
+        {
+            get => _sampleTime;
+            set
+            {
+                if(_sampleTime != value)
+                {
+                    _sampleTime = value;
+                    OnPropertyChanged(nameof(SampleTime));
+                }
+            }
+        }
+
+        private int _numCount;
+        public int NumCount
+        {
+            get => _numCount;
+            set
+            {
+                if(_numCount != value)
+                {
+                    _numCount = value;
+                    OnPropertyChanged(nameof(NumCount));
+                }
+            }
+        }
+
+        private int _lastUnit;
+        public int LastUnit
+        {
+            get => _lastUnit;
+            set
+            {
+                if(_lastUnit != value)
+                {
+                    _lastUnit = value;
+                    OnPropertyChanged(nameof(LastUnit));
+                    OnPropertyChanged(nameof(LastUnitName));
+                }
+            }
+        }
+
+        public string LastUnitName
+        {
+            get
+            {
+                if(LastUnitMapping.TryGetValue(LastUnit,out double lastUnit))
+                {
+                    return lastUnit + "";
+                }
+                return "";
+            }
+        }
+
+
         public StandDetailItem()
         {
 
@@ -65,6 +162,10 @@ namespace MeterVision.model
             StandDetailId = standDetail.StandDetailId;
             SrcImage = standDetail.SrcImage;
             StandValue = standDetail.StandValue;
+            StationId = standDetail.StationId;
+            SampleTime = standDetail.SampleTime;
+            NumCount = standDetail.NumCount;
+            LastUnit = standDetail.LastUnit;
         }
         ///////////////////////////////////////////////////////////
     }

+ 30 - 0
MeterVision/model/StationInfo.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MeterVision.model
+{
+    public class StationInfo
+    {
+        public string StandId { get; set; }
+        public string StationId { get; set; }
+        public string DeviceSn { get; set; }
+        public int NumCount { get; set; }
+        public int LastUnit { get; set; }
+
+        public double LastUnit2
+        {
+            get
+            {
+                if (StandDetailItem.LastUnitMapping.TryGetValue(LastUnit, out double lastUnit))
+                {
+                    return lastUnit;
+                }
+                return 0.0;
+            }
+        }
+    }
+
+}

+ 6 - 0
MeterVision/model/StationItem.cs

@@ -70,6 +70,7 @@ namespace MeterVision.model
             }
         }
 
+        public string Id { get; set; }
 
         public string StationId { get; set; }
 
@@ -87,6 +88,11 @@ namespace MeterVision.model
             }
         }
 
+        public string DeviceSn { get; set; }
+
+
+        public string StandId { get; set; }
+
         private int _meterType;
         public int MeterType
         {