<UserControl x:Class="MeterVision.Patch.UCCompMain"
             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.Patch"
             xmlns:local2="clr-namespace:MeterVision"
             xmlns:zdfflatui="clr-namespace:ZdfFlatUI;assembly=WPF.UI"
             mc:Ignorable="d" 
             Padding="5,2,5,5"
             Background="WhiteSmoke"
             d:DesignHeight="800" d:DesignWidth="1366">
    <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"/>
        </Style>
    </UserControl.Resources>
    <!--整体布局-->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="450" x:Name="colLeft" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <!--左侧-->
        <Border Grid.Column="0" BorderBrush="#C0C0C0" BorderThickness="0 0 1 0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40" />  <!--上部功能区-->
                    <RowDefinition Height="*" />   <!--中间列表区-->
                    <RowDefinition Height="40" />   <!--下部翻页区-->
                </Grid.RowDefinitions>
                
                <!--上部功能按钮区域-->
                <Grid Grid.Row="0" Margin="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <zdfflatui:FlatButton Grid.Column="0" x:Name="btnAddComp" HorizontalAlignment="Center"
                                              Background="#4CAF50" Content="新建比较"
                                                Click="BtnAddComp_Click" Foreground="White"
                                              Width="80" Height="28" FontSize="13" Margin="0 0 5 0" />

                    <zdfflatui:FlatButton Grid.Column="1" x:Name="btnDelComp" HorizontalAlignment="Center"
                                              Background="#FF4C4C" Content="删除比较"
                                                Click="BtnDelComp_Click" Foreground="White"
                                              Width="80" Height="28" FontSize="13" Margin="0 0 5 0" />

                    <zdfflatui:FlatButton Grid.Column="2" x:Name="btnRefresh" HorizontalAlignment="Right"
                                              Background="#2196F3" Foreground="White" Content="🔄"
                                          ToolTip="刷新数据列表"
                                          Click="BtnRefresh_Click" Margin="0 0 10 0"
                                          Width="30" Height="28" FontSize="20px"  />

                </Grid>
                <!--中间DataGrid列表区域-->
                <Border Grid.Row="1" BorderThickness="0" BorderBrush="#C0C0C0" Margin="0 0 5 0">
                    <!--嵌套一个DataGrid-->
                    <DataGrid x:Name="dgComp" GridLinesVisibility="All" HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent"
                              BorderBrush="#D3D3D3" HeadersVisibility="Column" SelectionMode="Single" SelectionUnit="FullRow"
                              HorizontalScrollBarVisibility="Disabled" CanUserReorderColumns="False" RowHeight="NaN"
                              SelectedItem="{Binding SelectedCompItem,Mode=TwoWay}"
                              AutoGenerateColumns="False" CanUserAddRows="False" HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch" Background="White" Padding="5" Margin="0">
                        <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,0,0" />
                                <Setter Property="HorizontalContentAlignment" Value="Center" />
                                <Setter Property="Margin" Value="0 0 0 0" />
                                <Setter Property="Padding" Value="5" />
                            </Style>

                            <!-- 自定义行的选中样式 -->
                            <Style TargetType="DataGridRow">
                                <Style.Triggers>
                                    <!-- 当行被选中时 -->
                                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
                                        <!-- 设置选中行的背景色 -->
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Setter Property="BorderThickness" Value="1" />
                                        <Setter Property="BorderBrush" Value="CornflowerBlue" />
                                    </DataTrigger>
                                </Style.Triggers>
                                <Setter Property="Margin" Value="0,0,5,5"/>
                                <Setter Property="BorderThickness" Value="1" />
                                <Setter Property="BorderBrush" Value="CadetBlue" />
                                <!-- 或者使用 Padding 属性，取决于你想要的效果 -->
                                <!-- <Setter Property="Padding" Value="0,5,0,5"/> -->
                            </Style>
                            <!-- 自定义选中单元格的背景色 -->
                            <Style TargetType="DataGridCell">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
                                        <!-- 设置选中单元格的背景色 -->
                                        <Setter Property="Background" Value="AliceBlue"/>
                                        <Setter Property="BorderBrush" Value="Red" />
                                        <!-- 设置选中单元格的前景色 -->
                                        <!--<Setter Property="Foreground" Value="Black"/>-->
                                    </DataTrigger>
                                </Style.Triggers>
                                <!--<Setter Property="Foreground" Value="White" />-->
                                <Setter Property="BorderBrush" Value="SeaGreen" />
                                <Setter Property="BorderThickness" Value="0" />
                            </Style>
                        </DataGrid.Resources>

                        <DataGrid.ContextMenu>
                            <ContextMenu>
                                <MenuItem x:Name="miDeletePatch" Header="删除比较" Click="MiDeleteCompr_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 Width="*">
                                <DataGridTemplateColumn.Header>
                                    <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=TotalCompRecords,
                                        StringFormat='比较列表 （共 {0} 个）',Mode=OneWay}" />
                                </DataGridTemplateColumn.Header>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" Margin="5 5 10 5">
                                            <StackPanel Orientation="Horizontal" Margin="0 0 0 5">
                                                <TextBlock Text="{Binding Index,StringFormat='{}{0}.'}" FontSize="14px" Foreground="#000000" />
                                            </StackPanel>
                                            
                                            <Border HorizontalAlignment="Stretch" BorderBrush="#D3D3D3" BorderThickness="0 0 0 1" Padding="0" Margin="0">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="40" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>

                                                    <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                                                        <TextBlock Text="新：" FontSize="14px" Foreground="#666666" />
                                                        <TextBlock Text="{Binding NPatchName}" FontSize="14px" Foreground="#000000" TextWrapping="Wrap"/>
                                                    </StackPanel>

                                                    <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Margin="0 5 0 5">
                                                        <TextBlock Text="{Binding NPatchTimeName}" FontSize="14px" Foreground="#666666" />
                                                    </StackPanel>

                                                    <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" Margin="0 5 0 5">
                                                        <TextBlock Text="正确率：" FontSize="14px" Foreground="#666666" />
                                                        <TextBlock FontSize="14px" Foreground="#000000">
                                                            <TextBlock.Text>
                                                                <MultiBinding StringFormat="{}{0}/{1} ({2:p1})">
                                                                    <Binding Path="NPatchEqualCount" />
                                                                    <Binding Path="NPatchDetailCount"/>
                                                                    <Binding Path="NPatchEqualRate"/>
                                                                </MultiBinding>
                                                            </TextBlock.Text>
                                                        </TextBlock>
                                                    </StackPanel>

                                                    <StackPanel Grid.Column="1" Grid.RowSpan="3" Orientation="Horizontal">
                                                        <TextBlock Text="VS" HorizontalAlignment="Center" VerticalAlignment="Center"                                                                    
                                                                   FontSize="14px" Foreground="Red" />
                                                    </StackPanel>

                                                    <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal">
                                                        <TextBlock Text="旧：" FontSize="14px" Foreground="#666666" />
                                                        <TextBlock Text="{Binding OPatchName}" FontSize="14px" Foreground="#000000"  TextWrapping="Wrap"/>
                                                    </StackPanel>

                                                    <StackPanel Grid.Row="1" Grid.Column="2" Orientation="Horizontal">
                                                        <TextBlock Text="{Binding OPatchTimeName}" FontSize="14px" Foreground="#666666" Margin="0 5 0 5"/>
                                                    </StackPanel>

                                                    <StackPanel Grid.Row="2" Grid.Column="2" Orientation="Horizontal" Margin="0 5 0 5">
                                                        <TextBlock Text="正确率：" FontSize="14px" Foreground="#666666" />
                                                        <TextBlock FontSize="14px" Foreground="#000000">
                                                            <TextBlock.Text>
                                                                <MultiBinding StringFormat="{}{0}/{1} ({2:p1})">
                                                                    <Binding Path="OPatchEqualCount" />
                                                                    <Binding Path="OPatchDetailCount"/>
                                                                    <Binding Path="OPatchEqualRate"/>
                                                                </MultiBinding>
                                                            </TextBlock.Text>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </Grid>
                                            </Border>

                                            <!--来自模板-->
                                            <StackPanel Orientation="Horizontal" Margin="0 5 0 5">
                                                <TextBlock Text="来自模板：" FontSize="14px" Foreground="#666666" />
                                                <TextBlock Text="{Binding StandName}" FontSize="14px" Foreground="#000000" />
                                                <TextBlock Text="{Binding StandCount,StringFormat='[{0}]'}" FontSize="14px" Foreground="#000000" />
                                            </StackPanel>
                                            
                                        </StackPanel>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                        
                    </DataGrid>
                </Border>
                <!--下部翻页控制区-->
                <Grid Grid.Row="2" Background="WhiteSmoke">
                    <StackPanel Grid.Row="2" Height="35" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0">

                        <Button x:Name="btnPatchPrePage" Content="上一页" Width="55" Margin="5" FontSize="13px" Click="BtnCompPrePage_Click"/>
                        <!--<TextBlock Text="2/10" Margin="5" FontSize="13px" VerticalAlignment="Center"/>-->
                        <StackPanel Orientation="Vertical" Margin="5" VerticalAlignment="Center">
                            <!--<TextBlock Text="{Binding TotalPatchRecords,StringFormat='共 {0} 条'}" HorizontalAlignment="Center"  FontSize="13px"/>-->
                            <TextBlock Margin="0" FontSize="13px" VerticalAlignment="Center" HorizontalAlignment="Center">
                                <TextBlock.Text>
                                    <!--<MultiBinding StringFormat="{}{0}/{1}页">-->
                                    <MultiBinding StringFormat="第{0}/{1}页">
                                        <Binding Path="PatchPage.PageNumber"/>
                                        <Binding Path="PatchPage.PageCount"/>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </StackPanel>
                        <Button x:Name="btnPatchNextPage" Content="下一页" Width="55" Margin="5" FontSize="13px" Click="BtnCompNextPage_Click"/>
                    </StackPanel>
                </Grid>
                
            </Grid>
        </Border>
        
        <!--右侧-->
        <Border Grid.Column="1" BorderBrush="#D3D3D3" BorderThickness="0 0 1 0" Padding="0 0 5 0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="40" />
                </Grid.RowDefinitions>
                <!--右上功能按钮区-->
                <Grid Grid.Row="0">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="5 0 2 0">
                        <Button Content="◀️" x:Name="btnLeftCtl" FontSize="20px" Width="28" Height="28" Visibility="Visible"
                                Click="BtnLeftCtl_Click"
                               Foreground="White" Background="#333333" Margin="0 0 5 0" />

                        <TextBlock x:Name="txtCompName" Text="请选择左侧比较" FontSize="14px" FontWeight="Bold" VerticalAlignment="Center" />
                        <!--<TextBlock Text="[2024-10-23 10:25:39]" FontSize="13px"  VerticalAlignment="Center" Margin="2 0 0 0"/>-->
                    </StackPanel>
                    <StackPanel x:Name="pnlDetailFunc" Orientation="Horizontal" HorizontalAlignment="Right">
                        <TextBlock Text="筛选条件" VerticalAlignment="Center" Margin="0 0 5 0" 
                                   Foreground="Black" FontSize="14px" FontWeight="Normal"/>
                        <ComboBox Grid.Column="1" x:Name="cmbRunFlag" FontSize="13px" Foreground="#000000" 
                                      DisplayMemberPath="Value" SelectedValuePath="Key" Width="110"
                                      ItemsSource="{Binding CompFindTypeKVs}"
                                      SelectedValue="{Binding SelectedCompFindType,Mode=TwoWay}"                                        
                                      Margin="0,0,10,0" Padding="4" VerticalAlignment="Center"/>

                        <!--ItemsSource="{x:Static local:ConfigItem.RulerDigitList}"-->

                        <!--<zdfflatui:FlatButton x:Name="btnStartTask" HorizontalAlignment="Right"
                                              Click="BtnStartTask_Click"
                                              Background="#2196F3" Content="开始批量任务" Foreground="White"
                                              Width="100" Height="28" FontSize="13" Margin="0 0 5 0" />-->

                        <zdfflatui:FlatButton Grid.Column="2" x:Name="btnRefreshDetail" HorizontalAlignment="Center"
                                              Background="#2196F3" Foreground="White" Content="🔄"
                                          ToolTip="刷新数据列表"
                                          Click="BtnRefreshDetail_Click" Margin="0 0 10 0"
                                          Width="30" Height="28" FontSize="20px"  />

                        <!--<Button Content="▶️" x:Name="btnRightCtl" FontSize="20px" Width="28" Height="28" Visibility="Visible"
                                Click="BtnRightCtl_Click"
                               Foreground="White" Background="#333333" Margin="0 0 5 0" />-->
                    </StackPanel>
                </Grid>
                <!--中间比较列表DataGrid-->
                <Border Grid.Row="1">
                    <local:UCCompGrid x:Name="ucCompGird" Padding="5 5 5 5" />
                </Border>
                <!--底部分页控件-->
                <StackPanel Grid.Row="2" Height="35" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0">
                    <!--<TextBlock Text="共 100 条数据" Margin="5" VerticalAlignment="Center" FontSize="13px"/>-->
                    <TextBlock Text="{Binding ElementName=ucCompGird,Path=TotalRecords,StringFormat='共 {0} 条数据'}" Margin="5" VerticalAlignment="Center" FontSize="13px"/>
                    <ComboBox Width="55" Margin="5" FontSize="13px" 
                              ItemsSource="{x:Static local2:ThisApp.PageSizeOptions}"
                              SelectedValue="{Binding mConfigItem.PatchPageSize}"/>
                    <Button x:Name="btnCompDetailFirstPage" Content="首页" Width="55" Margin="5" FontSize="13px" Click="BtnCompDetailFirstPage_Click"/>
                    <Button x:Name="btnCompDetailPrePage" Content="上一页" Width="55" Margin="5" FontSize="13px" Click="BtnCompDetailPrePage_Click"/>
                    <!--<TextBlock Text="第 2 页 / 共 10 页" Margin="5" FontSize="13px" VerticalAlignment="Center"/>-->
                    <TextBlock  Margin="5" FontSize="13px" VerticalAlignment="Center">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="第 {0} 页 / 共 {1} 页">
                                <Binding ElementName="ucCompGird" Path="PatchDetailPage.PageNumber"/>
                                <Binding ElementName="ucCompGird" Path="PatchDetailPage.PageCount"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                    <Button x:Name="btnCompDetailNextPage" Content="下一页" Width="55" Margin="5" FontSize="13px" Click="BtnCompDetailNextPage_Click"/>
                    <Button x:Name="btnCompDetailLastPage" Content="尾页" Width="55" Margin="5" FontSize="13px" Click="BtnCompDetailLastPage_Click"/>
                    <TextBox x:Name="txtCompDetailPageNumber" Width="55" Margin="5" TextAlignment="Center" FontSize="13px"
                             Text="{Binding ElementName=ucCompGird,Path=CompDetailPage.PageNumber,Mode=OneWay}"
                             MaxLength="5" PreviewTextInput="TextBox_PreviewTextInput" VerticalContentAlignment="Center"/>
                    <Button x:Name="btnCompDetailSpeciPage" Content="跳转" Width="55" Margin="5" FontSize="13px" Click="BtnCompDetailSpeciPage_Click"/>
                </StackPanel>
            </Grid>
        </Border>
                
        
        
        
    </Grid>
</UserControl>
