Services: Add Utils.RunForeground() to factor Task.Run and try-catch-Blocks out
Test / Run tests (push) Successful in 2m2s
Test / Run tests (push) Successful in 2m2s
This commit is contained in:
+17
-3
@@ -31,6 +31,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
@@ -209,16 +210,29 @@ namespace Elwig.Helpers {
|
||||
return Regex.Replace(iban.Trim(), ".{4}", "$0 ").Trim();
|
||||
}
|
||||
|
||||
public static void RunBackground(string title, Func<Task> a) {
|
||||
public static void RunBackground(string title, Func<Task> function) {
|
||||
Task.Run(async () => {
|
||||
try {
|
||||
await a();
|
||||
await function();
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(title, exc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static async Task RunForeground(Func<Task> function) {
|
||||
var isSTA = Thread.CurrentThread.GetApartmentState() == ApartmentState.STA;
|
||||
if (isSTA) Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
await function();
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
});
|
||||
if (isSTA) Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static void MailTo(string emailAddress) {
|
||||
MailTo([emailAddress]);
|
||||
}
|
||||
@@ -579,7 +593,7 @@ namespace Elwig.Helpers {
|
||||
await doc.Generate(ctx);
|
||||
}
|
||||
doc.SaveTo(filename);
|
||||
Process.Start("explorer.exe", filename);
|
||||
if (!App.Config.Debug) Process.Start("explorer.exe", filename);
|
||||
}
|
||||
} else {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
|
||||
@@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers.Export;
|
||||
using Elwig.Models.Dtos;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using LinqKit;
|
||||
@@ -262,30 +261,18 @@ namespace Elwig.Services {
|
||||
if (mode == ExportMode.SaveList) {
|
||||
var filename = InteractionService.SaveFile(DeliveryAncmtList.Name, DeliveryAncmtList.Name, "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await DeliveryAncmtListData.FromQuery(query, filterNames);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await DeliveryAncmtListData.FromQuery(query, filterNames);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await DeliveryAncmtListData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryAncmtList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await DeliveryAncmtListData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryAncmtList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using Elwig.ViewModels;
|
||||
@@ -726,16 +725,10 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static async Task GenerateDeliveryNote(int year, int did, ExportMode mode) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var doc = await DeliveryNote.Initialize(year, did);
|
||||
await Utils.ExportDocument(doc, mode, doc.Delivery.LsNr, (doc.Member, $"{DeliveryNote.Name} Nr. {doc.Delivery.LsNr}", $"Im Anhang finden Sie den {DeliveryNote.Name} Nr. {doc.Delivery.LsNr}"));
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var doc = await DeliveryNote.Initialize(year, did);
|
||||
await Utils.ExportDocument(doc, mode, doc.Delivery.LsNr, (doc.Member, $"{DeliveryNote.Name} Nr. {doc.Delivery.LsNr}", $"Im Anhang finden Sie den {DeliveryNote.Name} Nr. {doc.Delivery.LsNr}"));
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateDeliveryJournal(this DeliveryAdminViewModel vm, ExportSubject subject, ExportMode mode) {
|
||||
@@ -774,62 +767,42 @@ namespace Elwig.Services {
|
||||
if (mode == ExportMode.SaveList) {
|
||||
var filename = InteractionService.SaveFile(DeliveryJournal.Name, DeliveryJournal.Name, "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Export) {
|
||||
var filename = InteractionService.SaveFile(DeliveryJournal.Name, subject == ExportSubject.Selected ? $"Lieferung_{vm.SelectedDelivery?.LsNr}" : $"Lieferungen_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}", "elwig.zip");
|
||||
if (filename != null) {
|
||||
if (!filename.EndsWith(".elwig.zip")) filename += ".elwig.zip";
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var list = await query
|
||||
.Select(p => p.Delivery)
|
||||
.Distinct()
|
||||
.Include(d => d.Parts).ThenInclude(p => p.PartModifiers)
|
||||
.ToListAsync();
|
||||
var wbKgs = list
|
||||
.SelectMany(d => d.Parts)
|
||||
.Where(p => p.Kg != null)
|
||||
.Select(p => p.Kg!)
|
||||
.DistinctBy(k => k.KgNr)
|
||||
.OrderBy(k => k.KgNr)
|
||||
.ToList();
|
||||
await ElwigData.Export(filename, list, wbKgs, filterNames);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var list = await query
|
||||
.Select(p => p.Delivery)
|
||||
.Distinct()
|
||||
.Include(d => d.Parts).ThenInclude(p => p.PartModifiers)
|
||||
.ToListAsync();
|
||||
var wbKgs = list
|
||||
.SelectMany(d => d.Parts)
|
||||
.Where(p => p.Kg != null)
|
||||
.Select(p => p.Kg!)
|
||||
.DistinctBy(k => k.KgNr)
|
||||
.OrderBy(k => k.KgNr)
|
||||
.ToList();
|
||||
await ElwigData.Export(filename, list, wbKgs, filterNames);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Upload && App.Config.SyncUrl != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
await Utils.RunForeground(async () => {
|
||||
await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryJournal(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryJournal(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,17 +823,11 @@ namespace Elwig.Services {
|
||||
throw new ArgumentException("Invalid value for ExportSubject");
|
||||
}
|
||||
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await WineQualityStatisticsData.FromQuery(query, App.Client.OrderingMemberList);
|
||||
using var doc = new WineQualityStatistics(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await WineQualityStatisticsData.FromQuery(query, App.Client.OrderingMemberList);
|
||||
using var doc = new WineQualityStatistics(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateLocalityStatistics(this DeliveryAdminViewModel vm, ExportSubject subject) {
|
||||
@@ -878,17 +845,11 @@ namespace Elwig.Services {
|
||||
|
||||
var filename = InteractionService.SaveFile("Lieferstatistik pro Ort", $"Lieferstatistik-{vm.FilterSeason ?? Utils.CurrentLastSeason}", "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tbl = await WineLocalityStatisticsData.FromQuery(query, filterNames);
|
||||
await ods.AddTable(tbl);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tbl = await WineLocalityStatisticsData.FromQuery(query, filterNames);
|
||||
await ods.AddTable(tbl);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,38 +882,26 @@ namespace Elwig.Services {
|
||||
if (mode == ExportMode.SaveList) {
|
||||
var filename = InteractionService.SaveFile(DeliveryDepreciationList.Name, $"{DeliveryDepreciationList.Name}-{vm.FilterSeason ?? Utils.CurrentLastSeason}", "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tblTotal = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
tblTotal.FullName = DeliveryDepreciationList.Name;
|
||||
tblTotal.Name = "Gesamt";
|
||||
await ods.AddTable(tblTotal);
|
||||
foreach (var branch in await ctx.FetchBranches().ToListAsync()) {
|
||||
var tbl = await DeliveryJournalData.FromQuery(query.Where(p => p.Delivery.ZwstId == branch.ZwstId), filterNames);
|
||||
tbl.FullName = DeliveryDepreciationList.Name;
|
||||
tbl.Name = branch.Name;
|
||||
await ods.AddTable(tbl);
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
await Utils.RunForeground(async () => {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tblTotal = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
tblTotal.FullName = DeliveryDepreciationList.Name;
|
||||
tblTotal.Name = "Gesamt";
|
||||
await ods.AddTable(tblTotal);
|
||||
foreach (var branch in await ctx.FetchBranches().ToListAsync()) {
|
||||
var tbl = await DeliveryJournalData.FromQuery(query.Where(p => p.Delivery.ZwstId == branch.ZwstId), filterNames);
|
||||
tbl.FullName = DeliveryDepreciationList.Name;
|
||||
tbl.Name = branch.Name;
|
||||
await ods.AddTable(tbl);
|
||||
}
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryDepreciationList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await DeliveryJournalData.FromQuery(query, filterNames);
|
||||
using var doc = new DeliveryDepreciationList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,19 +930,13 @@ namespace Elwig.Services {
|
||||
|
||||
var filename = InteractionService.SaveFile("Liefermengen", "Liefermengen", "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tblTotal = await MemberDeliveryData.FromQuery(query, filterNames);
|
||||
var tbl = await MemberDeliveryPerVarietyData.FromQuery(query, filterNames);
|
||||
await ods.AddTable(tblTotal);
|
||||
await ods.AddTable(tbl);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var ods = new OdsFile(filename);
|
||||
var tblTotal = await MemberDeliveryData.FromQuery(query, filterNames);
|
||||
var tbl = await MemberDeliveryPerVarietyData.FromQuery(query, filterNames);
|
||||
await ods.AddTable(tblTotal);
|
||||
await ods.AddTable(tbl);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1196,8 +1139,7 @@ namespace Elwig.Services {
|
||||
$"Soll wirklich für {dids.Length:N0} Teillieferung(en) das Attribut\n'{attributeName}' gesetz werden?"))
|
||||
return;
|
||||
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
await Utils.RunForeground(async () => {
|
||||
using (var cnx = await AppDbContext.ConnectAsync()) {
|
||||
await cnx.ExecuteBatch($"""
|
||||
UPDATE delivery_part SET attrid = {attrid}
|
||||
@@ -1208,8 +1150,6 @@ namespace Elwig.Services {
|
||||
});
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1226,8 +1166,7 @@ namespace Elwig.Services {
|
||||
$"Soll wirklich für {dids.Length:N0} Teillieferung(en) der Zu-/Abschlag\n'{modifierName}' hinzugefügt werden?"))
|
||||
return;
|
||||
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
await Utils.RunForeground(async () => {
|
||||
using (var cnx = await AppDbContext.ConnectAsync()) {
|
||||
await cnx.ExecuteBatch($"""
|
||||
INSERT INTO delivery_part_modifier (year, did, dpnr, modid)
|
||||
@@ -1239,8 +1178,6 @@ namespace Elwig.Services {
|
||||
});
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1257,8 +1194,7 @@ namespace Elwig.Services {
|
||||
$"Soll wirklich für {dids.Length:N0} Teillieferung(en) der Zu-/Abschlag\n'{modifierName}' entfernt werden?"))
|
||||
return;
|
||||
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
await Utils.RunForeground(async () => {
|
||||
using (var cnx = await AppDbContext.ConnectAsync()) {
|
||||
await cnx.ExecuteBatch($"""
|
||||
DELETE FROM delivery_part_modifier
|
||||
@@ -1269,8 +1205,6 @@ namespace Elwig.Services {
|
||||
});
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,13 @@ namespace Elwig.Services {
|
||||
public static class InteractionService {
|
||||
|
||||
public static Func<string, string, string, string?>? Override;
|
||||
public static Action<string, string>? NextInformation;
|
||||
public static Action<string, string>? NextWarning;
|
||||
public static Action<string, string>? NextError;
|
||||
public static Func<string, string, bool>? NextContinue;
|
||||
public static Func<string, string, bool>? NextConfirmation;
|
||||
public static Func<string, string, bool>? NextQuestion;
|
||||
public static Func<string, string, string?>? NextSave;
|
||||
|
||||
public static readonly Dictionary<string, string> ExtensionFilters = new() {
|
||||
["pdf"] = "PDF-Datei (*.pdf)|*.pdf",
|
||||
@@ -19,7 +26,10 @@ namespace Elwig.Services {
|
||||
};
|
||||
|
||||
public static void ShowInformation(string title, string text) {
|
||||
if (Override != null) {
|
||||
if (NextInformation != null) {
|
||||
NextInformation(title, text);
|
||||
NextInformation = null;
|
||||
} else if (Override != null) {
|
||||
Override("information", title, text);
|
||||
} else {
|
||||
MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
@@ -27,7 +37,11 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static bool AskContinue(string title, string text) {
|
||||
if (Override != null) {
|
||||
if (NextContinue != null) {
|
||||
var r = NextContinue(title, text);
|
||||
NextContinue = null;
|
||||
return r;
|
||||
} else if (Override != null) {
|
||||
return Override("continue", title, text) != null;
|
||||
} else {
|
||||
return MessageBox.Show(text, title, MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) == MessageBoxResult.OK;
|
||||
@@ -35,7 +49,11 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static bool AskConfirmation(string title, string text) {
|
||||
if (Override != null) {
|
||||
if (NextConfirmation != null) {
|
||||
var r = NextConfirmation(title, text);
|
||||
NextConfirmation = null;
|
||||
return r;
|
||||
} else if (Override != null) {
|
||||
return Override("confirm", title, text) != null;
|
||||
} else {
|
||||
return MessageBox.Show(text, title, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.Yes;
|
||||
@@ -43,7 +61,11 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static bool AskQuestion(string title, string text, bool defaultResult) {
|
||||
if (Override != null) {
|
||||
if (NextQuestion != null) {
|
||||
var r = NextQuestion(title, text);
|
||||
NextQuestion = null;
|
||||
return r;
|
||||
} else if (Override != null) {
|
||||
return Override("question", title, text) != null;
|
||||
} else {
|
||||
return MessageBox.Show(text, title, MessageBoxButton.YesNo, MessageBoxImage.Question, defaultResult ? MessageBoxResult.Yes : MessageBoxResult.No) == MessageBoxResult.Yes;
|
||||
@@ -51,7 +73,10 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static void ShowWarning(string title, string text) {
|
||||
if (Override != null) {
|
||||
if (NextWarning != null) {
|
||||
NextWarning(title, text);
|
||||
NextWarning = null;
|
||||
} else if (Override != null) {
|
||||
Override("warning", title, text);
|
||||
} else {
|
||||
MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
@@ -59,7 +84,10 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static void ShowError(string title, string text) {
|
||||
if (Override != null) {
|
||||
if (NextError != null) {
|
||||
NextError(title, text);
|
||||
NextError = null;
|
||||
} else if (Override != null) {
|
||||
Override("error", title, text);
|
||||
} else {
|
||||
MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@@ -71,7 +99,7 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static void ShowException(string title, Exception exc, bool showExcType = false, bool isError = true) {
|
||||
ShowException(title, exc, showExcType, isError);
|
||||
ShowException(title, null, exc, showExcType, isError);
|
||||
}
|
||||
|
||||
public static void ShowException(string title, string? text, Exception exc, bool showExcType = false, bool isError = true) {
|
||||
@@ -101,7 +129,11 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static string? SaveFile(string title, string defaultFileName, string extension) {
|
||||
if (Override != null) {
|
||||
if (NextSave != null) {
|
||||
var r = NextSave(title, $"{defaultFileName}.{extension}");
|
||||
NextSave = null;
|
||||
return r;
|
||||
} else if (Override != null) {
|
||||
return Override("save", title, $"{defaultFileName}.{extension}");
|
||||
} else {
|
||||
var d = new SaveFileDialog() {
|
||||
|
||||
@@ -10,7 +10,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class MemberService {
|
||||
@@ -390,47 +389,29 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static async Task GenerateMemberDataSheet(Member m, ExportMode mode) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var doc = new MemberDataSheet(m);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, MemberDataSheet.Name, "Im Anhang finden Sie das aktuelle Stammdatenblatt"));
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var doc = new MemberDataSheet(m);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, MemberDataSheet.Name, "Im Anhang finden Sie das aktuelle Stammdatenblatt"));
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateDeliveryConfirmation(Member m, int year, ExportMode mode) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var b = await Billing.Create(year);
|
||||
await b.FinishSeason();
|
||||
await b.CalculateBuckets();
|
||||
App.HintContextChange();
|
||||
await Utils.RunForeground(async () => {
|
||||
var b = await Billing.Create(year);
|
||||
await b.FinishSeason();
|
||||
await b.CalculateBuckets();
|
||||
App.HintContextChange();
|
||||
|
||||
using var doc = new DeliveryConfirmation(year, m, null);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, $"{DeliveryConfirmation.Name} {year}", $"Im Anhang finden Sie die Anlieferungsbestätigung {year}"));
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
using var doc = new DeliveryConfirmation(year, m, null);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, $"{DeliveryConfirmation.Name} {year}", $"Im Anhang finden Sie die Anlieferungsbestätigung {year}"));
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateCreditNote(Member m, int year, int avnr, ExportMode mode) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var doc = await CreditNote.Initialize(year, avnr, m.MgNr, null);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, $"{CreditNote.Name} {doc.Payment.Variant.Name}", $"Im Anhang finden Sie die Traubengutschrift {doc.Payment.Variant.Name}"));
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var doc = await CreditNote.Initialize(year, avnr, m.MgNr, null);
|
||||
await Utils.ExportDocument(doc, mode, emailData: (m, $"{CreditNote.Name} {doc.Payment.Variant.Name}", $"Im Anhang finden Sie die Traubengutschrift {doc.Payment.Variant.Name}"));
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
public static async Task GenerateMemberList(this MemberAdminViewModel vm, ExportSubject subject, ExportMode mode) {
|
||||
@@ -477,86 +458,60 @@ namespace Elwig.Services {
|
||||
if (mode == ExportMode.SaveList) {
|
||||
var filename = InteractionService.SaveFile(MemberList.Name, MemberList.Name, "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await MemberListData.FromQuery(query, filterNames, filterNames.Where(f => f.StartsWith("Flächenbindung")).Select(f => f.Split(' ')[^1]));
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await MemberListData.FromQuery(query, filterNames, filterNames.Where(f => f.StartsWith("Flächenbindung")).Select(f => f.Split(' ')[^1]));
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Vcf) {
|
||||
var filename = InteractionService.SaveFile("Kontakte", "Mitglieder", "vcf");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var members = await query
|
||||
.OrderBy(m => m.MgNr)
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.ToListAsync();
|
||||
using var exporter = new VCard(filename);
|
||||
await exporter.ExportAsync(members);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var members = await query
|
||||
.OrderBy(m => m.MgNr)
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.ToListAsync();
|
||||
using var exporter = new VCard(filename);
|
||||
await exporter.ExportAsync(members);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Export) {
|
||||
var filename = InteractionService.SaveFile(MemberList.Name, subject == ExportSubject.Selected ? $"Mitglied_{vm.SelectedMember?.MgNr}" : $"Mitglieder_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}", "elwig.zip");
|
||||
if (filename != null) {
|
||||
if (!filename.EndsWith(".elwig.zip")) filename += ".elwig.zip";
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var members = await query
|
||||
.OrderBy(m => m.MgNr)
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.ToListAsync();
|
||||
var areaComs = await query
|
||||
.SelectMany(m => m.AreaCommitments)
|
||||
.Select(c => c.Contract).Distinct()
|
||||
.Include(c => c.Revisions)
|
||||
.ToListAsync();
|
||||
var wbKgs = members
|
||||
.Where(m => m.DefaultWbKg != null)
|
||||
.Select(m => m.DefaultWbKg!)
|
||||
.Union(areaComs.Select(c => c.Kg))
|
||||
.Distinct()
|
||||
.OrderBy(k => k.KgNr)
|
||||
.ToList();
|
||||
await ElwigData.Export(filename, members, areaComs, wbKgs, filterNames);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var members = await query
|
||||
.OrderBy(m => m.MgNr)
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.ToListAsync();
|
||||
var areaComs = await query
|
||||
.SelectMany(m => m.AreaCommitments)
|
||||
.Select(c => c.Contract).Distinct()
|
||||
.Include(c => c.Revisions)
|
||||
.ToListAsync();
|
||||
var wbKgs = members
|
||||
.Where(m => m.DefaultWbKg != null)
|
||||
.Select(m => m.DefaultWbKg!)
|
||||
.Union(areaComs.Select(c => c.Kg))
|
||||
.Distinct()
|
||||
.OrderBy(k => k.KgNr)
|
||||
.ToList();
|
||||
await ElwigData.Export(filename, members, areaComs, wbKgs, filterNames);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Upload && App.Config.SyncUrl != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
await Utils.RunForeground(async () => {
|
||||
await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var data = await MemberListData.FromQuery(query, filterNames, filterNames.Where(f => f.StartsWith("Flächenbindung")).Select(f => f.Split(' ')[^1]));
|
||||
using var doc = new MemberList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
var data = await MemberListData.FromQuery(query, filterNames, filterNames.Where(f => f.StartsWith("Flächenbindung")).Select(f => f.Split(' ')[^1]));
|
||||
using var doc = new MemberList(string.Join(" / ", filterNames), data);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class PaymentVariantService {
|
||||
@@ -192,29 +191,17 @@ namespace Elwig.Services {
|
||||
var filename = InteractionService.SaveFile($"Variantendaten {v.Name}", $"Variantendaten-{v.Name.Trim().Replace(' ', '-')}", "ods");
|
||||
if (filename == null)
|
||||
return;
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var data = await PaymentVariantSummaryData.ForPaymentVariant(v, ctx.PaymentVariantSummaryRows);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var data = await PaymentVariantSummaryData.ForPaymentVariant(v, ctx.PaymentVariantSummaryRows);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(data);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
} else {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var doc = await PaymentVariantSummary.Initialize(v.Year, v.AvNr);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var doc = await PaymentVariantSummary.Initialize(v.Year, v.AvNr);
|
||||
await Utils.ExportDocument(doc, mode);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,34 +224,22 @@ namespace Elwig.Services {
|
||||
|
||||
var filename = InteractionService.SaveFile("Überweisungsdaten", $"{App.Client.NameToken}-Überweisungsdaten-{v.Year}-{v.Name.Trim().Replace(' ', '-')}", Ebics.FileExtension);
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var e = new Ebics(v, filename, App.Client.ExportEbicsVersion, (Ebics.AddressMode)App.Client.ExportEbicsAddress);
|
||||
await e.ExportAsync(Transaction.FromPaymentVariant(v));
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var e = new Ebics(v, filename, App.Client.ExportEbicsVersion, (Ebics.AddressMode)App.Client.ExportEbicsAddress);
|
||||
await e.ExportAsync(Transaction.FromPaymentVariant(v));
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task GenerateAccountingList(int year, int avnr, string name) {
|
||||
var filename = InteractionService.SaveFile("Buchungsliste", $"{App.Client.NameToken}-Buchungsliste-{year}-{name.Trim().Replace(' ', '-')}", "ods");
|
||||
if (filename != null) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var tbl = await CreditNoteData.ForPaymentVariant(ctx, year, avnr);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(tbl);
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException(exc);
|
||||
}
|
||||
await Utils.RunForeground(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var tbl = await CreditNoteData.ForPaymentVariant(ctx, year, avnr);
|
||||
using var ods = new OdsFile(filename);
|
||||
await ods.AddTable(tbl);
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user