<fw:NChildWindow x:Class="Com.FirmLib.UI.Insuer.WinInsurancePolicyEditor"
             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:ui="clr-namespace:Com.FirmLib.UI"
             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}}" Click="btnOK_Click">
                <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 Height="Auto"></RowDefinition>
            <RowDefinition MinHeight="100" ></RowDefinition>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="200">
                <Label  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.StarLableKey}}" Content="保单编号:"></Label>

                <TextBox IsEnabled="{Binding PolicyFixed,Converter={x:Static fw:ConverterFactory.BoolOpposition}}"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.TextBoxKey}}" Margin="5">
                    <Binding Path="PolicyNo" Mode="TwoWay" UpdateSourceTrigger="LostFocus" >
                        <Binding.ValidationRules>
                            <fw:RequireValidationRule ></fw:RequireValidationRule>
                             <fw:LengthValidationRule MaxLength="50" ></fw:LengthValidationRule>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox>
                <Label  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.StarLableKey}}" Content="保单截止日期:"></Label>
                <DatePicker    Margin="5">
                    <DatePicker.SelectedDate>
                        <Binding Path="PolicyEndDate" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{x:Static wpf:DateTimeConverter.Date}">
                            <Binding.ValidationRules>
                                <fw:RequireValidationRule ValidationStep="ConvertedProposedValue"></fw:RequireValidationRule>
                            </Binding.ValidationRules>
                        </Binding>
                    </DatePicker.SelectedDate>
                </DatePicker>

                <Label  Content="保险文件:"></Label>

                <Grid  HorizontalAlignment="Stretch"  IsEnabled="{Binding IsEpire,Converter={x:Static fw:ConverterFactory.BoolOpposition}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBox Text="{Binding PolicyFile.Name}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.TextBoxKey}}" IsReadOnly="True" Margin="5">
                    </TextBox>
                    <Button Command="{Binding Commands.UploadCommand}" Grid.Column="1" Content="上传" Width="40" Height="23"></Button>
                </Grid>


                <Label  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.StarLableKey}}" Content="所属项目:"></Label>

                <TextBox IsEnabled="{Binding ProjectFixed,Converter={x:Static fw:ConverterFactory.BoolOpposition}}"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.TextBoxKey}}" Margin="5">
                    <Binding Path="ProjectNo" Mode="TwoWay" UpdateSourceTrigger="LostFocus" >
                        <Binding.ValidationRules>
                            <fw:RequireValidationRule ></fw:RequireValidationRule>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox>

                <Label   Content="项目本地名称:"></Label>

                <TextBlock  Margin="5" Text="{Binding LocalProjectName}">
                </TextBlock>
            </StackPanel>

            <StackPanel Grid.Column="1">
                <Label   Content="" Margin="1"></Label>
                <Button Margin="5" Command="{Binding Commands.SelectPolicyCommand}" IsEnabled="{Binding PolicyFixed,Converter={x:Static fw:ConverterFactory.BoolOpposition}}"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}"  VerticalAlignment="Center"   Content="从项目已有保单中选择" HorizontalAlignment="Left" Padding="5,0,5,0"/>
            </StackPanel>
        </Grid>


        <GroupBox IsEnabled="{Binding ProjectFixed,Converter={x:Static fw:ConverterFactory.BoolOpposition}}" Grid.Row="1" Grid.Column="0"  Margin="0,10,0,10" Header="保险商联系信息"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.GroupBoxKey}}"  >

            <ui:ContactInformationInput DataContext="{Binding ContactItem}" Width="200" HorizontalAlignment="Left"></ui:ContactInformationInput>

        </GroupBox>
        <GroupBox IsEnabled="{Binding IsEpire,Converter={x:Static fw:ConverterFactory.BoolOpposition}}" 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" Orientation="Horizontal">
                    <Button IsEnabled="True" Command="{Binding Commands.SelectAssetCommand}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"  Height="23" Margin="5" Content="选择项目内已存在的资产" />
                </StackPanel>
                <DataGrid Grid.Row="1"  AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding AssetItems,UpdateSourceTrigger=PropertyChanged}"
                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="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>
                                    <Button Command="{Binding Data.Commands.ScanAsset,Source={StaticResource ResourceKey=DATA} }" CommandParameter="{Binding}" Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.LinkButtonKey}}"   Content="查看资产详情" Padding="5,0,5,0"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>

                        </DataGridTemplateColumn>
                        <fw:TDataGridTextColumn Header="本地名称" Width="100" IsReadOnly="True"  Binding="{Binding Path=LocalName}"></fw:TDataGridTextColumn>
                        <fw:TDataGridTextColumn Header="本地编码"  Width="100" IsReadOnly="True"  Binding="{Binding Path=LocalCode}"></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>

                    </DataGrid.Columns>
                </DataGrid>
                </Grid>
        </GroupBox>
    </Grid>
</fw:NChildWindow>

