This commit is contained in:
2023-03-09 21:17:46 +01:00
parent 3b53fa599a
commit 69d5110735
6 changed files with 18 additions and 69 deletions

View File

@ -3,8 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WGneu"
StartupUri="Windows\MainWindow.xaml"
Startup="App_Startup"
Exit="App_Exit"
xmlns:ui="http://schemas.modernwpf.com/2019">
<Application.Resources>
<!--<ResourceDictionary>

View File

@ -18,20 +18,22 @@ namespace WGneu {
MainDispatcher = Dispatcher;
}
public void App_Startup(object sender, EventArgs e) {
protected override void OnStartup(StartupEventArgs e) {
Task.Run(() => Documents.Html.Init(PrintingReadyChanged));
Task.Run(() => Documents.Pdf.Init(PrintingReadyChanged));
base.OnStartup(e);
}
public void App_Exit(object sender, EventArgs e) {
protected override void OnExit(ExitEventArgs e) {
Task.Run(() => Documents.Pdf.Close());
base.OnExit(e);
}
private void PrintingReadyChanged() {
Dispatcher.BeginInvoke(App_PrintingReadyChanged, this, new EventArgs());
Dispatcher.BeginInvoke(OnPrintingReadyChanged, new EventArgs());
}
private void App_PrintingReadyChanged(object sender, EventArgs e) {
protected void OnPrintingReadyChanged(EventArgs e) {
foreach (Window w in Windows) {
foreach (var b in Utils.FindVisualChilds<Button>(w).Where(b => "Print".Equals(b.Tag))) {
b.IsEnabled = IsPrintingReady;

View File

@ -1,35 +0,0 @@
using RazorLight;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using WGneu.Models;
using System.Windows;
namespace WGneu.Documents {
class Template {
private static readonly string ROOT = @"C:\Users\lorenz\Desktop\";
public static async void Test() {
await Pdf.Convert(ROOT + "din-5008.html", ROOT + "test.pdf");
Pdf.UpdateMetadata(ROOT + "test.pdf", "Test Dokument", "Winzergenossenschaft für Matzen und Umgebung reg. Gen.m.b.H.");
Pdf.Show(ROOT + "test.pdf", "Test-Dokument");
}
public static void Generate(WgContext c) {
Task.Run(async () => {
try {
using var letter = new BusinessLetter("Test Dokument", c.Members.First());
await letter.Generate();
letter.Show();
} catch (Exception e) {
MessageBox.Show(e.ToString(), "PDF Generation", MessageBoxButton.OK, MessageBoxImage.Error);
}
});
}
}
}

View File

@ -7,18 +7,8 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" ResizeMode="CanResize" SizeToContent="Manual"
Loaded="Window_Loaded">
<Window.Resources>
<CollectionViewSource x:Key="countryViewSource"/>
<DataTemplate x:Key="asdf">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ComboBox HorizontalAlignment="Left" Margin="175,149,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Source={StaticResource countryViewSource}}" ItemTemplate="{StaticResource asdf}" SelectionChanged="ComboBox_SelectionChanged" IsEditable="True"/>
<Button x:Name="Button2" Content="Mitglieder" Margin="472,182,178,0" VerticalAlignment="Top" Click="Button2_Click"/>
<Button x:Name="Button3" Content="Print" Margin="425,255,225,0" VerticalAlignment="Top" Click="Button3_Click" Tag="Print"/>
<Button x:Name="Button4" Content="Generate" Margin="425,300,225,0" VerticalAlignment="Top" Click="Button4_Click" Tag="Print"/>
</Grid>
</Window>

View File

@ -15,23 +15,20 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WGneu.Documents;
using WGneu.Models;
namespace WGneu.Windows {
public partial class MainWindow : Window {
private readonly WgContext _context = new WgContext();
private CollectionViewSource countryViewSource;
public MainWindow() {
InitializeComponent();
countryViewSource = (CollectionViewSource)FindResource("countryViewSource");
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
_context.Countries.Load();
countryViewSource.Source = _context.Countries.Local.ToObservableCollection();
Button3.IsEnabled = App.IsPrintingReady;
Button4.IsEnabled = App.IsPrintingReady;
}
@ -45,20 +42,16 @@ namespace WGneu.Windows {
w.Show();
}
private void Button3_Click(object sender, EventArgs e) {
Documents.Template.Test();
}
private void Button4_Click(object sender, EventArgs e) {
Documents.Template.Generate(_context);
}
private void Button_Click(object sender, RoutedEventArgs e) {
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
Task.Run(async () => {
try {
using var letter = new BusinessLetter("Test Dokument", _context.Members.First());
await letter.Generate();
letter.Show();
} catch (Exception e) {
MessageBox.Show(e.ToString(), "PDF Generation", MessageBoxButton.OK, MessageBoxImage.Error);
}
});
}
}
}

View File

@ -287,8 +287,9 @@
<RadioButton x:Name="ContactEmailInput" GroupName="DefaultContact" Content="E-Mail" IsEnabled="False"
Checked="RadioButton_Changed" Unchecked="RadioButton_Changed"
HorizontalAlignment="Left" Margin="60,225,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
<Button x:Name="AreaCommitmentButton" Content="Flächenbindungen" Click="AreaCommitmentButton_Click"
HorizontalAlignment="Left" Margin="10,245,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Bottom" Grid.ColumnSpan="3"/>
</Grid>
</GroupBox>
</Grid>