Dialogs: Add DeliveryConfirmationsDialog
This commit is contained in:
32
Elwig/Dialogs/DeliveryConfirmationsDialog.xaml
Normal file
32
Elwig/Dialogs/DeliveryConfirmationsDialog.xaml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<local:ContextWindow x:Class="Elwig.Dialogs.DeliveryConfirmationsDialog"
|
||||||
|
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:Elwig.Windows"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
ResizeMode="NoResize"
|
||||||
|
Title="Anlieferungsbestätingungen - Elwig" Height="400" Width="600">
|
||||||
|
<Grid>
|
||||||
|
<GroupBox Header="Sortieren nach" Margin="10,10,10,10" Width="150" Height="80" VerticalAlignment="Top" HorizontalAlignment="Left">
|
||||||
|
<StackPanel Margin="5,5,0,5">
|
||||||
|
<RadioButton GroupName="Order" x:Name="OrderMgNrInput" Content="Mitgliedsnummer" IsChecked="True"/>
|
||||||
|
<RadioButton GroupName="Order" x:Name="OrderNameInput" Content="Name"/>
|
||||||
|
<RadioButton GroupName="Order" x:Name="OrderPlzInput" Content="PLZ, Ort, Name"/>
|
||||||
|
</StackPanel>
|
||||||
|
</GroupBox>
|
||||||
|
|
||||||
|
<TextBox x:Name="TextElement" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"
|
||||||
|
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="170,10,10,10" Height="Auto"/>
|
||||||
|
|
||||||
|
<Button x:Name="TestButton" Content="Stichprobe" FontSize="14" Width="150" Margin="10,10,10,74" Height="27"
|
||||||
|
Click="TestButton_Click"
|
||||||
|
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||||
|
<Button x:Name="ShowButton" Content="Vorschau" FontSize="14" Width="150" Margin="10,10,10,42" Height="27"
|
||||||
|
Click="ShowButton_Click"
|
||||||
|
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||||
|
<Button x:Name="PrintButton" Content="Drucken" FontSize="14" Width="150" Margin="10,10,10,10" Height="27"
|
||||||
|
Click="PrintButton_Click"
|
||||||
|
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||||
|
</Grid>
|
||||||
|
</local:ContextWindow>
|
101
Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs
Normal file
101
Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using Elwig.Documents;
|
||||||
|
using Elwig.Models;
|
||||||
|
using Elwig.Windows;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace Elwig.Dialogs {
|
||||||
|
public partial class DeliveryConfirmationsDialog : ContextWindow {
|
||||||
|
|
||||||
|
public readonly int Year;
|
||||||
|
|
||||||
|
public DeliveryConfirmationsDialog(int year) {
|
||||||
|
InitializeComponent();
|
||||||
|
Year = year;
|
||||||
|
Title = $"Anlieferungsbestätigungen - Lese {Year} - Elwig";
|
||||||
|
TextElement.Text = App.Client.TextDeliveryConfirmation;
|
||||||
|
if (!App.Config.Debug) {
|
||||||
|
TestButton.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnRenewContext() { }
|
||||||
|
|
||||||
|
private async Task UpdateTextParameter() {
|
||||||
|
var text = TextElement.Text;
|
||||||
|
if (text.Length == 0) text = null;
|
||||||
|
if (text != App.Client.TextDeliveryConfirmation) {
|
||||||
|
App.Client.TextDeliveryConfirmation = text;
|
||||||
|
await App.Client.UpdateValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Generate(int mode) {
|
||||||
|
|
||||||
|
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||||
|
await UpdateTextParameter();
|
||||||
|
|
||||||
|
var members = Context.Members.FromSqlRaw($"""
|
||||||
|
SELECT m.*
|
||||||
|
FROM member m
|
||||||
|
INNER JOIN delivery d ON d.mgnr = m.mgnr
|
||||||
|
WHERE d.year = {Year}
|
||||||
|
GROUP BY m.mgnr
|
||||||
|
""");
|
||||||
|
if (OrderMgNrInput.IsChecked == true) {
|
||||||
|
members = members
|
||||||
|
.OrderBy(m => m.MgNr);
|
||||||
|
} else if (OrderNameInput.IsChecked == true) {
|
||||||
|
members = members
|
||||||
|
.OrderBy(m => m.FamilyName)
|
||||||
|
.ThenBy(m => m.GivenName)
|
||||||
|
.ThenBy(m => m.MgNr);
|
||||||
|
} else if (OrderPlzInput.IsChecked == true) {
|
||||||
|
members = members
|
||||||
|
.OrderBy(m => m.PostalDest.AtPlz.Plz)
|
||||||
|
.ThenBy(m => m.PostalDest.AtPlz.Ort.Name)
|
||||||
|
.ThenBy(m => m.FamilyName)
|
||||||
|
.ThenBy(m => m.GivenName)
|
||||||
|
.ThenBy(m => m.MgNr);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<Member> list = await members.ToListAsync();
|
||||||
|
if (mode == 0) {
|
||||||
|
var r = new Random().Next(0, 10);
|
||||||
|
list = list.Where((_, n) => n % 10 == r);
|
||||||
|
}
|
||||||
|
|
||||||
|
using var doc = await Document.Merge(list.Select(m => new DeliveryConfirmation(Context, Year, m))); ;
|
||||||
|
await doc.Generate();
|
||||||
|
Mouse.OverrideCursor = null;
|
||||||
|
|
||||||
|
if (mode < 2) {
|
||||||
|
doc.Show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (App.Config.Debug) {
|
||||||
|
doc.Show();
|
||||||
|
} else {
|
||||||
|
await doc.Print();
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void TestButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
await Generate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ShowButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
await Generate(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void PrintButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
await Generate(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
using Elwig.Documents;
|
using Elwig.Dialogs;
|
||||||
using Elwig.Helpers;
|
using Elwig.Helpers;
|
||||||
using Elwig.Helpers.Billing;
|
using Elwig.Helpers.Billing;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
@ -46,32 +44,11 @@ namespace Elwig.Windows {
|
|||||||
CalculateBinsButton.IsEnabled = true;
|
CalculateBinsButton.IsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void DeliveryConfirmationButton_Click(object sender, RoutedEventArgs evt) {
|
private void DeliveryConfirmationButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
if (SeasonInput.Value is not int year)
|
if (SeasonInput.Value is not int year)
|
||||||
return;
|
return;
|
||||||
var res = MessageBox.Show(
|
var d = new DeliveryConfirmationsDialog(year);
|
||||||
$"Sollen wirklich alle Bestätigungen gedruckt werden?", "Ausdruck Bestätigen",
|
d.Show();
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
|
||||||
if (res != MessageBoxResult.Yes)
|
|
||||||
return;
|
|
||||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
|
||||||
using var doc = await Document.Merge(Context.Members.FromSqlRaw($"""
|
|
||||||
SELECT m.*
|
|
||||||
FROM member m
|
|
||||||
JOIN delivery d ON d.mgnr = m.mgnr
|
|
||||||
WHERE m.active AND d.year = {year}
|
|
||||||
GROUP BY m.mgnr
|
|
||||||
ORDER BY m.mgnr
|
|
||||||
""")
|
|
||||||
.ToList()
|
|
||||||
.Select(m => new DeliveryConfirmation(Context, year, m)));
|
|
||||||
await doc.Generate();
|
|
||||||
Mouse.OverrideCursor = null;
|
|
||||||
if (App.Config.Debug) {
|
|
||||||
doc.Show();
|
|
||||||
} else {
|
|
||||||
await doc.Print();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OverUnderDeliveryButton_Click(object sender, RoutedEventArgs evt) {
|
private void OverUnderDeliveryButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
|
Reference in New Issue
Block a user