<fw:NChildWindow x:Class="Com.FirmLib.UI.Seller.WinSellerInfo"
             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:wpf="clr-namespace:FWindSoft.Wpf;assembly=FWindSoft.Wpf"
             xmlns:uc="clr-namespace:Com.FirmLib.UI.Common"
                 xmlns:bllCommon="clr-namespace:Com.FirmLib.UI.BllCommon"
                 xmlns:dgx="urn:tom-englert.de/DataGridExtensions"
             mc:Ignorable="d" Title="供应商信息"
             d:DesignHeight="300" d:DesignWidth="500" Name="this" Height="{Binding Height,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UIElement}}"
                 Width="{Binding ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ScrollContentPresenter}}" >
    <fw:NChildWindow.Resources>
        <wpf:BindingProxy x:Key="DATA" Data="{Binding}"></wpf:BindingProxy>
    </fw:NChildWindow.Resources>
    <fw:NChildWindow.AttachElement>
        <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal" VerticalAlignment="Center">
            <Button Command="{Binding Data.Commands.SaveCommand,Source={StaticResource ResourceKey=DATA}}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"  BorderThickness="0"  FontFamily="{DynamicResource ResourceKey={x:Static wpf:FontsUtil.AwesomeKey}}">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{wpf:FontIcon Icon=Save}"  Width="30" FontSize="20"></TextBlock>
                        <TextBlock Text="保存" VerticalAlignment="Center" Margin="-5,0,0,0"></TextBlock>
                    </StackPanel>
                </Button.Content>
            </Button>
        </StackPanel>

    </fw:NChildWindow.AttachElement>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition MinHeight="150" MaxHeight="300"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" 
                    VerticalAlignment="Center" HorizontalAlignment="Left" Width="200">

            <fw:TextBoxEditor Text="{Binding Name,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"  VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5"
                              Command="{x:Static bllCommon:EditCommands.SingleUpdate}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Tag="Name"></fw:TextBoxEditor>

            <fw:TextBoxEditor Text="{Binding Url,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"   VerticalAlignment="Center" HorizontalAlignment="Stretch"  Margin="5"
                              Command="{x:Static bllCommon:EditCommands.SingleUpdate}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Tag="Url"></fw:TextBoxEditor>

        </StackPanel>
        <TabControl Grid.Row="1" Grid.Column="0" IsEnabled="True">
            <TabItem Header="供应产品目录">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition ></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition Width="110"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <ListBox Grid.Row="0" BorderThickness="0" VerticalAlignment="Center" Grid.Column="0" ItemsSource="{Binding Root.Items}" SelectedItem="{Binding Root.CurrentItem,Mode=TwoWay}">
                            <ListBox.ItemsPanel >
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" Width="{Binding Path=Width,RelativeSource={RelativeSource AncestorType=ListBox}}"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="{x:Type ListBoxItem}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                <StackPanel Orientation="Horizontal">
                                                    <Border x:Name="BTN" BorderThickness="0,1,1,1"  BorderBrush="#D1D1D1">
                                                        <TextBlock x:Name="TXT"   Text="{Binding RefItem.Name}"  Margin="5" Opacity="0.8"></TextBlock>
                                                    </Border>
                                                   
                                                </StackPanel>
                                                <ControlTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}"
                                                 Value="{x:Null}">
                                                        <Setter TargetName="BTN" Property="BorderThickness" Value="1,1,1,1"></Setter>
                                                    </DataTrigger>
                                                    <Trigger Property="IsSelected" Value="True">
                                                        <Setter TargetName="BTN" Property="Background" Value="#63B8FF"></Setter>
                                                        <Setter TargetName="TXT" Property="Foreground" Value="Black"></Setter>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>
                        <Button Grid.Column="1" Grid.Row="0" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}" Command="{Binding Commands.AddProductTypeCommand}"  Height="23"  Margin="10,5" Content="添加供应型号"/>

                    </Grid>

                    <ListBox Grid.Row="1" Grid.Column="0" BorderThickness="0"  ItemsSource="{Binding Root.CurrentItem.Nodes}" SelectedItem="{Binding Root.CurrentItem.CurrentItem,Mode=TwoWay}" SelectionChanged="ListBox_SelectionChanged">
                        <ListBox.ItemsPanel >
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" Width="{Binding Path=Width,RelativeSource={RelativeSource AncestorType=ListBox}}"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="|" x:Name="Txt"></TextBlock>
                                                <TextBlock Margin="5,0,5,0" x:Name="TXTN" Text="{Binding RefItem.Name}" Foreground="Blue"  TextDecorations="Underline">
                                                </TextBlock>
                                            </StackPanel>
                                            <ControlTemplate.Triggers>
                                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}"
                                                 Value="{x:Null}">
                                                    <Setter TargetName="Txt" Property="Visibility" Value="Collapsed"></Setter>
                                                </DataTrigger>
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter TargetName="TXTN" Property="Foreground" Value="Black"></Setter>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>

                    <DataGrid Name="ProductTypeGrid" Grid.Row="2" Grid.Column="0"    AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Root.CurrentItem.CurrentItem.Nodes}"
                CanUserAddRows="False"
                CanUserDeleteRows="False"
                VerticalScrollBarVisibility="Auto"
                HorizontalScrollBarVisibility="Auto"
                IsReadOnly="True"
                SelectionUnit="Cell"
                HeadersVisibility="Column" 
                CanUserSortColumns="True"   
                              dgx:DataGridFilter.IsAutoFilterEnabled="True"
                  AlternationCount="2"
                >
                        <DataGrid.CellStyle >
                            <Style TargetType="DataGridCell" BasedOn="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}">
                                <Setter Property="IsEnabled"  Value="False"></Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{ Binding Column.DisplayIndex,RelativeSource={RelativeSource Self}}"  Value="0">
                                        <Setter Property="IsEnabled" Value="True"></Setter>
                                    </DataTrigger>
                                     <DataTrigger Binding="{ Binding Column.DisplayIndex,RelativeSource={RelativeSource Self}}"  Value="1">
                                        <Setter Property="IsEnabled" Value="True"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.CellStyle >
                        <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow">
                                <Setter Property="ContextMenu">
                                    <Setter.Value>
                                        <ContextMenu>
                                            <MenuItem Header="删除供应型号" Command="{Binding Data.Commands.DeleteCommand,Source={StaticResource ResourceKey=DATA}}" CommandParameter="{Binding }"></MenuItem>
                                        </ContextMenu>
                                    </Setter.Value>
                                </Setter>
                                <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>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="操作"  Width="100" IsReadOnly="True" >
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <!--IsEnabled="False",暂时没有这个功能，所以置灰，190917，mxg-->
                                            <Button 
                                            IsEnabled="False"
                                            Command="{Binding DataContext.Commands.ManageCommand,ElementName=this}" CommandParameter="{Binding }"
                                                Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}" 
                                                VerticalAlignment="Center"   Content="查看型号详情" HorizontalAlignment="Left" Padding="5,0,5,0"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>

                            </DataGridTemplateColumn>
                            <fw:TDataGridTextColumn Header="型号" Width="100" IsReadOnly="True"  Binding="{Binding Path=RefItem.TypeName}"></fw:TDataGridTextColumn>

                        </DataGrid.Columns>
                    
                    </DataGrid>
                </Grid>
            </TabItem>
        </TabControl>
     
        <GroupBox Grid.Row="2" Grid.Column="0"  Margin="0,10,0,10" Header="该厂家供应产品的所有项目"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.GroupBoxKey}}"  >

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition ></RowDefinition>
                </Grid.RowDefinitions>
                <StackPanel HorizontalAlignment="Right">
                    <Button Command="{Binding Commands.AddContract}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"  Height="23" Margin="10" Content="新项目添加供应合同" />
                </StackPanel>
                <ListBox Grid.Row="1" ItemsSource="{Binding ProjectItems}" BorderThickness="0" Padding="-5,0,-5,0">
                    <ListBox.ItemsPanel >
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal" Width="{Binding Path=Width,RelativeSource={RelativeSource AncestorType=ListBox}}"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="{x:Type ListBoxItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Border BorderThickness="1"  BorderBrush="Black" Margin="5" Padding="5" fw:MaskOptions.IsManualHide="true" fw:MaskOptions.IsShow="{Binding IsLoading}">
<fw:MaskOptions.MaskTemplate>
                                            <ControlTemplate>
                                                <Border Background="Gray" Opacity="0.5">
                                                    <ProgressBar  VerticalAlignment="Center" Margin="5" IsIndeterminate="True"></ProgressBar>
                                                </Border>
                                            </ControlTemplate>
                                        </fw:MaskOptions.MaskTemplate>

                                            <Grid Width="150" Height="80" >
                                                <Grid.RowDefinitions>
                                                    <RowDefinition></RowDefinition>
                                                    <RowDefinition Height="Auto"></RowDefinition>
                                                </Grid.RowDefinitions>
                                                <StackPanel Orientation="Vertical" Grid.Row="0">
                                                    <Grid>
                                                        <TextBlock Margin="5,0,5,0" Name="TxtName" FontSize="20" Text="{Binding ProjectLocalName}"></TextBlock>
                                                         <Button  HorizontalAlignment="Right" VerticalAlignment="Center" Content="刷新" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}" Command="{Binding Data.Commands.RefreshCommand,Source={StaticResource ResourceKey=DATA}}" CommandParameter="{Binding}" ></Button>
                                                    </Grid>
                                                 
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Margin="5,0,5,0"  Text="涉及供应合同："  />
                                                        <TextBlock Margin="5,0,5,0" x:Name="TXTN" Text="{Binding ContractCount}" TextDecorations="Underline"/>
                                                        <TextBlock Margin="5,0,5,0"  Text="个" />
                                                    </StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Margin="5,0,5,0"  Text="涉及供应资产："  />
                                                        <TextBlock Margin="5,0,5,0"  Text="{Binding AssetCount}" TextDecorations="Underline"/>
                                                        <TextBlock Margin="5,0,5,0"  Text="个" />
                                                    </StackPanel>
                                                </StackPanel>
                                                <Button Grid.Row="1" Grid.Column="0" x:Name="BTNU" HorizontalAlignment="Right" Content="进入项目" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}" Command="{Binding Data.Commands.GoToProject,Source={StaticResource ResourceKey=DATA}}" CommandParameter="{Binding}" ></Button>
                                            </Grid>
                                        </Border>

                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
            </Grid>
         
        </GroupBox>
    </Grid>
</fw:NChildWindow>

