This commit is contained in:
@ -58,6 +58,7 @@ namespace Elwig.Windows {
|
||||
public IEnumerable<Member> Recipients = [];
|
||||
|
||||
protected Document? PrintDocument;
|
||||
protected Dictionary<Member, List<Document>>? PrintMemberDocuments;
|
||||
protected Dictionary<Member, List<Document>>? EmailDocuments;
|
||||
|
||||
public static readonly DependencyProperty PostalAllCountProperty = DependencyProperty.Register(nameof(PostalAllCount), typeof(int), typeof(MailWindow));
|
||||
@ -262,6 +263,11 @@ namespace Elwig.Windows {
|
||||
rb.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void Menu_Help_Log_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new MailLogWindow();
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void ContinueButton_Click(object sender, RoutedEventArgs evt) {
|
||||
TabControl.SelectedIndex = 1;
|
||||
TabControl.AllowDrop = false;
|
||||
@ -477,6 +483,12 @@ namespace Elwig.Windows {
|
||||
PostalWishCount = Recipients.Count(m => m.ContactViaPost);
|
||||
var countEmail = (modeEmail == 2 ? EmailAllCount : modeEmail == 1 ? EmailWishCount : 0);
|
||||
PostalNoEmailCount = PostalAllCount - countEmail;
|
||||
var countPostal = (modePostal == 3 ? PostalAllCount : modePostal == 2 ? PostalWishCount : modePostal == 1 ? PostalNoEmailCount : 0);
|
||||
if (IsLoaded) {
|
||||
StatusRecipients.Text = $"{Recipients.Count():N0}";
|
||||
StatusPostalRecipients.Text = $"{countPostal:N0}";
|
||||
StatusEmailRecipients.Text = $"{countEmail:N0}";
|
||||
}
|
||||
ResetDocuments();
|
||||
}
|
||||
|
||||
@ -763,11 +775,13 @@ namespace Elwig.Windows {
|
||||
EmailDocuments = email;
|
||||
}
|
||||
|
||||
var printDocs = memberDocs
|
||||
var printMemberDocs = memberDocs
|
||||
.Where(d =>
|
||||
printMode == 3 ||
|
||||
(printMode == 2 && d.Member.ContactViaPost) ||
|
||||
(printMode == 1 && !emailRecipients.Contains(d.Member.MgNr)))
|
||||
.ToList();
|
||||
var printDocs = printMemberDocs
|
||||
.SelectMany(m => {
|
||||
var docs = m.Docs.Select(d => d.Doc).ToList();
|
||||
if (docs.Count == 0 || m.Docs[0].Type == DocType.Custom) {
|
||||
@ -792,6 +806,7 @@ namespace Elwig.Windows {
|
||||
ProgressBar.Value = 100.0 * emailNum / totalNum + v * printNum / totalNum;
|
||||
}));
|
||||
PrintDocument = print;
|
||||
PrintMemberDocuments = printMemberDocs.ToDictionary(m => m.Member, m => m.Docs.Select(d => d.Doc).ToList());
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
UnlockInputs();
|
||||
@ -801,6 +816,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
} else {
|
||||
PrintDocument = null;
|
||||
PrintMemberDocuments = null;
|
||||
}
|
||||
ProgressBar.Value = 100.0;
|
||||
|
||||
@ -837,7 +853,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void PrintButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (PrintDocument == null) return;
|
||||
if (PrintDocument == null || PrintMemberDocuments == null) return;
|
||||
|
||||
PrintButton.IsEnabled = false;
|
||||
GenerateButton.IsEnabled = false;
|
||||
@ -851,6 +867,14 @@ namespace Elwig.Windows {
|
||||
PrintDocument.Show();
|
||||
} else {
|
||||
await PrintDocument.Print();
|
||||
await Utils.AddSentMails(
|
||||
PrintMemberDocuments.Select(d => (
|
||||
"postal", d.Key.MgNr, d.Key.AdministrativeName,
|
||||
new string[] { d.Value.Select(d => (d as BusinessDocument)?.Address).FirstOrDefault(a => a != null) ?? d.Key.FullAddress },
|
||||
d.Value.Select(d => d.Title).FirstOrDefault("Briefkopf"),
|
||||
d.Value.Select(d => d.Title).ToArray()
|
||||
))
|
||||
);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
@ -882,6 +906,7 @@ namespace Elwig.Windows {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
var subject = EmailSubjectInput.Text;
|
||||
var text = EmailBodyInput.Text;
|
||||
await Utils.AddSentMailBody(subject, text, EmailDocuments.Count);
|
||||
foreach (var (m, docs) in EmailDocuments) {
|
||||
using var msg = new MimeMessage();
|
||||
msg.From.Add(new MailboxAddress(App.Client.NameFull, App.Config.Smtp.Value.From));
|
||||
@ -896,6 +921,12 @@ namespace Elwig.Windows {
|
||||
}
|
||||
msg.Body = body;
|
||||
await client!.SendAsync(msg);
|
||||
await Utils.AddSentMails([(
|
||||
"email", m.MgNr, m.AdministrativeName,
|
||||
m.EmailAddresses.OrderBy(a => a.Nr).Select(a => a.Address).ToArray(),
|
||||
subject,
|
||||
docs.Select(d => d.Title).ToArray()
|
||||
)]);
|
||||
}
|
||||
|
||||
MessageBox.Show("Erfolgreich alle E-Mails verschickt!", "Rundschreiben verschicken", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
@ -944,7 +975,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void PostalInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
ResetDocuments();
|
||||
UpdatePostalEmailRecipients();
|
||||
}
|
||||
|
||||
private void OrderInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
|
Reference in New Issue
Block a user