<fw:NChildWindow x:Class="Com.FirmLib.UI.Maintainer.WinMaintainerInfo"
             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 ></RowDefinition>
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <ListBox Grid.Row="0" Grid.Column="0" BorderThickness="0" VerticalAlignment="Center" 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">
                                                    <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>
                        <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button IsEnabled="False" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"   Height="23"  Margin="5" Content="管理设备族常见问题"/>
                            <Button Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}" Command="{Binding Commands.AddProductTypeCommand}"  Height="23" Margin="5" Content="添加维修型号" />
                        </StackPanel>
                    </Grid>



                 <DataGrid Grid.Row="1" Grid.Column="0"   AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Root.CurrentItem.Nodes}"
                CanUserAddRows="False"
                CanUserDeleteRows="False"
                VerticalScrollBarVisibility="Auto"
                HorizontalScrollBarVisibility="Auto"
                SelectionUnit="FullRow"
                HeadersVisibility="Column" 
                CanUserSortColumns="True"  
                           dgx:DataGridFilter.IsAutoFilterEnabled="True"
                CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                  AlternationCount="2"
                >
                        <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>
                                        <StackPanel Orientation="Horizontal">
                                            <Button  Command="{Binding Data.Commands.ScanProductTypeCommand,Source={StaticResource ResourceKey=DATA} }" CommandParameter="{Binding}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}"   Content="查看" HorizontalAlignment="Left" Padding="5,0,5,0"/>
                                            <Button Command="{Binding Data.Commands.EditProductTypeCommand,Source={StaticResource ResourceKey=DATA} }" CommandParameter="{Binding}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}"   Content="编辑型号" HorizontalAlignment="Left" Padding="5,0,5,0"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>

                            </DataGridTemplateColumn>
                            <fw:TDataGridTextColumn Header="品牌" Width="100" IsReadOnly="True"  Binding="{Binding Path=RefItem.BrandName}"></fw:TDataGridTextColumn>
                            <fw:TDataGridTextColumn Header="产品名"  Width="*" IsReadOnly="True"  Binding="{Binding Path=RefItem.Products,Converter={x:Static wpf:ConverterFactory.ItemsToString}}"></fw:TDataGridTextColumn>

                            <fw:TDataGridTextColumn Header="型号"  Width="*" IsReadOnly="True"  Binding="{Binding Path=RefItem.ProductTypes,Converter={x:Static wpf:ConverterFactory.ItemsToString}}"></fw:TDataGridTextColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
        </TabControl>

        <GroupBox Grid.Row="2" Grid.Column="0"  Margin="-5,0,-5,0" 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.AddProjectAsset}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"  Height="23" Margin="10" Content="新项目添加维护设备" />
                </StackPanel>
                <ListBox Grid.Row="1" ItemsSource="{Binding ProjectAssetItems}" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                    <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="170" 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 ValidityAssetCount}" 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 NearOutDateAssetCount}" 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>

