<Window
    x:Class="Rdh.SocketServer.Client.Views.MainWindowView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Rdh.SocketServer.Client.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:model="clr-namespace:Rdh.SocketServer.Client.Models"
    xmlns:prism="http://prismlibrary.com/"
    xmlns:viewmodels="clr-namespace:Rdh.SocketServer.Client.ViewModels"
    Title="电子药箱服务端"
    Width="800"
    Height="450"
    d:DataContext="{d:DesignInstance Type=viewmodels:MainWindowViewModel}"
    prism:ViewModelLocator.AutoWireViewModel="True"
    mc:Ignorable="d">
    <Window.Resources>
        <Style TargetType="DataGrid">
            <Setter Property="BorderThickness" Value="0" />
        </Style>
    </Window.Resources>
    <Grid Margin="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TabControl>
            <TabItem Header="有效数据">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <DataGrid
                        AutoGenerateColumns="False"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"
                        IsReadOnly="True"
                        ItemsSource="{Binding Pockets}"
                        SelectedValue="{Binding SelectedData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                        <DataGrid.Columns>
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding ReceivedTime, StringFormat='yyyy-MM-dd HH:mm:ss'}"
                                Header="接收时间" />
                            <DataGridTextColumn
                                Width="100"
                                Binding="{Binding ClientIP}"
                                Header="药箱IP" />
                            <DataGridTextColumn
                                Width="100"
                                Binding="{Binding Data.ProtocolDataInfo.EleMedKitCode}"
                                Header="药箱编号" />
                            <DataGridTextColumn
                                Width="100"
                                Binding="{Binding Data.ProtocolDataInfo.Command}"
                                Header="数据类型" />
                            <DataGridTextColumn
                                Width="*"
                                Binding="{Binding Data.ContentSource}"
                                Header="内容" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <StackPanel
                        Grid.Row="1"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                        <Button
                            Padding="20,5"
                            Command="{Binding DeleteDataCommand}"
                            Content="删除所选数据" />
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="无效数据">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <DataGrid
                        AutoGenerateColumns="False"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"
                        IsReadOnly="True"
                        ItemsSource="{Binding InvalidPockets}">
                        <DataGrid.Columns>
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding ReceivedTime, StringFormat='yyyy-MM-dd HH:mm:ss'}"
                                Header="接收时间" />
                            <DataGridTextColumn
                                Width="100"
                                Binding="{Binding ClientIP}"
                                Header="药箱IP" />
                            <DataGridTextColumn
                                Width="200"
                                Binding="{Binding Data.Message}"
                                Header="提示" />
                            <DataGridTextColumn
                                Width="*"
                                Binding="{Binding Data.ContentSource}"
                                Header="内容" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <StackPanel
                        Grid.Row="1"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                        <Button
                            Padding="20,5"
                            Command="{Binding ClearCommand}"
                            CommandParameter="{x:Static viewmodels:MainWindowViewModel.ViewOfInvalid}"
                            Content="清空" />
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem>
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="客户端:" />
                        <TextBlock Text="{Binding ListClients.Count}" />
                    </StackPanel>
                </TabItem.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <DataGrid
                        Grid.Row="1"
                        AutoGenerateColumns="False"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"
                        IsReadOnly="True"
                        ItemsSource="{Binding ListClients}">
                        <DataGrid.Columns>
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding Model.ID}"
                                Header="ID" />
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding Model.IP}"
                                Header="IP" />
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding Model.Port}"
                                Header="端口" />
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding CreateTime, StringFormat='yyyy-MM-dd HH:mm:ss'}"
                                Header="创建时间" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem>
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="日志:" />
                        <TextBlock Text="{Binding ListLogs.Count}" />
                    </StackPanel>
                </TabItem.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <DataGrid
                        Grid.Row="0"
                        AutoGenerateColumns="False"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"
                        IsReadOnly="True"
                        ItemsSource="{Binding ListLogs}">
                        <DataGrid.Columns>
                            <DataGridTextColumn
                                Width="150"
                                Binding="{Binding CreateTime, StringFormat='yyyy-MM-dd HH:mm:ss'}"
                                Header="时间" />
                            <DataGridTextColumn
                                Width="*"
                                Binding="{Binding Content}"
                                Header="内容" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <StackPanel
                        Grid.Row="1"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                        <Button
                            Padding="20,5"
                            Command="{Binding ClearCommand}"
                            CommandParameter="{x:Static viewmodels:MainWindowViewModel.ViewOfLog}"
                            Content="清空" />
                    </StackPanel>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Window>
