[#39] ChartWindow: Add try/catch block around initialization
This commit is contained in:
@ -14,6 +14,8 @@ using ScottPlot.Plottables;
|
|||||||
using ScottPlot;
|
using ScottPlot;
|
||||||
using Xceed.Wpf.Toolkit.Primitives;
|
using Xceed.Wpf.Toolkit.Primitives;
|
||||||
using ScottPlot.Control;
|
using ScottPlot.Control;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
|
|
||||||
namespace Elwig.Windows {
|
namespace Elwig.Windows {
|
||||||
public partial class ChartWindow : ContextWindow {
|
public partial class ChartWindow : ContextWindow {
|
||||||
@ -101,12 +103,26 @@ namespace Elwig.Windows {
|
|||||||
PaymentVar = await Context.PaymentVariants.FindAsync(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
|
PaymentVar = await Context.PaymentVariants.FindAsync(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found");
|
||||||
Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found");
|
Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found");
|
||||||
|
|
||||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetVaributes(Context, Year));
|
try {
|
||||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetVaributes(Context, Year));
|
||||||
GraphEntries = [
|
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||||
..paymentEntries,
|
GraphEntries = [
|
||||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
|
..paymentEntries,
|
||||||
];
|
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
|
||||||
|
];
|
||||||
|
} catch (KeyNotFoundException ex) {
|
||||||
|
var key = ex.Message.Split('\'')[1].Split('\'')[0];
|
||||||
|
MessageBox.Show($"Fehler beim Laden der Auszahlungsvariante:\n\n" +
|
||||||
|
$"Mit unbekanntem Attribut '{key}' kann nicht umgegangen werden.", "Fehler",
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
MessageBox.Show($"Fehler beim Laden der Auszahlungsvariante:\n\n" +
|
||||||
|
$"Die Daten der Auszahlungsvariante entsprechen nicht dem benötigtem Format.", "Fehler",
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
MessageBox.Show("Fehler beim Laden der Auszahlungsvariante:\n\n" + ex.Message, "Fehler",
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
Vaributes = Utils.GetVaributeList(Context, Year);
|
Vaributes = Utils.GetVaributeList(Context, Year);
|
||||||
GraphEntries.ForEach(e => {
|
GraphEntries.ForEach(e => {
|
||||||
e.Vaributes.ForEach(v => {
|
e.Vaributes.ForEach(v => {
|
||||||
|
Reference in New Issue
Block a user