<Window x:Class="XLAB2.TypeSizeDirectoryWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Типоразмеры СИ"
        Height="900"
        Width="1500"
        MinHeight="760"
        MinWidth="1220"
        Loaded="Window_Loaded"
        WindowStartupLocation="CenterOwner">
    <Grid Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="2.1*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="2.1*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0"
              Margin="0,0,0,12">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Grid.Row="0">
                <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="Поиск по типам и типоразмерам:" />
                    <TextBox Width="360"
                             VerticalAlignment="Center"
                             Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
            </DockPanel>

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

        <GroupBox Grid.Row="1"
                  Header="Типы СИ">
            <DataGrid ItemsSource="{Binding TipsItems}"
                      SelectedItem="{Binding SelectedTips, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить"
                                  Command="{Binding AddTipsCommand}" />
                        <MenuItem Header="Изменить"
                                  Command="{Binding EditTipsCommand}" />
                        <MenuItem Header="Удалить"
                                  Command="{Binding DeleteTipsCommand}" />
                        <Separator />
                        <MenuItem Header="Виды клейм..."
                                  Command="{Binding ManageTpvdklCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Область измерений" Width="260" Binding="{Binding MeasurementAreaName}" />
                    <DataGridTextColumn Header="Наименование типа СИ" Width="260" Binding="{Binding InstrumentName}" />
                    <DataGridTextColumn Header="Тип СИ" Width="*" Binding="{Binding TypeName}" />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>

        <GroupBox Grid.Row="2"
                  Margin="0,12,0,0"
                  Header="Типоразмеры СИ">
            <DataGrid ItemsSource="{Binding TprzItems}"
                      SelectedItem="{Binding SelectedTprz, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить" Command="{Binding AddTprzCommand}" />
                        <MenuItem Header="Изменить" Command="{Binding EditTprzCommand}" />
                        <MenuItem Header="Удалить" Command="{Binding DeleteTprzCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Диапазон" Width="*" Binding="{Binding RangeText}" />
                    <DataGridTextColumn Header="Х-ка точности" Width="260" Binding="{Binding AccuracyText}" />
                    <DataGridTextColumn Header="№ Госреестра" Width="130" Binding="{Binding RegistryTypeSizeNumber}" />
                </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="Регламент МК для типоразмера СИ">
                <DataGrid ItemsSource="{Binding TprmkItems}"
                          SelectedItem="{Binding SelectedTprmk, Mode=TwoWay}"
                          AutoGenerateColumns="False"
                          CanUserAddRows="False"
                          IsReadOnly="True"
                          HeadersVisibility="Column">
                    <DataGrid.ContextMenu>
                        <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="Добавить" Command="{Binding AddTprmkCommand}" />
                            <MenuItem Header="Изменить" Command="{Binding EditTprmkCommand}" />
                            <MenuItem Header="Удалить" Command="{Binding DeleteTprmkCommand}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="PreviewMouseRightButtonDown"
                                         Handler="DataGridRow_PreviewMouseRightButtonDown" />
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Вид МК" Width="130" Binding="{Binding VerificationTypeName}" />
                        <DataGridTextColumn Header="Организация" Width="*" Binding="{Binding OrganizationName}" />
                        <DataGridTextColumn Header="Место МК" Width="170" Binding="{Binding PlaceName}" />
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>

            <GroupBox Grid.Column="2"
                      Header="Циклы и периоды МК">
                <DataGrid ItemsSource="{Binding TprmcpItems}"
                          SelectedItem="{Binding SelectedTprmcp, Mode=TwoWay}"
                          AutoGenerateColumns="False"
                          CanUserAddRows="False"
                          IsReadOnly="True"
                          HeadersVisibility="Column">
                    <DataGrid.ContextMenu>
                        <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="Добавить" Command="{Binding AddTprmcpCommand}" />
                            <MenuItem Header="Изменить" Command="{Binding EditTprmcpCommand}" />
                            <MenuItem Header="Удалить" Command="{Binding DeleteTprmcpCommand}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="PreviewMouseRightButtonDown"
                                         Handler="DataGridRow_PreviewMouseRightButtonDown" />
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Период, мес." Width="*" Binding="{Binding PeriodMonths}" />
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>
        </Grid>

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