<UserControl x:Class="VIZ.Package.Module.PackageTaskView"
             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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:fcore="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
             xmlns:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
             xmlns:storage="clr-namespace:VIZ.Package.Storage;assembly=VIZ.Package.Storage"
             xmlns:resource="clr-namespace:VIZ.Package.Module.Resource;assembly=VIZ.Package.Module.Resource"
             xmlns:local="clr-namespace:VIZ.Package.Module"
             xmlns:domain="clr-namespace:VIZ.Package.Domain;assembly=VIZ.Package.Domain"
             d:DataContext="{d:DesignInstance Type=local:PackageTaskViewModel}" 
             mc:Ignorable="d" x:Name="uc"
             d:DesignHeight="45" d:DesignWidth="800">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Package.Module.Resource;component/Style/IconButton/IconButton_Default.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <fcore:Bool2ImageSourceConverter x:Key="Bool2ImageSourceConverter"
                                             TrueResult="/VIZ.Package.Module.Resource;component/Icons/status_runing_32x32.png"
                                             FalseResult="/VIZ.Package.Module.Resource;component/Icons/status_pause_32x32.png"
                                             NullResult="/VIZ.Package.Module.Resource;component/Icons/status_pause_32x32.png"></fcore:Bool2ImageSourceConverter>
            <fcore:Bool2BoolConverter x:Key="Bool2BoolConverter"></fcore:Bool2BoolConverter>
            <fcore:StringNotNull2VisibilityConverter x:Key="StringNotNull2VisibilityConverter"></fcore:StringNotNull2VisibilityConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <dxg:GridControl ItemsSource="{Binding Path=ItemsSource}" ShowBorder="False">
            <dxg:GridControl.Columns>
                <dxg:GridColumn Header="编号" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="40" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Row.ID}" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="状态" FieldName="Status" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="80" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="20" Height="20" Margin="0,3,0,3" HorizontalAlignment="Center" VerticalAlignment="Center"
                                   Source="{Binding Path=Row.IsRunning,Converter={StaticResource Bool2ImageSourceConverter}}"></Image>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="名称" FieldName="Name" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
                <dxg:GridColumn Header="备注" FieldName="Remark" AllowSorting="False" AllowColumnFiltering="False">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings AcceptsReturn="False"></dxe:TextEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="页编号" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"
                                       Text="{Binding Row.PageModel.PageNum,StringFormat={}{0:D4}}"></TextBlock>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="场景" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                Binding="{Binding Path=PageModel.Scene,Mode=OneWay}"></dxg:GridColumn>
                <dxg:GridColumn Header="层" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                Binding="{Binding Path=PageModel.Layer,Mode=OneWay}"></dxg:GridColumn>
                <dxg:GridColumn Header="插件" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                Binding="{Binding Path=PageModel.PluginName,Mode=OneWay}"></dxg:GridColumn>
                <dxg:GridColumn Header="更新间隔（秒）" FieldName="Interval" AllowResizing="False" AllowColumnFiltering="False" Width="100">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings MaskType="Numeric" HorizontalContentAlignment="Left"></dxe:TextEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="预览更新时间" ReadOnly="True"
                                AllowResizing="False" Width="100">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Row.PreviewUpdateTime,StringFormat=hh:mm:ss}"
                                       VerticalAlignment="Center" Margin="3,0,3,0"></TextBlock>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="版子更新时间" ReadOnly="True"
                                AllowResizing="False" Width="100">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Row.TakeUpdateTime,StringFormat=hh:mm:ss}"
                                       VerticalAlignment="Center" Margin="3,0,3,0"></TextBlock>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="更新预览" FieldName="IsPreviewEnabled" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="80">
                    <dxg:GridColumn.EditSettings>
                        <dxe:CheckEditSettings></dxe:CheckEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="更新版子" FieldName="IsTakeEnabled" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="80">
                    <dxg:GridColumn.EditSettings>
                        <dxe:CheckEditSettings></dxe:CheckEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="错误信息" FieldName="Status" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="80" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="20" Height="20" Margin="0,3,0,3" HorizontalAlignment="Center" VerticalAlignment="Center"
                                   Source="/VIZ.Package.Module.Resource;component/Icons/message_32x32.png"
                                   ToolTip="{Binding Path=Row.ErrorMessage}"
                                   Visibility="{Binding Path=Row.ErrorMessage,Converter={StaticResource StringNotNull2VisibilityConverter}}"></Image>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn Header="更新信息" FieldName="Status" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="80" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="20" Height="20" Margin="0,3,0,3" HorizontalAlignment="Center" VerticalAlignment="Center"
                                   Source="/VIZ.Package.Module.Resource;component/Icons/message_32x32.png"
                                   ToolTip="{Binding Path=Row.UpdateMessage}"
                                   Visibility="{Binding Path=Row.UpdateMessage,Converter={StaticResource StringNotNull2VisibilityConverter}}"></Image>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn AllowSorting="False" AllowColumnFiltering="False"
                                AllowResizing="False" Width="100" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                <fcommon:IconButton Style="{StaticResource IconButton_Menu_Mask}"
                                                    Icon="/VIZ.Package.Module.Resource;component/Icons/icon_play_32x32.png"
                                                    IsEnabled="{Binding Path=Row.IsRunning,Converter={StaticResource Bool2BoolConverter}}"
                                                    Command="{Binding ElementName=uc,Path=DataContext.StartCommand}"
                                                    CommandParameter="{Binding Row}"
                                                    ToolTip="开始"></fcommon:IconButton>
                                <fcommon:IconButton Style="{StaticResource IconButton_Menu_Mask}" Margin="10,0,0,0"
                                                    Icon="/VIZ.Package.Module.Resource;component/Icons/icon_pause_32x32.png"
                                                    IsEnabled="{Binding Path=Row.IsRunning}"
                                                    Command="{Binding ElementName=uc,Path=DataContext.StopCommand}"
                                                    CommandParameter="{Binding Row}"
                                                    ToolTip="停止"></fcommon:IconButton>
                            </StackPanel>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView IsColumnMenuEnabled="False" RowMinHeight="32"
                               AllowEditing="True" ShowIndicator="False"
                               NavigationStyle="Cell" ShowVerticalLines="False"
                               ShowGroupPanel="False" EditorShowMode="MouseDown"
                               AllowDragDrop="True"
                               ShowBandsPanel="False"
                               ShowTotalSummary="False"
                               ShowFixedTotalSummary="False"
                               ShowDragDropHint="False"
                               ShowTargetInfoInDragDropHint="false">
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</UserControl>
