<UserControl
    x:Class="HBLConsole.View.DeviceManageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:HBLConsole.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pry="clr-namespace:HBLConsole.PryUserControl;assembly=HBLConsole.PryUserControl"
    xmlns:vm="clr-namespace:HBLConsole.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

    <UserControl.DataContext>
        <vm:DeviceManageViewModel />
    </UserControl.DataContext>

    <UserControl.Resources>
        <ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <Style x:Key="TextBlockStyle" TargetType="TextBlock">
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="18" />
                        <Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                        <Setter Property="HorizontalAlignment" Value="Center" />
                    </Style>

                    <Style x:Key="TextBoxStyle" TargetType="TextBox">
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="22" />
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" />
                        <Setter Property="BorderBrush" Value="#FF23CACA" />
                        <Setter Property="CaretBrush" Value="Aqua" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>

                    <Style x:Key="buttonStyle" TargetType="Button">
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="20" />
                        <Setter Property="Foreground" Value="#FFDE7889" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Grid>
                                        <ContentControl
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Content="{TemplateBinding Content}"
                                            Foreground="{TemplateBinding Foreground}" />
                                        <pry:Quadrilateral
                                            x:Name="poly"
                                            Stroke="#FFDE7889"
                                            StrokeThickness="2" />
                                    </Grid>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="poly" Property="FillColor" Value="#22DE7889" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">

            <TextBlock Style="{StaticResource TextBlockStyle}" Text="请选择客户端启动设备类型：" />

            <ComboBox
                Width="150"
                Margin="0,0,20,0"
                VerticalAlignment="Center"
                BorderBrush="#FF23CACA"
                BorderThickness="1"
                FontFamily="楷体"
                FontSize="20"
                Foreground="#ff23caca"
                IsEditable="False"
                ItemsSource="{Binding ClientDevices}"
                SelectedIndex="0"
                Style="{StaticResource ComboBoxStyle}"
                Text="{Binding ClientDeviceType}" />

            <Button
                Width="140"
                Margin="0,0,20,0"
                Background="#FF19B7EC"
                Command="{Binding NewConnectCommand}"
                Content="新建连接"
                FontFamily="楷体"
                FontSize="18"
                Template="{StaticResource NewButtonTemp}">
                <Button.Foreground>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#FFBB662A" />
                        <GradientStop Offset="1" Color="White" />
                    </LinearGradientBrush>
                </Button.Foreground>
            </Button>

            <!--<Button
                Width="140"
                Command="{Binding SaveConnectSetCommand}"
                Content="保存"
                FontFamily="楷体"
                FontSize="18"
                Template="{StaticResource SaveButtonTemp}">
                <Button.Foreground>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Color="#FFBB662A" />
                        <GradientStop Offset="1" Color="White" />
                    </LinearGradientBrush>
                </Button.Foreground>
            </Button>-->
        </StackPanel>

        <ScrollViewer
            Grid.Row="1"
            Margin="0,10,0,0"
            HorizontalScrollBarVisibility="Hidden"
            VerticalScrollBarVisibility="Hidden">
            <ItemsControl ItemsSource="{Binding communicationSets}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,0,30">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.1*" />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <!--#region 标题显示及操作-->
                            <Grid Margin="0,0,0,20">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.5*" />
                                    <ColumnDefinition Width="0.3*" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <pry:TitleTextBlock />

                                <TextBlock
                                    Margin="5"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    FontFamily="楷体"
                                    FontSize="20"
                                    Foreground="Aqua"
                                    Text="{Binding DeviceName}" />
                            </Grid>
                            <!--#endregion-->

                            <!--#region 西门子设备-->
                            <Grid Grid.Row="1" Visibility="{Binding Path=deviceType, Converter={StaticResource VisibleConvert}, ConverterParameter=Siemens}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition Width="0.2*" />
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition Height="20" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <TextBlock
                                        Grid.Column="0"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="IP地址：" />
                                    <TextBox
                                        Grid.Column="1"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.IP}" />

                                    <TextBlock
                                        Grid.Column="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="端口号：" />
                                    <TextBox
                                        Grid.Column="3"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.PortNum}" />

                                    <TextBlock
                                        Grid.Column="4"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="PLC类型：" />
                                    <ComboBox
                                        Grid.Column="5"
                                        Margin="0,0,20,0"
                                        VerticalAlignment="Center"
                                        BorderBrush="#FF23CACA"
                                        BorderThickness="1"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#ff23caca"
                                        IsEditable="False"
                                        ItemsSource="{Binding Path=Device.PlcTypes}"
                                        SelectedIndex="0"
                                        Style="{StaticResource ComboBoxStyle}"
                                        Text="{Binding Path=Device.PlcType}" />

                                    <Button
                                        Grid.Column="7"
                                        Command="{Binding RemoveCommand}"
                                        CommandParameter="{Binding DeviceName}"
                                        Content="删除"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#FFDE7889"
                                        Template="{StaticResource ButtonTemplate}" />

                                    <TextBlock
                                        Grid.Row="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="机架号：" />
                                    <TextBox
                                        Grid.Row="2"
                                        Grid.Column="1"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.Rack}" />

                                    <TextBlock
                                        Grid.Row="2"
                                        Grid.Column="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="插槽号：" />
                                    <TextBox
                                        Grid.Row="2"
                                        Grid.Column="3"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.Slot}" />

                                    <CheckBox
                                        Grid.Row="2"
                                        Grid.Column="7"
                                        Width="100"
                                        Height="20"
                                        Margin="10"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Center"
                                        Background="#FF2AB2E7"
                                        Content="IsActive"
                                        FontSize="16"
                                        Foreground="#ddd"
                                        IsChecked="{Binding IsActive}"
                                        Template="{StaticResource CbTemplate}" />
                                </Grid>
                            </Grid>
                            <!--#endregion-->

                            <!--#region Modbus Tcp 设备-->

                            <Grid Grid.Row="2" Visibility="{Binding Path=deviceType, Converter={StaticResource VisibleConvert}, ConverterParameter=TCP}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition Width="0.2*" />
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition Height="20" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>


                                    <TextBlock
                                        Grid.Column="0"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="IP地址：" />
                                    <TextBox
                                        Grid.Column="1"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.IP}" />

                                    <TextBlock
                                        Grid.Column="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="端口号：" />
                                    <TextBox
                                        Grid.Column="3"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.PortNum}" />

                                    <TextBlock
                                        Grid.Column="4"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="站号：" />
                                    <TextBox
                                        Grid.Column="5"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.StationNo}" />

                                    <Button
                                        Grid.Column="7"
                                        Command="{Binding RemoveCommand}"
                                        CommandParameter="{Binding DeviceName}"
                                        Content="删除"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#FFDE7889"
                                        Template="{StaticResource ButtonTemplate}" />

                                    <CheckBox
                                        Grid.Row="2"
                                        Grid.Column="7"
                                        Width="100"
                                        Height="20"
                                        Margin="10"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Center"
                                        Background="#FF2AB2E7"
                                        Content="IsActive"
                                        FontSize="16"
                                        Foreground="#ddd"
                                        IsChecked="{Binding IsActive}"
                                        Template="{StaticResource CbTemplate}" />

                                </Grid>
                            </Grid>

                            <!--#endregion-->

                            <!--#region Modbus RTU 设备-->

                            <Grid Grid.Row="3" Visibility="{Binding Path=deviceType, Converter={StaticResource VisibleConvert}, ConverterParameter=Serial}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="0.5*" />
                                        <ColumnDefinition Width="0.2*" />
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition Height="20" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <TextBlock Style="{StaticResource TextBlockStyle}" Text="端口号：" />
                                    <ComboBox
                                        Grid.Column="1"
                                        Margin="0,0,20,0"
                                        VerticalAlignment="Center"
                                        BorderBrush="#FF23CACA"
                                        BorderThickness="1"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#ff23caca"
                                        IsEditable="False"
                                        ItemsSource="{Binding Path=Device.Ports}"
                                        SelectedIndex="0"
                                        Style="{StaticResource ComboBoxStyle}"
                                        Text="{Binding Path=Device.ComSerialPort}" />

                                    <TextBlock
                                        Grid.Column="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="波特率：" />
                                    <ComboBox
                                        Grid.Column="3"
                                        Margin="0,0,20,0"
                                        VerticalAlignment="Center"
                                        BorderBrush="#FF23CACA"
                                        BorderThickness="1"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#ff23caca"
                                        IsEditable="False"
                                        ItemsSource="{Binding Path=Device.BaudRates}"
                                        SelectedIndex="0"
                                        Style="{StaticResource ComboBoxStyle}"
                                        Text="{Binding Path=Device.BaudRate}" />


                                    <TextBlock
                                        Grid.Column="4"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="奇偶：" />
                                    <ComboBox
                                        Grid.Column="5"
                                        Margin="0,0,20,0"
                                        VerticalAlignment="Center"
                                        BorderBrush="#FF23CACA"
                                        BorderThickness="1"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#ff23caca"
                                        IsEditable="False"
                                        ItemsSource="{Binding Path=Device.Paritys}"
                                        SelectedIndex="0"
                                        Style="{StaticResource ComboBoxStyle}"
                                        Text="{Binding Path=Device.Parity}" />

                                    <TextBlock
                                        Grid.Row="2"
                                        Grid.Column="0"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="数据位：" />
                                    <TextBox
                                        Grid.Row="2"
                                        Grid.Column="1"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.DataBit}" />
                                    <TextBlock
                                        Grid.Row="2"
                                        Grid.Column="2"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="停止位：" />
                                    <TextBox
                                        Grid.Row="2"
                                        Grid.Column="3"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.StopBit}" />

                                    <TextBlock
                                        Grid.Row="2"
                                        Grid.Column="4"
                                        Style="{StaticResource TextBlockStyle}"
                                        Text="站号：" />
                                    <TextBox
                                        Grid.Row="2"
                                        Grid.Column="5"
                                        Margin="0,0,20,0"
                                        Style="{StaticResource TextBoxStyle}"
                                        Text="{Binding Path=Device.StationNo}" />

                                    <Button
                                        Grid.Column="7"
                                        Command="{Binding RemoveCommand}"
                                        CommandParameter="{Binding DeviceName}"
                                        Content="删除"
                                        FontFamily="楷体"
                                        FontSize="20"
                                        Foreground="#FFDE7889"
                                        Template="{StaticResource ButtonTemplate}" />

                                    <CheckBox
                                        Grid.Row="2"
                                        Grid.Column="7"
                                        Width="100"
                                        Height="20"
                                        Margin="10"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Center"
                                        Background="#FF2AB2E7"
                                        Content="IsActive"
                                        FontSize="16"
                                        Foreground="#ddd"
                                        IsChecked="{Binding IsActive}"
                                        Template="{StaticResource CbTemplate}" />
                                </Grid>
                            </Grid>

                            <!--#endregion-->

                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

        </ScrollViewer>
    </Grid>
</UserControl>
