<UserControl x:Class="MainShell.DeviceMaintance.View.IoTestView"
             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:mw="http://www.maxwell-gp.com/"
             mc:Ignorable="d" 
             d:DesignHeight="560" d:DesignWidth="980">
    <UserControl.Resources>
        <Style x:Key="IoTestGroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource ProcessWideCardGroupBoxStyle}">
            <Setter Property="Margin" Value="0,0,0,16"/>
        </Style>

        <Style x:Key="IoTestLabelStyle" TargetType="Label" BasedOn="{StaticResource ProcessLabelStyle}">
            <Setter Property="Width" Value="95"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
        </Style>

        <Style x:Key="IoTestNumberBoxStyle" TargetType="{x:Type mw:IntNumberBox}" BasedOn="{StaticResource ProcessLargeIntNumberBoxStyle}">
            <Setter Property="Width" Value="110"/>
            <Setter Property="Margin" Value="0,0,12,8"/>
        </Style>

        <Style x:Key="IoTestButtonStyle" TargetType="Button" BasedOn="{StaticResource TestButtonStyle}">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="32"/>
            <Setter Property="Margin" Value="0,0,12,0"/>
        </Style>

        <Style x:Key="IoTestResultBorderStyle" TargetType="Border">
            <Setter Property="Background" Value="#F8FAFC"/>
            <Setter Property="BorderBrush" Value="{StaticResource ProcessCardBorderBrush}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="CornerRadius" Value="4"/>
            <Setter Property="Padding" Value="12,8"/>
            <Setter Property="Margin" Value="0,4,0,0"/>
        </Style>

        <Style x:Key="IoTestCheckBoxStyle" TargetType="CheckBox">
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="0,0,18,8"/>
        </Style>
    </UserControl.Resources>

    <Grid Background="{StaticResource ProcessPageBackgroundBrush}">
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="4" Padding="0,0,4,0">
            <StackPanel Margin="0,0,0,4">
                <GroupBox Header="Delta IO状态" Style="{StaticResource IoTestGroupBoxStyle}">
                    <StackPanel>
                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="控制卡状态"/>
                            <TextBlock VerticalAlignment="Center" Text="{Binding CardStatusText}" TextWrapping="Wrap" Width="620"/>
                            <Button Style="{StaticResource IoTestButtonStyle}" Content="刷新状态" Click="{mw:Action RefreshCardStatus}"/>
                        </WrapPanel>
                    </StackPanel>
                </GroupBox>

                <GroupBox Header="数字量 Bit 测试" Style="{StaticResource IoTestGroupBoxStyle}">
                    <StackPanel>
                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="CardNo"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.CardNo}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Node"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.Node}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Slot"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.Slot}"/>
                        </WrapPanel>

                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Index"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.Index}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="SubIndex"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.SubIndex}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="BitNo"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.BitNo}"/>
                        </WrapPanel>

                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="IoType"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.IoType}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="ReadIoType"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding BitState.ReadIoType}"/>
                            <CheckBox Style="{StaticResource IoTestCheckBoxStyle}" Content="写入值" IsChecked="{Binding BitState.WriteValue}"/>
                            <CheckBox Style="{StaticResource IoTestCheckBoxStyle}" Content="读取结果" IsChecked="{Binding BitState.ReadValue}" IsEnabled="False"/>
                        </WrapPanel>

                        <WrapPanel Margin="0,4,0,0">
                            <Button Style="{StaticResource IoTestButtonStyle}" Content="读取 Bit" Click="{mw:Action ReadBit}"/>
                            <Button Style="{StaticResource IoTestButtonStyle}" Content="写入 Bit" Click="{mw:Action WriteBit}"/>
                            <TextBlock VerticalAlignment="Center" Text="{Binding BitState.ReturnCode, StringFormat=返回码：{0}}"/>
                        </WrapPanel>

                        <Border Style="{StaticResource IoTestResultBorderStyle}">
                            <TextBlock Text="{Binding BitState.ResultMessage}" TextWrapping="Wrap"/>
                        </Border>
                    </StackPanel>
                </GroupBox>

                <GroupBox Header="模拟量 DA 测试" Style="{StaticResource IoTestGroupBoxStyle}">
                    <StackPanel>
                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="CardNo"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.CardNo}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Node"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.Node}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Slot"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.Slot}"/>
                        </WrapPanel>

                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="Index"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.Index}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="SubIndex"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.SubIndex}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="ByteSize"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.ByteSize}"/>
                        </WrapPanel>

                        <WrapPanel>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="IoType"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.IoType}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="写入值"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.WriteRawValue}"/>
                            <Label Style="{StaticResource IoTestLabelStyle}" Content="读取值"/>
                            <mw:IntNumberBox Style="{StaticResource IoTestNumberBoxStyle}" Value="{Binding DaState.ReadRawValue}" IsEnabled="False"/>
                        </WrapPanel>

                        <WrapPanel>
                            <CheckBox Style="{StaticResource IoTestCheckBoxStyle}" Content="有符号" IsChecked="{Binding DaState.Signed}"/>
                            <Button Style="{StaticResource IoTestButtonStyle}" Content="读取 DA" Click="{mw:Action ReadDa}"/>
                            <Button Style="{StaticResource IoTestButtonStyle}" Content="写入 DA" Click="{mw:Action WriteDa}"/>
                            <TextBlock VerticalAlignment="Center" Text="{Binding DaState.ReturnCode, StringFormat=返回码：{0}}"/>
                        </WrapPanel>

                        <Border Style="{StaticResource IoTestResultBorderStyle}">
                            <TextBlock Text="{Binding DaState.ResultMessage}" TextWrapping="Wrap"/>
                        </Border>
                    </StackPanel>
                </GroupBox>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
