ContextWindow: Change renew context event handling
This commit is contained in:
@ -16,20 +16,20 @@ namespace Elwig.Windows {
|
||||
protected Control[] ExemptInputs { private get; set; }
|
||||
protected Control[] RequiredInputs { private get; set; }
|
||||
|
||||
private bool _IsEditing;
|
||||
private bool _IsCreating;
|
||||
private bool _isEditing;
|
||||
private bool _isCreating;
|
||||
protected bool IsEditing {
|
||||
get { return _IsEditing; }
|
||||
get { return _isEditing; }
|
||||
set {
|
||||
_IsEditing = value;
|
||||
LockContext = IsEditing;
|
||||
_isEditing = value;
|
||||
LockContext = IsEditing || IsCreating;
|
||||
}
|
||||
}
|
||||
protected bool IsCreating {
|
||||
get { return _IsCreating; }
|
||||
get { return _isCreating; }
|
||||
set {
|
||||
_IsCreating = value;
|
||||
LockContext = IsEditing;
|
||||
_isCreating = value;
|
||||
LockContext = IsEditing || IsCreating;
|
||||
}
|
||||
}
|
||||
protected bool DoShowWarningWindows = true;
|
||||
@ -99,7 +99,7 @@ namespace Elwig.Windows {
|
||||
|
||||
abstract protected void UpdateButtons();
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
protected override async Task OnRenewContext() {
|
||||
for (int i = 0; i < PlzInputs.Length; i++)
|
||||
UpdatePlz(PlzInputs[i], PlzOrtInputs[i]);
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ namespace Elwig.Windows {
|
||||
ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
ControlUtils.RenewItemsSource(KgInput, await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr);
|
||||
ControlUtils.RenewItemsSource(AreaComTypeInput, await Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToListAsync(), i => (i as AreaComType)?.VtrgId);
|
||||
ControlUtils.RenewItemsSource(WineCultivationInput, await Context.WineCultivations.OrderBy(c => c.Name).ToListAsync(), i => (i as WineCult)?.CultId);
|
||||
|
@ -52,8 +52,8 @@ namespace Elwig.Windows {
|
||||
FillInputs(App.Client);
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
ControlUtils.RenewItemsSource(SeasonList, await Context.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First);
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId);
|
||||
|
@ -214,8 +214,8 @@ namespace Elwig.Windows {
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
await RefreshGraphList();
|
||||
}
|
||||
|
||||
|
@ -7,30 +7,32 @@ using System.Windows.Threading;
|
||||
namespace Elwig.Windows {
|
||||
public abstract class ContextWindow : Window {
|
||||
|
||||
public static readonly int RenewSec = 10;
|
||||
|
||||
protected AppDbContext Context { get; private set; }
|
||||
protected bool LockContext { get; set; } = false;
|
||||
|
||||
private readonly DispatcherTimer ContextRenewTimer;
|
||||
private static readonly int ContextRenewSec = 10;
|
||||
private readonly DispatcherTimer _timer;
|
||||
private bool _renewPending = false;
|
||||
|
||||
public ContextWindow() : base() {
|
||||
ContextRenewTimer = new DispatcherTimer();
|
||||
ContextRenewTimer.Tick += new EventHandler(OnRenewContext);
|
||||
ContextRenewTimer.Interval = new TimeSpan(0, 0, ContextRenewSec);
|
||||
ContextRenewTimer.Start();
|
||||
_timer = new DispatcherTimer();
|
||||
_timer.Tick += new EventHandler(OnShouldRenewContext);
|
||||
_timer.Interval = new TimeSpan(0, 0, RenewSec);
|
||||
_timer.Start();
|
||||
Context = new();
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
|
||||
private void OnRenewContext(object? sender, EventArgs evt) {
|
||||
if (LockContext || !Context.HasBackendChanged) return;
|
||||
Context.Dispose();
|
||||
Context = new();
|
||||
RenewContext().GetAwaiter().GetResult();
|
||||
private async void OnShouldRenewContext(object? sender, EventArgs evt) {
|
||||
if (!Context.HasBackendChanged) return;
|
||||
_renewPending = true;
|
||||
if (LockContext) return;
|
||||
await RenewContext();
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs evt) {
|
||||
RenewContext().GetAwaiter().GetResult();
|
||||
OnRenewContext().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs evt) {
|
||||
@ -38,6 +40,14 @@ namespace Elwig.Windows {
|
||||
Context.Dispose();
|
||||
}
|
||||
|
||||
abstract protected Task RenewContext();
|
||||
protected async Task RenewContext() {
|
||||
if (!_renewPending) return;
|
||||
Context.Dispose();
|
||||
Context = new();
|
||||
await OnRenewContext();
|
||||
_renewPending = false;
|
||||
}
|
||||
|
||||
abstract protected Task OnRenewContext();
|
||||
}
|
||||
}
|
||||
|
@ -415,8 +415,8 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
|
||||
if (Member != null) {
|
||||
if (Context.Members.Find(Member.MgNr) is not Member m) {
|
||||
@ -798,6 +798,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
FinishButton.Cursor = null;
|
||||
DeliveryList.SelectedItem = null;
|
||||
await RenewContext();
|
||||
RefreshInputs();
|
||||
InitInputs();
|
||||
}
|
||||
@ -820,6 +821,7 @@ namespace Elwig.Windows {
|
||||
DisableWeighingButtons();
|
||||
HideFinishNewPartDeliveryCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
await RenewContext();
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
|
@ -131,8 +131,8 @@ namespace Elwig.Windows {
|
||||
ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
|
||||
ControlUtils.RenewItemsSource(DefaultKgInput, await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr);
|
||||
await RefreshMemberList();
|
||||
|
Reference in New Issue
Block a user