DeliveryAdminWindow: Small quality of life fixes

This commit is contained in:
2023-09-09 21:33:37 +02:00
parent 0b05cc4e10
commit 898cece0d3
6 changed files with 97 additions and 24 deletions

View File

@ -84,8 +84,8 @@ namespace Elwig {
var list = new List<IScale>(); var list = new List<IScale>();
foreach (var s in Config.Scales) { foreach (var s in Config.Scales) {
var id = s[0];
try { try {
var id = s[0];
var type = s[1]?.ToLower(); var type = s[1]?.ToLower();
var model = s[2]; var model = s[2];
var cnx = s[3]; var cnx = s[3];
@ -99,6 +99,7 @@ namespace Elwig {
throw new ArgumentException($"Invalid scale type: \"{type}\""); throw new ArgumentException($"Invalid scale type: \"{type}\"");
} }
} catch (Exception e) { } catch (Exception e) {
list.Add(new InvalidScale(id));
MessageBox.Show($"Unable to create scale {s[0]}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"Unable to create scale {s[0]}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error);
} }
} }

View File

@ -11,6 +11,9 @@ namespace Elwig.Helpers {
public bool IsMatzen => Client == Type.Matzen; public bool IsMatzen => Client == Type.Matzen;
public bool IsWinzerkeller => Client == Type.Winzerkeller; public bool IsWinzerkeller => Client == Type.Winzerkeller;
public bool IsWolkersdorf => Client == Type.Winzerkeller && App.ZwstId == "W";
public bool IsHaugsdorf => Client == Type.Winzerkeller && App.ZwstId == "H";
public bool IsSitzendorf => Client == Type.Winzerkeller && App.ZwstId == "S";
public string NameToken; public string NameToken;
public string NameShort; public string NameShort;

View File

@ -0,0 +1,44 @@
using System;
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
public class InvalidScale : IScale {
public string Manufacturer => "NONE";
public string Model => "NONE";
public string ScaleId { get; private set; }
public int InternalScaleNr => 0;
public bool IsReady => false;
public bool HasFillingClearance => false;
public int? WeightLimit => null;
public string? LogPath => null;
public InvalidScale(string id) {
ScaleId = id;
}
public void Dispose() {
GC.SuppressFinalize(this);
}
public Task<WeighingResult> Weigh() {
throw new NotImplementedException();
}
public Task<WeighingResult> GetCurrentWeight() {
throw new NotImplementedException();
}
public Task Empty() {
throw new NotImplementedException();
}
public Task GrantFillingClearance() {
throw new NotImplementedException();
}
public Task RevokeFillingClearance() {
throw new NotImplementedException();
}
}
}

View File

@ -32,6 +32,7 @@ namespace Elwig.Windows {
LockContext = IsEditing; LockContext = IsEditing;
} }
} }
protected bool DoShowWarningWindows = true;
protected bool IsClosing { get; private set; } protected bool IsClosing { get; private set; }
private TextBox[] TextBoxInputs; private TextBox[] TextBoxInputs;
@ -363,7 +364,7 @@ namespace Elwig.Windows {
} }
protected bool InputLostFocus(TextBox input, ValidationResult res, string? msg = null) { protected bool InputLostFocus(TextBox input, ValidationResult res, string? msg = null) {
if (!res.IsValid && !IsClosing && (IsEditing || IsCreating)) if (DoShowWarningWindows && !res.IsValid && !IsClosing && (IsEditing || IsCreating))
System.Windows.MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); System.Windows.MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
return res.IsValid; return res.IsValid;
} }

View File

@ -160,10 +160,10 @@
<Label Content="Mitglied:" Margin="10,10,0,0" Grid.Column="0"/> <Label Content="Mitglied:" Margin="10,10,0,0" Grid.Column="0"/>
<TextBox x:Name="MgNrInput" Width="48" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Left" TextAlignment="Right" <TextBox x:Name="MgNrInput" Width="48" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Left" TextAlignment="Right"
TextChanged="MgNrInput_TextChanged" LostFocus="MgNrInput_LostFocus"/> TextChanged="MgNrInput_TextChanged" LostFocus="MgNrInput_LostFocus" KeyUp="Input_KeyUp"/>
<ComboBox x:Name="MemberInput" Grid.Column="1" Margin="53,10,10,10" IsEditable="True" <ComboBox x:Name="MemberInput" Grid.Column="1" Margin="53,10,10,10" IsEditable="True"
ItemTemplate="{StaticResource MemberAdminNameTemplate}" TextSearch.TextPath="AdministrativeName" ItemTemplate="{StaticResource MemberAdminNameTemplate}" TextSearch.TextPath="AdministrativeName"
SelectionChanged="MemberInput_SelectionChanged"/> SelectionChanged="MemberInput_SelectionChanged" KeyUp="Input_KeyUp"/>
<Label Content="Wohnort:" Margin="10,38,0,0" Grid.Column="0"/> <Label Content="Wohnort:" Margin="10,38,0,0" Grid.Column="0"/>
<TextBox x:Name="MemberAddressField" Grid.Column="1" Margin="0,40,10,10" FontSize="12" Height="22" <TextBox x:Name="MemberAddressField" Grid.Column="1" Margin="0,40,10,10" FontSize="12" Height="22"
@ -209,15 +209,15 @@
<Label Content="Sorte:" Margin="10,10,0,0" Grid.Column="0"/> <Label Content="Sorte:" Margin="10,10,0,0" Grid.Column="0"/>
<TextBox x:Name="SortIdInput" Width="36" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Left" <TextBox x:Name="SortIdInput" Width="36" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Left"
TextChanged="SortIdInput_TextChanged" LostFocus="SortIdInput_LostFocus"/> TextChanged="SortIdInput_TextChanged" LostFocus="SortIdInput_LostFocus" KeyUp="Input_KeyUp"/>
<ComboBox x:Name="WineVarietyInput" Grid.Row="1" Grid.Column="1" Margin="41,10,10,10" <ComboBox x:Name="WineVarietyInput" Grid.Row="1" Grid.Column="1" Margin="41,10,10,10"
ItemTemplate="{StaticResource WineVarietyTemplate}" TextSearch.TextPath="Name" ItemTemplate="{StaticResource WineVarietyTemplate}" TextSearch.TextPath="Name"
SelectionChanged="WineVarietyInput_SelectionChanged"/> SelectionChanged="WineVarietyInput_SelectionChanged" KeyUp="Input_KeyUp"/>
<Label Content="Attribute:" Margin="10,40,0,0" Grid.Column="0"/> <Label Content="Attribute:" Margin="10,40,0,0" Grid.Column="0"/>
<xctk:CheckComboBox x:Name="AttributesInput" Grid.Row="1" Grid.Column="1" Margin="0,40,10,10" <xctk:CheckComboBox x:Name="AttributesInput" Grid.Row="1" Grid.Column="1" Margin="0,40,10,10"
DisplayMemberPath="Name" Delimiter=", " AllItemsSelectedContent="Alle" DisplayMemberPath="Name" Delimiter=", " AllItemsSelectedContent="Alle"
ItemSelectionChanged="AttributesInput_SelectionChanged"/> ItemSelectionChanged="AttributesInput_SelectionChanged" KeyUp="Input_KeyUp"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
@ -246,7 +246,7 @@
SelectionChanged="WineQualityLevelInput_SelectionChanged"/> SelectionChanged="WineQualityLevelInput_SelectionChanged"/>
<CheckBox x:Name="AbgewertetInput" Content="Abgewertet" IsEnabled="False" <CheckBox x:Name="AbgewertetInput" Content="Abgewertet" IsEnabled="False"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,75,10,10" Grid.Column="1"/> VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,75,10,10" Grid.Column="0" Grid.ColumnSpan="2"/>
</Grid> </Grid>
</GroupBox> </GroupBox>

View File

@ -60,6 +60,8 @@ namespace Elwig.Windows {
SearchInput.TextChanged -= SearchInput_TextChanged; SearchInput.TextChanged -= SearchInput_TextChanged;
SeasonInput.Value = Utils.CurrentLastSeason; SeasonInput.Value = Utils.CurrentLastSeason;
DoShowWarningWindows = false;
if (IsReceipt) { if (IsReceipt) {
Title = "Übernahme - Elwig"; Title = "Übernahme - Elwig";
TodayOnlyInput.IsChecked = true; TodayOnlyInput.IsChecked = true;
@ -149,7 +151,7 @@ namespace Elwig.Windows {
ClearDefaultValues(); ClearDefaultValues();
HandPickedInput.IsChecked = null; HandPickedInput.IsChecked = null;
if (App.Client.IsMatzen) { if (App.Client.IsMatzen || App.Client.IsWolkersdorf) {
GerebeltGewogenInput.IsChecked = true; GerebeltGewogenInput.IsChecked = true;
GerebeltGewogenInput.IsEnabled = false; GerebeltGewogenInput.IsEnabled = false;
SetDefaultValue(GerebeltGewogenInput); SetDefaultValue(GerebeltGewogenInput);
@ -159,6 +161,8 @@ namespace Elwig.Windows {
UnsetDefaultValue(GerebeltGewogenInput); UnsetDefaultValue(GerebeltGewogenInput);
} }
WineQualityLevelInput.IsEnabled = false;
SetDefaultValue(HandPickedInput); SetDefaultValue(HandPickedInput);
ValidateRequiredInputs(); ValidateRequiredInputs();
} }
@ -180,6 +184,16 @@ namespace Elwig.Windows {
CancelCreatingButton.IsEnabled = DeliveryList.SelectedItem == null || DeliveryPartList.SelectedItem == null; CancelCreatingButton.IsEnabled = DeliveryList.SelectedItem == null || DeliveryPartList.SelectedItem == null;
} }
private void Input_KeyUp(object sender, KeyEventArgs evt) {
if (sender is not Control ctrl) return;
if (evt.Key != Key.Enter) return;
if (ctrl == MgNrInput || ctrl == MemberInput) {
SortIdInput.Focus(); SortIdInput.SelectAll();
} else if (ctrl == SortIdInput || ctrl == WineVarietyInput || ctrl == AttributesInput) {
GradationOeInput.Focus(); GradationOeInput.SelectAll();
}
}
private async Task RefreshDeliveryList() { private async Task RefreshDeliveryList() {
await RefreshDeliveryListQuery(); await RefreshDeliveryListQuery();
} }
@ -412,7 +426,7 @@ namespace Elwig.Windows {
await RefreshDeliveryList(); await RefreshDeliveryList();
var d = DeliveryList.SelectedItem as Delivery; var d = DeliveryList.SelectedItem as Delivery;
var y = d?.Year ?? Utils.CurrentLastSeason; var y = d?.Year ?? Utils.CurrentLastSeason;
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr); ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId); ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId); ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.Where(a => IsCreating || a.IsActive).OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.Where(a => IsCreating || a.IsActive).OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
@ -763,8 +777,9 @@ namespace Elwig.Windows {
InitInputs(); InitInputs();
} }
private void CancelCreatingButton_Click(object sender, RoutedEventArgs evt) { private async void CancelCreatingButton_Click(object sender, RoutedEventArgs evt) {
ControlUtils.RenewItemsSource(AttributesInput, Context.WineAttributes.OrderBy(a => a.Name).ToList(), i => (i as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
if (DeliveryList.SelectedItem is not Delivery d) { if (DeliveryList.SelectedItem is not Delivery d) {
// switch away from creating mode // switch away from creating mode
IsCreating = false; IsCreating = false;
@ -785,8 +800,11 @@ namespace Elwig.Windows {
} }
} }
private void NewDeliveryButton_Click(object? sender, RoutedEventArgs? evt) { private async void NewDeliveryButton_Click(object? sender, RoutedEventArgs? evt) {
ControlUtils.RenewItemsSource(AttributesInput, Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).ToList(), i => (i as WineAttr)?.AttrId); TodayOnlyInput.IsChecked = true;
SearchInput.Text = "";
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
IsCreating = true; IsCreating = true;
DeliveryList.IsEnabled = false; DeliveryList.IsEnabled = false;
DeliveryPartList.IsEnabled = false; DeliveryPartList.IsEnabled = false;
@ -1131,10 +1149,11 @@ namespace Elwig.Windows {
private void EnableWeighingButtons() { private void EnableWeighingButtons() {
WeighingManualButton.IsEnabled = true; WeighingManualButton.IsEnabled = true;
WeighingAButton.IsEnabled = true; var n = App.Scales.Count;
WeighingBButton.IsEnabled = true; WeighingAButton.IsEnabled = n > 0 && App.Scales[0].IsReady;
WeighingCButton.IsEnabled = true; WeighingBButton.IsEnabled = n > 1 && App.Scales[1].IsReady;
WeighingDButton.IsEnabled = true; WeighingCButton.IsEnabled = n > 2 && App.Scales[2].IsReady;
WeighingDButton.IsEnabled = n > 3 && App.Scales[3].IsReady;
} }
private async Task UpdateLsNr() { private async Task UpdateLsNr() {
@ -1245,8 +1264,10 @@ namespace Elwig.Windows {
} }
private void ModifiersInput_SelectionChanged(object sender, ItemSelectionChangedEventArgs evt) { private void ModifiersInput_SelectionChanged(object sender, ItemSelectionChangedEventArgs evt) {
if ((IsEditing || IsCreating) && App.Client.IsMatzen) { if (!IsEditing && !IsCreating) return;
var mod = ModifiersInput.SelectedItems.Cast<Modifier>(); var mod = ModifiersInput.SelectedItems.Cast<Modifier>();
var source = ModifiersInput.ItemsSource.Cast<Modifier>();
if (App.Client.IsMatzen) {
var kl = mod.Where(m => m.Name.StartsWith("Klasse ")); var kl = mod.Where(m => m.Name.StartsWith("Klasse "));
if (kl.Count() > 1) { if (kl.Count() > 1) {
foreach (var r in kl.Take(kl.Count() - 1)) ModifiersInput.SelectedItems.Remove(r); foreach (var r in kl.Take(kl.Count() - 1)) ModifiersInput.SelectedItems.Remove(r);
@ -1255,11 +1276,14 @@ namespace Elwig.Windows {
} }
private void LesewagenInput_Changed(object sender, RoutedEventArgs evt) { private void LesewagenInput_Changed(object sender, RoutedEventArgs evt) {
if ((IsEditing || IsCreating) && App.Client.IsMatzen) { if (!IsEditing && !IsCreating) return;
var mod = ModifiersInput.SelectedItems.Cast<Modifier>(); var mod = ModifiersInput.SelectedItems.Cast<Modifier>();
var source = ModifiersInput.ItemsSource.Cast<Modifier>();
var lw = LesewagenInput.IsChecked == true;
if (App.Client.IsMatzen) {
var kl = mod.Where(m => m.Name.StartsWith("Klasse ")).Select(m => m.ModId).LastOrDefault("A")[0]; var kl = mod.Where(m => m.Name.StartsWith("Klasse ")).Select(m => m.ModId).LastOrDefault("A")[0];
if (LesewagenInput.IsChecked == true) kl++; else kl--; if (lw) kl++; else kl--;
var newKl = ModifiersInput.ItemsSource.Cast<Modifier>().Where(m => m.ModId == kl.ToString()).FirstOrDefault(); var newKl = source.Where(m => m.ModId == kl.ToString()).FirstOrDefault();
if (newKl != null) ModifiersInput.SelectedItems.Add(newKl); if (newKl != null) ModifiersInput.SelectedItems.Add(newKl);
} }
CheckBox_Changed(sender, evt); CheckBox_Changed(sender, evt);