From 4460de99751f95e9839b37ef493dc1468575eb7f Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 30 Mar 2026 19:35:53 +0200 Subject: [PATCH] [#77] Entities: Add AreaComContract to group area commitments together --- Elwig/Controls/IntegerUpDown.cs | 13 +- Elwig/Dialogs/AreaComModifyDialog.xaml.cs | 13 +- Elwig/Dialogs/AreaComTransferDialog.xaml | 8 +- Elwig/Dialogs/AreaComTransferDialog.xaml.cs | 26 +- Elwig/Documents/MemberDataSheet.cs | 12 +- Elwig/Helpers/AppDbContext.cs | 34 ++- Elwig/Helpers/AppDbUpdater.cs | 2 +- Elwig/Helpers/Export/ElwigData.cs | 290 ++++++++++++++------ Elwig/Helpers/Validator.cs | 2 +- Elwig/Models/Entities/AreaCom.cs | 31 +-- Elwig/Models/Entities/AreaComContract.cs | 78 ++++++ Elwig/Resources/Sql/37-38.sql | 239 ++++++++++++++++ Elwig/Services/AreaComService.cs | 69 +++-- Elwig/Services/MemberService.cs | 14 +- Elwig/Services/SyncService.cs | 45 +-- Elwig/ViewModels/AreaComAdminViewModel.cs | 8 +- Elwig/ViewModels/MemberAdminViewModel.cs | 1 - Elwig/Windows/AreaComAdminWindow.xaml | 160 ++++++----- Elwig/Windows/AreaComAdminWindow.xaml.cs | 168 ++++++++---- Elwig/Windows/MemberAdminWindow.xaml.cs | 1 - Elwig/Windows/OriginHierarchyWindow.xaml.cs | 4 +- Tests/Resources/Sql/BillingDelete.sql | 2 +- Tests/Resources/Sql/BillingInsert.sql | 13 +- Tests/Resources/Sql/ServiceDelete.sql | 2 +- Tests/Resources/Sql/ServiceInsert.sql | 16 +- Tests/fetch-resources.bat | 2 +- 26 files changed, 918 insertions(+), 335 deletions(-) create mode 100644 Elwig/Models/Entities/AreaComContract.cs create mode 100644 Elwig/Resources/Sql/37-38.sql diff --git a/Elwig/Controls/IntegerUpDown.cs b/Elwig/Controls/IntegerUpDown.cs index dba367a..39ca3a3 100644 --- a/Elwig/Controls/IntegerUpDown.cs +++ b/Elwig/Controls/IntegerUpDown.cs @@ -41,13 +41,21 @@ namespace Elwig.Controls { incButton!.Click += IncrementButton_Click; decButton!.Click += DecrementButton_Click; base.OnApplyTemplate(); + UpdateButtons(); + } + + private void UpdateButtons() { + var incButton = GetTemplateChild("IncrementButton") as RepeatButton; + var decButton = GetTemplateChild("DecrementButton") as RepeatButton; + incButton?.IsEnabled = Maximum == null || Value < Maximum; + decButton?.IsEnabled = Minimum == null || Value > Minimum; } private void IntegerUpDown_TextChanged(object sender, TextChangedEventArgs evt) { var idx = CaretIndex; - Text = new string(Text.Where(char.IsAsciiDigit).Take(4).ToArray()); + Text = new string([.. Text.Where(char.IsAsciiDigit).Take(4)]); CaretIndex = idx; - evt.Handled = !(Value >= Minimum && Value <= Maximum); + evt.Handled = !((!Minimum.HasValue || Value >= Minimum) && (!Maximum.HasValue || Value <= Maximum)); if (idx >= 4) { if (Value < Minimum) { Value = Minimum; @@ -56,6 +64,7 @@ namespace Elwig.Controls { } CaretIndex = 4; } + UpdateButtons(); } private void IntegerUpDown_LostFocus(object sender, RoutedEventArgs evt) { diff --git a/Elwig/Dialogs/AreaComModifyDialog.xaml.cs b/Elwig/Dialogs/AreaComModifyDialog.xaml.cs index 0c2da99..cb891c6 100644 --- a/Elwig/Dialogs/AreaComModifyDialog.xaml.cs +++ b/Elwig/Dialogs/AreaComModifyDialog.xaml.cs @@ -1,4 +1,5 @@ using Elwig.Helpers; +using System; using System.Windows; using System.Windows.Controls; @@ -12,23 +13,27 @@ namespace Elwig.Dialogs { public string OrigYearTo { get; set; } public string Area { get; set; } - public AreaComModifyDialog(int? yearFrom, int? yearTo, int area, bool delete) { + public AreaComModifyDialog(int? yearFrom, int? yearTo, int area, bool delete, bool forceRetroactive = false) { Area = $"{area:N0}"; OrigYearFrom = $"{yearFrom}"; OrigYearTo = $"{yearTo}"; InitializeComponent(); Title = delete ? "Flächenbindung löschen" : "Flächenbindung bearbeiten"; RetroactiveInput.Content = delete ? "Rückwirkend löschen" : "Rückwirkend bearbeiten"; + forceRetroactive = forceRetroactive || yearFrom.HasValue && yearTo.HasValue && yearFrom.Value == yearTo.Value; + RetroactiveInput.IsEnabled = !forceRetroactive; if (delete) { QuestionBlock1.Visibility = Visibility.Hidden; QuestionBlock2.Visibility = Visibility.Visible; DescBlock1.Visibility = Visibility.Hidden; DescBlock2.Visibility = Visibility.Visible; } - if ((yearTo.HasValue && yearTo < Utils.CurrentNextSeason) || (yearFrom.HasValue && yearFrom >= Utils.CurrentNextSeason)) { + SeasonInput.Minimum = yearFrom.HasValue ? yearFrom + 1 : null; + SeasonInput.Maximum = yearTo.HasValue ? yearTo : null; + if (forceRetroactive || (yearTo.HasValue && yearTo < Utils.CurrentYear) || (yearFrom.HasValue && yearFrom >= Utils.CurrentYear)) { RetroactiveInput.IsChecked = true; } else { - SeasonInput.Text = $"{Utils.CurrentNextSeason}"; + SeasonInput.Text = $"{Utils.CurrentYear}"; } } @@ -48,7 +53,7 @@ namespace Elwig.Dialogs { DescBlock2.Visibility = Visibility.Hidden; } else { SeasonInput.IsEnabled = true; - SeasonInput.Text = $"{Utils.CurrentNextSeason}"; + SeasonInput.Text = $"{Math.Max(SeasonInput.Minimum ?? Utils.CurrentYear, Utils.CurrentYear)}"; DescBlock1.Visibility = QuestionBlock1.Visibility; DescBlock2.Visibility = QuestionBlock2.Visibility; } diff --git a/Elwig/Dialogs/AreaComTransferDialog.xaml b/Elwig/Dialogs/AreaComTransferDialog.xaml index fcec9d1..51f4f6e 100644 --- a/Elwig/Dialogs/AreaComTransferDialog.xaml +++ b/Elwig/Dialogs/AreaComTransferDialog.xaml @@ -8,7 +8,7 @@ ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True" WindowStartupLocation="CenterOwner" DataContext="{Binding RelativeSource={RelativeSource Self}}" - Title="Flächenbindungen übertragen" Height="260" Width="450"> + Title="Flächenbindungen übertragen" Height="240" Width="450"> - + - - - + + @@ -176,91 +176,119 @@ - - + + - + - + -