<UserControl x:Class="CANModule.Views.CANView"
             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:oxy="http://oxyplot.org/wpf"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:local="clr-namespace:CANModule.Views"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             mc:Ignorable="d"
             xmlns:prism="http://prismlibrary.com/"
             xmlns:cons="clr-namespace:UIShare.Converters;assembly=UIShare"
             Background="White"
             prism:ViewModelLocator.AutoWireViewModel="True"
             Height="850"
             Width="900">
    <prism:Dialog.WindowStyle>
        <Style BasedOn="{StaticResource DialogUserManageStyle}"
               TargetType="Window" />
    </prism:Dialog.WindowStyle>
    <UserControl.Resources>
        <cons:HexConverter x:Key="HexConverter" />
    </UserControl.Resources>
    <GroupBox Padding="0,0,0,0"
              MouseLeftButtonDown="MouseLeftButtonDown">
        <GroupBox.Header>
            <Grid  Margin="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Text="CAN手动设置"
                           Foreground="White"
                           VerticalAlignment="Center"
                           Margin="5,0,10,0" />
                <Button Content="关闭"
                        Grid.Column="2"
                        Margin="150 0 0 0"
                        Width="60"
                        Command="{Binding CloseCommand}"
                        Height="25" />
            </Grid>
        </GroupBox.Header>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="829*" />
                <ColumnDefinition Width="69*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!-- TreeView 用于显示不同选项 -->
            <TreeView Grid.Row="1"
                      Grid.ColumnSpan="2">
                <!-- 调试选项 -->
                <TreeViewItem Header="调试选项">
                    <Button Content="初始化TSMaster"
                            Command="{Binding InitTSMasterCommand}"
                            CommandParameter="初始化TSMaster" />
                    <Button Content="释放TSMaster"
                            Command="{Binding ReleaseTSMasterCommand}"
                            CommandParameter="释放TSMaster" />
                 
                </TreeViewItem>

                <!-- 监视选项 -->
                <TreeViewItem Header="监视">
                    <DataGrid x:Name="表格" Width="800"
                              Height="450"
                              VirtualizingPanel.IsVirtualizing="True"
                              IsReadOnly="True"
                              ItemsSource="{Binding CanMessageList, Mode=OneWay}">

                    </DataGrid>
                </TreeViewItem>

                <!-- DBC 配置 -->
                <TreeViewItem Header="DBC">
                    <Label Content="请注意,要在断开CAN卡的情况下才能操作DBC!"
                           Foreground="Red" />
                    <Button Content="卸载所有DBC"
                            Command="{Binding UpLoadDBCCommand}"
                            CommandParameter="卸载DBC" />
                    <StackPanel Orientation="Horizontal">
                        <Button Content="更换DBC"
                                Command="{Binding ChangeDBCCommand}"
                                CommandParameter="更换DBC" />
                        <Label Content="DBC文件路径"
                               VerticalContentAlignment="Center" />
                        <TextBox Text="{Binding DBCPath,Mode=TwoWay}"
                                 MinWidth="100"
                                 materialDesign:HintAssist.Hint=""
                                 VerticalAlignment="Center" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Button Content="加载DBC"
                                Command="{Binding LoadDBCCommand}"
                                CommandParameter="加载DBC" />
                        <Label Content="通道(从0开始)"
                               VerticalContentAlignment="Center" />
                        <TextBox Text="{Binding DBCChannel,Mode=TwoWay}"
                                 materialDesign:HintAssist.Hint=""
                                 MinWidth="100"
                                 VerticalAlignment="Center" />
                        <CheckBox Margin="5 0 0 0"
                                  IsChecked="{Binding IsSaved}" />
                        <Label Content="加载记录保存"
                               VerticalContentAlignment="Center" />
                    </StackPanel>
                    <DataGrid ItemsSource="{Binding DBCAutoLoadList}"
                              Width="650"
                              IsReadOnly="True"
                              AutoGenerateColumns="False"
                              SelectedItem="{Binding SelectedDcAutoLoad}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="通道"
                                                Binding="{Binding DBCChannel}"
                                                Width="60" />
                            <DataGridTextColumn Header="文件路径"
                                                Binding="{Binding DBCFilePath}"
                                                Width="*" />
                        </DataGrid.Columns>
                        <DataGrid.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="删除"
                                          Foreground="Red"
                                          Command="{Binding DeleteDcAutoLoadCommand}" />
                            </ContextMenu>
                        </DataGrid.ContextMenu>
                    </DataGrid>
                    <Button Content="查看DBC"
                            Command="{Binding CheckDBCCommand}"
                            CommandParameter="查看DBC" />
                </TreeViewItem>

                <!-- CAN卡连接选项 -->
                <TreeViewItem Header="CAN卡连接">
                    <Button Content="连接"
                            Command="{Binding ConnectCanCommand}"
                            CommandParameter="连接" />
                    <Button Content="断开"
                            Command="{Binding CloseCanCommand}"
                            CommandParameter="断开" />
                    <Button Content="清空循环发送报文"
                            Command="{Binding ClearCycleCommand}"
                            CommandParameter="清空循环发送报文" />

                </TreeViewItem>

                <!-- DBC报文发送 -->
                <TreeViewItem Header="DBC报文发送">
                    <DockPanel>
                        <Label Content="报文" />
                        <ComboBox MinWidth="100"
                                  materialDesign:HintAssist.Hint=""
                                  SelectedItem="{Binding SelectedMessage}"
                                  ItemsSource="{Binding Message}" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="信号" />
                        <ComboBox SelectedItem="{Binding SelectedSignal}"
                                  ItemsSource="{Binding Signal}"
                                  materialDesign:HintAssist.Hint=""
                                  MinWidth="100" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="信号值" />
                        <TextBox Text="{Binding SignalValue}"
                                 materialDesign:HintAssist.Hint=""
                                 MinWidth="100" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="循环发送时间间隔(ms)(0为单次发送)" />
                        <TextBox Text="{Binding CycleSendInterval}"
                                 materialDesign:HintAssist.Hint=""
                                 MinWidth="100" />
                    </DockPanel>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="通道(从0开始)"
                               VerticalContentAlignment="Center" />
                        <TextBox Text="{Binding MessageSendChannel}"
                                 materialDesign:HintAssist.Hint=""
                                 MinWidth="100"
                                 VerticalAlignment="Center"
                                 Margin="0,10,10,10" />
                        <Button Content="加载报文"
                                Command="{Binding LoadMessageCommand}"
                                CommandParameter="加载报文"
                                Margin="10" />
                        <Button Content="设置信号并发送"
                                Command="{Binding SetAndSendMessageCommand}"
                                CommandParameter="设置" />
                        <CheckBox Content="直接发送"
                                  IsChecked="{Binding IsDirectlySend}" />
                    </StackPanel>
                </TreeViewItem>

                <TreeViewItem Header="自定义报文发送">
                    <DockPanel>
                        <Label Content="通道" />
                        <ComboBox MinWidth="100"
                                  materialDesign:HintAssist.Hint=""
                                  SelectedItem="{Binding AIdxChn}"
                                  ItemsSource="{Binding APP_CHANNEL}"
                                 />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="ID" />
                        <TextBox MinWidth="100"
                                 materialDesign:HintAssist.Hint=""
                                 Text="{Binding AID, Converter={StaticResource HexConverter}, Mode=TwoWay}" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="DLC" />
                        <TextBox MinWidth="200"
                                 materialDesign:HintAssist.Hint=""
                                 Text="{Binding ADLC}" />
                        <CheckBox Content="自动设定"
                                  IsChecked="{Binding AutoSetting}" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="报文" />
                        <TextBox MinWidth="200"
                                 materialDesign:HintAssist.Hint=""
                                 Text="{Binding CustomMessage}" />
                    </DockPanel>
                    <DockPanel>
                        <Label Content="循环发送时间间隔(ms)(0为单次发送)" />
                        <TextBox Text="{Binding CustomSendCycleInterval}"
                                 materialDesign:HintAssist.Hint=""
                                 MinWidth="100" />
                    </DockPanel>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Content="发送帧"
                                  IsChecked="{Binding AIsTx}" />
                        <CheckBox Content="扩展帧"
                                  IsChecked="{Binding AIsExt}" />
                        <CheckBox Content="远程帧"
                                  IsChecked="{Binding AIsRemote}" />
                        <CheckBox Content="FD"
                                  IsChecked="{Binding AIsFD}" />
                        <CheckBox Content="BRS"
                                  IsChecked="{Binding AIsBRS}" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Button Content="发送"
                                Command="{Binding SendCustomMessageCommand}"
                                 />
                        <CheckBox Margin="10"
                                  Content="更新到数据库"
                                  IsChecked="{Binding UpdateToDB}" />
                    </StackPanel>
                </TreeViewItem>

                <!-- 报文录制 -->
                <TreeViewItem Header="报文录制">
                    <DockPanel>
                        <Label Content="路径(开始录制时使用)"
                               VerticalContentAlignment="Center" />
                        <TextBox MinWidth="100"
                                 materialDesign:HintAssist.Hint=""
                                 Text="{Binding BLFPath}"
                                 VerticalContentAlignment="Center" />
                        <Button Content="选择路径"
                                Margin="10 0"
                                Command="{Binding SelectBLFPathCommand}"
                                CommandParameter="选择路径" />
                        <Button Content="保存路径"
                                Command="{Binding SaveBLFPathCommand}"
                                CommandParameter="保存路径" />
                    </DockPanel>
                    <StackPanel Orientation="Horizontal">
                        <Button Content="开始录制"
                                Command="{Binding StartTranscirbeCommand}"
                                CommandParameter="开始录制" />
                        <Button Content="结束录制"
                                Margin="10 0"
                                Command="{Binding EndTranscirbeCommand}"
                                CommandParameter="结束录制" />
                    </StackPanel>
                </TreeViewItem>
            </TreeView>
        </Grid>
    </GroupBox>
</UserControl>
