<UserControl x:Class="SlnMesnac.WPF.Views.StatisticsPageView"
             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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:SlnMesnac.WPF.Views"
             mc:Ignorable="d" 
             d:DesignHeight="900" d:DesignWidth="1920">
    <UserControl.Resources>
        <cvt:IsCheckedConverter x:Key="IsCheckedConverter"/>
        <cvt:IsSuccessConverter x:Key="IsSuccessConverter"/>
        <cvt:MultiBindingConverter x:Key="QueryConvert"></cvt:MultiBindingConverter>
        <Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="FontSize" Value="18"/>
        </Style>


        <!-- 定义样式 -->
        <Style x:Key="CustomDatePicker" TargetType="DatePicker">

            <!-- 设置背景颜色 -->
            <Setter Property="Background" Value="LightBlue"></Setter>
            <!-- 设置边框颜色 -->
            <Setter Property="BorderBrush" Value="DarkBlue"></Setter>
            <!-- 设置字体样式 -->
            <Setter Property="FontSize" Value="14"></Setter>
            <!-- 设置前景色（文本颜色） -->
            <Setter Property="Foreground" Value="Black"></Setter>


        </Style>


        <!-- 定义日历的样式 -->
        <Style x:Key="CustomCalendarStyle" TargetType="Calendar">
            <!-- 设置背景颜色 -->
            <Setter Property="Background" Value="White"></Setter>
            <!-- 设置边框颜色 -->
            <Setter Property="BorderBrush" Value="Blue"></Setter>

            <Setter Property="Width" Value="250"></Setter>
            <Setter Property="Height" Value="250"></Setter>
            <!-- 设置字体样式 -->
            <Setter Property="FontSize" Value="12"></Setter>
        </Style>


        <Style TargetType="DataGrid">
            <!--网格线颜色-->
            <Setter Property="CanUserResizeColumns" Value="false"/>
            <Setter Property="Background" Value="#1152AC" />
            <Setter Property="BorderBrush" Value="#4285DE" />
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="HorizontalGridLinesBrush">
                <Setter.Value>
                    <SolidColorBrush Color="#4285DE"/>
                </Setter.Value>
            </Setter>
            <Setter Property="VerticalGridLinesBrush">
                <Setter.Value>
                    <SolidColorBrush Color="#1152AC"/>
                </Setter.Value>
            </Setter>
        </Style>
        <!--列头标题栏样式-->
        <Style TargetType="DataGridColumnHeader">
            <!--<Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>-->
            <!--<Setter Property="Background" Value="#dddddd"/>
            <Setter Property="Foreground" Value="Black"/>-->
            <!--<Setter Property="BorderThickness" Value="1" />-->
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="BorderBrush" Value="#dddddd" />
            <Setter Property="Height" Value="40"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="Background" Value="#4285DE"/>
            <Setter Property="Foreground" Value="White"/>
        </Style>

        <!--单元格样式-->
        <Style TargetType="DataGridCell">
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="BorderBrush" Value="#4285DE" />
            <Setter Property="Height" Value="40"/>
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid Background="{TemplateBinding Background}" >
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="#4285DE"/>
                    <Setter Property="Foreground" Value="#dddddd"/>
                </Trigger>
            </Style.Triggers>

        </Style>
    </UserControl.Resources>


    <Border Grid.Row="1" Grid.Column="1" BorderBrush="#0288d1" BorderThickness="2" CornerRadius="5" Background="Transparent" Margin="5">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="0.8*"/>
                <RowDefinition Height="9*"/>
            </Grid.RowDefinitions>
            <!--<Border Grid.Row="0" BorderBrush="CadetBlue" BorderThickness="0,0,0,1" CornerRadius="0" Background="Transparent" Margin="1,1,5,5" >
                <TextBlock Text="绑定记录" FontSize="20" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Border>-->
            <Border Grid.Row="0" BorderBrush="#0288d1" BorderThickness="0,0,0,1" CornerRadius="0" Background="#1157b9" Margin="1,1,5,5" >
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Button x:Name="listButton" Margin="100 0 0 0"
                            Content="历史记录" Background="#FF1752E1"
                            Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Click="list_Click">

                    </Button>
                    <Button x:Name="modelButton" Margin="10 0 0 0" Background="#FF384E83"
                            Content="型号统计" 
                            Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Click="model_Click">

                    </Button>
                </StackPanel>
            </Border>
            <Border Grid.Row="1" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
                <Grid Margin="10,5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="8*"/>
                    </Grid.RowDefinitions>
                    <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Center">
                        <TextBlock Text="开始时间"   Margin="10 0" Foreground="White" FontSize="20"  VerticalAlignment="Center"/>

                        <DatePicker  Style="{StaticResource CustomDatePicker}"
                            x:Name="BeginTime" FontSize="20"  
                            Width="170"  Margin="10 0"  BorderBrush="White"
                            materialDesign:CalendarAssist.IsHeaderVisible="False">
                            <DatePicker.SelectedDate >
                                <Binding
                                        Path="BeginDate"
                                        UpdateSourceTrigger="PropertyChanged">
                                    <Binding.ValidationRules>
                                    </Binding.ValidationRules>
                                </Binding>
                            </DatePicker.SelectedDate>

                        </DatePicker>

                        <TextBlock Text="结束时间" Margin="10 0" Foreground="White" FontSize="20"  VerticalAlignment="Center"/>
                        <DatePicker  Style="{StaticResource CustomDatePicker}"
                            x:Name="EndTime"  Margin="10 0"  
                            Width="170"  BorderBrush="White" FontSize="20"
                            materialDesign:CalendarAssist.IsHeaderVisible="False">
                            <DatePicker.SelectedDate>
                                <Binding
                                        Path="EndDate"
                                        UpdateSourceTrigger="PropertyChanged">
                                    <Binding.ValidationRules>
                                    </Binding.ValidationRules>
                                </Binding>
                            </DatePicker.SelectedDate>
                        </DatePicker>

                        <Button Margin="10 0"
                            Content="时间查询"  Command="{Binding QueryCommand}"
                            Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}">
                            <Button.CommandParameter>
                                <MultiBinding Converter="{StaticResource QueryConvert}">
                                    <Binding ElementName="BeginTime" Path="Text"/>
                                    <Binding ElementName="EndTime"  Path="Text"/>
                                </MultiBinding>
                            </Button.CommandParameter>
                        </Button>
                        <TextBox Background="AliceBlue" Text="{Binding QueryCode}"  Margin="50 0 10 0" Foreground="Black" FontSize="20" Width="280" VerticalAlignment="Center"/>
                        <Button
                            Content="型号/条码查询"  Command="{Binding QueryCodeCommand}"
                            Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}">
                            <Button.CommandParameter>
                                <MultiBinding Converter="{StaticResource QueryConvert}">
                                    <Binding ElementName="BeginTime" Path="Text"/>
                                    <Binding ElementName="EndTime"  Path="Text"/>
                                </MultiBinding>
                            </Button.CommandParameter>
                        </Button>
                        <ComboBox Width="70" Margin="70 0 20 0" Background="White" Foreground="Green" SelectedItem="{Binding SelectedOption}">
                            <ComboBoxItem Content="OK" />
                            <ComboBoxItem Content="NG" />
                            <ComboBoxItem Content="" />
                        </ComboBox>
                        <Button
                            Content="结果查询"  Command="{Binding QueryResultCommand}"
                            Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}">
                        </Button>
                        <TextBlock  Text="记录数:"  Foreground="White" FontSize="25" Margin="250 0 0 0"/>
                        <TextBlock  Text="{Binding LogoIdentifyDataGrid.Count}"  Foreground="White" FontSize="25" Margin="10 0 0 0"/>
                    </WrapPanel>
                   
                    <UniformGrid Grid.Row="1">
                        <DataGrid x:Name="listDataGrid"  Grid.Row="0" ItemsSource="{Binding LogoIdentifyDataGrid}" Background="#00000000" 
                       ColumnHeaderHeight="35"   Height="{Binding Path=ActualHeight, ElementName=ScanPanel}" 
                      RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0"  FontSize="20"
                      GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto"  LoadingRow="dgvMH_LoadingRow"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"  BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
                      Foreground="White"  >
                            <!--修改选中字体颜色-->
                            <DataGrid.Columns>
                                <DataGridTemplateColumn  Width="55" Header="序号"  >
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTextColumn Binding="{Binding ProductCode}" Header="产品条码" Width="2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}"/>
                                <DataGridTextColumn Binding="{Binding MaterialType}" Header="产品型号" Width="2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding MaterialName}" Header="产品名称" Width="2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding isChecked, Converter={StaticResource IsCheckedConverter}}" Header="是否检测" Width="*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding Result, Converter={StaticResource IsSuccessConverter}}" Header="检测结果" Width="*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding RecordTime,StringFormat=\{0:yyyy-MM-dd HH:mm:ss\}}" Header="扫描时间" Width="1.5*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}"/>

                            </DataGrid.Columns>
                        </DataGrid>


                        <DataGrid x:Name="modelDataGrid" Visibility="Collapsed" Grid.Row="0" ItemsSource="{Binding ModelDataGrid}" Background="#00000000" 
                       ColumnHeaderHeight="35"   Height="{Binding Path=ActualHeight, ElementName=ScanPanel}" 
                      RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0"  FontSize="20"
                      GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto"  LoadingRow="dgvMH_LoadingRow"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"  BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
                      Foreground="White"  >
                            <!--修改选中字体颜色-->
                            <DataGrid.Columns>

                                <DataGridTextColumn Binding="{Binding No}" Header="序号" Width="0.3*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding MaterialType}" Header="产品编码" Width="2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding ProductName}" Header="产品型号" Width="3*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding IsChecked, Converter={StaticResource IsCheckedConverter}}" Header="是否检测" Width="*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding PassAmount}" Header="通过数" Width="1.2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding TotalAmount}" Header="总数量" Width="1.2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding PassRate}" Header="通过率" Width="1.2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />

                            </DataGrid.Columns>
                        </DataGrid>
                    </UniformGrid>
                </Grid>
            </Border>
        </Grid>
    </Border>
</UserControl>
