Fix Original/Default input detection in DeliveryAdminWindow
This commit is contained in:
@ -25,6 +25,10 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetInputNotDefault(Control input) {
|
||||
SetControlBrush(input, Brushes.Gold);
|
||||
}
|
||||
|
||||
public static void SetInputChanged(Control input) {
|
||||
SetControlBrush(input, Brushes.Orange);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ namespace Elwig.Windows {
|
||||
private RadioButton[] RadioButtonInputs;
|
||||
private readonly Dictionary<Control, bool> Valid;
|
||||
private readonly Dictionary<Control, object?> OriginalValues;
|
||||
private readonly Dictionary<Control, object?> DefaultValues;
|
||||
|
||||
public AdministrationWindow() : base() {
|
||||
IsEditing = false;
|
||||
@ -58,6 +59,7 @@ namespace Elwig.Windows {
|
||||
RadioButtonInputs = Array.Empty<RadioButton>();
|
||||
Valid = new();
|
||||
OriginalValues = new();
|
||||
DefaultValues = new();
|
||||
Closing += OnClosing;
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
@ -101,6 +103,12 @@ namespace Elwig.Windows {
|
||||
return (sender is Control c) && RequiredInputs.Contains(c);
|
||||
}
|
||||
|
||||
protected void FinishInputFilling() {
|
||||
FillOriginalValues();
|
||||
ValidateDefaultValues();
|
||||
ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
protected void ClearInputStates() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
ControlUtils.ClearInputState(tb);
|
||||
@ -121,10 +129,25 @@ namespace Elwig.Windows {
|
||||
Valid[input] = false;
|
||||
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (input is CheckComboBox ccb && ccb.SelectedItem == null && ccb.ItemsSource != null) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (input is CheckBox ckb && ckb.IsChecked != true) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
Valid[input] = false;
|
||||
} else if (input is RadioButton rb && rb.IsChecked != true) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
Valid[input] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ValidateDefaultValues() {
|
||||
foreach (var input in DefaultValues.Keys) {
|
||||
if (InputIsNotDefault(input))
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
}
|
||||
}
|
||||
|
||||
protected void LockInputs() {
|
||||
foreach (var tb in TextBoxInputs) {
|
||||
tb.IsReadOnly = true;
|
||||
@ -159,6 +182,10 @@ namespace Elwig.Windows {
|
||||
OriginalValues.Clear();
|
||||
}
|
||||
|
||||
protected void ClearDefaultValues() {
|
||||
DefaultValues.Clear();
|
||||
}
|
||||
|
||||
protected void FillOriginalValues() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
OriginalValues[tb] = tb.Text;
|
||||
@ -174,10 +201,34 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void SetOriginalValue(Control input, object? value) {
|
||||
OriginalValues[input] = value;
|
||||
if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UnsetOriginalValue(Control input) {
|
||||
OriginalValues.Remove(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
|
||||
protected void SetDefaultValue(Control input, object? value) {
|
||||
DefaultValues[input] = value;
|
||||
if (!InputHasChanged(input)) {
|
||||
if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void UnsetDefaultValue(Control input) {
|
||||
DefaultValues.Remove(input);
|
||||
if (!InputHasChanged(input)) {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ClearInputs(bool validate = true) {
|
||||
@ -218,6 +269,24 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
protected bool InputIsNotDefault(Control input) {
|
||||
if (!DefaultValues.ContainsKey(input)) {
|
||||
return false;
|
||||
} else if (input is TextBox tb) {
|
||||
return DefaultValues[tb]?.ToString() != tb.Text;
|
||||
} else if (input is ComboBox sb) {
|
||||
return DefaultValues[sb] != sb.SelectedItem;
|
||||
} else if (input is CheckComboBox ccb) {
|
||||
return !ccb.SelectedItems.Cast<object>().ToArray().SequenceEqual(((object[]?)DefaultValues[ccb]) ?? Array.Empty<object>());
|
||||
} else if (input is CheckBox cb) {
|
||||
return (DefaultValues[cb] != null) != (cb.IsChecked ?? false);
|
||||
} else if (input is RadioButton rb) {
|
||||
return (DefaultValues[rb] != null) != (rb.IsChecked ?? false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool HasChanged =>
|
||||
!IsValid ||
|
||||
TextBoxInputs.Any(InputHasChanged) ||
|
||||
@ -269,6 +338,8 @@ namespace Elwig.Windows {
|
||||
if (res.IsValid) {
|
||||
if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
@ -299,6 +370,8 @@ namespace Elwig.Windows {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
@ -311,6 +384,8 @@ namespace Elwig.Windows {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
@ -326,6 +401,8 @@ namespace Elwig.Windows {
|
||||
ValidateInput(input, true);
|
||||
if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
@ -344,6 +421,8 @@ namespace Elwig.Windows {
|
||||
ValidateInput(input, true);
|
||||
if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
} else if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
} else {
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
|
@ -80,14 +80,13 @@ namespace Elwig.Windows {
|
||||
AreaComTypeInput.SelectedItem = a.AreaComType;
|
||||
WineCultivationInput.SelectedItem = a.WineCult;
|
||||
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
private async void InitInputs() {
|
||||
FbNrInput.Text = (await Context.NextFbNr()).ToString();
|
||||
MgNrInput.Text = Member.MgNr.ToString();
|
||||
FillOriginalValues();
|
||||
ValidateRequiredInputs();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
|
@ -192,7 +192,8 @@
|
||||
DisplayMemberPath="Name" TextSearch.TextPath="Name"/>
|
||||
|
||||
<Label Content="Anmerkung:" Margin="10,100,0,10"/>
|
||||
<TextBox x:Name="CommentInput" Grid.Column="1" Margin="0,100,10,10"/>
|
||||
<TextBox x:Name="CommentInput" Grid.Column="1" Margin="0,100,10,10"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
@ -261,10 +262,12 @@
|
||||
</Grid>
|
||||
|
||||
<CheckBox x:Name="ManualWeighingInput" Content="Handwiegung" IsEnabled="False"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,45,10,10" Grid.Column="0" Grid.ColumnSpan="2"/>
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,45,10,10" Grid.Column="0" Grid.ColumnSpan="2"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"/>
|
||||
|
||||
<CheckBox x:Name="GerebeltGewogenInput" Content="Gerebelt gewogen"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,75,10,10" Grid.Column="0" Grid.ColumnSpan="2"/>
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,75,10,10" Grid.Column="0" Grid.ColumnSpan="2"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"/>
|
||||
|
||||
<Button x:Name="WeighingManualButton" Content="Handwiegung" Width="120"
|
||||
Click="WeighingManualButton_Click"
|
||||
@ -299,7 +302,8 @@
|
||||
ItemSelectionChanged="ModifiersInput_SelectionChanged"/>
|
||||
|
||||
<Label Content="Anmerkung:" Margin="10,40,0,10"/>
|
||||
<TextBox x:Name="PartCommentInput" Grid.Column="1" Margin="0,40,10,10" Grid.ColumnSpan="2"/>
|
||||
<TextBox x:Name="PartCommentInput" Grid.Column="1" Margin="0,40,10,10" Grid.ColumnSpan="2"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
|
||||
<Label Content="Temperatur:" Margin="10,70,0,10"/>
|
||||
<Grid Grid.Column="1" Height="25" Margin="0,70,10,10" VerticalAlignment="Top">
|
||||
@ -314,9 +318,11 @@
|
||||
</Grid>
|
||||
|
||||
<CheckBox x:Name="LesewagenInput" Content="Lesewagen" Margin="10,75,0,0" Grid.Column="2"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"/>
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"/>
|
||||
<CheckBox x:Name="HandPickedInput" Content="Handlese" Margin="10,105,0,0" Grid.Column="2" IsThreeState="True"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"/>
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
@ -74,6 +74,10 @@ namespace Elwig.Windows {
|
||||
WeighingCButton.Visibility = Visibility.Hidden;
|
||||
WeighingDButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
if (App.Client.Client == ClientParameters.Type.Matzen) {
|
||||
SetDefaultValue(GerebeltGewogenInput, true);
|
||||
}
|
||||
}
|
||||
|
||||
public DeliveryAdminWindow(int mgnr) : this() {
|
||||
@ -120,11 +124,13 @@ namespace Elwig.Windows {
|
||||
|
||||
private void InitialInputs() {
|
||||
HandPickedInput.IsChecked = null;
|
||||
SetDefaultValue(HandPickedInput, null);
|
||||
if (App.Client.Client == ClientParameters.Type.Matzen) {
|
||||
GerebeltGewogenInput.IsChecked = true;
|
||||
GerebeltGewogenInput.IsEnabled = false;
|
||||
} else {
|
||||
GerebeltGewogenInput.IsChecked = false;
|
||||
UnsetDefaultValue(GerebeltGewogenInput);
|
||||
GerebeltGewogenInput.IsEnabled = true;
|
||||
}
|
||||
ClearOriginalValues();
|
||||
@ -372,7 +378,7 @@ namespace Elwig.Windows {
|
||||
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.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(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
|
||||
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.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);
|
||||
ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync(), i => (i as WineQualLevel)?.QualId);
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == y).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId);
|
||||
ControlUtils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId), i => (i as WineOrigin)?.HkId);
|
||||
@ -433,12 +439,12 @@ namespace Elwig.Windows {
|
||||
TemperatureInput.Text = "";
|
||||
AcidInput.Text = "";
|
||||
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
private void FillInputs(DeliveryPart p) {
|
||||
ClearOriginalValues();
|
||||
FillInputs(p.Delivery);
|
||||
ClearOriginalValues();
|
||||
|
||||
SortIdInput.Text = p?.SortId ?? "";
|
||||
ControlUtils.SelectCheckComboBoxItems(AttributesInput, p?.Attributes, i => (i as WineAttr)?.AttrId);
|
||||
@ -457,7 +463,7 @@ namespace Elwig.Windows {
|
||||
LesewagenInput.IsChecked = p?.IsLesewagen ?? false;
|
||||
HandPickedInput.IsChecked = p?.IsHandPicked;
|
||||
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
private async Task<DeliveryPart> UpdateDeliveryPart(Delivery? d, DeliveryPart? p) {
|
||||
@ -698,10 +704,10 @@ namespace Elwig.Windows {
|
||||
if (m != null) MgNrInput.Text = m.MgNr.ToString();
|
||||
MemberAddressField.Text = m?.FullAddress;
|
||||
if (m == null) {
|
||||
UnsetOriginalValue(WineKgInput);
|
||||
UnsetDefaultValue(WineKgInput);
|
||||
WineKgInput.SelectedIndex = 0;
|
||||
} else {
|
||||
SetOriginalValue(WineKgInput, m.DefaultKg);
|
||||
SetDefaultValue(WineKgInput, m.DefaultKg);
|
||||
WineKgInput.SelectedItem = m.DefaultKg;
|
||||
}
|
||||
}
|
||||
@ -732,6 +738,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void CancelCreatingButton_Click(object sender, RoutedEventArgs evt) {
|
||||
ControlUtils.RenewItemsSource(AttributesInput, Context.WineAttributes.OrderBy(a => a.Name).ToList(), i => (i as WineAttr)?.AttrId);
|
||||
if (DeliveryList.SelectedItem is not Delivery d) {
|
||||
// switch away from creating mode
|
||||
IsCreating = false;
|
||||
@ -753,6 +760,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private 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);
|
||||
IsCreating = true;
|
||||
DeliveryList.IsEnabled = false;
|
||||
DeliveryPartList.IsEnabled = false;
|
||||
@ -824,7 +832,7 @@ namespace Elwig.Windows {
|
||||
ShowNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
await RefreshDeliveryList();
|
||||
RefreshDeliveryParts();
|
||||
RefreshInputs();
|
||||
@ -853,7 +861,6 @@ namespace Elwig.Windows {
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
|
||||
@ -1028,14 +1035,14 @@ namespace Elwig.Windows {
|
||||
|
||||
private void UpdateWineQualityLevels() {
|
||||
if (!GetInputValid(GradationKmwInput)) {
|
||||
UnsetOriginalValue(WineQualityLevelInput);
|
||||
UnsetDefaultValue(WineQualityLevelInput);
|
||||
WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.Where(q => q.QualId == "WEI").ToList();
|
||||
return;
|
||||
}
|
||||
var kmw = double.Parse(GradationKmwInput.Text);
|
||||
WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.Where(q => q.MinKmw == null || q.MinKmw <= kmw).ToList();
|
||||
var qual = Context.GetWineQualityLevel(kmw).GetAwaiter().GetResult();
|
||||
SetOriginalValue(WineQualityLevelInput, qual);
|
||||
SetDefaultValue(WineQualityLevelInput, qual);
|
||||
if (WineQualityLevelInput.SelectedItem == null || (WineQualityLevelInput.SelectedItem is WineQualLevel selected && !selected.IsPredicate)) {
|
||||
WineQualityLevelInput.SelectedItem = qual;
|
||||
}
|
||||
@ -1099,11 +1106,13 @@ namespace Elwig.Windows {
|
||||
var kg = (WineKgInput.SelectedItem as AT_Kg)?.WbKg;
|
||||
if (qual == null || kg == null) {
|
||||
WineOriginInput.IsEnabled = (IsEditing || IsCreating);
|
||||
UnsetDefaultValue(WineOriginInput);
|
||||
return;
|
||||
}
|
||||
WineOriginInput.IsEnabled = false;
|
||||
var o = kg.Origin;
|
||||
while (o != null && o.Level > qual.OriginLevel) o = o.Parent;
|
||||
SetDefaultValue(WineOriginInput, o);
|
||||
WineOriginInput.SelectedItem = o;
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,7 @@ namespace Elwig.Windows {
|
||||
BranchInput.SelectedItem = Context.Branches.First();
|
||||
ActiveInput.IsChecked = true;
|
||||
ContactPostalInput.IsChecked = true;
|
||||
FillOriginalValues();
|
||||
ValidateRequiredInputs();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
@ -213,7 +212,7 @@ namespace Elwig.Windows {
|
||||
LockInputs();
|
||||
UpdatePhoneNrInputVisibility();
|
||||
UnlockSearchInputs();
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
await RefreshMemberList();
|
||||
RefreshInputs();
|
||||
SearchInput.Text = "";
|
||||
@ -237,7 +236,6 @@ namespace Elwig.Windows {
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
UpdatePhoneNrInputVisibility();
|
||||
UnlockSearchInputs();
|
||||
@ -513,7 +511,7 @@ namespace Elwig.Windows {
|
||||
|
||||
Menu_Member_SendEmail.IsEnabled = m.Email != null;
|
||||
|
||||
FillOriginalValues();
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
new protected void ClearInputs(bool validate = false) {
|
||||
|
Reference in New Issue
Block a user