<UserControl
    x:Class="BPA.SingleDevice.View.MaterialBindingView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:BPA.SingleDevice.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

    <bpa:DialogContainer>
        <Grid Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--#region 功能按钮-->
            <StackPanel
                Grid.Row="0"
                Margin="5"
                HorizontalAlignment="Right"
                bpa:PanelHelper.Spacing="15"
                Orientation="Horizontal">
                <Button
                    Width="250"
                    HorizontalAlignment="Right"
                    Command="{Binding RefreshCommand}"
                    Content="刷新"
                    Style="{DynamicResource DarkButton}" />
                <Button
                    Width="300"
                    HorizontalAlignment="Right"
                    Command="{Binding AddCommand}"
                    Content="物料绑定"
                    Style="{DynamicResource DarkButton}" />
            </StackPanel>

            <!--#endregion-->

            <!--#region 列表-->
            <bpa:ControlDisplay Grid.Row="1">
                <DataGrid
                    Grid.Row="1"
                    bpa:HeaderHelper.HorizontalAlignment="Center"
                    AutoGenerateColumns="False"
                    BorderBrush="Gray"
                    BorderThickness="1"
                    CanUserAddRows="False"
                    CanUserDeleteRows="False"
                    CanUserReorderColumns="False"
                    CanUserResizeColumns="False"
                    CanUserResizeRows="False"
                    GridLinesVisibility="All"
                    IsReadOnly="True"
                    ItemsSource="{Binding MaterialBindInfos}"
                    RowHeight="70"
                    SelectionMode="Single"
                    Style="{StaticResource DataGridLargeScrollStyle}">
                    <DataGrid.Columns>
                        <DataGridTextColumn
                            Width="*"
                            Binding="{Binding MaterialName}"
                            FontSize="36"
                            Header="物料名称" />
                        <DataGridTextColumn
                            Width="200"
                            Binding="{Binding MaterialCode}"
                            Header="物料编码" />
                        <DataGridTextColumn
                            Width="140"
                            Binding="{Binding DeviceNum}"
                            Header="设备号" />
                        <DataGridTextColumn
                            Width="140"
                            Binding="{Binding WarehouseNum}"
                            Header="通道号" />
                        <DataGridTextColumn
                            Width="410"
                            Binding="{Binding LastModified}"
                            Header="最后修改时间" />
                        <DataGridTemplateColumn Width="500" Header="操作">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Button
                                            Width="300"
                                            Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:MaterialBindingView}}"
                                            CommandParameter="{Binding Id}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="Edit2Fill" />
                                        </Button>
                                        <Button
                                            Width="150"
                                            Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:MaterialBindingView}}"
                                            CommandParameter="{Binding Id}"
                                            Style="{StaticResource TextErrorButton}">
                                            <bpa:Icon Type="DeleteBinFill" />
                                        </Button>
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </bpa:ControlDisplay>
            <bpa:MessageContainer Grid.Row="1" Identifier="MaterialBindingView" />
            <!--#endregion-->
        </Grid>
    </bpa:DialogContainer>
</UserControl>
