<mah:MetroWindow x:Class="ZKuP.Belegung"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ZKuP"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        mc:Ignorable="d"
        Title="BE-Flächenbelegung" MinHeight="385" Height="600" MinWidth="750" Width="1100" Loaded="MetroWindow_Loaded" Closing="MetroWindow_Closing" LocationChanged="Window_LocationChanged">
    <mah:MetroWindow.Resources>
        <local:ComboBoxDisplayConverter x:Key="ComboBoxDisplayConverter"></local:ComboBoxDisplayConverter>
    </mah:MetroWindow.Resources>

    <Grid x:Name="gridBelegung">
        <Grid.RowDefinitions>
            <RowDefinition Height="1.8*" MaxHeight="270"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="0.1*"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch">
                <TextBlock Text="BE Fläche:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>
                <ComboBox x:Name="cbBE" Margin="5" SelectionChanged="cbBE_SelectionChanged">
                    <ComboBox.ToolTip>
                        <StackPanel>
                            <TextBlock Text="Bei Auswahl einer BE-Fläche wird die Liste auf die angegebene BE-Fläche gefiltert"/>
                            <TextBlock Text="Wird der leere Eintrag gewählt, werden alle angezeigt"/>
                        </StackPanel>
                    </ComboBox.ToolTip>
                </ComboBox>

                <TextBlock Text="Maßnahme/Bemerkung:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>
                <TextBox x:Name="tbBemerkung" IsEnabled="False" Margin="5" Height="87" AcceptsReturn="True"/>
                <!--<TextBlock Text="Projektleiter:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>-->
                <!--<ComboBox x:Name="cbPL" Margin="5" SelectionChanged="cbPL_SelectionChanged"/>-->
            </StackPanel>

            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,10,10,0" Grid.Column="2">
                <TextBlock Text="Start der Buchung:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>
                <DatePicker x:Name="dpVon" Margin="5" IsEnabled="False" local:DatePickerHelper.ShowTodayButton="True" local:DatePickerHelper.ShowTodayButtonContent="Heute" />
                <TextBlock Text="Ende der Buchung:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>
                <DatePicker x:Name="dpBis" Margin="5" IsEnabled="False" local:DatePickerHelper.ShowTodayButton="True" local:DatePickerHelper.ShowTodayButtonContent="Heute" LostFocus="dpBis_LostFocus"/>
                <TextBlock Text="Buchung für Firma:" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="5"/>
                <ComboBox x:Name="cbFirma" ItemsSource="{Binding}" IsEnabled="False" SelectedValuePath="idFirmen" Margin="5" IsEditable="True" PreviewTextInput="cbFirma_TextInput" SelectionChanged="cbFirma_SelectionChanged">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Width="{Binding ActualWidth, ElementName=cbFirma, Mode=OneWay}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="280"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0" Text="{Binding idFirmen}" Padding="5,2" FontWeight="Normal" Foreground="LightGray"/>
                                <TextBlock Grid.Column="1" Text="{Binding Name}" Padding="5,2" FontWeight="Bold"/>
                                <TextBlock Grid.Column="2" Text="{Binding Beauftragte_Leistung}" Padding="5,2" Foreground="Gray"/>
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </StackPanel>

            <Button x:Name="btnBookBE" Content="BE Fläche buchen" Height="40" IsEnabled="True" Grid.ColumnSpan="3" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="10,0,10,20" Click="btnBookBE_Click"/>
        </Grid>

        <!--<StackPanel Grid.Row="1" VerticalAlignment="Stretch">-->
        <TextBlock x:Name="lblBE" Text="Alle aktuell gebuchten BE-Flächen:" FontSize="14" Grid.Row="1" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="10,0,0,5"/>
        <DataGrid x:Name="dgBelegung" EnableRowVirtualization="False" DataContext="{Binding}" ItemsSource="{Binding ., Mode=OneWay}" Grid.Row="1" Margin="10,30,10,50" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"  CellEditEnding="dgBelegung_CellEditEnding" DataContextChanged="dgBelegung_DataContextChanged">
            <DataGrid.Columns>
                <DataGridTextColumn Header="#" Binding="{Binding beNr}" IsReadOnly="True" MinWidth="30" MaxWidth="30">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource MahApps.Styles.DataGridColumnHeader}">
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextAlignment" Value="Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="BE Name" Binding="{Binding beFlaeche}" MinWidth="140" Width="*" IsReadOnly="True"/>
                <DataGridTemplateColumn Header="von" IsReadOnly="False" MinWidth="100" MaxWidth="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DatePicker x:Name="dpVonDG" IsEnabled="False" Loaded="dpVonDG_Loaded" local:DatePickerHelper.ShowTodayButton="True" local:DatePickerHelper.ShowTodayButtonContent="Heute" SelectedDate="{Binding von, StringFormat=\{0:dd.MM.yyyy\}, ValidatesOnDataErrors=False, ValidatesOnExceptions=False, ValidatesOnNotifyDataErrors=False}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="bis" MinWidth="100" MaxWidth="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DatePicker x:Name="dpBisDG" IsEnabled="False" Loaded="dpBisDG_Loaded" local:DatePickerHelper.ShowTodayButton="True" local:DatePickerHelper.ShowTodayButtonContent="Heute" SelectedDate="{Binding bis, StringFormat=\{0:dd.MM.yyyy\}, ValidatesOnDataErrors=False, ValidatesOnExceptions=False, ValidatesOnNotifyDataErrors=False}" LostFocus="dpBisDG_LostFocus"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Maßnahme/Bemerkung" MinWidth="150">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox x:Name="tbDGBemerkung" AcceptsReturn="True" Text="{Binding Bemerkung, Mode=OneWay}" Loaded="tbDGBemerkung_Loaded" IsEnabled="False" LostKeyboardFocus="tbDGBemerkung_LostKeyboardFocus" LostFocus="tbDGBemerkung_LostFocus"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="PL" Binding="{Binding Projektleiter}" MinWidth="100" Width="150" IsReadOnly="True"/>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="ⓘ" MinWidth="20" MaxWidth="20" Height="20" ToolTip="Zugewiesene Firmen anzeigen" Padding="0,-5,0,0" FontSize="20" Click="InfoButton_Click"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="3" MinWidth="20" MaxWidth="20" Height="20" Padding="0,2,0,0" Foreground="Red" ToolTip="Buchung stornieren" ToolTipService.ShowOnDisabled="True" FontFamily="Wingdings 2" FontSize="18" Click="DeleteButton_Click" Loaded="DelButton_Loaded"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        
        <Button x:Name="btnCurrentlyBooked" Content="Aktuell belegte Flächen anzeigen" Grid.Row="1" Grid.ColumnSpan="3" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="10,0,10,5" Click="btnCurrentlyBooked_Click"/>
        <!--</StackPanel>-->

        <Popup x:Name="pop" AllowsTransparency="True" Closed="Pop_Closed">
            <StackPanel Orientation="Vertical" Background="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" Margin="5">
                <TextBlock Text="Firmen, denen aktuell diese Fläche zugewiesen ist:" Margin="5"/>
                <DataGrid x:Name="dgFirmen" Visibility="Visible" ItemsSource="{Binding .}" Height="200" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeRows="False" IsReadOnly="True">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                        <DataGridTextColumn Header="Verantwortl. MA" Binding="{Binding Verantwortlicher_MA_Firma}"/>
                        <DataGridTextColumn Header="Tel. Firma" Binding="{Binding Tel_Nr_Verantwortlicher_Firma}"/>
                        <DataGridTextColumn Header="Anz. Fzg." Binding="{Binding Anzahl_Fzg}">
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="TextBlock">
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="Beauftragte Leistung" Binding="{Binding Beauftragte_Leistung}"/>
                        <DataGridTextColumn Header="Arbeitsbeginn" Binding="{Binding Arbeitsbeginn, StringFormat=\{0:dd.MM.yyyy\}}">
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="TextBlock">
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="Arbeitsende" Binding="{Binding Arbeitsende, StringFormat=\{0:dd.MM.yyyy\}}">
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="TextBlock">
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="Ansprechpartner intern" Binding="{Binding Ansprechpartner_Intern}"/>
                        <DataGridTextColumn Header="Tel. Ansprechpartner" Binding="{Binding Tel_Nr_Ansprechpartner_Intern}"/>
                    </DataGrid.Columns>
                </DataGrid>
            </StackPanel>
        </Popup>
    </Grid>
</mah:MetroWindow>
