<UserControl
    x:Class="BPA.SingleDevice.View.MaterialManagementView"
    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">

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

    <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}" />

                <!--<Button
                    HorizontalAlignment="Right"
                    Command="{Binding SaveCommand}"
                    Content="保存修改"
                    Style="{DynamicResource SuccessButton}" />-->
            </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 MaterialInfos}"
                    RowHeight="70"
                    SelectionMode="Single"
                    Style="{StaticResource DataGridLargeScrollStyle}">
                    <DataGrid.Columns>
                        <!--<DataGridTextColumn
                            Width="100"
                            Binding="{Binding ID}"
                            Header="ID" />-->
                        <DataGridTextColumn
                            Width="*"
                            Binding="{Binding Name}"
                            Header="物料名称" />
                        <DataGridTextColumn
                            Width="200"
                            Binding="{Binding MaterialCode}"
                            Header="物料编码" />
                        <!--<DataGridCheckBoxColumn
                            Width="100"
                            Binding="{Binding IsActive, UpdateSourceTrigger=PropertyChanged}"
                            Header="启用" />-->
                        <DataGridTextColumn
                            Width="420"
                            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:MaterialManagementView}}"
                                            CommandParameter="{Binding ID}"
                                            Foreground="#2196F3"
                                            Style="{StaticResource TextButton}">
                                            <bpa:Icon Type="Edit2Fill" />
                                        </Button>
                                        <Button
                                            Width="150"
                                            Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:MaterialManagementView}}"
                                            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="MaterialManagementView" />
            <!--#endregion-->
        </Grid>
    </bpa:DialogContainer>
</UserControl>
