diff --git a/Elwig/Dialogs/NewSeasonDialog.xaml b/Elwig/Dialogs/NewSeasonDialog.xaml
new file mode 100644
index 0000000..1720c41
--- /dev/null
+++ b/Elwig/Dialogs/NewSeasonDialog.xaml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+
+
+
+
+
+
+
+
diff --git a/Elwig/Dialogs/NewSeasonDialog.xaml.cs b/Elwig/Dialogs/NewSeasonDialog.xaml.cs
new file mode 100644
index 0000000..4f1ece4
--- /dev/null
+++ b/Elwig/Dialogs/NewSeasonDialog.xaml.cs
@@ -0,0 +1,30 @@
+using Elwig.Helpers;
+using Elwig.Models.Entities;
+using System.Collections.Generic;
+using System.Windows;
+
+namespace Elwig.Dialogs {
+ public partial class NewSeasonDialog : Window {
+
+ public IEnumerable Currencies { get; set; }
+ public int Year { get; set; }
+
+ public string CurrencyCode => (CurrencyInput.SelectedItem as Currency)!.Code;
+ public byte Precision => (byte)(PrecisionInput.SelectedIndex + 2);
+ public bool CopyModifiers { get; set; }
+
+ public NewSeasonDialog(Season? s, IEnumerable currencies) {
+ Currencies = currencies;
+ CopyModifiers = s != null;
+ InitializeComponent();
+ CopyModifiersInput.IsEnabled = s != null;
+ ControlUtils.SelectItemWithPk(CurrencyInput, s?.CurrencyCode ?? "EUR");
+ PrecisionInput.SelectedIndex = (s?.Precision ?? 4) - 2;
+ }
+
+ private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {
+ DialogResult = true;
+ Close();
+ }
+ }
+}
diff --git a/Elwig/Windows/BaseDataWindow.xaml b/Elwig/Windows/BaseDataWindow.xaml
index e7713ba..e2260af 100644
--- a/Elwig/Windows/BaseDataWindow.xaml
+++ b/Elwig/Windows/BaseDataWindow.xaml
@@ -399,7 +399,7 @@
-
@@ -411,6 +411,12 @@
+
+
diff --git a/Elwig/Windows/BaseDataWindow.xaml.Season.cs b/Elwig/Windows/BaseDataWindow.xaml.Season.cs
index d0d9b0d..50047e7 100644
--- a/Elwig/Windows/BaseDataWindow.xaml.Season.cs
+++ b/Elwig/Windows/BaseDataWindow.xaml.Season.cs
@@ -1,10 +1,14 @@
-using Elwig.Helpers;
+using Elwig.Dialogs;
+using Elwig.Helpers;
using Elwig.Models.Entities;
using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Input;
namespace Elwig.Windows {
public partial class BaseDataWindow {
@@ -13,17 +17,23 @@ namespace Elwig.Windows {
private bool _seasonUpdate = false;
private async Task SeasonsInitEditing(AppDbContext ctx) {
+ SeasonAddButton.IsEnabled = false;
+ SeasonRemoveButton.IsEnabled = false;
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons
.OrderByDescending(s => s.Year)
.Include(s => s.Modifiers)
+ .Include(s => s.Currency)
.ToListAsync());
SeasonList_SelectionChanged(null, null);
}
private async Task SeasonsFinishEditing(AppDbContext ctx) {
+ SeasonAddButton.IsEnabled = true;
+ SeasonRemoveButton.IsEnabled = true;
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons
.OrderByDescending(s => s.Year)
.Include(s => s.Modifiers)
+ .Include(s => s.Currency)
.ToListAsync());
_seasonChanged = false;
}
@@ -133,5 +143,84 @@ namespace Elwig.Windows {
InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, false, 4, s.Precision));
Season_Changed(sender, evt);
}
+
+ private async void SeasonAddButton_Click(object sender, RoutedEventArgs evt) {
+ var s = SeasonList.ItemsSource.Cast().FirstOrDefault();
+ var year = Utils.CurrentYear;
+ if (year == s?.Year) year++;
+
+ List currencies;
+ using (var ctx = new AppDbContext()) {
+ currencies = await ctx.Currencies
+ .OrderBy(c => c.Code)
+ .ToListAsync();
+ }
+ var d = new NewSeasonDialog(s, currencies);
+ if (d.ShowDialog() == true) {
+ Mouse.OverrideCursor = Cursors.AppStarting;
+ try {
+ using var ctx = new AppDbContext();
+ ctx.Add(new Season {
+ Year = year,
+ CurrencyCode = d.CurrencyCode,
+ Precision = d.Precision,
+ MaxKgPerHa = s?.MaxKgPerHa ?? 10000,
+ VatNormal = s?.VatNormal ?? 0.10,
+ VatFlatrate = s?.VatFlatrate ?? 0.13,
+ MinKgPerBusinessShare = s?.MinKgPerBusinessShare ?? 500,
+ MaxKgPerBusinessShare = s?.MaxKgPerBusinessShare ?? 1000,
+ PenaltyPerKgValue = s?.PenaltyPerKgValue,
+ PenaltyAmoutValue = s?.PenaltyAmoutValue,
+ PenaltyNoneValue = s?.PenaltyNoneValue,
+ PenaltyPerBsAmountValue = s?.PenaltyPerBsAmountValue,
+ PenaltyPerBsNoneValue = s?.PenaltyPerBsNoneValue,
+ BusinessShareValueValue = s?.BusinessShareValueValue,
+ CalcMode = s?.CalcMode ?? 0,
+ });
+ if (s != null && d.CopyModifiers) {
+ ctx.AddRange(s.Modifiers.Select(m => new Modifier {
+ Year = year,
+ ModId = m.ModId,
+ Ordering = m.Ordering,
+ Name = m.Name,
+ AbsValue = m.AbsValue,
+ RelValue = m.RelValue,
+ IsStandard = m.IsStandard,
+ IsQuickSelect = m.IsQuickSelect,
+ }));
+ }
+ await ctx.SaveChangesAsync();
+ } catch (Exception exc) {
+ var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
+ if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
+ MessageBox.Show(str, "Saison anlegen", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ await App.HintContextChange();
+ Mouse.OverrideCursor = null;
+ SeasonList.SelectedIndex = 0;
+ }
+ }
+
+ private async void SeasonRemoveButton_Click(object sender, RoutedEventArgs evt) {
+ if (SeasonList.SelectedItem is not Season s)
+ return;
+ var r = MessageBox.Show(
+ $"Soll die Saison {s.Year} wirklich unwiderruflich gelöscht werden?",
+ "Saison löschen", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
+ if (r == MessageBoxResult.OK) {
+ Mouse.OverrideCursor = Cursors.AppStarting;
+ try {
+ using var ctx = new AppDbContext();
+ ctx.Remove(s);
+ await ctx.SaveChangesAsync();
+ } catch (Exception exc) {
+ var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
+ if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
+ MessageBox.Show(str, "Saison löschen", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ await App.HintContextChange();
+ Mouse.OverrideCursor = null;
+ }
+ }
}
}
diff --git a/Elwig/Windows/BaseDataWindow.xaml.cs b/Elwig/Windows/BaseDataWindow.xaml.cs
index ac9d780..54956fb 100644
--- a/Elwig/Windows/BaseDataWindow.xaml.cs
+++ b/Elwig/Windows/BaseDataWindow.xaml.cs
@@ -331,7 +331,7 @@ namespace Elwig.Windows {
LockInputs();
}
- await HintContextChange();
+ await App.HintContextChange();
}
private void FillInputs(ClientParameters p, Season? s) {
diff --git a/Elwig/Windows/MailWindow.xaml b/Elwig/Windows/MailWindow.xaml
index 857f6ae..b176a80 100644
--- a/Elwig/Windows/MailWindow.xaml
+++ b/Elwig/Windows/MailWindow.xaml
@@ -54,7 +54,7 @@
-