<Page x:Class="FLY.Thick.FilmCasting.UI.DbViewer.PgSelect"
      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:FLY.Thick.FilmCasting.UI.DbViewer"
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
      mc:Ignorable="d" 
      d:DesignHeight="600" d:DesignWidth="800"
      Title="PageSelect" d:DataContext="{d:DesignInstance local:PgSelectVm}">
    <Page.Resources>

    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <StackPanel>
            <TextBlock Text="查找" Margin="{StaticResource ControlMargin}" FontSize="{StaticResource FontSize.H1}" />
            <StackPanel Margin="{StaticResource ControlMargin}">
                <TextBlock FontSize="{StaticResource FontSize.H3}" Text="数据库" />
                <TextBlock Text="{Binding ErrorMsg}" Margin="{StaticResource ControlMargin}">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="{StaticResource MahApps.Brushes.Accent}"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsDbErr}" Value="true">
                                    <Setter Property="Foreground" Value="{StaticResource MahApps.Brushes.Control.Validation}"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </StackPanel>
            <StackPanel Margin="{StaticResource ControlMargin}">
                
                <StackPanel Orientation="Horizontal" >
                    <TextBlock FontSize="{StaticResource FontSize.H4}" Margin="{StaticResource ControlMargin}">
                        数据源:<Run Text="{Binding MonthPath,Mode=OneWay}"/>
                    </TextBlock>
                    <Button Style="{StaticResource MahApps.Styles.Button.Square}" Margin="{StaticResource ControlMargin}" Padding="{StaticResource Padding.Button}" Content="选择数据源" Command="{Binding SelectMonthPathCmd}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Margin="{StaticResource ControlMargin}">
                        <Run Text="{Binding DbBeginTime,Mode=OneWay}"/>~<Run Text="{Binding DbEndTime,Mode=OneWay}"/>
                    </TextBlock>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel>
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <DatePicker
                                    Width="200"
                                            Margin="{StaticResource ControlMargin}"
                                            HorizontalAlignment="Center"
                                            HorizontalContentAlignment="Stretch"
                                            controls:TextBoxHelper.UseFloatingWatermark="True"
                                            controls:TextBoxHelper.Watermark="开始日期"
                                            controls:TextBoxHelper.WatermarkAlignment="Right" 
                                            DisplayDateStart="{Binding DbBeginTime,Mode=OneWay}"
                                            DisplayDateEnd="{Binding DbEndTime,Mode=OneWay}"
                                            SelectedDate="{Binding BeginDate}"/>
                                <DatePicker Grid.Column="1"
                                            Width="200"
                                            Margin="{StaticResource ControlMargin}"
                                            HorizontalAlignment="Center"
                                            HorizontalContentAlignment="Stretch"
                                            controls:TextBoxHelper.UseFloatingWatermark="True"
                                            controls:TextBoxHelper.Watermark="结束日期"
                                            controls:TextBoxHelper.WatermarkAlignment="Right" 
                                            DisplayDateStart="{Binding DbBeginTime,Mode=OneWay}"
                                            DisplayDateEnd="{Binding DbEndTime,Mode=OneWay}"
                                            SelectedDate="{Binding EndDate}"/>
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBox Margin="{StaticResource ControlMargin}" 
                         controls:TextBoxHelper.ButtonCommand="{Binding SearchCmd}"
                         controls:TextBoxHelper.ClearTextButton="True"
                         controls:TextBoxHelper.UseFloatingWatermark="True"
                         controls:TextBoxHelper.Watermark="输入产品名称查找"
                                 Text="{Binding ProductNameFilter}">
                                    <TextBox.InputBindings>
                                        <KeyBinding Key="Return" 
                                    Command="{Binding ButtonSearch, Mode=OneWay}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TextBox}, Path=Text, Mode=OneWay}" />
                                    </TextBox.InputBindings>
                                    <TextBox.Style>
                                        <Style BasedOn="{StaticResource MahApps.Styles.TextBox}" TargetType="{x:Type TextBox}">
                                            <Style.Triggers>
                                                <Trigger Property="controls:TextBoxHelper.HasText" Value="True">
                                                    <Setter Property="controls:TextBoxHelper.ButtonContent" Value="r" />
                                                    <Setter Property="controls:TextBoxHelper.ButtonContentTemplate" Value="{x:Null}" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBox.Style>
                                </TextBox>
                                <TextBox Grid.Column="1" Margin="{StaticResource ControlMargin}" 
                         controls:TextBoxHelper.ButtonCommand="{Binding SearchCmd}"
                         controls:TextBoxHelper.ClearTextButton="True"
                         controls:TextBoxHelper.UseFloatingWatermark="True"
                         controls:TextBoxHelper.Watermark="输入批号查找"
                                 Text="{Binding BatchFilter}">
                                    <TextBox.InputBindings>
                                        <KeyBinding Key="Return" 
                                    Command="{Binding ButtonSearch, Mode=OneWay}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TextBox}, Path=Text, Mode=OneWay}" />
                                    </TextBox.InputBindings>
                                    <TextBox.Style>
                                        <Style BasedOn="{StaticResource MahApps.Styles.TextBox}" TargetType="{x:Type TextBox}">
                                            <Style.Triggers>
                                                <Trigger Property="controls:TextBoxHelper.HasText" Value="True">
                                                    <Setter Property="controls:TextBoxHelper.ButtonContent" Value="r" />
                                                    <Setter Property="controls:TextBoxHelper.ButtonContentTemplate" Value="{x:Null}" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBox.Style>
                                </TextBox>
                            </Grid>
                            
                        </StackPanel>
                        
                        <Button Style="{StaticResource Styles.Button.Circle.Accent}" Margin="{StaticResource ControlMargin}" Grid.Column="1" VerticalAlignment="Bottom" Command="{Binding SearchCmd}">
                            <iconPacks:Material Kind="Magnify" />
                        </Button>
                    </StackPanel>
                    <StackPanel Grid.Column="1" Margin="0,-25,0,0">
                        <StackPanel Orientation="Horizontal">
                            <Button Style="{StaticResource Styles.Button.Circle.Accent}" Command="{Binding DeleteCmd}">
                                <iconPacks:MaterialDesign Height="25" Width="25"
                                           Kind="Delete" />
                            </Button>
                        </StackPanel>
                        <StackPanel  Orientation="Horizontal">
                            <controls:ToggleSwitch 
                                           Header="静止数据"
                                       Margin="{StaticResource ControlMargin}"
                                       IsOn="{Binding IsJustRunning}"
                                       OffContent="包含"
                                       OnContent="不含"
                                       Style="{StaticResource MahApps.Styles.ToggleSwitch}" />
                            <Button Style="{StaticResource Styles.Button.Circle.Accent}" VerticalAlignment="Bottom" Command="{Binding OkCmd}">
                                <iconPacks:PackIconFontAwesome Width="40" Height="40"
                                           Kind="CheckCircleSolid" />
                            </Button>
                        </StackPanel>
                    </StackPanel>

                </Grid>

            </StackPanel>
        </StackPanel>
        <Button VerticalAlignment="Top" HorizontalAlignment="Right" Style="{StaticResource Styles.Button.Circle.Accent}" Margin="{StaticResource ControlMargin}" Grid.Column="1"  Command="BrowseBack">
            <iconPacks:PackIconMaterial Kind="ArrowLeft" />
        </Button>
        <DataGrid Grid.Row="1" x:Name="dgridProfiles" AutoGenerateColumns="False" IsReadOnly="True" 
                  ItemsSource="{Binding Profiles}"
                      RowStyle="{StaticResource MahApps.Styles.DataGridRow}"
                      
                  SelectionUnit="FullRow"
                      >

            <DataGrid.Style>
                <Style BasedOn="{StaticResource MahApps.Styles.DataGrid}" TargetType="{x:Type DataGrid}">
                    <Setter Property="AlternatingRowBackground" Value="{StaticResource MahApps.Brushes.Gray10}" />
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding PName}" Header="产品名称"/>
                <DataGridTextColumn Binding="{Binding Batch}" Header="批号"/>
                <DataGridTextColumn Binding="{Binding Number}" Header="卷号"/>
                <DataGridTextColumn Binding="{Binding StartTime}" Header="开始时间"/>
                <DataGridTextColumn Binding="{Binding EndTime}" Header="结束时间"/>
                <DataGridTextColumn Binding="{Binding IsFinished}" Header="已完成"/>
                <DataGridTextColumn Binding="{Binding Target}" Header="目标值"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Page>
