diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index 379a7f1..e79789d 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -104,6 +104,7 @@ namespace Elwig.Windows { cb.SelectionChanged += ComboBox_SelectionChanged; foreach (var lb in ListBoxInputs) lb.SelectionChanged += ComboBox_SelectionChanged; + LockInputs(); } private void OnClosing(object? sender, CancelEventArgs evt) { diff --git a/Elwig/Windows/AreaComAdminWindow.xaml.cs b/Elwig/Windows/AreaComAdminWindow.xaml.cs index a2b3f12..8f4dd2c 100644 --- a/Elwig/Windows/AreaComAdminWindow.xaml.cs +++ b/Elwig/Windows/AreaComAdminWindow.xaml.cs @@ -39,10 +39,6 @@ namespace Elwig.Windows { ViewModel.FilterSeason = Utils.CurrentYear; } - protected override async Task OnInit(AppDbContext ctx) { - LockInputs(); - } - private void FocusSearchInput(object sender, RoutedEventArgs evt) { if (!IsEditing && !IsCreating) { SearchInput.Focus(); @@ -451,17 +447,19 @@ namespace Elwig.Windows { } private async void ActiveAreaCommitmentInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(); } private async void SearchInput_TextChanged(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; var binding = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty); binding?.UpdateSource(); await RefreshList(true); } private async void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) { - if (ViewModel.FilterSeason == null) return; + if (!HasContextLoaded || ViewModel.FilterSeason == null) return; await RefreshList(); } diff --git a/Elwig/Windows/BaseDataWindow.xaml.cs b/Elwig/Windows/BaseDataWindow.xaml.cs index 390be7d..a28d5f5 100644 --- a/Elwig/Windows/BaseDataWindow.xaml.cs +++ b/Elwig/Windows/BaseDataWindow.xaml.cs @@ -153,10 +153,6 @@ namespace Elwig.Windows { ParameterExportEbicsAddress.IsEnabled = true; } - protected override async Task OnInit(AppDbContext ctx) { - LockInputs(); - } - protected override async Task OnRenewContext(AppDbContext ctx) { await base.OnRenewContext(ctx); FillInputs(App.Client, await ctx.FetchSeasons(Utils.CurrentLastSeason).SingleOrDefaultAsync()); diff --git a/Elwig/Windows/ContextWindow.cs b/Elwig/Windows/ContextWindow.cs index ea58985..c179432 100644 --- a/Elwig/Windows/ContextWindow.cs +++ b/Elwig/Windows/ContextWindow.cs @@ -18,6 +18,8 @@ namespace Elwig.Windows { } } + protected bool HasContextLoaded { get; private set; } + private bool _renewPending = false; private readonly RoutedCommand CtrlR = new("CtrlR", typeof(ContextWindow), [new KeyGesture(Key.R, ModifierKeys.Control)]); @@ -51,6 +53,7 @@ namespace Elwig.Windows { Mouse.OverrideCursor = Cursors.AppStarting; using var ctx = new AppDbContext(); await OnRenewContext(ctx); + HasContextLoaded = true; await OnInit(ctx); Mouse.OverrideCursor = null; } diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAdminWindow.xaml.cs index 8f7aa4e..9ed81a2 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAdminWindow.xaml.cs @@ -122,7 +122,8 @@ namespace Elwig.Windows { Menu_Export_UploadSeason.IsEnabled = App.Config.SyncUrl != null; } - public DeliveryAdminWindow(int mgnr) : this() { + public DeliveryAdminWindow(int mgnr) : + this() { ViewModel.FilterMember = DeliveryService.GetMember(mgnr) ?? throw new ArgumentException("MgNr argument has invalid value"); ViewModel.Title = $"Lieferungen - {ViewModel.FilterMember.AdministrativeName} - Elwig"; ViewModel.EnableAllSeasons = true; @@ -132,7 +133,6 @@ namespace Elwig.Windows { await base.OnInit(ctx); OnSecondPassed(null, null); SecondsTimer.Start(); - LockInputs(); if (ViewModel.IsReceipt) { NewDeliveryButton_Click(null, null); if (await ctx.FetchSeasons(Utils.CurrentYear).SingleOrDefaultAsync() == null) { @@ -541,8 +541,6 @@ namespace Elwig.Windows { await RefreshList(); - var d = DeliveryList.SelectedItem as Delivery; - var y = d?.Year ?? ViewModel.FilterSeason ?? Utils.CurrentYear; ControlUtils.RenewItemsSource(MemberInput, await ctx.FetchMembers(includeNotActive: !IsCreating, includeContactInfo: true).ToListAsync()); ControlUtils.RenewItemsSource(BranchInput, await ctx.FetchBranches().ToListAsync()); ControlUtils.RenewItemsSource(WineVarietyInput, await ctx.FetchWineVarieties().ToListAsync()); @@ -678,17 +676,19 @@ namespace Elwig.Windows { } private async void SearchInput_TextChanged(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(true); } private async void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) { - if (ViewModel.FilterSeason == null || TodayOnlyInput == null || AllSeasonsInput == null) return; + if (!HasContextLoaded || ViewModel.FilterSeason == null || TodayOnlyInput == null || AllSeasonsInput == null) return; TodayOnlyInput.IsChecked = false; AllSeasonsInput.IsChecked = false; await RefreshList(); } private async void TodayOnlyInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; if (TodayOnlyInput.IsChecked == true && AllSeasonsInput.IsChecked == false) { ViewModel.FilterSeason = Utils.Today.Year; ViewModel.FilterTodayOnly = true; @@ -697,6 +697,7 @@ namespace Elwig.Windows { } private async void AllSeasonsInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; if (AllSeasonsInput.IsChecked == true) { SeasonInput.IsEnabled = false; ViewModel.FilterSeason = null; diff --git a/Elwig/Windows/DeliveryAncmtAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAncmtAdminWindow.xaml.cs index 321f32e..c2d8b06 100644 --- a/Elwig/Windows/DeliveryAncmtAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAncmtAdminWindow.xaml.cs @@ -39,10 +39,6 @@ namespace Elwig.Windows { ViewModel.FilterOnlyUpcoming = true; } - protected override async Task OnInit(AppDbContext ctx) { - LockInputs(); - } - private void Input_KeyUp(object sender, KeyEventArgs evt) { if (sender is not Control ctrl) return; if (evt.Key != Key.Enter) return; @@ -193,6 +189,7 @@ namespace Elwig.Windows { } private async void DeliveryScheduleList_SelectionChanged(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(); if (DeliveryScheduleList.SelectedItem is DeliverySchedule s) { Menu_DeliveryAncmtList_SaveSelected.IsEnabled = !IsEditing && !IsCreating; @@ -214,11 +211,13 @@ namespace Elwig.Windows { } private async void OnlyUpcomingInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshDeliveryScheduleList(); await RefreshList(true); } private async void FromAllSchedulesInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; if (ViewModel.FilterFromAllSchedules) { DeliveryScheduleList.SelectedItem = null; } else if (DeliveryScheduleList.SelectedItem == null) { @@ -228,11 +227,12 @@ namespace Elwig.Windows { } private async void SearchInput_TextChanged(object sender, TextChangedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(true); } private async void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) { - if (ViewModel.FilterSeason == null) return; + if (!HasContextLoaded || ViewModel.FilterSeason == null) return; ViewModel.FilterOnlyUpcoming = false; await RefreshDeliveryScheduleList(); await RefreshList(); diff --git a/Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs b/Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs index 110d064..b7eed50 100644 --- a/Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs @@ -33,10 +33,6 @@ namespace Elwig.Windows { ViewModel.FilterOnlyUpcoming = true; } - protected override async Task OnInit(AppDbContext ctx) { - LockInputs(); - } - private async Task RefreshList(bool updateSort = false) { var vm = ViewModel; var cursor = Mouse.OverrideCursor != null; @@ -124,15 +120,17 @@ namespace Elwig.Windows { } private async void OnlyUpcomingInput_Changed(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(); } private async void SearchInput_TextChanged(object sender, TextChangedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(true); } private async void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) { - if (ViewModel.FilterSeason == null) return; + if (!HasContextLoaded || ViewModel.FilterSeason == null) return; ViewModel.FilterOnlyUpcoming = false; await RefreshList(); } diff --git a/Elwig/Windows/MainWindow.xaml.cs b/Elwig/Windows/MainWindow.xaml.cs index 0cf7e89..fb20c90 100644 --- a/Elwig/Windows/MainWindow.xaml.cs +++ b/Elwig/Windows/MainWindow.xaml.cs @@ -41,6 +41,7 @@ namespace Elwig.Windows { } protected override async Task OnInit(AppDbContext ctx) { + await base.OnInit(ctx); if (Utils.HasInternetConnectivity()) { CheckSync(200); } diff --git a/Elwig/Windows/MemberAdminWindow.xaml.cs b/Elwig/Windows/MemberAdminWindow.xaml.cs index 53e45dc..7788c19 100644 --- a/Elwig/Windows/MemberAdminWindow.xaml.cs +++ b/Elwig/Windows/MemberAdminWindow.xaml.cs @@ -83,11 +83,8 @@ namespace Elwig.Windows { Menu_Export_UploadFilters.IsEnabled = App.Config.SyncUrl != null; Menu_Export_UploadAll.IsEnabled = App.Config.SyncUrl != null; ViewModel.ShowOnlyActiveMembers = true; - } - protected override async Task OnInit(AppDbContext ctx) { UpdateContactInfoVisibility(); - LockInputs(); } public void FocusMember(int mgnr) { @@ -334,7 +331,7 @@ namespace Elwig.Windows { } private async void ActiveMemberInput_Changed(object sender, RoutedEventArgs evt) { - if (!IsInitialized) return; + if (!HasContextLoaded) return; await RefreshList(); } @@ -491,6 +488,7 @@ namespace Elwig.Windows { } private async void SearchInput_TextChanged(object sender, RoutedEventArgs evt) { + if (!HasContextLoaded) return; await RefreshList(true); }