<UserControl x:Class="SlnMesnac.WPF.Page.IndexPage.HistorySearch"
             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:local="clr-namespace:SlnMesnac.WPF.Page.IndexPage"
             xmlns:cvt2="clr-namespace:SlnMesnac.WPF.Converter.Generate"
             mc:Ignorable="d" 
             d:DesignHeight="900" d:DesignWidth="1620" Background="Transparent">
    <UserControl.Resources>
        <!--<converters:IsCheckedConverter x:Key="IsCheckedConverter"/>-->
        <!-- 定义样式 -->
        <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 x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="FontSize" Value="18"/>
        </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="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="50"/>
                <RowDefinition Height="9*"/>
            </Grid.RowDefinitions>

            <Border Grid.Row="0" BorderBrush="#0288d1" BorderThickness="0,0,0,1" CornerRadius="0" Background="#1157b9" Margin="1,1,5,5" >
                <TextBlock Text="历史记录" FontSize="25" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </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="70"/>
                        <RowDefinition Height="4*"/>
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="horizontal" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <Label Content="MES订单号:"  FontSize="20" Foreground="Black"/>
                        <TextBox IsReadOnly="False" IsEnabled="True"  Text="{Binding MesOrderNo,Mode=TwoWay}" Width="250" FontSize="20" Foreground="Black" Margin="0 0 30 0" />
                        <Label Content="写入状态"  FontSize="20" Foreground="Black"/>

                        <ComboBox Width="70" Height="30" FontSize="20" SelectedItem="{Binding QueryIsCheck,Mode=TwoWay}" Margin="10,0,30,0" Foreground="Black">
                            <ComboBoxItem Content="成功" Background="White" Foreground="#4285DE"/>
                            <ComboBoxItem Content="失败"  Foreground="#4285DE"/>
                            <ComboBoxItem Content=""  Foreground="#4285DE"/>
                        </ComboBox>


                        <TextBlock Text="开始时间"   Margin="10 0" Foreground="Black" FontSize="20"  VerticalAlignment="Center"/>

                        <DatePicker  Style="{StaticResource CustomDatePicker}"
     x:Name="BeginTime" FontSize="20"  
     Width="170"  Margin="10 0"  BorderBrush="Black">
                            <!--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="Black" FontSize="20"  VerticalAlignment="Center"/>
                        <DatePicker  Style="{StaticResource CustomDatePicker}"
     x:Name="EndTime"  Margin="10 0"  
     Width="170"  BorderBrush="Black" FontSize="20">
                            <!--materialDesign:CalendarAssist.IsHeaderVisible="False">-->
                            <DatePicker.SelectedDate>
                                <Binding
                 Path="EndDate"
                 UpdateSourceTrigger="PropertyChanged">
                                    <Binding.ValidationRules>
                                    </Binding.ValidationRules>
                                </Binding>
                            </DatePicker.SelectedDate>
                        </DatePicker>
                        <Button Content="查询" Width="100" FontSize="20" Command="{Binding GetOrderInfoCommand}" CommandParameter="{Binding Name,ElementName=Search}"
                            Background="#009999" Style="{StaticResource  BUTTON_AGREE}" Margin="0,0,20,0"/>
                        <Button Content="导出" Width="100" FontSize="20" Command="{Binding ExportCommand}" CommandParameter="{Binding Name,ElementName=Search}"
                            Background="#009999" Style="{StaticResource  BUTTON_AGREE}" />
                    </StackPanel>
                    <UniformGrid Grid.Row="1">
                        <DataGrid x:Name="listDataGrid"  Grid.Row="0" ItemsSource="{Binding realreaddata}" Background="#00000000" 
                       ColumnHeaderHeight="35"   Height="{Binding Path=ActualHeight, ElementName=ScanPanel}" 
                      RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0"  FontSize="20"
                      GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" 
                      ScrollViewer.VerticalScrollBarVisibility="Auto"  BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
                      Foreground="Black"  >
                            <DataGrid.Columns>
                                <DataGridTextColumn Binding="{Binding objid}" Header="序号" Width="0.5*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}"/>
                                <DataGridTextColumn Binding="{Binding orderno}" Header="订单号" Width="1.2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding lineno}" Header="产线号" Width="0.5*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding producttype}" Header="产品类型" Width="2*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding rfidepc}" Header="原始EPC" Width="1.1*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding rfidascii}" Header="RFID编码" Width="3*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />
                                <DataGridTextColumn Binding="{Binding readtime,StringFormat=\{0:yyyy-MM-dd HH:mm:ss\}}" Header="读取时间" Width="1.5*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}"/>
                                <DataGridTextColumn Binding="{Binding writetime,StringFormat=\{0:yyyy-MM-dd HH:mm:ss\}}" Header="写入时间" Width="1.5*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}"/>

                                <!--<DataGridTextColumn Binding="{Binding writestatus}" Header="写入状态" Width="1*" ElementStyle="{StaticResource  DataGridTextColumnCenterSytle}" />-->
                                <DataGridTemplateColumn Header="写入状态" Width="1*">
                                    <DataGridTemplateColumn.CellStyle>
                                        <Style TargetType="DataGridCell">
                                            <Setter Property="HorizontalAlignment" Value="Center"/>
                                            <Setter Property="VerticalAlignment" Value="Center"/>
                                            <Setter Property="Background" Value="Transparent"/>
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="DataGridCell">
                                                        <Border Background="{TemplateBinding Background}"
                                BorderThickness="0"
                                Padding="5">
                                                            <ContentPresenter VerticalAlignment="Center" 
                                              HorizontalAlignment="Center"/>
                                                        </Border>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                            <Style.Triggers>
                                                <!-- 成功：绿色文字 -->
                                                <DataTrigger Binding="{Binding writestatus}" Value="成功">
                                                    <Setter Property="Foreground" Value="#FF008000"/>
                                                </DataTrigger>
                                                <!-- 失败：红色文字 -->
                                                <DataTrigger Binding="{Binding writestatus}" Value="失败">
                                                    <Setter Property="Foreground" Value="#FFFF0000"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </DataGridTemplateColumn.CellStyle>
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding writestatus}" 
                       HorizontalAlignment="Center" 
                       VerticalAlignment="Center"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>


                    </UniformGrid>

                </Grid>
            </Border>
        </Grid>
    </Border>


</UserControl>
