Windows: Add feature to save pdf in menu

This commit is contained in:
2024-03-28 16:54:51 +01:00
parent 9aa6cba1ff
commit b2f52072f8
6 changed files with 111 additions and 60 deletions

View File

@ -27,6 +27,7 @@ using System.Windows.Input;
using LinqKit;
using System.Linq.Expressions;
using Elwig.Models;
using Microsoft.Win32;
namespace Elwig.Helpers {
public static partial class Utils {
@ -478,6 +479,34 @@ namespace Elwig.Helpers {
return true;
}
public static async Task ExportDocument(Document doc, ExportMode mode, string? filename = null, (Member, string, string)? emailData = null) {
if (mode == ExportMode.Print && !App.Config.Debug) {
await doc.Generate();
await doc.Print();
} else if (mode == ExportMode.Email && emailData is (Member, string, string) e) {
await doc.Generate();
var success = await SendEmail(e.Item1, e.Item2, e.Item3, [doc]);
if (success)
MessageBox.Show("Die E-Mail wurde erfolgreich verschickt!", "E-Mail verschickt",
MessageBoxButton.OK, MessageBoxImage.Information);
} else if (mode == ExportMode.SavePdf) {
var d = new SaveFileDialog() {
FileName = $"{NormalizeFileName(filename ?? doc.Title)}.pdf",
DefaultExt = "pdf",
Filter = "PDF-Datei (*.pdf)|*.pdf",
Title = $"{doc.Title} speichern unter - Elwig"
};
if (d.ShowDialog() == true) {
await doc.Generate();
doc.SaveTo(d.FileName);
Process.Start("explorer.exe", d.FileName);
}
} else {
await doc.Generate();
doc.Show();
}
}
public static int? GetEntityIdentifier(object? obj) {
if (obj == null) {
return null;