[#39] ChartWindow: Add try/catch block around initialization
This commit is contained in:
@ -14,6 +14,8 @@ using ScottPlot.Plottables;
|
||||
using ScottPlot;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
using ScottPlot.Control;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
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");
|
||||
Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found");
|
||||
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetVaributes(Context, Year));
|
||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||
GraphEntries = [
|
||||
..paymentEntries,
|
||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
|
||||
];
|
||||
try {
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetVaributes(Context, Year));
|
||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||
GraphEntries = [
|
||||
..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);
|
||||
GraphEntries.ForEach(e => {
|
||||
e.Vaributes.ForEach(v => {
|
||||
|
Reference in New Issue
Block a user