<mah:MetroWindow xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
                 x:Class="BDU.Windows.UsersManage"
                 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:local="clr-namespace:BDU.Windows"
                 xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
                 d:DataContext="{d:DesignInstance Type=local:UsersManage}"
                 mc:Ignorable="d"
                 ShowTitleBar="False"
                 WindowStartupLocation="CenterScreen"
                 Height="450"
                 Width="820">
    <Grid>
        <GroupBox Header="用户管理"
                  MouseLeftButtonDown="GroupBox_MouseLeftButtonDown">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Menu>
                    <MenuItem Header="新增"
                              Click="AddUserClick"
                              FontSize="12">
                        <MenuItem.Icon>
                            <materialDesign:PackIcon Kind="UserAdd" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="编辑"
                              Click="EditUserClick"
                              FontSize="12">
                        <MenuItem.Icon>
                            <materialDesign:PackIcon Kind="UserEdit" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="删除"
                              Foreground="Red"
                              Click="DelUserClick"
                              FontSize="12">
                        <MenuItem.Icon>
                            <materialDesign:PackIcon Kind="UserOff" />
                        </MenuItem.Icon>
                    </MenuItem>
                </Menu>
                <DataGrid x:Name="userTable"
                          Grid.Row="1"
                          Grid.Column="0"
                          Background="Transparent"
                          IsReadOnly="True"
                          Margin="10"
                          AutoGenerateColumns="False"
                          ItemsSource="{Binding UserList}">
                    <DataGrid.Columns>
                        <DataGridTextColumn  Header="用户名"
                                             Binding="{Binding UserName}" />
                        <DataGridTextColumn Header="账户"
                                            Binding="{Binding UserAccount}" />
                        <DataGridTextColumn  Header="密码"
                                             Binding="{Binding PassWord}" />
                        <DataGridTemplateColumn Header="用户权限">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock x:Name="roleName"></TextBlock>
                                    <DataTemplate.Triggers>
                                        <DataTrigger Binding="{Binding Role}"
                                                     Value="0">
                                            <Setter TargetName="roleName"
                                                    Property="Text"
                                                    Value="用户"></Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Role}"
                                                     Value="1">
                                            <Setter TargetName="roleName"
                                                    Property="Text"
                                                    Value="管理员"></Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Role}"
                                                     Value="2">
                                            <Setter TargetName="roleName"
                                                    Property="Text"
                                                    Value="超级管理员"></Setter>
                                        </DataTrigger>
                                    </DataTemplate.Triggers>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="登录次数"
                                            Binding="{Binding LoginCount}" />
                        <DataGridTextColumn  Header="最后登录时间"
                                             Binding="{Binding LoginTime,StringFormat=yyyy-MM-dd hh:mm:ss}" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </GroupBox>
    </Grid>
</mah:MetroWindow>
