Sfoglia il codice sorgente

在批量识别中增加站点选择

djs 5 mesi fa
parent
commit
e96b0a139f

+ 2 - 2
MeterVision/Dlg/EditStandDetailCfg.xaml.cs

@@ -146,8 +146,8 @@ namespace MeterVision.Dlg
                 cmbMeterType.SelectedValue = standDetail.MeterType;
                 cmbFlowRate.Text = standDetail.FlowRate.ToString();
                 txtBrightVal.Text = standDetail.BrightVal.ToString();
-                txtNumCount.Text = standDetail.ToString();
-                txtIndCount.Text = standDetail.ToString();
+                txtNumCount.Text = standDetail.NumCount.ToString();
+                txtIndCount.Text = standDetail.IndCount.ToString();
                 cmbLastUnit.SelectedValue = standDetail.LastUnit;
 
                 txtFeatureRegion.Text = standDetail.FeatureRegion;

+ 0 - 1
MeterVision/FreeAi/FaBefore.cs

@@ -201,7 +201,6 @@ namespace MeterVision.FreeAi
             {
                 TryParseCoordinates(detailItem.MeterRegion, 2, ref beforeAI.CONFIG_METER_REGION);
 
-                //单张图计算最大流量,意义不大,也不太好确定时间,就按1小时计算吧
                 double hourDiffs = CalculateHourDifference(detailItem.LatestTime, detailItem.SampleTime);
                 beforeAI.MAX_FLOW_THRESHOLD = (ulong)(detailItem.FlowRate * hourDiffs * FaConstant.CUBE_VALUE);
                 //上次的值

+ 8 - 0
MeterVision/MeterVision.csproj

@@ -153,6 +153,7 @@
     <Compile Include="db\VComp.cs" />
     <Compile Include="db\VCompDetail.cs" />
     <Compile Include="db\VPatch.cs" />
+    <Compile Include="db\VPatchStation.cs" />
     <Compile Include="db\VStand.cs" />
     <Compile Include="Dlg\AboutWindow.xaml.cs">
       <DependentUpon>AboutWindow.xaml</DependentUpon>
@@ -240,6 +241,9 @@
     <Compile Include="Station\UCStationMain.xaml.cs">
       <DependentUpon>UCStationMain.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Station\UCVpsGrid.xaml.cs">
+      <DependentUpon>UCVpsGrid.xaml</DependentUpon>
+    </Compile>
     <Compile Include="UC\UCImage.xaml.cs">
       <DependentUpon>UCImage.xaml</DependentUpon>
     </Compile>
@@ -411,6 +415,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Station\UCVpsGrid.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="UC\UCImage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 3 - 3
MeterVision/Patch/UCPatchGrid.xaml.cs

@@ -293,10 +293,10 @@ namespace MeterVision.Patch
 
                 if(int.TryParse(standValueModel.StandValue,out int iStandValue))
                 {
-                    equalFlag = detailItem.CheckEquailityWithStandValue(iStandValue, detailItem.FinalValue) ? 1 : 0;
+                    //equalFlag = detailItem.CheckEquailityWithStandValue(iStandValue, detailItem.FinalValue) ? 1 : 0;
+                    equalFlag = detailItem.GetEqualFlag(iStandValue, detailItem.FinalValue);
                 }
                 
-
                 bool updateStandValue1 = DBPatch.UpdatePatchDetailStandValue(detailItem.PatchDetailId, standValueModel.StandValue,equalFlag);
                 bool updateStandValue2 = DBStand.UpdateStandDetailStandValue(detailItem.SrcImage, standValueModel.StandValue);
                 if (updateStandValue1 && updateStandValue2)
@@ -474,7 +474,7 @@ namespace MeterVision.Patch
                             {
                                 patchDetails[i+1].LatestValue = patchDetails[i].LatestValue;
                                 patchDetails[i+1].LatestComplete = patchDetails[i].LatestComplete;
-                                patchDetails[i+1].LatestTime = patchDetails[i].SampleTime;
+                                patchDetails[i + 1].LatestTime = patchDetails[i].LatestTime;
                             }
                             //更新改变了Latest的数据
                             if (DBPatch.UpdatePatchDetails_Latest(patchDetails[i + 1]))

+ 18 - 18
MeterVision/Patch/UCPatchMain.xaml.cs

@@ -482,24 +482,24 @@ namespace MeterVision.Patch
             //更新目录内容
             if (blTask && SelectedPatchItem != null)
             {
-                //VPatch vPatch = null;
-                //await Task.Run(() =>
-                //{
-                //    vPatch = DBPatch.GetVPatchById(SelectedPatchItem.PatchId);
-                //});
-
-                //if (vPatch != null)
-                //{
-                //    //var NewPatchItem = new PatchItem(vPatch);
-                //    foreach (var patchItem in PatchItemList)
-                //    {
-                //        if (patchItem.PatchId == vPatch.PatchId)
-                //        {
-                //            ObjectHelper.CopyMatchingFields(vPatch, patchItem);
-                //            break;
-                //        }
-                //    }//foreach
-                //}//if vpatch!=null
+                VPatch vPatch = null;
+                await Task.Run(() =>
+                {
+                    vPatch = DBPatch.GetVPatchById(SelectedPatchItem.PatchId);
+                });
+
+                if (vPatch != null)
+                {
+                    //var NewPatchItem = new PatchItem(vPatch);
+                    foreach (var patchItem in PatchItemList)
+                    {
+                        if (patchItem.PatchId == vPatch.PatchId)
+                        {
+                            ObjectHelper.CopyMatchingFields(vPatch, patchItem);
+                            break;
+                        }
+                    }//foreach
+                }//if vpatch!=null
                 RefresUIPatchItem(SelectedPatchItem.PatchId);
             }//blTask
         }

+ 3 - 3
MeterVision/Properties/AssemblyInfo.cs

@@ -8,7 +8,7 @@ using System.Windows;
 // 控制。更改这些特性值可修改
 // 与程序集关联的信息。
 [assembly: AssemblyTitle("MeterVision")]
-[assembly: AssemblyDescription("边缘抄表器AI模式验证测试工具")]
+[assembly: AssemblyDescription("边缘抄表器AI模式验证测试工具V2")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("北京鸿城鑫鼎智能科技有限公司")]
 [assembly: AssemblyProduct("MeterVision")]
@@ -51,5 +51,5 @@ using System.Windows;
 // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.1.0.2")]
-[assembly: AssemblyFileVersion("1.1.0.2")]
+[assembly: AssemblyVersion("2.1.0.2")]
+[assembly: AssemblyFileVersion("2.1.0.2")]

+ 134 - 0
MeterVision/Station/UCVpsGrid.xaml

@@ -0,0 +1,134 @@
+<UserControl x:Class="MeterVision.Station.UCVpsGrid"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:MeterVision.Station"
+             mc:Ignorable="d" 
+             Background="White"
+             BorderThickness="0"
+             Padding="5"
+             BorderBrush="#E0E0E0"             
+             d:DesignHeight="800" d:DesignWidth="1000">
+    <UserControl.Resources>
+        <Style TargetType="ContextMenu">
+            <Setter Property="Background" Value="White"/>
+            <Setter Property="BorderBrush" Value="#DDDDDD"/>
+            <Setter Property="BorderThickness" Value="1"/>
+        </Style>
+
+        <Style TargetType="MenuItem">
+            <Setter Property="Padding" Value="5,2"/>
+            <!--<Setter Property="Icon" Value="{StaticResource DefaultIcon}"/>-->
+        </Style>
+    </UserControl.Resources>
+
+    <Grid>
+        <DataGrid Name="dgStation" GridLinesVisibility="All" HorizontalGridLinesBrush="#D3D3D3" VerticalGridLinesBrush="#D3D3D3" RowHeight="60" BorderBrush="#D3D3D3"
+                  HeadersVisibility="Column" SelectionMode="Single" SelectionUnit="FullRow" HorizontalScrollBarVisibility="Auto" CanUserResizeColumns="False"  
+                  FrozenColumnCount="5"
+                  SelectedItem="{Binding SelectedStationItem,Mode=TwoWay}"
+                  AutoGenerateColumns="False" CanUserAddRows="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White">
+            <DataGrid.Resources>
+                <Style TargetType="DataGridColumnHeader">
+                    <Setter Property="Height" Value="40" />
+                    <!--Setter Property="Background" Value="White" /-->
+                    <Setter Property="Foreground" Value="Black" />
+                    <Setter Property="FontSize" Value="13px" />
+                    <Setter Property="FontWeight" Value="Bold" />
+                    <Setter Property="BorderBrush" Value="#D3D3D3" />
+                    <Setter Property="BorderThickness" Value="0,0,1,1" />
+                    <Setter Property="HorizontalContentAlignment" Value="Center" />
+                </Style>
+                <!-- 自定义行的选中样式 -->
+                <Style TargetType="DataGridRow">
+                    <Style.Triggers>
+                        <!-- 当行被选中时 -->
+                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
+                            <!-- 设置选中行的背景色 -->
+                            <Setter Property="Background" Value="AliceBlue"/>
+                        </DataTrigger>
+                    </Style.Triggers>
+                </Style>
+
+                <!-- 自定义选中单元格的背景色 -->
+                <Style TargetType="DataGridCell">
+                    <Style.Triggers>
+                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
+                            <!-- 设置选中单元格的背景色 -->
+                            <Setter Property="Background" Value="AliceBlue"/>
+                            <Setter Property="BorderBrush" Value="Transparent" />
+                        </DataTrigger>
+                    </Style.Triggers>
+                </Style>
+            </DataGrid.Resources>
+
+            <!--<DataGrid.ContextMenu>
+                <ContextMenu>
+                    <MenuItem x:Name="miDelete" Header="删除站点" Click="MiDelete_Click">
+                        <MenuItem.Icon>
+                            <Image Source="pack://application:,,,/MeterVision;component/Assest/mi_delete.png" Width="16" Height="16"/>
+                        </MenuItem.Icon>
+                    </MenuItem>
+                </ContextMenu>
+            </DataGrid.ContextMenu>-->
+
+            <DataGrid.Columns>
+                <!--使用自定义模板-->
+                <!--<DataGridTemplateColumn Header="序号" Width="50">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding Index}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>-->
+
+                <DataGridTemplateColumn Header="站点" Width="200">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <Grid>
+                                <Grid.RowDefinitions>
+                                    <RowDefinition Height="*" />
+                                    <RowDefinition Height="*" />
+                                </Grid.RowDefinitions>
+                                <Grid Grid.Row="0">
+                                    <Grid.ColumnDefinitions>
+                                        <ColumnDefinition Width="Auto" />
+                                        <ColumnDefinition Width="*" />
+                                    </Grid.ColumnDefinitions>
+                                    <TextBlock Text="{Binding Index}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Left" VerticalAlignment="Center"/>
+                                    <TextBlock Grid.Column="1" Text="{Binding StationId}" FontSize="13px" Margin="0 0 10 0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
+                                </Grid>
+                                <Grid Grid.Row="1">
+                                    <Grid.ColumnDefinitions>
+                                        <ColumnDefinition Width="*" />
+                                        <ColumnDefinition Width="*" />
+                                        <ColumnDefinition Width="*" />
+                                    </Grid.ColumnDefinitions>
+                                    <TextBlock Grid.Column="0" Text="{Binding EqualCount,StringFormat='正确:{0}'}" HorizontalAlignment="Left" VerticalAlignment="Center"
+                                               FontSize="13px" Foreground="#28a745" />
+                                    <TextBlock Grid.Column="1" Text="{Binding ErrorCount,StringFormat='错误:{0}'}" HorizontalAlignment="Left" VerticalAlignment="Center"
+                                               FontSize="13px" Foreground="#dc3545" />
+                                    <TextBlock Grid.Column="2" Text="{Binding InvalidCount,StringFormat='无效:{0}'}" HorizontalAlignment="Left" VerticalAlignment="Center"
+                                               FontSize="13px" Foreground="#FFA500" />
+                                </Grid>
+                            </Grid>
+                            
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+
+                <!--<DataGridTemplateColumn Header="标注" Width="50">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding MarkCountName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>-->
+
+            </DataGrid.Columns>
+
+        </DataGrid>
+
+    </Grid>
+</UserControl>

+ 251 - 0
MeterVision/Station/UCVpsGrid.xaml.cs

@@ -0,0 +1,251 @@
+using MeterVision.Config;
+using MeterVision.db;
+using MeterVision.model;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace MeterVision.Station
+{
+    /// <summary>
+    /// UCVpsGrid.xaml 的交互逻辑
+    /// </summary>
+    public partial class UCVpsGrid : UserControl, INotifyPropertyChanged
+    {
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        protected void OnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+        public ObservableCollection<VPatchStation> StationItemList { get; set; }
+
+        public event Action<VPatchStation> OnItemChanged;
+
+        private VPatchStation _selectedItem;
+
+        public VPatchStation SelectedItem
+        {
+            get => _selectedItem;
+            set
+            {
+                if(_selectedItem != value)
+                {
+                    _selectedItem = value;
+                    OnPropertyChanged(nameof(SelectedItem));
+                    OnItemChanged?.Invoke(value);
+                }
+            }
+        }
+
+
+        //要查找的站点ID
+        private string _findStationId;
+        public string FindStationId
+        {
+            get => _findStationId;
+            private set
+            {
+                if (_findStationId != value)
+                {
+                    _findStationId = value;
+                }
+            }
+        }
+
+        private string _patchId;
+        public string PatchId
+        {
+            get => _patchId;
+            private set
+            {
+                if (_patchId != value)
+                {
+                    _patchId = value;
+                }
+            }
+        }
+
+        public void ChangeFind(string stationId, string patchId)
+        {
+            bool blChangeFindStationId = false;
+            bool blChangePatchId = false;
+
+            if (stationId != _findStationId)
+            {
+                FindStationId = stationId;
+                blChangeFindStationId = true;
+            }
+
+            if (patchId != _patchId)
+            {
+                PatchId = patchId;
+                blChangePatchId = true;
+            }
+
+
+            if (blChangeFindStationId || blChangePatchId)
+            {
+                StationPage.InitDefaulValue();
+                LoadStationItemList(true);
+            }
+        }
+
+        public CfginiItem mConfigItem { get; set; }
+
+        public PageModel StationPage { get; set; }
+
+        private int _totalRecords;
+        public int TotalRecords
+        {
+            get => _totalRecords;
+            set
+            {
+                if (_totalRecords != value)
+                {
+                    _totalRecords = value;
+                    OnPropertyChanged(nameof(TotalRecords));
+                }
+            }
+        }
+
+
+
+        public UCVpsGrid()
+        {
+            InitializeComponent();
+            StationItemList = new ObservableCollection<VPatchStation>();
+            dgStation.ItemsSource = StationItemList;
+
+            mConfigItem = CfginiItem.GetConfigItem();
+
+            StationPage = new PageModel
+            {
+                PageSize = mConfigItem.PatchPageSize,
+                PageNumber = 1
+            };
+
+            mConfigItem.OnPatchPageSizeChanged += MConfigItem_OnPatchPageSizeChanged;
+
+            this.DataContext = this;
+        }
+        private void MConfigItem_OnPatchPageSizeChanged(int pageSize)
+        {
+            StationPage.InitDefaulValue(pageSize);
+            LoadStationItemList(true);
+        }
+
+        private async void LoadStationItemList(bool scrollTop)
+        {
+            StationItemList.Clear();
+
+            if (FindStationId == null)
+            {
+                return;
+            }
+
+            try
+            {
+                var result = await Task.Run(() =>
+                {
+                    return DBPatch.GetPagedPatchStations(StationPage.PageNumber, StationPage.PageSize,PatchId);
+                });
+
+                //更新分页信息
+                TotalRecords = result.Item1;
+                StationPage.PageCount = result.Item2;
+                List<VPatchStation> stationList = result.Item3;
+
+                //在主线中更新数据
+                Application.Current.Dispatcher.Invoke(() =>
+                {
+                    int index = 0;
+                    foreach (VPatchStation station in stationList)
+                    {
+                        index++;
+                        //StationItem item = new StationItem(station);
+                        //item.Index = index + ((StationPage.PageNumber - 1) * StationPage.PageSize);
+                        //StationItemList.Add(item);
+                        station.Index = index + ((StationPage.PageNumber - 1) * StationPage.PageSize);
+                    }
+
+                    SelectedItem = null;
+                    if (StationItemList.Count > 0 && scrollTop)
+                    {
+                        dgStation.ScrollIntoView(dgStation.Items[0]);
+                    }
+                });
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(Application.Current.MainWindow,
+                    $"加载数据是发生错误:{ex.Message}", "错误",
+                    MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+            SelectedItem = null;
+        }
+
+
+        public void NextPage()
+        {
+            if (StationPage.PageNumber < StationPage.PageCount)
+            {
+                StationPage.PageNumber += 1;
+                LoadStationItemList(true);
+            }
+        }
+
+        public void PrePage()
+        {
+            if (StationPage.PageNumber > 1)
+            {
+                StationPage.PageNumber -= 1;
+                LoadStationItemList(true);
+            }
+        }
+
+        public void FirstPage()
+        {
+            if (StationPage.PageNumber > 1)
+            {
+                StationPage.PageNumber = 1;
+                LoadStationItemList(true);
+            }
+        }
+
+        public void LastPage()
+        {
+            if (StationPage.PageNumber < StationPage.PageCount)
+            {
+                StationPage.PageNumber = StationPage.PageCount;
+                LoadStationItemList(true);
+            }
+        }
+
+        public void SpeciPage(int pageNumber)
+        {
+            if (pageNumber != StationPage.PageNumber &&
+                pageNumber > 0 && pageNumber <= StationPage.PageCount)
+            {
+                StationPage.PageNumber = pageNumber;
+                LoadStationItemList(true);
+            }
+        }
+
+        //---------------------------------------------------------------------
+    }
+}

+ 98 - 3
MeterVision/db/DBPatch.cs

@@ -246,12 +246,13 @@ namespace MeterVision.db
                 new SQLiteParameter("@DebugInfo", detail.DebugInfo),
                 new SQLiteParameter("@LogPath", detail.LogPath)
             };
-
             // 执行更新操作并返回受影响的行数
             return SQLiteHelper.ExecuteNonQuery(sql, parameters) > 0;
         }
 
 
+
+
         public static bool UpdatePatchDetailStandValue(string patchDetailId,string standValue,int equalFlag)
         {
             string sql = @"
@@ -646,7 +647,9 @@ namespace MeterVision.db
                 stand_name,
                 detail_count, 
                 run_count, 
-                equal_count
+                equal_count,
+                invalid_count,
+                error_count
             FROM v_patch
             WHERE patch_id = @PatchId;";
 
@@ -670,7 +673,9 @@ namespace MeterVision.db
                         StandName = reader["stand_name"].ToString(),
                         DetailCount = reader["detail_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["detail_count"]),
                         RunCount = reader["run_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["run_count"]),
-                        EqualCount = reader["equal_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["equal_count"])
+                        EqualCount = reader["equal_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["equal_count"]),
+                        InvalidCount = reader["invalid_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["invalid_count"]),
+                        ErrorCount = reader["error_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["error_count"]),
                     };
                 }
             }
@@ -678,6 +683,96 @@ namespace MeterVision.db
             return vPatch;
         }
 
+        public static Tuple<int, int, List<VPatchStation>> GetPagedPatchStations(int pageNumber, int pageSize,string patchId)
+        {
+            // 计算偏移量
+            int offset = (pageNumber - 1) * pageSize;
+
+            string sql = @"
+                SELECT patch_id, station_id, total_count, error_count,equal_count, invalid_count
+                FROM v_patch_detail_station 
+                WHERE patch_id = @PatchId OR patch_id = ''
+                ORDER BY station_id ASC  -- 根据需要修改排序字段
+                LIMIT @PageSize OFFSET @Offset;";
+
+            // 定义参数
+            SQLiteParameter[] parameters = new SQLiteParameter[]
+            {
+                new SQLiteParameter("@PatchId", patchId),
+                new SQLiteParameter("@PageSize", pageSize),
+                new SQLiteParameter("@Offset", offset)
+            };
+
+            // 执行查询并读取数据
+            List<VPatchStation> vpsDetails = new List<VPatchStation>();
+            using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(sql, parameters.ToArray()))
+            {
+                while (reader.Read())
+                {
+                    VPatchStation patchDetail = new VPatchStation
+                    {
+                        PatchId = reader.GetString(reader.GetOrdinal("patch_id")),                     
+                        StationId = reader.GetString(reader.GetOrdinal("station_id")),
+                        TotalCount = reader.GetInt32(reader.GetOrdinal("total_count")),
+                        ErrorCount = reader.GetInt32(reader.GetOrdinal("error_count")),
+                        EqualCount = reader.GetInt32(reader.GetOrdinal("equal_count")),
+                        InvalidCount = reader.GetInt32(reader.GetOrdinal("invalid_count"))
+                    };
+                    vpsDetails.Add(patchDetail);
+                }
+            }
+
+            // 获取总记录数,用于计算总页数
+            string countSql = "SELECT COUNT(*) FROM v_patch_detail_station WHERE patch_id = @PatchId OR patch_id = ''";
+            int totalRecords = Convert.ToInt32(SQLiteHelper.GetSingle(countSql, parameters.ToArray()));
+
+            // 计算总页数
+            int totalPages = (int)Math.Ceiling((double)totalRecords / pageSize);
+
+            // 返回总记录数、总页数和分页结果
+            return Tuple.Create(totalRecords, totalPages, vpsDetails);
+        }
+
+        public static VPatchStation GetPatchStation(string patchId,string stationId)
+        {
+            VPatchStation vps = null;
+
+            // 查询 SQL,从 v_patch 视图中获取数据
+            string query = @"
+            SELECT patch_id, station_id, total_count, error_count,equal_count, invalid_count
+            FROM v_patch_detail_station
+            WHERE patch_id = @PatchId AND station_id=@StationId;";
+
+            // 构造参数
+            SQLiteParameter[] parameters = new SQLiteParameter[]
+            {
+                new SQLiteParameter("@PatchId", patchId),
+                new SQLiteParameter("@StationId", stationId),
+            };
+
+            // 执行查询
+            using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(query, parameters))
+            {
+                if (reader.Read())
+                {
+                    vps = new VPatchStation
+                    {
+                        PatchId = reader["patch_id"].ToString(),
+                        StationId = reader["station_id"].ToString(),
+                        TotalCount = reader["total_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["total_count"]),
+                        EqualCount = reader["equal_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["equal_count"]),
+                        ErrorCount = reader["error_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["error_count"]),
+                        InvalidCount = reader["invalid_count"] == DBNull.Value ? 0 : Convert.ToInt32(reader["invalid_count"])
+                    };
+                }
+            }
+
+            return vps;
+        }
+
+
+
+
         //获取所有的识别任务
         public static List<VPatch> GetAllVPatchs()
         {

+ 5 - 5
MeterVision/db/DBStand.cs

@@ -298,7 +298,7 @@ namespace MeterVision.db
                                 new SQLiteParameter("@StationId", standDetail.StationId),
                                 new SQLiteParameter("@DeviceSn", standDetail.DeviceSn),
                                 new SQLiteParameter("@SampleTime",standDetail.SampleTime),
-                                new SQLiteParameter("@NumCount", standDetail.ENumCount),
+                                new SQLiteParameter("@ENumCount", standDetail.ENumCount),
                                 new SQLiteParameter("@ELastUnit", standDetail.ELastUnit),
                             };
                             SQLiteHelper.ExecuteNonQuery(detailSql, detailParams, transaction);
@@ -889,8 +889,8 @@ namespace MeterVision.db
                         stand_id,
                         station_id,
                         device_sn,
-                        MAX(num_count) AS num_count,
-                        MAX(last_unit) AS last_unit
+                        MAX(e_num_count) AS num_count,
+                        MAX(e_last_unit) AS last_unit
                     FROM
                         t_stand_detail
                     WHERE
@@ -916,8 +916,8 @@ namespace MeterVision.db
                             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("e_num_count")),
-                            LastUnit = reader.GetInt32(reader.GetOrdinal("e_last_unit"))
+                            NumCount = reader.GetInt32(reader.GetOrdinal("num_count")),
+                            LastUnit = reader.GetInt32(reader.GetOrdinal("last_unit"))
                         };
                         result.Add(station);
                     }

+ 58 - 5
MeterVision/db/TPatchDetail.cs

@@ -28,7 +28,10 @@ namespace MeterVision.db
         public long CompleteValue { get; set; } //识别后的完整结果
         public int ValueChanged { get; set; }
         public int ResultMeter { get; set; }   //识别后的水表类型
+
+        //0:还未运行比较 1:比较后相等 2:比较后不等 3:比较后识别无效
         public int EqualFlag { get; set; }
+
         public string AiVer { get; set; }
         public string DebugInfo { get; set; }
         public string LogPath { get; set; }
@@ -115,16 +118,20 @@ namespace MeterVision.db
 
             //EqualFlag,这里需要判断,是否相等、约等、不等
             //先简单判断
+            //20250317 delte by djs (无标准值的数据不会进入到这里
             if (string.IsNullOrWhiteSpace(StandValue))
             {
-                EqualFlag = 2;
+                //EqualFlag = 2;
+                EqualFlag = -1; //无标准值可供比较(理论上不会出现这种情况)
             }
             else
             {
                 if (double.TryParse(StandValue, out double dStandValue))
                 {
-                    EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
-                }
+                    //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                    EqualFlag = GetEqualFlag(dStandValue, FinalValue);
+                 
+                }//if
             }
         }
 
@@ -151,14 +158,15 @@ namespace MeterVision.db
             //先简单判断
             if (string.IsNullOrWhiteSpace(StandValue))
             {
-                EqualFlag = 2;
+                EqualFlag = -1;
             }
             else
             {
                 //if (int.TryParse(StandValue, out int iStandValue))
                 if(double.TryParse(StandValue,out double dStandValue))
                 {
-                    EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                    //EqualFlag = CheckEquailityWithStandValue(dStandValue, FinalValue) ? 1 : 0;
+                    EqualFlag = GetEqualFlag(dStandValue, FinalValue);
                 }
             }           
         }
@@ -211,6 +219,51 @@ namespace MeterVision.db
             return isEqual;
         }
 
+        public int GetEqualFlag(double standValue, long finalValue)
+        {
+            bool isEqual = false;
+            //比较结果值与标准值是否相等
+            if (MeterType == ResultMeter)
+            {
+                if (MeterType == 1)
+                {
+                    //数字+指针(只比较数字部分)
+                    //获取真正数据部分的值
+                    int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
+                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                    //isEqual = (standValue1 == finalValue1);
+
+                    //判断如何按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
+
+                    //上面的值,也就规划为数字的整数
+                    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+                    return isEqual ? 1 : 0;
+                }
+                else if (MeterType == 2)
+                {
+                    //全指针
+                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    return isEqual ? 1 : 0;
+                }
+                else if (MeterType == 3)
+                {
+                    //全数字
+                    //return (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    return isEqual ? 1 : 0;
+                }
+                else
+                {
+                    return 2;
+                }
+            }
+            else
+            {
+                return 2;
+            }
+        }
+
         //----------------------------------------------
     }
     ////////////////////////////////////////////////////////////

+ 78 - 0
MeterVision/db/VPatchStation.cs

@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MeterVision.db
+{
+    public class VPatchStation : INotifyPropertyChanged
+    {
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        protected void OnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+
+        public string PatchId{ get; set;}
+
+        public string StationId { get; set; }
+
+        public int TotalCount { get; set; }
+
+        private int _errorCount;
+        public int ErrorCount
+        {
+            get => _errorCount;
+            set
+            {
+                if(_errorCount != value)
+                {
+                    _errorCount = value;
+                    OnPropertyChanged(nameof(ErrorCount));
+                }
+            }
+        }
+
+        private int _equalCount;
+        public int EqualCount
+        {
+            get => _equalCount;
+            set
+            {
+                if (_equalCount != value)
+                {
+                    _equalCount = value;
+                    OnPropertyChanged(nameof(EqualCount));
+                }
+            }
+        }
+
+
+        private int _invalidCount;
+        public int InvalidCount
+        {
+            get => _invalidCount;
+            set
+            {
+                if (_invalidCount != value)
+                {
+                    _invalidCount = value;
+                    OnPropertyChanged(nameof(InvalidCount));
+                }
+            }
+        }
+
+        public int Index { get; set; }
+
+
+        public VPatchStation()
+        {
+
+        }
+        //-------------------------------------------------------
+    }
+}

+ 184 - 77
MeterVision/model/PatchDetailItem.cs

@@ -715,31 +715,60 @@ namespace MeterVision.model
         }
 
 
+        //public string GetEqualFlagName()
+        //{
+        //    if(RunFlag == 1)
+        //    {
+        //        if (string.IsNullOrWhiteSpace(StandValue))
+        //        {
+        //            return "-";
+        //        }
+        //        else
+        //        {
+        //            if (EqualFlag == 1)
+        //            {
+        //                return "√";
+        //            }
+        //            else
+        //            {
+        //                if(MeterType == ResultMeter  && MeterType > 0)
+        //                {
+        //                    return "×";
+        //                }
+        //                else
+        //                {
+        //                    return "∅";
+        //                }
+        //            }
+        //        }
+        //    }
+        //    else
+        //    {
+        //        return "a";
+        //    }
+        //}
+
         public string GetEqualFlagName()
         {
-            if(RunFlag == 1)
+            if (RunFlag == 1)
             {
-                if (string.IsNullOrWhiteSpace(StandValue))
+                if (EqualFlag == 1)
                 {
-                    return "-";
+                    return "√";
+                }
+                else if(EqualFlag == 0)
+                {
+                    //错误的
+                    return "×";
+                }
+                else if(EqualFlag == 2)
+                {
+                    //无效的
+                    return "∅";
                 }
                 else
                 {
-                    if (EqualFlag == 1)
-                    {
-                        return "√";
-                    }
-                    else
-                    {
-                        if(MeterType == ResultMeter  && MeterType > 0)
-                        {
-                            return "×";
-                        }
-                        else
-                        {
-                            return "∅";
-                        }
-                    }
+                    return "";
                 }
             }
             else
@@ -748,32 +777,66 @@ namespace MeterVision.model
             }
         }
 
+        //public string GetEqualFlagColor()
+        //{
+        //    if(RunFlag == 1)
+        //    {
+        //        if (string.IsNullOrWhiteSpace(StandValue))
+        //        {
+        //            //flag = 2
+        //            return "#666666";
+        //        }
+        //        else
+        //        {
+        //            if (EqualFlag == 1)
+        //            {
+        //                //flag = 1
+        //                return "#28a745 ";
+        //            }
+        //            else
+        //            {
+        //                if(MeterType == ResultMeter && MeterType > 0)
+        //                {
+        //                    return "#dc3545 ";
+        //                }
+        //                else
+        //                {
+        //                    return "#FFA500";
+        //                }
+        //            }
+        //        }
+        //    }
+        //    else
+        //    {
+        //        return "666666";
+        //    }
+        //}
+
         public string GetEqualFlagColor()
         {
-            if(RunFlag == 1)
+            if (RunFlag == 1)
             {
                 if (string.IsNullOrWhiteSpace(StandValue))
                 {
-                    //flag = 2
                     return "#666666";
                 }
                 else
                 {
                     if (EqualFlag == 1)
-                    {
-                        //flag = 1
+                    {                 
                         return "#28a745 ";
                     }
+                    else if(EqualFlag == 2)
+                    {
+                        return "#FFA500";
+                    }
+                    else if(EqualFlag == 0)
+                    {
+                        return "#dc3545 ";
+                    }
                     else
                     {
-                        if(MeterType == ResultMeter && MeterType > 0)
-                        {
-                            return "#dc3545 ";
-                        }
-                        else
-                        {
-                            return "#FFA500";
-                        }
+                        return "666666";
                     }
                 }
             }
@@ -913,53 +976,51 @@ namespace MeterVision.model
             return dValue.ToString();
         }
 
-
-
-        public static bool CheckEquailityWithStandValue(string standValue,string finalValue)
-        {
-            ////return standValue.Equals(FinalValue);
-            //string finalValue = FinalValue;
-
-            // 获取整数部分
-            string standIntegerPart = standValue.Split('.')[0];
-            string finalIntegerPart = finalValue.Split('.')[0];
-
-            // 比较整数部分
-            if (standIntegerPart != finalIntegerPart)
-            {
-                return false;
-            }
-
-            // 获取小数部分,若没有小数部分,则默认为空字符串
-            string standDecimalPart = standValue.Contains(".") ? standValue.Split('.')[1] : "";
-            string finalDecimalPart = finalValue.Contains(".") ? finalValue.Split('.')[1] : "";
-
-            // 如果standValue有小数部分,则根据其小数位数调整finalValue的小数部分
-            if (!string.IsNullOrEmpty(standDecimalPart))
-            {
-                // 获取standValue小数部分的位数
-                int decimalPlaces = standDecimalPart.Length;
-
-                // 截取FinalValue的小数部分,或者补充零
-                if (finalDecimalPart.Length > decimalPlaces)
-                {
-                    // 截取多余的小数位
-                    finalDecimalPart = finalDecimalPart.Substring(0, decimalPlaces);
-                }
-                else if (finalDecimalPart.Length < decimalPlaces)
-                {
-                    // 补充零
-                    finalDecimalPart = finalDecimalPart.PadRight(decimalPlaces, '0');
-                }
-
-                // 比较调整后的小数部分
-                return standDecimalPart == finalDecimalPart;
-            }
-
-            // 如果standValue没有小数部分,只比较整数部分
-            return true;
-
-        }
+        //public static bool CheckEquailityWithStandValue(string standValue,string finalValue)
+        //{
+        //    ////return standValue.Equals(FinalValue);
+        //    //string finalValue = FinalValue;
+
+        //    // 获取整数部分
+        //    string standIntegerPart = standValue.Split('.')[0];
+        //    string finalIntegerPart = finalValue.Split('.')[0];
+
+        //    // 比较整数部分
+        //    if (standIntegerPart != finalIntegerPart)
+        //    {
+        //        return false;
+        //    }
+
+        //    // 获取小数部分,若没有小数部分,则默认为空字符串
+        //    string standDecimalPart = standValue.Contains(".") ? standValue.Split('.')[1] : "";
+        //    string finalDecimalPart = finalValue.Contains(".") ? finalValue.Split('.')[1] : "";
+
+        //    // 如果standValue有小数部分,则根据其小数位数调整finalValue的小数部分
+        //    if (!string.IsNullOrEmpty(standDecimalPart))
+        //    {
+        //        // 获取standValue小数部分的位数
+        //        int decimalPlaces = standDecimalPart.Length;
+
+        //        // 截取FinalValue的小数部分,或者补充零
+        //        if (finalDecimalPart.Length > decimalPlaces)
+        //        {
+        //            // 截取多余的小数位
+        //            finalDecimalPart = finalDecimalPart.Substring(0, decimalPlaces);
+        //        }
+        //        else if (finalDecimalPart.Length < decimalPlaces)
+        //        {
+        //            // 补充零
+        //            finalDecimalPart = finalDecimalPart.PadRight(decimalPlaces, '0');
+        //        }
+
+        //        // 比较调整后的小数部分
+        //        return standDecimalPart == finalDecimalPart;
+        //    }
+
+        //    // 如果standValue没有小数部分,只比较整数部分
+        //    return true;
+
+        //}
 
 
         public bool CheckEquailityWithStandValue(int standValue, long finalValue)
@@ -989,6 +1050,52 @@ namespace MeterVision.model
             }
             return isEqual;
         }
+
+
+        public int GetEqualFlag(double standValue, long finalValue)
+        {
+            bool isEqual = false;
+            //比较结果值与标准值是否相等
+            if (MeterType == ResultMeter)
+            {
+                if (MeterType == 1)
+                {
+                    //数字+指针(只比较数字部分)
+                    //获取真正数据部分的值
+                    int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
+                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                    //isEqual = (standValue1 == finalValue1);
+
+                    //判断如何按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
+
+                    //上面的值,也就规划为数字的整数
+                    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+                    return isEqual ? 1 : 0;
+                }
+                else if (MeterType == 2)
+                {
+                    //全指针
+                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    return isEqual ? 1 : 0;
+                }
+                else if (MeterType == 3)
+                {
+                    //全数字
+                    //return (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    return isEqual ? 1 : 0;
+                }
+                else
+                {
+                    return 2;
+                }
+            }
+            else
+            {
+                return 2;
+            }
+        }
         /////////////////////////////
     }
 }