[#15] MailWindow: Add Rundschreiben-Funktion
This commit is contained in:
@ -254,5 +254,9 @@ namespace Elwig {
|
||||
w.FocusMember(mgnr);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static MailWindow FocusMailWindow() {
|
||||
return FocusWindow<MailWindow>(() => new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ namespace Elwig.Documents {
|
||||
|
||||
public static string Name => "Dokument";
|
||||
|
||||
private static readonly double GenerationProportion = 0.125;
|
||||
protected static readonly double GenerationProportion = 0.125;
|
||||
|
||||
private TempFile? _pdfFile = null;
|
||||
protected TempFile? _pdfFile = null;
|
||||
protected string? _pdfPath;
|
||||
protected string? PdfPath => _pdfPath ?? _pdfFile?.FilePath;
|
||||
|
||||
public bool ShowFoldMarks = App.Config.Debug;
|
||||
public bool DoubleSided = false;
|
||||
@ -59,6 +61,10 @@ namespace Elwig.Documents {
|
||||
return new MergedDocument(docs);
|
||||
}
|
||||
|
||||
public static Document FromPdf(string path) {
|
||||
return new PdfDocument(path);
|
||||
}
|
||||
|
||||
private async Task<string> Render() {
|
||||
string name;
|
||||
if (this is BusinessLetter) {
|
||||
@ -87,20 +93,28 @@ namespace Elwig.Documents {
|
||||
|
||||
public async Task Generate(IProgress<double>? progress = null) {
|
||||
progress?.Report(0.0);
|
||||
if (this is MergedDocument m) {
|
||||
if (this is PdfDocument) {
|
||||
// nothing to do
|
||||
} else if (this is MergedDocument m) {
|
||||
var pdf = new TempFile("pdf");
|
||||
var tmpHtmls = new List<TempFile>();
|
||||
var tmpFiles = new List<string>();
|
||||
var n = m.Documents.Count();
|
||||
int i = 0;
|
||||
foreach (var doc in m.Documents) {
|
||||
if (doc is PdfDocument) {
|
||||
tmpFiles.Add(doc.PdfPath!);
|
||||
continue;
|
||||
}
|
||||
var tmpHtml = new TempFile("html");
|
||||
await File.WriteAllTextAsync(tmpHtml.FilePath, await doc.Render(), Utils.UTF8);
|
||||
tmpHtmls.Add(tmpHtml);
|
||||
tmpFiles.Add(tmpHtml.FileName);
|
||||
i++;
|
||||
progress?.Report(GenerationProportion * 100 * i / n);
|
||||
}
|
||||
progress?.Report(GenerationProportion * 100);
|
||||
await Pdf.Convert(tmpHtmls.Select(f => f.FileName), pdf.FileName, DoubleSided, new Progress<double>(v => progress?.Report(GenerationProportion * 100 + v * (1 - GenerationProportion))));
|
||||
await Pdf.Convert(tmpFiles, pdf.FileName, DoubleSided, new Progress<double>(v => progress?.Report(GenerationProportion * 100 + v * (1 - GenerationProportion))));
|
||||
foreach (var tmp in tmpHtmls) {
|
||||
tmp.Dispose();
|
||||
}
|
||||
@ -118,13 +132,13 @@ namespace Elwig.Documents {
|
||||
}
|
||||
|
||||
public void SaveTo(string pdfPath) {
|
||||
if (_pdfFile == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
||||
File.Copy(_pdfFile.FilePath, pdfPath);
|
||||
if (PdfPath == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
||||
File.Copy(PdfPath, pdfPath);
|
||||
}
|
||||
|
||||
public async Task Print(int copies = 1) {
|
||||
if (_pdfFile == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
||||
await Pdf.Print(_pdfFile.FilePath, copies);
|
||||
if (PdfPath == null) throw new InvalidOperationException("Pdf file has not been generated yet");
|
||||
await Pdf.Print(PdfPath, copies);
|
||||
}
|
||||
|
||||
public void Show() {
|
||||
@ -132,10 +146,14 @@ namespace Elwig.Documents {
|
||||
Pdf.Show(_pdfFile.NewReference(), Title + (this is BusinessDocument b ? $" - {b.Member.Name}" : ""));
|
||||
}
|
||||
|
||||
private class MergedDocument : Document {
|
||||
public IEnumerable<Document> Documents;
|
||||
public MergedDocument(IEnumerable<Document> docs) : base("Mehrere Dokumente") {
|
||||
Documents = docs;
|
||||
private class MergedDocument(IEnumerable<Document> docs) : Document("Mehrere Dokumente") {
|
||||
public IEnumerable<Document> Documents = docs;
|
||||
}
|
||||
|
||||
private class PdfDocument : Document {
|
||||
public PdfDocument(string pdfPath) :
|
||||
base(Path.GetFileNameWithoutExtension(pdfPath)) {
|
||||
_pdfPath = pdfPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
Elwig/Helpers/ActionCommand.cs
Normal file
22
Elwig/Helpers/ActionCommand.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public class ActionCommand : ICommand {
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
private readonly Action Action;
|
||||
|
||||
public ActionCommand(Action action) {
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public void Execute(object parameter) {
|
||||
Action();
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -61,6 +61,8 @@ namespace Elwig.Helpers {
|
||||
public string? TextDeliveryNote;
|
||||
public string? TextDeliveryConfirmation;
|
||||
public string? TextCreditNote;
|
||||
public string? TextEmailSubject;
|
||||
public string? TextEmailBody;
|
||||
|
||||
public ClientParameters(AppDbContext ctx) : this(ctx.ClientParameters.ToDictionary(e => e.Param, e => e.Value)) { }
|
||||
|
||||
@ -108,6 +110,10 @@ namespace Elwig.Helpers {
|
||||
if (TextDeliveryConfirmation == "") TextDeliveryConfirmation = null;
|
||||
TextCreditNote = parameters.GetValueOrDefault("TEXT_CREDITNOTE");
|
||||
if (TextCreditNote == "") TextCreditNote = null;
|
||||
TextEmailSubject = parameters.GetValueOrDefault("TEXT_EMAIL_SUBJECT");
|
||||
if (TextEmailSubject == "") TextEmailSubject = null;
|
||||
TextEmailBody = parameters.GetValueOrDefault("TEXT_EMAIL_BODY");
|
||||
if (TextEmailBody == "") TextEmailBody = null;
|
||||
} catch {
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
@ -143,6 +149,8 @@ namespace Elwig.Helpers {
|
||||
("TEXT_DELIVERYNOTE", TextDeliveryNote),
|
||||
("TEXT_DELIVERYCONFIRMATION", TextDeliveryConfirmation),
|
||||
("TEXT_CREDITNOTE", TextCreditNote),
|
||||
("TEXT_EMAIL_SUBJECT", TextEmailSubject),
|
||||
("TEXT_EMAIL_BODY", TextEmailBody)
|
||||
];
|
||||
}
|
||||
|
||||
@ -163,6 +171,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
await App.HintContextChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,10 @@ namespace Elwig.Models.Entities {
|
||||
public virtual PostalDest PostalDest { get; private set; }
|
||||
|
||||
[ForeignKey("DefaultKgNr")]
|
||||
public virtual AT_Kg? DefaultKg { get; private set; }
|
||||
public virtual WbKg? DefaultWbKg { get; private set; }
|
||||
|
||||
[NotMapped]
|
||||
public AT_Kg? DefaultKg => DefaultWbKg?.AtKg;
|
||||
|
||||
[ForeignKey("ZwstId")]
|
||||
public virtual Branch? Branch { get; private set; }
|
||||
|
@ -20,6 +20,9 @@ namespace Elwig.Models.Entities {
|
||||
[InverseProperty("Kg")]
|
||||
public virtual ISet<WbRd> Rds { get; private set; }
|
||||
|
||||
[InverseProperty("DefaultWbKg")]
|
||||
public virtual ISet<Member> Members { get; private set; }
|
||||
|
||||
[NotMapped]
|
||||
public WbGem Gem => AtKg.Gem.WbGem;
|
||||
|
||||
|
259
Elwig/Windows/MailWindow.xaml
Normal file
259
Elwig/Windows/MailWindow.xaml
Normal file
@ -0,0 +1,259 @@
|
||||
<local:ContextWindow
|
||||
x:Class="Elwig.Windows.MailWindow"
|
||||
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"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
mc:Ignorable="d"
|
||||
MinWidth="650" MinHeight="400" Height="600" Width="950"
|
||||
Closed="Window_Closed"
|
||||
Title="Rundschreiben - Elwig">
|
||||
<Window.Resources>
|
||||
<Style TargetType="Label">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="Padding" Value="2,4,2,4"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
</Style>
|
||||
<Style TargetType="TextBox">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="TextWrapping" Value="NoWrap"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<TabControl x:Name="TabControl" BorderThickness="0" PreviewDragOver="Document_PreviwDragOver" AllowDrop="True" Drop="Document_Drop">
|
||||
<TabItem Header="Dokumente" Visibility="Collapsed">
|
||||
<Grid>
|
||||
<Grid Width="600" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="25"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Verfügbare Dokumente"
|
||||
Grid.Column="0" Margin="10,8,10,10"/>
|
||||
<ListBox x:Name="AvaiableDocumentsList"
|
||||
Grid.Column="0" Margin="10,30,10,10"
|
||||
SelectionChanged="AvaiableDocumentsList_SelectionChanged"/>
|
||||
|
||||
<Button x:Name="DocumentAddButton" Content="" FontFamily="Segoe MDL2 Assets" FontSize="14"
|
||||
Grid.Column="1" Margin="0,0,0,30" VerticalAlignment="Center" Height="25" IsEnabled="False"
|
||||
Click="DocumentAddButton_Click"/>
|
||||
<Button x:Name="DocumentRemoveButton" Content="" FontFamily="Segoe MDL2 Assets" FontSize="14" Padding="1.5,0,0,0"
|
||||
Grid.Column="1" Margin="0,30,0,0" VerticalAlignment="Center" Height="25" IsEnabled="False"
|
||||
Click="DocumentRemoveButton_Click"/>
|
||||
|
||||
<Label Content="Ausgewählte Dokumente"
|
||||
Grid.Column="2" Margin="10,8,10,10"/>
|
||||
<ListBox x:Name="SelectedDocumentsList" DisplayMemberPath="Name"
|
||||
Grid.Column="2" Margin="10,30,10,37"
|
||||
SelectionChanged="SelectedDocumentsList_SelectionChanged">
|
||||
<ListBox.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{Binding Path=DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>
|
||||
</ListBox.InputBindings>
|
||||
</ListBox>
|
||||
<Button x:Name="SelectDocumentButton" Content="Durchsuchen..."
|
||||
Grid.Column="2" VerticalAlignment="Bottom" Margin="10,10,10,10" Height="22"
|
||||
Click="SelectDocumentButton_Click"/>
|
||||
</Grid>
|
||||
|
||||
<GroupBox x:Name="DocumentBox" Header="Dokument" Margin="10,170,10,47" Width="580" HorizontalAlignment="Left">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<CheckBox x:Name="DocumentNonDeliverersInput" Content="Auch Nicht-Lieferanten miteinbeziehen"
|
||||
Margin="10,10,10,10" Grid.Column="1"/>
|
||||
|
||||
<Label x:Name="DocumentFooterLabel" Content="Fußtext:" Margin="10,40,0,10"/>
|
||||
<TextBox x:Name="DeliveryConfirmationFooterInput" Grid.Column="1"
|
||||
Margin="0,40,10,10" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
|
||||
AcceptsReturn="True" VerticalScrollBarVisibility="Visible"/>
|
||||
<TextBox x:Name="CreditNoteFooterInput" Grid.Column="1"
|
||||
Margin="0,10,10,10" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
|
||||
AcceptsReturn="True" VerticalScrollBarVisibility="Visible"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Adressaten" Margin="610,10,10,47">
|
||||
<Grid>
|
||||
<RadioButton GroupName="Recipients" x:Name="RecipientsActiveMembersInput" Content="aktive Mitglieder"
|
||||
Margin="10,10,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
|
||||
<RadioButton GroupName="Recipients" x:Name="RecipientsAreaComMembersInput" Content="Mitglieder mit Flächenbindung"
|
||||
Margin="10,30,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
|
||||
<RadioButton GroupName="Recipients" x:Name="RecipientsDeliveryMembersInput" Content="Lieferanten der Saison"
|
||||
Margin="10,50,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
|
||||
<RadioButton GroupName="Recipients" x:Name="RecipientsNonDeliveryMembersInput" Content="Nicht-Lieferanten der Saison"
|
||||
Margin="10,70,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
|
||||
<RadioButton GroupName="Recipients" x:Name="RecipientsCustomInput" Content="Benutzerdefiniert"
|
||||
Margin="10,90,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
|
||||
|
||||
<Label Content="Zwst.:" x:Name="MemberBranchLabel" Margin="10,120,0,10"/>
|
||||
<xctk:CheckComboBox x:Name="MemberBranchInput" AllItemsSelectedContent="Alle Stammzweigstellen" Delimiter=", " DisplayMemberPath="Name"
|
||||
Margin="50,120,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
|
||||
ItemSelectionChanged="MemberInput_SelectionChanged"/>
|
||||
|
||||
<Label Content="Gem.:" x:Name="MemberKgLabel" Margin="10,150,0,10"/>
|
||||
<xctk:CheckComboBox x:Name="MemberKgInput" AllItemsSelectedContent="Alle Stammgemeinden" Delimiter=", " DisplayMemberPath="Name"
|
||||
IsSelectAllActive="True" SelectAllContent="Alle Stammgemeinden"
|
||||
Margin="50,150,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
|
||||
ItemSelectionChanged="MemberInput_SelectionChanged"/>
|
||||
|
||||
<Label Content="Vtrg.:" x:Name="MemberAreaComLabel" Margin="10,180,0,10"/>
|
||||
<xctk:CheckComboBox x:Name="MemberAreaComInput" AllItemsSelectedContent="Alle Vertragsarten" Delimiter=", " DisplayMemberPath="VtrgId"
|
||||
IsSelectAllActive="True" SelectAllContent="Alle Vertragsarten"
|
||||
Margin="50,180,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
|
||||
ItemSelectionChanged="MemberInput_SelectionChanged"/>
|
||||
|
||||
<xctk:CheckComboBox x:Name="MemberCustomInput" AllItemsSelectedContent="Alle Mitglieder" Delimiter=", " DisplayMemberPath="AdministrativeName"
|
||||
IsSelectAllActive="True" SelectAllContent="Alle Mitglieder"
|
||||
Margin="10,120,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
|
||||
ItemSelectionChanged="MemberInput_SelectionChanged"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<Button x:Name="ContinueButton" Content="Weiter"
|
||||
Margin="10,10,10,10" Height="27" Width="100" Padding="9,3" FontSize="14"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Right"
|
||||
Click="ContinueButton_Click"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Absenden" Visibility="Collapsed">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="1.5*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="80"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<GroupBox Header="Post" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,5,10" Grid.Column="0">
|
||||
<Grid>
|
||||
<GroupBox Header="Zusenden an..." Margin="10,10,10,10" Height="150" Width="220" VerticalAlignment="Top" HorizontalAlignment="Left">
|
||||
<StackPanel>
|
||||
<RadioButton x:Name="PostalAllInput" Margin="10,10,10,2.5">
|
||||
<TextBlock>
|
||||
... alle (<Run Text="{Binding Path=PostalAllCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
|
||||
</TextBlock>
|
||||
</RadioButton>
|
||||
<RadioButton x:Name="PostalWishInput" Margin="10,2.5,10,2.5" IsChecked="True">
|
||||
<TextBlock>
|
||||
...Mitglieder, die Zusendung<LineBreak/>
|
||||
per Post wünschen (<Run Text="{Binding Path=PostalWishCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
|
||||
</TextBlock>
|
||||
</RadioButton>
|
||||
<RadioButton x:Name="PostalNoEmailInput" Margin="10,2.5,10,2.5">
|
||||
<TextBlock>
|
||||
...Mitglieder, die keine<LineBreak/>
|
||||
E-Mail erhalten würden (<Run Text="{Binding Path=PostalNoEmailCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
|
||||
</TextBlock>
|
||||
</RadioButton>
|
||||
<RadioButton x:Name="PostalNobodyInput" Margin="10,2.5,10,10" Content="...niemanden (0)"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Sortieren nach" Margin="10,180,10,10" Width="180" 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>
|
||||
|
||||
<CheckBox x:Name="DoublePagedInput" Margin="20,270,10,10" Content="Doppelseitig drucken"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"/>
|
||||
|
||||
<TextBox x:Name="PostalSender1" IsEnabled="False"
|
||||
Margin="10,300,10,10"/>
|
||||
<TextBox x:Name="PostalSender2"
|
||||
Margin="10,330,10,10"/>
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="E-Mail" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,10,10,10" Grid.Column="1">
|
||||
<Grid>
|
||||
<GroupBox Header="Zusenden an..." Margin="80,10,10,10" Width="220" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left">
|
||||
<StackPanel>
|
||||
<RadioButton x:Name="EmailAllInput" Margin="10,10,10,2.5" Checked="EmailInput_Changed">
|
||||
<TextBlock>
|
||||
...alle mit E-Mail-Adressen (<Run Text="{Binding Path=EmailAllCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
|
||||
</TextBlock>
|
||||
</RadioButton>
|
||||
<RadioButton x:Name="EmailWishInput" Margin="10,2.5,10,2.5" IsChecked="True" Checked="EmailInput_Changed">
|
||||
<TextBlock>
|
||||
...Mitglieder, die Zusendung<LineBreak/>
|
||||
per E-Mail wünschen (<Run Text="{Binding Path=EmailWishCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
|
||||
</TextBlock>
|
||||
</RadioButton>
|
||||
<RadioButton x:Name="EmailNobodyInput" Margin="10,2.5,10,10" Content="...niemanden (0)" Checked="EmailInput_Changed"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<Label Content="Betreff:" Margin="10,130,10,10"/>
|
||||
<TextBox x:Name="EmailSubjectInput" Margin="80,130,10,10"/>
|
||||
|
||||
<Label Content="Nachricht:" Margin="10,160,10,10"/>
|
||||
<TextBox x:Name="EmailBodyInput"
|
||||
Margin="80,160,10,10" VerticalAlignment="Stretch" Height="Auto"
|
||||
TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<Grid Grid.Row="1" Grid.ColumnSpan="2" Width="400" Height="59">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="0.7*"/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
<ColumnDefinition Width="0.4*"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="0.6*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="GenerateButton" Content="Generieren"
|
||||
Grid.Row="0" Grid.Column="0" FontSize="14"
|
||||
Click="GenerateButton_Click"/>
|
||||
<ProgressBar x:Name="ProgressBar"
|
||||
Grid.Row="2" Grid.Column="0" SnapsToDevicePixels="True"/>
|
||||
|
||||
<Button x:Name="PreviewButton" Content="Vorschau" IsEnabled="False"
|
||||
Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="3" FontSize="14"
|
||||
Click="PreviewButton_Click"/>
|
||||
<Button x:Name="PrintButton" Content="Drucken" IsEnabled="False"
|
||||
Grid.Row="2" Grid.Column="2" FontSize="14"/>
|
||||
<Button x:Name="EmailButton" Content="E-Mails verschicken" IsEnabled="False"
|
||||
Grid.Row="2" Grid.Column="4" FontSize="14"/>
|
||||
</Grid>
|
||||
|
||||
<Button x:Name="BackButton" Content="Zurück" Grid.Row="1"
|
||||
Margin="10,10,10,10" Height="27" Width="100" Padding="9,3" FontSize="14"
|
||||
VerticalAlignment="Bottom" HorizontalAlignment="Left"
|
||||
Click="BackButton_Click"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</local:ContextWindow>
|
557
Elwig/Windows/MailWindow.xaml.cs
Normal file
557
Elwig/Windows/MailWindow.xaml.cs
Normal file
@ -0,0 +1,557 @@
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Dtos;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class MailWindow : ContextWindow {
|
||||
|
||||
// used for document sorting while generating!
|
||||
public enum DocType { Undefined, Custom, MemberDataSheet, DeliveryConfirmation, CreditNote }
|
||||
|
||||
public class SelectedDoc(DocType type, string name, object? details = null) {
|
||||
public DocType Type = type;
|
||||
public string Name { get; set; } = name;
|
||||
public object? Details = details;
|
||||
}
|
||||
|
||||
public class GeneratedDoc {
|
||||
public DocType Type;
|
||||
public Document Doc;
|
||||
|
||||
public GeneratedDoc(string pdfPath) {
|
||||
Type = DocType.Custom;
|
||||
Doc = Document.FromPdf(pdfPath);
|
||||
}
|
||||
|
||||
public GeneratedDoc(Document doc) {
|
||||
Type = doc is MemberDataSheet ? DocType.MemberDataSheet :
|
||||
doc is DeliveryConfirmation ? DocType.DeliveryConfirmation :
|
||||
doc is CreditNote ? DocType.CreditNote : DocType.Undefined;
|
||||
Doc = doc;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly string[] AvaiableDocuments = [
|
||||
MemberDataSheet.Name,
|
||||
DeliveryConfirmation.Name,
|
||||
CreditNote.Name,
|
||||
];
|
||||
|
||||
protected Season? Season;
|
||||
public ObservableCollection<SelectedDoc> SelectedDocs = [];
|
||||
public IEnumerable<Member> Recipients = [];
|
||||
|
||||
protected Document? PrintDocument;
|
||||
protected Dictionary<Member, List<Document>>? EmailDocuments;
|
||||
|
||||
public static readonly DependencyProperty PostalAllCountProperty = DependencyProperty.Register("PostalAllCount", typeof(int), typeof(MailWindow));
|
||||
public int PostalAllCount {
|
||||
get => (int)GetValue(PostalAllCountProperty);
|
||||
private set => SetValue(PostalAllCountProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PostalWishCountProperty = DependencyProperty.Register("PostalWishCount", typeof(int), typeof(MailWindow));
|
||||
public int PostalWishCount {
|
||||
get => (int)GetValue(PostalWishCountProperty);
|
||||
private set => SetValue(PostalWishCountProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PostalNoEmailCountProperty = DependencyProperty.Register("PostalNoEmailCount", typeof(int), typeof(MailWindow));
|
||||
public int PostalNoEmailCount {
|
||||
get => (int)GetValue(PostalNoEmailCountProperty);
|
||||
private set => SetValue(PostalNoEmailCountProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EmailAllCountProperty = DependencyProperty.Register("EmailAllCount", typeof(int), typeof(MailWindow));
|
||||
public int EmailAllCount {
|
||||
get => (int)GetValue(EmailAllCountProperty);
|
||||
private set => SetValue(EmailAllCountProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EmailWishCountProperty = DependencyProperty.Register("EmailWishCount", typeof(int), typeof(MailWindow));
|
||||
public int EmailWishCount {
|
||||
get => (int)GetValue(EmailWishCountProperty);
|
||||
private set => SetValue(EmailWishCountProperty, value);
|
||||
}
|
||||
|
||||
private ICommand _deleteCommand;
|
||||
public ICommand DeleteCommand => _deleteCommand ??= new ActionCommand(() => {
|
||||
var idx = SelectedDocumentsList.SelectedIndex;
|
||||
if (idx == -1)
|
||||
return;
|
||||
SelectedDocs.RemoveAt(SelectedDocumentsList.SelectedIndex);
|
||||
SelectedDocumentsList.SelectedIndex = idx < SelectedDocumentsList.Items.Count ? idx : idx - 1;
|
||||
});
|
||||
|
||||
// powershell -Command "$(Get-WmiObject -Class Win32_Printer | Where-Object {$_.Default -eq $True}).Name"
|
||||
public MailWindow() {
|
||||
InitializeComponent();
|
||||
AvaiableDocumentsList.ItemsSource = AvaiableDocuments;
|
||||
SelectedDocumentsList.ItemsSource = SelectedDocs;
|
||||
|
||||
DocumentNonDeliverersInput.Visibility = Visibility.Hidden;
|
||||
DocumentFooterLabel.Visibility = Visibility.Hidden;
|
||||
DeliveryConfirmationFooterInput.Visibility = Visibility.Hidden;
|
||||
CreditNoteFooterInput.Visibility = Visibility.Hidden;
|
||||
RecipientsActiveMembersInput.IsChecked = true;
|
||||
|
||||
DeliveryConfirmationFooterInput.Text = App.Client.TextDeliveryConfirmation;
|
||||
CreditNoteFooterInput.Text = App.Client.TextCreditNote;
|
||||
|
||||
PostalSender1.Text = App.Client.Sender1;
|
||||
PostalSender2.Text = App.Client.Sender2;
|
||||
EmailSubjectInput.Text = App.Client.TextEmailSubject ?? "Rundschreiben";
|
||||
EmailBodyInput.Text = App.Client.TextEmailBody ?? "Sehr geehrtes Mitglied,\n\nim Anhang finden Sie das aktuelle Rundschreiben.\n\nIhre Winzergenossenschaft\n";
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext() {
|
||||
Season = await Context.Seasons.OrderBy(s => s.Year).LastOrDefaultAsync();
|
||||
var l = new List<string> {
|
||||
MemberDataSheet.Name
|
||||
};
|
||||
if (Season != null) {
|
||||
l.Add($"{DeliveryConfirmation.Name} {Season.Year}");
|
||||
l.AddRange(Season.PaymentVariants.Where(v => !v.TestVariant).OrderBy(v => v.AvNr).Select(v => $"{CreditNote.Name} – {v.Name}"));
|
||||
}
|
||||
AvaiableDocumentsList.ItemsSource = l;
|
||||
|
||||
ControlUtils.RenewItemsSource(MemberBranchInput, await Context.Branches
|
||||
.Where(b => b.Members.Any())
|
||||
.OrderBy(b => b.Name)
|
||||
.ToListAsync(), b => (b as Branch)?.ZwstId);
|
||||
if (MemberBranchInput.SelectedItems.Count == 0) MemberBranchInput.SelectAll();
|
||||
ControlUtils.RenewItemsSource(MemberKgInput, await Context.Katastralgemeinden
|
||||
.Where(k => k.WbKg.Members.Any())
|
||||
.OrderBy(k => k.Name)
|
||||
.ToListAsync(), k => (k as AT_Kg)?.KgNr);
|
||||
if (MemberKgInput.SelectedItems.Count == 0) MemberKgInput.SelectAll();
|
||||
ControlUtils.RenewItemsSource(MemberAreaComInput, await Context.AreaCommitmentTypes
|
||||
.OrderBy(a => a.VtrgId)
|
||||
.ToListAsync(), a => (a as AreaComType)?.VtrgId);
|
||||
if (MemberAreaComInput.SelectedItems.Count == 0) MemberAreaComInput.SelectAll();
|
||||
ControlUtils.RenewItemsSource(MemberCustomInput, await Context.Members
|
||||
.Where(m => m.IsActive)
|
||||
.OrderBy(m => m.FamilyName)
|
||||
.ThenBy(m => m.GivenName)
|
||||
.ToListAsync(), m => (m as Member)?.MgNr);
|
||||
if (MemberCustomInput.SelectedItems.Count == 0) MemberCustomInput.SelectAll();
|
||||
|
||||
await UpdateRecipients();
|
||||
}
|
||||
|
||||
private void ContinueButton_Click(object sender, RoutedEventArgs evt) {
|
||||
TabControl.SelectedIndex = 1;
|
||||
TabControl.AllowDrop = false;
|
||||
}
|
||||
|
||||
private void BackButton_Click(object sender, RoutedEventArgs evt) {
|
||||
TabControl.SelectedIndex = 0;
|
||||
TabControl.AllowDrop = true;
|
||||
}
|
||||
|
||||
private void Document_Drop(object sender, DragEventArgs evt) {
|
||||
if (evt.Data.GetDataPresent(DataFormats.FileDrop)) {
|
||||
var files = (string[])evt.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (var file in files) {
|
||||
if (Path.GetExtension(file) == ".pdf") {
|
||||
SelectedDocs.Add(new(DocType.Custom, Path.GetFileName(file), file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Document_PreviwDragOver(object sender, DragEventArgs evt) {
|
||||
evt.Handled = TabControl.SelectedIndex == 0;
|
||||
}
|
||||
|
||||
private void AvaiableDocumentsList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
DocumentAddButton.IsEnabled = AvaiableDocumentsList.SelectedIndex != -1;
|
||||
}
|
||||
|
||||
private void SelectedDocumentsList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
DocumentRemoveButton.IsEnabled = SelectedDocumentsList.SelectedIndex != -1;
|
||||
if (SelectedDocumentsList.SelectedItem is SelectedDoc doc) {
|
||||
DocumentBox.Header = doc.Name;
|
||||
if (doc.Type == DocType.DeliveryConfirmation) {
|
||||
DocumentNonDeliverersInput.Visibility = Visibility.Visible;
|
||||
DocumentFooterLabel.Visibility = Visibility.Visible;
|
||||
DeliveryConfirmationFooterInput.Visibility = Visibility.Visible;
|
||||
CreditNoteFooterInput.Visibility = Visibility.Hidden;
|
||||
DocumentFooterLabel.Margin = new(10, 40, 0, 10);
|
||||
} else if (doc.Type == DocType.CreditNote) {
|
||||
DocumentNonDeliverersInput.Visibility = Visibility.Hidden;
|
||||
DocumentFooterLabel.Visibility = Visibility.Visible;
|
||||
DeliveryConfirmationFooterInput.Visibility = Visibility.Hidden;
|
||||
CreditNoteFooterInput.Visibility = Visibility.Visible;
|
||||
DocumentFooterLabel.Margin = new(10, 10, 0, 10);
|
||||
} else {
|
||||
DocumentNonDeliverersInput.Visibility = Visibility.Hidden;
|
||||
DocumentFooterLabel.Visibility = Visibility.Hidden;
|
||||
DeliveryConfirmationFooterInput.Visibility = Visibility.Hidden;
|
||||
CreditNoteFooterInput.Visibility = Visibility.Hidden;
|
||||
}
|
||||
} else {
|
||||
DocumentBox.Header = "Dokument";
|
||||
DocumentNonDeliverersInput.Visibility = Visibility.Hidden;
|
||||
DocumentFooterLabel.Visibility = Visibility.Hidden;
|
||||
DeliveryConfirmationFooterInput.Visibility = Visibility.Hidden;
|
||||
CreditNoteFooterInput.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
|
||||
private void DocumentAddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var idx = AvaiableDocumentsList.SelectedIndex;
|
||||
if (AvaiableDocumentsList.SelectedItem is not string s)
|
||||
return;
|
||||
if (idx == 0) {
|
||||
SelectedDocs.Add(new(DocType.MemberDataSheet, s, null));
|
||||
} else if (idx == 1) {
|
||||
SelectedDocs.Add(new(DocType.DeliveryConfirmation, s, (Season!.Year, DocumentNonDeliverersInput.IsChecked == true)));
|
||||
} else if (idx >= 2) {
|
||||
var name = s.Split(" – ")[^1];
|
||||
var pv = Context.PaymentVariants.Single(v => v.Year == Season!.Year && v.Name == name)!;
|
||||
SelectedDocs.Add(new(DocType.CreditNote, s, (pv.Year, pv.AvNr)));
|
||||
}
|
||||
SelectedDocumentsList.SelectedIndex = SelectedDocs.Count - 1;
|
||||
}
|
||||
|
||||
private void DocumentRemoveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
DeleteCommand.Execute(null);
|
||||
}
|
||||
|
||||
private void SelectDocumentButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var d = new OpenFileDialog() {
|
||||
Title = "Dokument auswählen - Elwig",
|
||||
DefaultExt = ".pdf",
|
||||
Filter = "PDF-Datei (*.pdf)|*.pdf",
|
||||
Multiselect = true,
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
foreach (var file in d.FileNames) {
|
||||
if (Path.GetExtension(file) == ".pdf") {
|
||||
SelectedDocs.Add(new(DocType.Custom, Path.GetFileName(file), file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void RecipientsInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
var vis = RecipientsCustomInput.IsChecked == true ? Visibility.Hidden : Visibility.Visible;
|
||||
MemberBranchLabel.Visibility = vis;
|
||||
MemberBranchInput.Visibility = vis;
|
||||
MemberKgLabel.Visibility = vis;
|
||||
MemberKgInput.Visibility = vis;
|
||||
MemberAreaComInput.Visibility = RecipientsAreaComMembersInput.IsChecked == true ? Visibility.Visible : Visibility.Hidden;
|
||||
MemberAreaComLabel.Visibility = RecipientsAreaComMembersInput.IsChecked == true ? Visibility.Visible : Visibility.Hidden;
|
||||
MemberCustomInput.Visibility = RecipientsCustomInput.IsChecked == true ? Visibility.Visible : Visibility.Hidden;
|
||||
await UpdateRecipients();
|
||||
}
|
||||
|
||||
private async void MemberInput_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
await UpdateRecipients();
|
||||
}
|
||||
|
||||
private async Task UpdateRecipients() {
|
||||
if (RecipientsCustomInput.IsChecked == true) {
|
||||
Recipients = MemberCustomInput.SelectedItems.Cast<Member>().ToList();
|
||||
} else {
|
||||
// FIXME NOT WORKING ON SECOND OPENING OF WINDOW
|
||||
var year = (!await Context.Deliveries.AnyAsync()) ? 0 : await Context.Deliveries.Select(d => d.Year).MaxAsync();
|
||||
|
||||
IQueryable<Member> query = Context.Members.Where(m => m.IsActive);
|
||||
if (MemberBranchInput.SelectedItems.Count != MemberBranchInput.Items.Count) {
|
||||
var zwst = MemberBranchInput.SelectedItems.Cast<Branch>().Select(b => b.ZwstId).ToList();
|
||||
query = query.Where(m => zwst.Contains(m.ZwstId));
|
||||
}
|
||||
if (MemberKgInput.SelectedItems.Count != MemberKgInput.Items.Count) {
|
||||
var kgs = MemberKgInput.SelectedItems.Cast<AT_Kg>().Select(k => k.KgNr).ToList();
|
||||
query = query.Where(m => kgs.Contains((int)m.DefaultKgNr));
|
||||
}
|
||||
|
||||
if (RecipientsAreaComMembersInput.IsChecked == true) {
|
||||
var vtrg = MemberAreaComInput.SelectedItems.Cast<AreaComType>().Select(a => a.VtrgId).ToList();
|
||||
query = query.Where(m => m.AreaCommitments.Any(a => a.YearFrom <= year && (a.YearTo == null || a.YearTo >= year) && vtrg.Contains(a.VtrgId)));
|
||||
} else if (year > 0 && RecipientsDeliveryMembersInput.IsChecked == true) {
|
||||
query = query.Where(m => m.Deliveries.Any(d => d.Year == year));
|
||||
} else if (year > 0 && RecipientsNonDeliveryMembersInput.IsChecked == true) {
|
||||
query = query.Where(m => !m.Deliveries.Any(d => d.Year == year));
|
||||
}
|
||||
Recipients = await query.ToListAsync();
|
||||
}
|
||||
UpdatePostalEmailRecipients();
|
||||
}
|
||||
|
||||
private void EmailInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
UpdatePostalEmailRecipients();
|
||||
}
|
||||
|
||||
private void UpdatePostalEmailRecipients() {
|
||||
EmailAllCount = Recipients.Count(m => m.EmailAddresses.Count > 0);
|
||||
EmailWishCount = Recipients.Count(m => m.EmailAddresses.Count > 0 && m.ContactViaEmail);
|
||||
PostalAllCount = Recipients.Count();
|
||||
PostalWishCount = Recipients.Count(m => m.ContactViaPost);
|
||||
var m = EmailAllInput.IsChecked == true ? 3 : EmailWishInput.IsChecked == true ? 2 : 1;
|
||||
PostalNoEmailCount = PostalAllCount - (m == 3 ? EmailAllCount : m == 2 ? EmailWishCount : 0);
|
||||
}
|
||||
|
||||
private async Task UpdateTextParameters() {
|
||||
var changed = false;
|
||||
|
||||
var dcText = DeliveryConfirmationFooterInput.Text.Trim();
|
||||
if (dcText.Length == 0) dcText = null;
|
||||
if (dcText != App.Client.TextDeliveryConfirmation) {
|
||||
App.Client.TextDeliveryConfirmation = dcText;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
var cdText = CreditNoteFooterInput.Text.Trim();
|
||||
if (cdText.Length == 0) cdText = null;
|
||||
if (cdText != App.Client.TextCreditNote) {
|
||||
App.Client.TextCreditNote = cdText;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
var emailSubject = EmailSubjectInput.Text.Trim();
|
||||
if (emailSubject.Length == 0) emailSubject = null;
|
||||
if (emailSubject != App.Client.TextEmailSubject) {
|
||||
App.Client.TextEmailSubject = emailSubject;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
var emailBody = EmailBodyInput.Text.Trim();
|
||||
if (emailBody.Length == 0) emailBody = null;
|
||||
if (emailBody != App.Client.TextEmailBody) {
|
||||
App.Client.TextEmailBody = emailBody;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
await App.Client.UpdateValues();
|
||||
}
|
||||
|
||||
private void DisposeDocs() {
|
||||
PrintDocument?.Dispose();
|
||||
PrintDocument = null;
|
||||
if (EmailDocuments != null) {
|
||||
foreach (var (m, docs) in EmailDocuments) {
|
||||
foreach (var d in docs) {
|
||||
d.Dispose();
|
||||
}
|
||||
}
|
||||
EmailDocuments = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, EventArgs evt) {
|
||||
DisposeDocs();
|
||||
}
|
||||
|
||||
private async void GenerateButton_Click(object sender, RoutedEventArgs evt) {
|
||||
PreviewButton.IsEnabled = false;
|
||||
PrintButton.IsEnabled = false;
|
||||
EmailButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
GenerateButton.IsEnabled = false;
|
||||
|
||||
DisposeDocs();
|
||||
await UpdateTextParameters();
|
||||
|
||||
IEnumerable<Member> recipients = Recipients;
|
||||
if (OrderMgNrInput.IsChecked == true) {
|
||||
recipients = recipients
|
||||
.OrderBy(m => m.MgNr)
|
||||
.ToList();
|
||||
} else if (OrderNameInput.IsChecked == true) {
|
||||
recipients = recipients
|
||||
.OrderBy(m => m.FamilyName)
|
||||
.ThenBy(m => m.GivenName)
|
||||
.ThenBy(m => m.MgNr)
|
||||
.ToList();
|
||||
} else if (OrderPlzInput.IsChecked == true) {
|
||||
recipients = recipients
|
||||
.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)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var doublePaged = DoublePagedInput.IsChecked == true;
|
||||
var docs = SelectedDocs.OrderByDescending(d => d.Type).ToList();
|
||||
|
||||
Dictionary<int, IDictionary<int, DeliveryConfirmationDeliveryData>> dcData = [];
|
||||
Dictionary<(int, int), (IDictionary<int, CreditNoteDeliveryData>, IDictionary<int, PaymentMember>, BillingData)> cnData = [];
|
||||
foreach (var doc in docs) {
|
||||
if (doc.Type == DocType.DeliveryConfirmation) {
|
||||
var details = ((int, bool))doc.Details!;
|
||||
var year = details.Item1;
|
||||
dcData[year] = await DeliveryConfirmationDeliveryData.ForSeason(Context.DeliveryParts, year);
|
||||
} else if (doc.Type == DocType.CreditNote) {
|
||||
var details = ((int, int))doc.Details!;
|
||||
var year = details.Item1;
|
||||
var avnr = details.Item2;
|
||||
try {
|
||||
cnData[(year, avnr)] = (
|
||||
await CreditNoteDeliveryData.ForPaymentVariant(Context.CreditNoteDeliveryRows, Context.Seasons, year, avnr),
|
||||
await Context.MemberPayments.Where(p => p.Year == year && p.AvNr == avnr).ToDictionaryAsync(c => c.MgNr),
|
||||
BillingData.FromJson((await Context.PaymentVariants.FindAsync(year, avnr))!.Data)
|
||||
);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
GenerateButton.IsEnabled = true;
|
||||
Mouse.OverrideCursor = null;
|
||||
return;
|
||||
}
|
||||
await Context.GetMemberAreaCommitmentBuckets(year, 0);
|
||||
}
|
||||
}
|
||||
|
||||
var memberDocs = recipients.Select(m => new {
|
||||
Member = m,
|
||||
Docs = docs.SelectMany<SelectedDoc, GeneratedDoc>(doc => {
|
||||
if (doc.Type == DocType.Custom) {
|
||||
return [new GeneratedDoc((string)doc.Details!)];
|
||||
} else if (doc.Type == DocType.MemberDataSheet) {
|
||||
return [new GeneratedDoc(new MemberDataSheet(m, Context))];
|
||||
} else if (doc.Type == DocType.DeliveryConfirmation) {
|
||||
var details = ((int, bool))doc.Details!;
|
||||
var year = details.Item1;
|
||||
var include = details.Item2;
|
||||
DeliveryConfirmationDeliveryData data;
|
||||
if (dcData[year].TryGetValue(m.MgNr, out var d)) {
|
||||
data = d;
|
||||
} else if (include) {
|
||||
data = DeliveryConfirmationDeliveryData.CreateEmpty(year, m);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return [new GeneratedDoc(new DeliveryConfirmation(Context, year, m, data))];
|
||||
} else if (doc.Type == DocType.CreditNote) {
|
||||
var details = ((int, int))doc.Details!;
|
||||
var year = details.Item1;
|
||||
var avnr = details.Item2;
|
||||
var data = cnData[(year, avnr)];
|
||||
try {
|
||||
return [new GeneratedDoc(new CreditNote(
|
||||
Context, data.Item2[m.MgNr], data.Item1[m.MgNr],
|
||||
data.Item3.ConsiderContractPenalties,
|
||||
data.Item3.ConsiderTotalPenalty,
|
||||
data.Item3.ConsiderAutoBusinessShares,
|
||||
Context.GetMemberUnderDelivery(year, m.MgNr).GetAwaiter().GetResult()
|
||||
))];
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
throw new NotImplementedException("Invalid DocType");
|
||||
}
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
|
||||
var printMode = PostalAllInput.IsChecked == true ? 3 :
|
||||
PostalWishInput.IsChecked == true ? 2 :
|
||||
PostalNoEmailInput.IsChecked == true ? 1 : 0;
|
||||
var emailMode = EmailAllInput.IsChecked == true ? 2 : EmailWishInput.IsChecked == true ? 1 : 0;
|
||||
|
||||
double printNum = printMode == 3 ? PostalAllCount : printMode == 2 ? PostalWishCount : printMode == 2 ? PostalNoEmailCount : 0;
|
||||
double emailNum = emailMode == 2 ? EmailAllCount : emailMode == 1 ? EmailWishCount : 0;
|
||||
double totalNum = printNum + emailNum;
|
||||
|
||||
var email = memberDocs
|
||||
.Where(d => d.Docs.Count > 0 && d.Member.EmailAddresses.Any() && (emailMode == 2 || (emailMode == 1 && d.Member.ContactViaEmail)))
|
||||
.ToDictionary(d => d.Member, m => {
|
||||
var docs = m.Docs.Select(d => d.Doc).ToList();
|
||||
foreach (var doc in docs) {
|
||||
doc!.DoubleSided = false;
|
||||
if (doc is BusinessDocument b)
|
||||
b.IncludeSender = false;
|
||||
};
|
||||
return docs;
|
||||
});
|
||||
var emailRecipients = email.Select(d => d.Key.MgNr).ToHashSet();
|
||||
foreach (var item1 in email.Select((e, i) => new { Index = i, e.Key, e.Value })) {
|
||||
foreach (var item2 in item1.Value.Select((d, i) => new { Index = i, Doc = d})) {
|
||||
await item2.Doc.Generate(new Progress<double>(v => {
|
||||
ProgressBar.Value = v * (item2.Index + 1) / item1.Value.Count / totalNum + 100.0 * item1.Index / totalNum;
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (email.Count > 0) {
|
||||
EmailDocuments = email;
|
||||
}
|
||||
|
||||
var printDocs = memberDocs
|
||||
.Where(d =>
|
||||
printMode == 3 ||
|
||||
(printMode == 2 && d.Member.ContactViaPost) ||
|
||||
(printMode == 1 && !emailRecipients.Contains(d.Member.MgNr)))
|
||||
.SelectMany(m => {
|
||||
var docs = m.Docs.Select(d => d.Doc).ToList();
|
||||
if (docs.Count == 0 || m.Docs[0].Type == DocType.Custom) {
|
||||
docs.Insert(0, new Letterhead(m.Member));
|
||||
}
|
||||
docs.ForEach(doc => doc.DoubleSided = doublePaged);
|
||||
if (docs.Count > 0 && docs[0] is BusinessDocument b)
|
||||
b.IncludeSender = true;
|
||||
return docs;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (printDocs.Count > 0) {
|
||||
var print = Document.Merge(printDocs);
|
||||
print.DoubleSided = doublePaged;
|
||||
await print.Generate(new Progress<double>(v => {
|
||||
ProgressBar.Value = 100.0 * emailNum / totalNum + v * printNum / totalNum;
|
||||
}));
|
||||
PrintDocument = print;
|
||||
}
|
||||
ProgressBar.Value = 100.0;
|
||||
|
||||
GenerateButton.IsEnabled = true;
|
||||
Mouse.OverrideCursor = null;
|
||||
PreviewButton.IsEnabled = true;
|
||||
//PrintButton.IsEnabled = true;
|
||||
//EmailButton.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void PreviewButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var d = new OpenFolderDialog() {
|
||||
Title = "Ordner auswählen - Elwig",
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
PrintDocument?.SaveTo($"{d.FolderName}/Print.pdf");
|
||||
if (EmailDocuments != null) {
|
||||
foreach (var (m, docs) in EmailDocuments) {
|
||||
var folder = $"{d.FolderName}/E-Mail/{m.AdministrativeName}";
|
||||
Directory.CreateDirectory(folder);
|
||||
foreach (var item in docs.Select((d, i) => new { Index = i, Doc = d })) {
|
||||
var doc = item.Doc;
|
||||
var name = Regex.Replace(doc.Title.Replace('/', '-'), @"[^A-Za-z0-9ÄÜÖẞäöüß-]+", "_");
|
||||
doc.SaveTo($"{folder}/{item.Index + 1:00}.{name}.pdf");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
Process.Start("explorer.exe", d.FolderName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,12 @@
|
||||
<Window x:Class="Elwig.Windows.MainWindow"
|
||||
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"
|
||||
Title="Elwig" MinHeight="400" MinWidth="325" Height="450" Width="800" ResizeMode="CanResize"
|
||||
Title="Elwig" Height="390" Width="520" ResizeMode="CanMinimize"
|
||||
Loaded="Window_Loaded" Closing="Window_Closing">
|
||||
<Window.Resources>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="9,3"/>
|
||||
<Setter Property="Height" Value="32"/>
|
||||
@ -19,13 +16,16 @@
|
||||
<Grid>
|
||||
<Menu BorderThickness="0,0,0,1" VerticalAlignment="Top" Height="19" BorderBrush="LightGray" Background="White">
|
||||
<MenuItem Header="Datenbank">
|
||||
<MenuItem Header="Backup erstellen"/>
|
||||
<MenuItem Header="Abfragen stellen" Click="Menu_Database_Query_Click"/>
|
||||
<!--MenuItem Header="Backup erstellen"/-->
|
||||
</MenuItem>
|
||||
<MenuItem Header="Hilfe">
|
||||
<MenuItem x:Name="HelpMenu" Header="Hilfe">
|
||||
<MenuItem Header="Über"/>
|
||||
<MenuItem x:Name="TestWindowButton" Header="Test-Fenster" Click="Menu_Help_TestWindow_Click"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<Grid Height="100" VerticalAlignment="Top" Margin="25,25,0,0">
|
||||
|
||||
<Grid Height="100" VerticalAlignment="Top" Margin="0,45,0,0" Width="260">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@ -45,19 +45,16 @@
|
||||
</Grid>
|
||||
|
||||
<Button x:Name="MemberAdminButton" Content="Mitglieder" Click="MemberAdminButton_Click"
|
||||
Margin="50,160,0,0"/>
|
||||
<Button x:Name="ReceiptButton" Content="Übernahme" Click="ReceiptButton_Click"
|
||||
Margin="50,200,0,0"/>
|
||||
Margin="0,180,210,0"/>
|
||||
<Button x:Name="MailButton" Content="Rundschreiben" Click="MailButton_Click"
|
||||
Margin="210,180,0,0"/>
|
||||
<Button x:Name="DeliveryAdminButton" Content="Lieferungen" Click="DeliveryAdminButton_Click"
|
||||
Margin="50,240,0,0"/>
|
||||
<Button x:Name="SeasonFinishButton" Content="Leseabschluss" Click="SeasonFinishButton_Click"
|
||||
Margin="50,280,0,0"/>
|
||||
Margin="0,220,210,0"/>
|
||||
<Button x:Name="ReceiptButton" Content="Übernahme" Click="ReceiptButton_Click"
|
||||
Margin="210,220,0,0"/>
|
||||
<Button x:Name="BaseDataButton" Content="Stammdaten" Click="BaseDataButton_Click"
|
||||
Margin="50,320,0,0"/>
|
||||
|
||||
<Button x:Name="TestWindowButton" Content="Test Fenster" Click="TestWindowButton_Click"
|
||||
Margin="260,280,0,0"/>
|
||||
<Button x:Name="QueryWindowButton" Content="Datenbankabfragen" Click="QueryWindowButton_Click"
|
||||
Margin="260,320,0,0"/>
|
||||
Margin="0,260,210,0"/>
|
||||
<Button x:Name="SeasonFinishButton" Content="Leseabschluss" Click="SeasonFinishButton_Click"
|
||||
Margin="210,260,0,0"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -11,7 +11,7 @@ namespace Elwig.Windows {
|
||||
VersionField.Text = "Version: " + (v == null ? "?" : $"{v.Major}.{v.Minor}.{v.Build}") + $" – {App.BranchName}";
|
||||
if (App.Client.Client == null) VersionField.Text += " (Unbekannt)";
|
||||
if (!App.Config.Debug) {
|
||||
TestWindowButton.Visibility = Visibility.Hidden;
|
||||
HelpMenu.Items.Remove(TestWindowButton);
|
||||
//QueryWindowButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private void Window_Closing(object sender, CancelEventArgs evt) {
|
||||
if (App.NumWindows > 1) {
|
||||
var res = MessageBox.Show("Es sind noch weitere Fenster geschlossen.\nSollen alle Fenster geschlossen werden?",
|
||||
var res = MessageBox.Show("Es sind noch weitere Fenster geöffnet.\nSollen alle Fenster geschlossen werden?",
|
||||
"Elwig beenden", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (res != MessageBoxResult.Yes) {
|
||||
evt.Cancel = true;
|
||||
@ -30,6 +30,16 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_Help_TestWindow_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new TestWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void Menu_Database_Query_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new QueryWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void MemberAdminButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new MemberAdminWindow();
|
||||
w.Show();
|
||||
@ -44,26 +54,16 @@ namespace Elwig.Windows {
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void DeliveryListButton_Click(object sender, RoutedEventArgs evt) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void TestWindowButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new TestWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void QueryWindowButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new QueryWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void BaseDataButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusBaseData();
|
||||
}
|
||||
|
||||
private void SeasonFinishButton_Click(object sender, RoutedEventArgs e) {
|
||||
private void SeasonFinishButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusSeasonFinish();
|
||||
}
|
||||
|
||||
private void MailButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusMailWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user