<UserControl
    x:Class="BPA.SingleDevice.View.RawMaterialManagementView"
    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:BPA.SingleDevice.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
    xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

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

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

            <!--#region 功能按钮-->
            <StackPanel
                Grid.Row="0"
                Margin="10"
                HorizontalAlignment="Right"
                bpa:PanelHelper.Spacing="15"
                Orientation="Horizontal">
                <Button
                    HorizontalAlignment="Right"
                    Command="{Binding AddCommand}"
                    Content="添加原料"
                    Style="{DynamicResource DarkButton}" />

                <!--<Button
                    HorizontalAlignment="Right"
                    Command="{Binding SaveCommand}"
                    Content="保存修改"
                    Style="{DynamicResource SuccessButton}" />-->
            </StackPanel>

            <!--#endregion-->

            <!--#region 列表-->
            <bpa:ControlDisplay Grid.Row="1">
                <DataGrid
                    Grid.Row="1"
                    AutoGenerateColumns="False"
                    BorderBrush="Gray"
                    BorderThickness="1"
                    CanUserAddRows="False"
                    GridLinesVisibility="All"
                    IsReadOnly="True"
                    ItemsSource="{Binding RawMaterInfos}"
                    RowHeight="35"
                    SelectionMode="Single">
                    <!--<DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <Border>
                        <TextBlock HorizontalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource DataGridRowIndexConverter}}" />
                    </Border>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>-->
                    <DataGrid.Columns>
                        <DataGridTextColumn
                            Width="*"
                            Binding="{Binding Name}"
                            Header="原料名称" />
                        <DataGridTextColumn
                            Width="100"
                            Binding="{Binding DeviceNum}"
                            Header="设备编号" />
                        <DataGridTextColumn
                            Width="120"
                            Binding="{Binding WarehouseNum}"
                            Header="设备料仓编号" />
                        <DataGridTextColumn
                            Width="180"
                            Binding="{Binding LastModified}"
                            Header="最后修改时间" />
                        <DataGridTemplateColumn Width="150" Header="操作">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Button
                                            Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
                                            CommandParameter="{Binding Id}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="Edit2Fill" />
                                        </Button>
                                        <Button
                                            Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
                                            CommandParameter="{Binding Id}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="CopyleftFill" />
                                        </Button>
                                        <Button
                                            Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
                                            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="RawMaterialManagementView" />
            <!--#endregion-->

        </Grid>
    </bpa:DialogContainer>
</UserControl>
