[#44] BaseDataWindow: Add button to add/delete seasons
All checks were successful
Test / Run tests (push) Successful in 2m1s
All checks were successful
Test / Run tests (push) Successful in 2m1s
This commit is contained in:
@ -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<Season>().FirstOrDefault();
|
||||
var year = Utils.CurrentYear;
|
||||
if (year == s?.Year) year++;
|
||||
|
||||
List<Currency> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user