Skip to content

Commit

Permalink
Merge pull request #14 from izzappel/feature/print-person-detail
Browse files Browse the repository at this point in the history
Feature/print person detail
  • Loading branch information
izzappel authored May 3, 2017
2 parents bb6b636 + ffcb461 commit 727ead2
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 38 deletions.
12 changes: 12 additions & 0 deletions ZuegerAddressbook/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:ZuegerAdressbook.View.Controls"
x:Class="ZuegerAdressbook.App"
xmlns:converter="clr-namespace:ZuegerAdressbook.Converters"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
Expand All @@ -13,6 +14,17 @@
<Setter Property="FontFamily" Value="fonts/#Frutiger LT Com 55 Roman" />
</Style>
<SolidColorBrush x:Key="ControlBackgroundColor" Color="#FFDDDDDD" />

<converter:EnumBooleanConverter x:Key="enumBooleanConverter" />
<converter:BooleanVisibilityConverter x:Key="booleanVisibilityConverter"/>
<converter:EnumVisibilityConverter x:Key="enumVisibilityConverter"/>
<converter:NullableVisibilityConverter x:Key="nullableVisibilityConverter"/>

<Style TargetType="{x:Type TextBlock}" x:Key="FontAwesomeIcon">
<Setter Property="FontFamily" Value="fonts/#FontAwesome"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
1 change: 1 addition & 0 deletions ZuegerAddressbook/IocConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public override void Load()
Bind<MainViewModel>().ToSelf().InTransientScope();
Bind<PersonViewModel>().ToSelf().InTransientScope();
Bind<DocumentViewModel>().ToSelf().InTransientScope();
Bind<PrintPersonDetailsViewModel>().ToSelf().InTransientScope();
}
}
}
13 changes: 1 addition & 12 deletions ZuegerAddressbook/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
Icon="Icons/48/address-book.png"
d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}">
<Window.Resources>
<converter:EnumBooleanConverter x:Key="enumBooleanConverter" />
<converter:BooleanVisibilityConverter x:Key="booleanVisibilityConverter"/>
<converter:EnumVisibilityConverter x:Key="enumVisibilityConverter"/>
<converter:NullableVisibilityConverter x:Key="nullableVisibilityConverter"/>

<Style TargetType="{x:Type TextBlock}" x:Key="FontAwesomeIcon">
<Setter Property="FontFamily" Value="fonts/#FontAwesome"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="VerticalAlignment" Value="Center" />
</Style>

<Style TargetType="{x:Type TextBox}">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="0,0,0,1"/>
Expand Down Expand Up @@ -146,7 +135,7 @@
</Button>
</ToolBar>
<ToolBar Header="Drucken" Loaded="FrameworkElement_OnLoaded">
<Button ToolBar.OverflowMode="Never">
<Button Command="{Binding PrintPersonDetailCommand}" ToolBar.OverflowMode="Never">
<StackPanel Orientation="Vertical">
<Image Source="Icons/48/profile-group.png"/>
<TextBlock HorizontalAlignment="Center"><Run Text="Personen"/></TextBlock>
Expand Down
24 changes: 0 additions & 24 deletions ZuegerAddressbook/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,6 @@ public MainWindow()
DataContext = _viewModel;
}

private void AddDocumentButton_OnClick(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();

var result = fileDialog.ShowDialog();
if (result == true)
{
// Open document
string filename = fileDialog.FileName;
}
}

private void BirthdayFilterToggle_OnChecked(object sender, RoutedEventArgs e)
{
if (BirthdayFilterToggle.IsChecked.GetValueOrDefault())
{
//_viewModel.SortPersonsByBirthday();
}
else
{
//_viewModel.SortPersonsByName();
}
}

private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
ToolBar toolBar = sender as ToolBar;
Expand Down
8 changes: 8 additions & 0 deletions ZuegerAddressbook/Printing/PersonDetail.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<FlowDocument x:Class="ZuegerAdressbook.Printing.PersonDetail"
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:local="clr-namespace:ZuegerAdressbook.Printing">
<Section x:Name="Section"></Section>
</FlowDocument>
113 changes: 113 additions & 0 deletions ZuegerAddressbook/Printing/PersonDetail.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZuegerAdressbook.ViewModels;

namespace ZuegerAdressbook.Printing
{
/// <summary>
/// Interaction logic for PersonDetail.xaml
/// </summary>
public partial class PersonDetail : FlowDocument
{
private List<PersonViewModel> _persons;

public PersonDetail(IList<PersonViewModel> persons)
{
InitializeComponent();
PagePadding = new Thickness(20);
_persons = new List<PersonViewModel>(persons);

var table = new Table();
table.FontFamily = new FontFamily(new Uri("pack://application:,,,/ZuegerAddressbook.Name;component/Resources/Fonts/"), "#Frutiger LT Com 55 Roman");
table.FontSize = 11;
table.CellSpacing = 0;
var tableRowGroup = new TableRowGroup();

tableRowGroup.Rows.Add(CreateHeaderRow());
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("Anrede", person => person.Title));
tableRowGroup.Rows.Add(CreateRow("Name", person => person.Lastname));
tableRowGroup.Rows.Add(CreateRow("Vorname", person => person.Firstname));
tableRowGroup.Rows.Add(CreateRow("Strasse / Hausnr.", person => person.Street1));
tableRowGroup.Rows.Add(CreateRow("PLZ / Ort", person => person.Plz + " " + person.City));
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("Festnetz", person => person.PhoneNumber));
tableRowGroup.Rows.Add(CreateRow("Mobile", person => person.MobileNumber));
tableRowGroup.Rows.Add(CreateRow("E-Mail", person => person.EmailAddress));
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("Geburtsdatum", person => person.Birthdate.HasValue ? person.Birthdate.Value.ToShortDateString() : "-"));
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("SBB-Ermässigung", person => "-"));
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("Passnummer", person => person.PassportNumber));
tableRowGroup.Rows.Add(CreateRow("Pass gültig bis", person => ""));
tableRowGroup.Rows.Add(CreateEmptyRow());
tableRowGroup.Rows.Add(CreateRow("Bemerkungen", person => person.Notes));
tableRowGroup.Rows.Add(CreateEmptyRow());

table.RowGroups.Add(tableRowGroup);
Section.Blocks.Add(table);
}

private TableRow CreateRow(string title, Func<PersonViewModel, string> personPropertySelector)
{
var row = new TableRow();
row.Cells.Add(Cell(Text(title)));
_persons.ForEach(person => row.Cells.Add(Cell(Text(personPropertySelector(person)))));

return row;
}

private TableRow CreateHeaderRow()
{
var headerRow = new TableRow();
headerRow.FontWeight = FontWeights.Bold;
headerRow.Background = new SolidColorBrush(Colors.Yellow);
headerRow.Cells.Add(Cell(Text("Stammdaten")));
var personEnumerator = _persons.GetEnumerator();
for (var index = 1; personEnumerator.MoveNext() == true; index++)
{
headerRow.Cells.Add(Cell(Text(string.Format("{0}. Person", index))));
}

return headerRow;
}

private TableRow CreateEmptyRow()
{
var emptyRow = new TableRow();
emptyRow.Cells.Add(Cell(Text(string.Empty)));
_persons.ForEach(person => emptyRow.Cells.Add(Cell(Text(string.Empty))));

return emptyRow;
}

private TableCell Cell(Block inlineElement)
{
var cell = new TableCell(inlineElement);
cell.Padding = new Thickness(5);
cell.BorderBrush = new SolidColorBrush(Colors.Black);
cell.BorderThickness = new Thickness(0.5);

return cell;
}

private Paragraph Text(string text)
{
return new Paragraph(new Run(text));
}

}
}
29 changes: 29 additions & 0 deletions ZuegerAddressbook/Printing/PersonDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ZuegerAdressbook.ViewModels;

namespace ZuegerAdressbook.Printing
{
public class PersonDetailViewModel : ViewModelBase
{
public ObservableCollection<PersonViewModel> Persons { get; set; }

public PersonDetailViewModel()
{
Persons = new ObservableCollection<PersonViewModel>();
}

public PersonDetailViewModel(IList<PersonViewModel> persons)
{
Persons = new ObservableCollection<PersonViewModel>(persons);
for (int i = 0; i < 100; i++)
{
foreach (var person in persons)
{
Persons.Add(person);
}
}

}
}
}
6 changes: 5 additions & 1 deletion ZuegerAddressbook/Service/IMessageDialogService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ZuegerAdressbook.Service
using System.Windows.Documents;

namespace ZuegerAdressbook.Service
{
public interface IMessageDialogService
{
Expand All @@ -13,5 +15,7 @@ public interface IMessageDialogService
void OpenInformationDialog(string title, string message);

void OpenErrorDialog(string title, string message);

void OpenPrintDialog(FlowDocument document, string description);
}
}
17 changes: 17 additions & 0 deletions ZuegerAddressbook/Service/MessageDialogService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace ZuegerAdressbook.Service
{
Expand Down Expand Up @@ -68,5 +70,20 @@ public void OpenErrorDialog(string title, string message)
{
MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error);
}

public void OpenPrintDialog(FlowDocument document, string description)
{
PrintDialog printDialog = new PrintDialog();

IDocumentPaginatorSource dps = document;
if (printDialog.ShowDialog() == true)
{
document.PageHeight = printDialog.PrintableAreaHeight;
document.PageWidth = printDialog.PrintableAreaWidth;
document.ColumnGap = 0;
document.ColumnWidth = printDialog.PrintableAreaWidth;
printDialog.PrintDocument(dps.DocumentPaginator, description);
}
}
}
}
106 changes: 106 additions & 0 deletions ZuegerAddressbook/View/PrintPersonDetailsDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<Window x:Class="ZuegerAdressbook.View.PrintPersonDetailsDialog"
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:zugab="clr-namespace:ZuegerAdressbook"
xmlns:local="clr-namespace:ZuegerAdressbook.View"
xmlns:vm="clr-namespace:ZuegerAdressbook.ViewModels"
xmlns:converter="clr-namespace:ZuegerAdressbook.Converters"
mc:Ignorable="d"
Icon="../Icons/48/address-book.png"
Title="Drucken" Height="500" Width="500"
d:DataContext="{d:DesignInstance vm:PrintPersonDetailsViewModel, IsDesignTimeCreatable=True}">
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Background="#FFF9F9F9" BorderThickness="0,0,0,1" BorderBrush="#FF333333" SnapsToDevicePixels="True">
<StackPanel Orientation="Horizontal">
<TextBlock Padding="20" FontSize="15pt">Bitte Personen zum Drucken auswählen:</TextBlock>
</StackPanel>
</Border>

<ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedListPerson}" Margin="5 5 0 0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource FontAwesomeIcon}" Visibility="{Binding Gender, ConverterParameter=Female, Converter={StaticResource enumVisibilityConverter}}"><Run Text="&#xF182;"/></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource FontAwesomeIcon}" Visibility="{Binding Gender, ConverterParameter=Male, Converter={StaticResource enumVisibilityConverter}}"><Run Text="&#xF183;"/></TextBlock>

<TextBlock Grid.Column="2" Grid.Row="0" VerticalAlignment="Center">
<Run Text="{Binding Lastname}" />
<Run Text="{Binding Firstname}" />
</TextBlock>
<TextBlock Visibility="{Binding Birthdate, Converter={StaticResource nullableVisibilityConverter}}" Grid.Column="3" Grid.Row="0" Margin="5,0,0,0" VerticalAlignment="Center">
<Run Text="{Binding Birthdate, StringFormat=({0:dd. MMMM yyyy})}" />
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

<StackPanel Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Margin="5 0 5 0">
<Button Command="{Binding AddSelectedToSelectedPersonsCommand}" Margin="0 5 0 5">
<StackPanel Orientation="Vertical">
<Image Source="../Icons/48/sign-right.png"/>
</StackPanel>
</Button>
<Button Command="{Binding RemoveSelectedFromSelectedPersonsCommand}" Margin="0 5 0 5">
<StackPanel Orientation="Vertical">
<Image Source="../Icons/48/sign-left.png"/>
</StackPanel>
</Button>
</StackPanel>

<ListBox Grid.Column="2" Grid.Row="1" ItemsSource="{Binding SelectedPersons}" SelectedItem="{Binding SelectedSelectedPerson}" Margin="0 5 5 0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource FontAwesomeIcon}" Visibility="{Binding Gender, ConverterParameter=Female, Converter={StaticResource enumVisibilityConverter}}"><Run Text="&#xF182;"/></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource FontAwesomeIcon}" Visibility="{Binding Gender, ConverterParameter=Male, Converter={StaticResource enumVisibilityConverter}}"><Run Text="&#xF183;"/></TextBlock>

<TextBlock Grid.Column="2" Grid.Row="0" VerticalAlignment="Center">
<Run Text="{Binding Lastname}" />
<Run Text="{Binding Firstname}" />
</TextBlock>
<TextBlock Visibility="{Binding Birthdate, Converter={StaticResource nullableVisibilityConverter}}" Grid.Column="3" Grid.Row="0" Margin="5,0,0,0" VerticalAlignment="Center">
<Run Text="{Binding Birthdate, StringFormat=({0:dd. MMMM yyyy})}" />
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

<StackPanel Grid.Column="3" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5 5 5 5">
<Button Command="{Binding PrintPersonDetailCommand}" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="../Icons/48/sign-check.png"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"><Run Text="Drucken"/></TextBlock>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Window>
Loading

0 comments on commit 727ead2

Please sign in to comment.