<Window x:Class="XLAB2.PrsnDirectoryWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Персоны"
        Height="940"
        Width="1500"
        MinHeight="780"
        MinWidth="1240"
        Loaded="Window_Loaded"
        WindowStartupLocation="CenterOwner">
    <Grid Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="2.1*" />
            <RowDefinition Height="1.8*" />
            <RowDefinition Height="1.8*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0"
                   Margin="0,0,0,12">
            <Button DockPanel.Dock="Right"
                    Width="110"
                    Margin="12,0,0,0"
                    Command="{Binding RefreshCommand}"
                    Content="Обновить" />
            <StackPanel Orientation="Horizontal">
                <TextBlock Margin="0,0,8,0"
                           VerticalAlignment="Center"
                           Text="Поиск по PRSN" />
                <TextBox Width="360"
                         Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
            </StackPanel>
        </DockPanel>

        <GroupBox Grid.Row="1"
                  Header="Персоны (PRSN)">
            <DataGrid ItemsSource="{Binding PrsnItems}"
                      SelectedItem="{Binding SelectedPrsn, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить"
                                  Command="{Binding AddPrsnCommand}" />
                        <MenuItem Header="Изменить"
                                  Command="{Binding EditPrsnCommand}" />
                        <MenuItem Header="Удалить"
                                  Command="{Binding DeletePrsnCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="ID" Width="80" Binding="{Binding Id}" />
                    <DataGridTextColumn Header="ФИО" Width="240" Binding="{Binding FullName}" />
                    <DataGridTextColumn Header="Телефон" Width="140" Binding="{Binding Phone}" />
                    <DataGridTextColumn Header="E-mail" Width="180" Binding="{Binding Email}" />
                    <DataGridTextColumn Header="Организации" Width="220" Binding="{Binding OrganizationNames}" />
                    <DataGridTextColumn Header="Виды деятельности" Width="220" Binding="{Binding ActivityNames}" />
                    <DataGridTextColumn Header="Клейма" Width="260" Binding="{Binding StampNames}" />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>

        <GroupBox Grid.Row="2"
                  Margin="0,12,0,0"
                  Header="Персонал организации/подразделения (PRFR)">
            <DataGrid ItemsSource="{Binding PrfrItems}"
                      SelectedItem="{Binding SelectedPrfr, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить"
                                  Command="{Binding AddPrfrCommand}" />
                        <MenuItem Header="Изменить"
                                  Command="{Binding EditPrfrCommand}" />
                        <MenuItem Header="Удалить"
                                  Command="{Binding DeletePrfrCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="ID" Width="80" Binding="{Binding EmploymentId}" />
                    <DataGridTextColumn Header="Организация" Width="*" Binding="{Binding OrganizationName}" />
                    <DataGridTextColumn Header="Должность" Width="220" Binding="{Binding PositionName}" />
                    <DataGridTextColumn Header="Дата приёма" Width="120" Binding="{Binding HireDate, StringFormat=d}" />
                    <DataGridTextColumn Header="Дата увольнения" Width="130" Binding="{Binding DismissalDate, StringFormat=d}" />
                    <DataGridTextColumn Header="Таб. №" Width="110" Binding="{Binding PersonnelNumber}" />
                    <DataGridTextColumn Header="Виды деятельности" Width="220" Binding="{Binding ActivityNames}" />
                    <DataGridTextColumn Header="Клейма" Width="240" Binding="{Binding StampNames}" />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>

        <Grid Grid.Row="3"
              Margin="0,12,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="12" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <GroupBox Grid.Column="0"
                      Header="Вид деятельности персоны (PRFRVD)">
                <DataGrid ItemsSource="{Binding PrfrvdItems}"
                          SelectedItem="{Binding SelectedPrfrvd, Mode=TwoWay}"
                          AutoGenerateColumns="False"
                          CanUserAddRows="False"
                          IsReadOnly="True"
                          HeadersVisibility="Column">
                    <DataGrid.ContextMenu>
                        <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="Добавить"
                                      Command="{Binding AddPrfrvdCommand}" />
                            <MenuItem Header="Изменить"
                                      Command="{Binding EditPrfrvdCommand}" />
                            <MenuItem Header="Удалить"
                                      Command="{Binding DeletePrfrvdCommand}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="PreviewMouseRightButtonDown"
                                         Handler="DataGridRow_PreviewMouseRightButtonDown" />
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" Width="90" Binding="{Binding Id}" />
                        <DataGridTextColumn Header="Вид деятельности" Width="*" Binding="{Binding ActivityName}" />
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>

            <GroupBox Grid.Column="2"
                      Header="Дополнительные сведения о поверителе/калибровщике (PRDSPV)">
                <DataGrid ItemsSource="{Binding PrdspvItems}"
                          SelectedItem="{Binding SelectedPrdspv, Mode=TwoWay}"
                          AutoGenerateColumns="False"
                          CanUserAddRows="False"
                          IsReadOnly="True"
                          HeadersVisibility="Column">
                    <DataGrid.ContextMenu>
                        <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="Добавить"
                                      Command="{Binding AddPrdspvCommand}" />
                            <MenuItem Header="Изменить"
                                      Command="{Binding EditPrdspvCommand}" />
                            <MenuItem Header="Удалить"
                                      Command="{Binding DeletePrdspvCommand}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="PreviewMouseRightButtonDown"
                                         Handler="DataGridRow_PreviewMouseRightButtonDown" />
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" Width="90" Binding="{Binding Id}" />
                        <DataGridTextColumn Header="Вид клейма" Width="180" Binding="{Binding StampTypeName}" />
                        <DataGridTextColumn Header="Шифр клейма" Width="140" Binding="{Binding StampCode}" />
                        <DataGridTextColumn Header="Дата получения" Width="130" Binding="{Binding ReceivedOn, StringFormat=d}" />
                        <DataGridTextColumn Header="Доп. сведения" Width="*" Binding="{Binding Notes}" />
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>
        </Grid>

        <TextBlock Grid.Row="4"
                   Margin="0,8,0,0"
                   Foreground="DimGray"
                   Text="{Binding StatusText}" />

        <StackPanel Grid.Row="5"
                    Margin="0,12,0,0"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Width="90"
                    IsCancel="True"
                    Content="Закрыть" />
        </StackPanel>
    </Grid>
</Window>
