<?xml version="1.0" encoding="utf-8"?>
<navigation:Page x:Class="SalesAnalysis.Invoices" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" Style="{StaticResource PageStyle}" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 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:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:local="clr-namespace:SalesAnalysis.Web" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">

    <Grid x:Name="LayoutRoot">
        <!--  DomainDataSource control provides the connection between the DomainContext
              object that manages the data and controls that are bound to the data. -->
        <riaControls:DomainDataSource x:Name="_ddsInvoices" LoadSize="200" AutoLoad="True" QueryName="GetInvoicesQuery" LoadingData="_ddsInvoices_LoadingData" LoadedData="_ddsInvoices_LoadedData">
            <!-- NorthWindDomainContext is the auto-generated DomainContext class 
                in the Invoices.Web.Services namespace -->
            <riaControls:DomainDataSource.DomainContext>
                <local:NorthWindDomainContext />
            </riaControls:DomainDataSource.DomainContext>

            <!-- sorting is required for delayed data retrieval -->
            <riaControls:DomainDataSource.SortDescriptors>
                <riaControls:SortDescriptor PropertyPath="Country" Direction="Ascending" />
                <riaControls:SortDescriptor PropertyPath="CustomerName" Direction="Ascending" />
            </riaControls:DomainDataSource.SortDescriptors>

            <!-- group descriptors like in ICollectionView -->
            <riaControls:DomainDataSource.GroupDescriptors>
                <riaControls:GroupDescriptor PropertyPath="Country" />
                <riaControls:GroupDescriptor PropertyPath="CustomerName" />
            </riaControls:DomainDataSource.GroupDescriptors>
        </riaControls:DomainDataSource>

        <Grid Style="{StaticResource ContentStackPanelStyle}">

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <!-- header area -->
            <StackPanel x:Name="ContentStackPanel">

                <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" Text="{Binding Path=ApplicationStrings.InvoicesPageTitle, Source={StaticResource ResourceWrapper}}" />
                <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}" Text="NorthWind Invoices" />

            </StackPanel>

            <StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
                <TextBlock Text="Product Filter:" Margin="5 0 5 0" VerticalAlignment="Center" />
                <Border Background="White" BorderBrush="#ffe7ebe7" BorderThickness="2" CornerRadius="8" Padding="8 0 12 0">
                    <StackPanel Orientation="Horizontal">
                        <TextBox Name="_txtFilter" BorderThickness="0" Padding="0" Width="120" VerticalAlignment="Center" KeyDown="_txtFilter_KeyDown" LostFocus="_txtFilter_LostFocus" />
                        <Image Source="../Assets/Images/search.png" MouseLeftButtonDown="_imgFilter_MouseLeftButtonDown" />
                    </StackPanel>
                </Border>
                <HyperlinkButton Name="_btnSave" Content="Save..." Margin="5 0" VerticalAlignment="Center" Click="_btnSave_Click" />
                <HyperlinkButton Name="_btnPrint" Content="Print..." Margin="5 0" VerticalAlignment="Center" Click="_btnPrint_Click" />
            </StackPanel>

            <!-- Invoices grid -->
            <c1:C1FlexGrid Name="_flex" Grid.Row="1" AutoGenerateColumns="False" ItemsSource="{Binding Data, ElementName=_ddsInvoices}" BorderBrush="DarkGray" BorderThickness="1" FontFamily="Segoe UI" AreRowGroupHeadersFrozen="False" ShowMarquee="True" GridLinesVisibility="None" RowBackground="Transparent" AlternatingRowBackground="Transparent" CursorBackground="Transparent" EditorBackground="Transparent" TopLeftCellBackground="#FFC6C6C6" RowHeaderBackground="#FFE7E7E7" RowHeaderSelectedBackground="#FFF5C795" GridLinesBrush="#FFD0D7E5" HeaderGridLinesBrush="#FF909192" SelectionBackground="#FFEAECF5">
                <c1:C1FlexGrid.ColumnHeaderSelectedBackground>
                    <LinearGradientBrush EndPoint="0,1">
                        <GradientStop Color="#FFFFC996" Offset="0" />
                        <GradientStop Color="#FFFF9B68" Offset="1" />
                    </LinearGradientBrush>
                </c1:C1FlexGrid.ColumnHeaderSelectedBackground>
                <c1:C1FlexGrid.ColumnHeaderBackground>
                    <LinearGradientBrush EndPoint="0,1">
                        <GradientStop Color="#FFF1F3F3" Offset="0" />
                        <GradientStop Color="#FFC8C9CA" Offset="1" />
                    </LinearGradientBrush>
                </c1:C1FlexGrid.ColumnHeaderBackground>
                <c1:C1FlexGrid.Columns>
                    <c1:Column Header="Order Date" Binding="{Binding OrderDate, StringFormat='d'}" Width="*" />
                    <c1:Column Header="Salesperson" Binding="{Binding Salesperson}" Width="2*" TextTrimming="WordEllipsis" />
                    <c1:Column Header="Product" Binding="{Binding ProductName}" Width="2*" TextTrimming="WordEllipsis" />
                    <c1:Column Header="Unit Price" Binding="{Binding UnitPrice, StringFormat='n2'}" Width="*" HorizontalAlignment="Right" />
                    <c1:Column Header="Quantity" Binding="{Binding Quantity, StringFormat='n0'}" Width="*" HorizontalAlignment="Right" />
                    <c1:Column Header="Discount" Binding="{Binding Discount, StringFormat='p0'}" Width="*" HorizontalAlignment="Right" />
                    <c1:Column Header="Total Amount" Binding="{Binding ExtendedPrice, StringFormat='n2'}" Width="*" HorizontalAlignment="Right" GroupAggregate="Sum" />
                </c1:C1FlexGrid.Columns>
            </c1:C1FlexGrid>

            <!-- status bar -->
            <TextBlock Name="_tbStatus" Grid.Row="3" HorizontalAlignment="Right" Margin="0 6 0 4" />
            <TextBlock Grid.Row="3" Text=" " Margin="0 6 0 4" />

        </Grid>
    </Grid>

</navigation:Page>