<fw:BaseWindow x:Class="Com.FirmLib.UI.Seller.WinSupplyAssetSelector"
             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:fw="http://schemas.FWind/xaml"
             xmlns:uc="clr-namespace:Com.FirmLib.UI.Common"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:wpf="clr-namespace:SAGA.DotNetUtils.WPF;assembly=SAGA.DotNetUtils"
               xmlns:dgx="urn:tom-englert.de/DataGridExtensions"
             Name="this" Title="选择供应资产"
               Height="550" Width="600" WindowStartupLocation="CenterOwner">
    <fw:BaseWindow.Resources>
        <fw:BindingProxy x:Key="DATA" Data="{Binding}"></fw:BindingProxy>
    </fw:BaseWindow.Resources>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="30"></RowDefinition>
        </Grid.RowDefinitions>
        <TabControl x:Name="TabControl" SelectionChanged="TabControl_SelectionChanged">
            <TabItem Header="系统推荐" DataContext="{Binding RecommendAssetSelecter,Mode=OneWay}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition  Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <!--搜索框-->
                    <wpf:SearchInputEditor  Grid.Row="0" Text="{Binding FilterName,Mode=TwoWay}"  WaterText="输入资产本地名称进行搜索" Command="{Binding Commands.SearchCommand}" Margin="0,5,0,5" VerticalAlignment="Center" HorizontalAlignment="Stretch" >
                    </wpf:SearchInputEditor>

                    <DataGrid  Grid.Row="1" dgx:DataGridFilter.IsAutoFilterEnabled="True" AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Data.RecommendAssetItems,Source={StaticResource ResourceKey=DATA}}"
                CanUserAddRows="False"
                CanUserDeleteRows="False"
                VerticalScrollBarVisibility="Auto"
                HorizontalScrollBarVisibility="Auto"
                SelectionUnit="FullRow"
                HeadersVisibility="Column" 
                CanUserSortColumns="True"   
                CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                  AlternationCount="2"
                >
                        <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow" BasedOn="{StaticResource ResourceKey={x:Type DataGridRow}}">
                                <Setter Property="Height" Value="30"></Setter>
                                <Style.Triggers>

                                    <Trigger Property="ItemsControl.AlternationIndex"
                                 Value="0">
                                        <Setter Property="Background" Value="White" />
                                    </Trigger>
                                    <Trigger Property="ItemsControl.AlternationIndex"
                                 Value="1">
                                        <Setter Property="Background" Value="#FFE6E3DD" />
                                    </Trigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=Item.IsEnabled }" Value="False">
                                        <Setter Property="Background" Value="GreenYellow" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Width="30" dgx:DataGridFilterColumn.IsFilterVisible="False">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Command="{Binding Data.Commands.SelectedAssetChanged,Source={StaticResource ResourceKey=DATA}}" CommandParameter="{Binding }" IsEnabled="{Binding IsEnabled}" HorizontalAlignment="Center" VerticalAlignment="Center">

                                        </CheckBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <fw:TDataGridTextColumn Header="资产本地名称" Width="120" IsReadOnly="True"  Binding="{Binding Path=LocalName}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="资产本地编码"  Width="120" IsReadOnly="True"  Binding="{Binding Path=LocalCode}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="资产编码"  Width="100" IsReadOnly="True"  Binding="{Binding Path=AssetNo}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="品牌"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Brand}"></fw:TDataGridTextColumn>

                            <fw:TDataGridTextColumn Header="产品名"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Product}"></fw:TDataGridTextColumn>

                            <fw:TDataGridTextColumn Header="型号"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Type}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="供应商名称"  Width="100" IsReadOnly="True"  Binding="{Binding Path=SellerName}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="所属合同编码"  Width="120" IsReadOnly="True"  Binding="{Binding Path=SellerContractNo}"></fw:TDataGridTextColumn>


                        </DataGrid.Columns>

                    </DataGrid>

                    <fw:NavigationPager Margin="5"  CurrentPageIndex="{Binding CurrentPageIndex,Mode=TwoWay}" TotalPageCount="{Binding PageCount,Mode=OneWay}" Grid.Row="2"  HorizontalAlignment="Right" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PageIndexChanged">
                                <i:InvokeCommandAction Command="{Binding Commands.PageIndexChangedCommand}" CommandParameter="{Binding Path=CurrentPageIndex}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </fw:NavigationPager>
                </Grid>

            </TabItem>

            <TabItem Header="全部资产" DataContext="{Binding AllAssetSelecter,Mode=OneWay}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition  Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <!--搜索框-->
                    <wpf:SearchInputEditor  Grid.Row="0" Text="{Binding FilterName,Mode=TwoWay}"  WaterText="输入资产本地名称进行搜索" Command="{Binding Commands.SearchCommand}" Margin="0,5,0,5" VerticalAlignment="Center" HorizontalAlignment="Stretch" >
                    </wpf:SearchInputEditor>

                    <DataGrid dgx:DataGridFilter.IsAutoFilterEnabled="True"  Grid.Row="1"  AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Data.AllAssetItems,Source={StaticResource ResourceKey=DATA}}"
                CanUserAddRows="False"
                CanUserDeleteRows="False"
                VerticalScrollBarVisibility="Auto"
                HorizontalScrollBarVisibility="Auto"
                SelectionUnit="FullRow"
                HeadersVisibility="Column" 
                CanUserSortColumns="True"   
                CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                               
                  AlternationCount="2"
                >
                        <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow" BasedOn="{StaticResource ResourceKey={x:Type DataGridRow}}">
                                <Setter Property="Height" Value="30"></Setter>
                                <Style.Triggers>

                                    <Trigger Property="ItemsControl.AlternationIndex"
                                 Value="0">
                                        <Setter Property="Background" Value="White" />
                                    </Trigger>
                                    <Trigger Property="ItemsControl.AlternationIndex"
                                 Value="1">
                                        <Setter Property="Background" Value="#FFE6E3DD" />
                                    </Trigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=Item.IsEnabled }" Value="False">
                                        <Setter Property="Background" Value="GreenYellow" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>
                        <DataGrid.Columns>
                            <DataGridTemplateColumn dgx:DataGridFilterColumn.IsFilterVisible="False"  Width="30">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Command="{Binding Data.Commands.SelectedAssetChanged,Source={StaticResource ResourceKey=DATA}}" CommandParameter="{Binding }" IsEnabled="{Binding IsEnabled}" HorizontalAlignment="Center" VerticalAlignment="Center">

                                        </CheckBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <fw:TDataGridTextColumn    Header="资产本地名称" Width="120" IsReadOnly="True"  Binding="{Binding Path=LocalName}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn   Header="资产本地编码"  Width="120" IsReadOnly="True"  Binding="{Binding Path=LocalCode}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn   Header="资产编码"  Width="100" IsReadOnly="True"  Binding="{Binding Path=AssetNo}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn   Header="品牌"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Brand}"></fw:TDataGridTextColumn>

                            <fw:TDataGridTextColumn   Header="产品名"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Product}"></fw:TDataGridTextColumn>

                            <fw:TDataGridTextColumn  Header="型号"  Width="100" IsReadOnly="True"  Binding="{Binding Path=Type}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn  Header="供应商名称"  Width="100" IsReadOnly="True"  Binding="{Binding Path=SellerName}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn  Header="所属合同编码"  Width="120" IsReadOnly="True"  Binding="{Binding Path=SellerContractNo}"></fw:TDataGridTextColumn>


                        </DataGrid.Columns>

                    </DataGrid>

                    <fw:NavigationPager Margin="5"  CurrentPageIndex="{Binding CurrentPageIndex,Mode=TwoWay}" TotalPageCount="{Binding PageCount,Mode=OneWay}" Grid.Row="2"  HorizontalAlignment="Right">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PageIndexChanged">
                                <i:InvokeCommandAction Command="{Binding Commands.PageIndexChangedCommand}" CommandParameter="{Binding Path=CurrentPageIndex}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </fw:NavigationPager>
                </Grid>
            </TabItem>

        </TabControl>

        <TextBlock Grid.Row="1" Margin="0,5" Text="{Binding SelectedAssetCount,StringFormat=选中{0}}" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
        <StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Button Command="{Binding Commands.EnsureCommand}" CommandParameter="{Binding ElementName=this}"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"  Height="23" Width="60"   Content="确定" Click="btnOK_Click"/>

        </StackPanel>
    </Grid>
</fw:BaseWindow>
