<view:BeWoView x:Class="BeWo.View.BargeldkassenView"
               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:view="clr-namespace:BeWo.View"
               xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
               xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
               xmlns:validation="clr-namespace:BeWo.Validation"
               xmlns:core="clr-namespace:BS.Shared.Core;assembly=BS.Shared"
               xmlns:controls="clr-namespace:BeWo.View.Controls"
               Height="Auto" Width="Auto" HorizontalAlignment="Stretch"
               mc:Ignorable="d" VerticalAlignment="Stretch" Focusable="True">
    <view:BeWoView.Resources>
        <Style x:Key="bargeldkassenListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Background" Value="#00FFFFFF" />
            <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="Padding" Value="2,0,0,0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" SnapsToDevicePixels="True" Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                    Content="{TemplateBinding Content}"
                                    ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style x:Key="HyperlinkStyle" TargetType="{x:Type Hyperlink}">
            <Setter Property="Foreground" Value="#FF2B508B" />
            <!--<Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#FFAFAFAF" />
                </Trigger>
            </Style.Triggers>-->
        </Style>
    </view:BeWoView.Resources>
    <GroupBox Header="Bargeldkassen" Style="{StaticResource ObjectEditGroupBox}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <Button Content="Neue Kasse hinzufügen" Margin="3" Click="ButtonOpenAddBargeldkasseClick" IsEnabled="{Binding Path=DarfBargeldTransaktionAnlegen, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />
                <controls:PopupNonTopmost x:Name="popup_newBargeldkasse">
                    <Border Background="White" Padding="3" BorderThickness="1" BorderBrush="Gray">
                        <GroupBox x:Name="groupbox_newBargeldkasse" Header="Neue Kasse hinzufügen" Style="{DynamicResource ObjectEditGroupBox}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                
                                <Label Grid.Column="0" Grid.Row="0" Content="Kassenname" VerticalAlignment="Center" />
                                <TextBox Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Height="23" Margin="3,0,3,3" Text="{validation:ValidationBinding Path=NewVM.Kassenname}" />
                                
                                <Label Grid.Column="0" Grid.Row="1" Content="Auszahlungsintervall" VerticalAlignment="Center" />
                                <dxe:ComboBoxEdit Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Height="23" HorizontalAlignment="Left" Width="150" IsTextEditable="False" 
                                                  Margin="3,0,3,3" IsEnabled="{Binding Path=DarfBargeldtransaktionenBearbeiten, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"
									              ItemsSource="{Binding Path=Values, Source={x:Static core:DisplayEnum.Auszahlungsintervall}}" EditValue="{validation:ValidationBinding Path=NewVM.Auszahlungsintervall}" />
                                
                                <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
                                    <Button Click="ButtonAddBargeldkasseClick" Content="Hinzufügen" Height="25"
                                            FontWeight="Normal" Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" />
                                    
                                    <Button HorizontalAlignment="Right" VerticalAlignment="Center" Height="25"
                                            Margin="3" Content="Abbrechen" Click="ButtonCancelAddBargeldkasseClick" />
                                </StackPanel>
                            </Grid>
                        </GroupBox>
                    </Border>
                </controls:PopupNonTopmost>
                <!--<Button Content="Neue Zahlung hinzufügen" Margin="3" Click="ButtonOpenAddBargeldtransaktionClick" IsEnabled="{Binding Path=DarfBargeldTransaktionAnlegen, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />-->
                <controls:PopupNonTopmost x:Name="popup_newBargeldtransaktion" Placement="MousePoint">
                    <Border Background="White" Padding="3" BorderThickness="1" BorderBrush="Gray">
                        <GroupBox x:Name="groupbox_newBargeldtransaktion" Header="Neue Zahlung zu einer Kasse hinzufügen" Style="{DynamicResource ObjectEditGroupBox}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <!-- RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}} -->
                                <!--<Label Grid.Column="0" Grid.Row="0" Content="Kasse" VerticalAlignment="Center" />
                                <dxe:ComboBoxEdit Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Height="23" Margin="3,0,3,3"  ItemsSource="{Binding VMList}" Width="150" x:Name="NewTransaktionKassenCB" 
                                                  EditValue="{validation:ValidationBinding Path=SelectedBargeldkasse, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />-->

                                <Label Grid.Column="0" Grid.Row="0" Content="Datum" VerticalAlignment="Center" />
                                <dxe:DateEdit Grid.Column="1" Grid.Row="0" MaskType="DateTimeAdvancingCaret"
                                              EditValue="{validation:ValidationBinding Path=NewBargeldtransaktion.Zahlungsdatum, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" Height="23" Margin="3" x:Name="NewTransaktionDatumDateEdit" />

                                <Label Grid.Column="0" Grid.Row="1" Content="Art" VerticalAlignment="Center" />
                                <dxe:ComboBoxEdit Grid.Column="1" Grid.Row="1" Height="23" IsTextEditable="False" Margin="3,0,3,3"
										          ItemsSource="{Binding Path=Values, Source={x:Static core:DisplayEnum.Zahlungstyp}}" x:Name="NewTransaktionZahlungstypComboBoxEdit"
                                                  EditValue="{validation:ValidationBinding Path=NewBargeldtransaktion.Zahlungstyp, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />

                                <Label Grid.Column="0" Grid.Row="2" Content="Betrag" VerticalAlignment="Center" />
                                <dxe:TextEdit Grid.Column="1" Grid.Row="2" MaskType="Numeric" Mask="########0.00" MaskUseAsDisplayFormat="True" Height="23" Margin="3" x:Name="NewTransaktionBetragTextEdit" 
                                              EditValue="{validation:ValidationBinding Path=NewBargeldtransaktion.Betrag, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />

                                <Label Grid.Column="0" Grid.Row="3" Content="Notiz" VerticalAlignment="Center" />
                                <TextBox Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" Height="60" Margin="3,0,3,3"
                                         ScrollViewer.CanContentScroll="False" VerticalScrollBarVisibility="Auto"
									     HorizontalScrollBarVisibility="Hidden" TextWrapping="Wrap" AcceptsReturn="True"
									     AutoWordSelection="True" Language="de-DE" SpellCheck.IsEnabled="True"
                                         x:Name="NewTransaktionNotizTextBox"
                                         Text="{Binding Path=NewBargeldtransaktion.Notice, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"/>

                                <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
                                    <Button Click="ButtonAddBargeldtransaktionClick" Content="Hinzufügen" Height="25"
                                            FontWeight="Normal" Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" />
                                    <Button HorizontalAlignment="Right" VerticalAlignment="Center" Height="25"
                                            Margin="3" Content="Abbrechen" Click="ButtonCancelAddBargeldtransaktionClick" />
                                </StackPanel>
                            </Grid>
                        </GroupBox>
                    </Border>
                </controls:PopupNonTopmost>
            </StackPanel>
            <TabControl Grid.Row="1" Margin="5" ItemsSource="{Binding VMList}" x:Name="tabcontrol_bargeldkassen" Visibility="{Binding VMList.Count, Converter={StaticResource CollectionCountToVisibilityConverter}}">
                <TabControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Kassenname}" />
                            <Button VerticalAlignment="Center" Height="20"
                                    ToolTip="Bargeldkasse umbenennen"
                                    Margin="3" Content="!" FontFamily="Wingdings"
                                    IsEnabled="{Binding Path=DarfBargeldtransaktionenBearbeiten, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"
                                    Click="KassennamenChangeButtonClick">
                                <Button.Visibility>
                                    <MultiBinding Converter="{StaticResource BoolVisibilityMultiConverter }">
                                        <Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType={x:Type TabItem}}" />
                                    </MultiBinding>
                                </Button.Visibility>
                            </Button>
                            <controls:PopupNonTopmost x:Name="popup_kassennamenEdit">
                                <Border Background="White" Padding="3" BorderThickness="1" BorderBrush="Gray">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <TextBox Width="200" Grid.Row="0" Grid.Column="0" Height="23" Margin="3" Text="{validation:ValidationBinding Path=Kassenname, UpdateSourceTrigger=PropertyChanged}" />
                                        
                                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                                            <Button Content="Speichern" Margin="3" Click="KassennamenChangeSaveButtonClick" />
                                            <Button Content="Abbrechen" Margin="3" Click="KassennamenChangeCancelButtonClick" />
                                        </StackPanel>
                                    </Grid>
                                </Border>
                            </controls:PopupNonTopmost>
                            <Button VerticalAlignment="Center" Height="20"
                                    Click="BtnDeleteBargeldkasseClick"
                                    Tag="{Binding}"
                                    ToolTip="Bargeldkasse entfernen"
                                    Style="{DynamicResource CloseButtonStyle}" Margin="3" >
                                <Button.Visibility>
                                    <MultiBinding Converter="{StaticResource BoolVisibilityMultiConverter }">
                                        <Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType={x:Type TabItem}}" />
										<Binding Path="DarfBargeldTransaktionLoeschen" RelativeSource="{RelativeSource AncestorType={x:Type view:BargeldkassenView}}" />
                                    </MultiBinding>
                                </Button.Visibility>
                            </Button>
                        </StackPanel>
                    </DataTemplate>
                </TabControl.ItemTemplate>
                <TabControl.ContentTemplate>
                    <DataTemplate>
                        <Grid Tag="{Binding}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="2">
                                <Button Content="Neue Zahlung hinzufügen" Margin="3" Tag="{Binding}" Click="ButtonOpenAddBargeldtransaktionClick" IsEnabled="{Binding Path=DarfBargeldTransaktionAnlegen, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />
                                
                                <Label VerticalAlignment="Center">Kassenbestand</Label>
                                <dxe:TextEdit MaskType="Numeric" Mask="c" MaskUseAsDisplayFormat="True" Height="23" Margin="3" EditMode="InplaceInactive"
										            Width="80" EditValue="{Binding Path=Kassenbestand, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" FontWeight="Bold" />

                                <Label VerticalAlignment="Center">Auszahlungsintervall</Label>
                                <dxe:ComboBoxEdit VerticalAlignment="Center" Height="23" HorizontalAlignment="Left" Width="100" IsTextEditable="False" Margin="3,0,3,3"
									                    ItemsSource="{Binding Path=Values, Source={x:Static core:DisplayEnum.Auszahlungsintervall}}"
									                    EditValue="{Binding Path=Auszahlungsintervall, UpdateSourceTrigger=PropertyChanged}"
                                                        IsEnabled="{Binding Path=DarfBargeldtransaktionenBearbeiten, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"
                                                        EditValueChanged="AuszahlungsIntervallCBEditValueChanged"/>
                            </StackPanel>

                            <StackPanel Grid.Column="3" Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
                                <ComboBox x:Name="KassenbuchMonatsCB" Margin="3" ItemsSource="{Binding Path=MonatsComboBoxSource, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"
                                                SelectedItem="{Binding Path=PreselectedMonth, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}, Mode=OneWay}"/>
                                <ComboBox x:Name="KassenbuchJahresCB" Margin="3" ItemsSource="{Binding Path=JahresComboBoxSource, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"
                                                SelectedItem="{Binding Path=PreselectedYear, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}, Mode=OneWay}"/>

                                <TextBlock Margin="3" FontSize="14" VerticalAlignment="Center" PreviewMouseLeftButtonDown="KlassenbuchLinkOnPreviewMouseLeftButtonDown" Tag="{Binding}" IsEnabled="{Binding Path=Bargeldtransaktionen.VMList.Count, Converter={StaticResource CollectionCountToBoolConverter}, UpdateSourceTrigger=PropertyChanged}">
                                        <Hyperlink x:Name="LinkKassenbuchDrucken" TargetName="_NewWindow" Style="{StaticResource HyperlinkStyle}">
                                            <Run Text="Kassenbuch drucken" />
                                        </Hyperlink>
                                </TextBlock>
                            </StackPanel>

                            <GroupBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" x:Name="BlubbTest" Style="{StaticResource ObjectEditGroupBox}" Header="Ein- und Auszahlungen">
                                <dxg:GridControl Name="grid_bargeldtransaktionen" Tag="{Binding}" MaxWidth="{Binding ElementName=BlubbTest, Path=ActualWidth}" ItemsSource="{Binding Path=Bargeldtransaktionen.VMList}" CustomColumnSort="GridBargeldtransaktionenOnCustomColumnSort">
                                    <dxg:GridControl.Columns>
                                        <dxg:GridColumn Header="" FixedWidth="True" Width="24" ReadOnly="True" Visible="{Binding Path=DarfBargeldtransaktionenBearbeiten, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Button Content="r" Tag="{Binding}" Click="ButtonBargeldtransaktionDeleteClick" FontFamily="Webdings" Width="18" Height="18" VerticalAlignment="Center" IsEnabled="{Binding Path=DarfBargeldTransaktionLoeschen, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="Datum" FixedWidth="True" FieldName="Zahlungsdatum" EditSettings="{dxe:DateSettings DisplayFormat=d}" AllowEditing="{Binding Path=BargeldtransaktionenBearbeitenAlsDefaultBooelan, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}" />
                                        <dxg:GridColumn Header="Art" FixedWidth="True" FieldName="Zahlungstyp" AllowEditing="{Binding Path=BargeldtransaktionenBearbeitenAlsDefaultBooelan, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:ComboBoxEditSettings ItemsSource="{Binding Path=Values, Source={x:Static core:DisplayEnum.Zahlungstyp}}" IsTextEditable="False" />
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="Betrag" FixedWidth="True" FieldName="Betrag" AllowEditing="{Binding Path=BargeldtransaktionenBearbeitenAlsDefaultBooelan, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:TextEditSettings MaskType="Numeric" Mask="c" MaskUseAsDisplayFormat="True" />
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="Notiz" FieldName="Notice" AllowEditing="{Binding Path=BargeldtransaktionenBearbeitenAlsDefaultBooelan, RelativeSource={RelativeSource AncestorType={x:Type view:BargeldkassenView}}}"/>
                                        <dxg:GridColumn FieldName="X" Header="Drucken" ReadOnly="True">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock x:Name="textblock_link_pdfexport" VerticalAlignment="Center" Margin="3,0,0,0">
                                                            <Hyperlink x:Name="LinkZahlungsbelegDrucken" Click="LinkZahlungsbelegDruckenClick" TargetName="_NewWindow" Foreground="#FF2B508B">
                                                                <Run Text="Zahlungsbeleg drucken" />
                                                            </Hyperlink>
                                                    </TextBlock>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                        </dxg:GridColumn>
                                    </dxg:GridControl.Columns>
                                    <dxg:GridControl.View>
                                        <dxg:TableView NavigationStyle="Cell" Margin="2,2,2,2" AutoWidth="True" ShowGroupPanel="False" ShowGroupedColumns="False" ShowTotalSummary="False" />
                                    </dxg:GridControl.View>
                                </dxg:GridControl>
                            </GroupBox>
                        </Grid>
                    </DataTemplate>
                </TabControl.ContentTemplate>
            </TabControl>
        </Grid>
    </GroupBox>
</view:BeWoView>
