ControlUtils: Cleanup SelectItem() method and use accordingly
This commit is contained in:
Elwig
App.xaml.cs
Helpers
Windows
AdministrationWindow.csAreaComAdminWindow.xaml.csBaseDataWindow.xaml.AreaCom.csBaseDataWindow.xaml.Branch.csBaseDataWindow.xaml.Mod.csBaseDataWindow.xaml.Season.csBaseDataWindow.xaml.WineAttr.csBaseDataWindow.xaml.WineCult.csBaseDataWindow.xaml.csChartWindow.xaml.csDeliveryAdminWindow.xamlDeliveryAdminWindow.xaml.csMailWindow.xaml.csMemberAdminWindow.xaml.csOriginHierarchyWindow.xaml.csPaymentVariantsWindow.xaml.cs
@ -198,15 +198,15 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void FillOriginalValues() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
OriginalValues[tb] = Utils.GetEntityIdentifier(tb.Text);
|
||||
OriginalValues[tb] = ControlUtils.GetInputHashCode(tb);
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
OriginalValues[cb] = Utils.GetEntityIdentifier(cb.SelectedItem);
|
||||
OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
|
||||
foreach (var ccb in CheckComboBoxInputs)
|
||||
OriginalValues[ccb] = Utils.GetEntityIdentifier(ccb.SelectedItems);
|
||||
OriginalValues[ccb] = ControlUtils.GetInputHashCode(ccb);
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
OriginalValues[cb] = Utils.GetEntityIdentifier(cb.IsChecked);
|
||||
OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
OriginalValues[rb] = Utils.GetEntityIdentifier(rb.IsChecked);
|
||||
OriginalValues[rb] = ControlUtils.GetInputHashCode(rb);
|
||||
}
|
||||
|
||||
protected void SetOriginalValue(Control input, object? value) {
|
||||
@ -232,7 +232,7 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void SetDefaultValue(Control input, object? value) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
DefaultValues[input] = value != null ? Utils.GetEntityIdentifier(value) : null;
|
||||
DefaultValues[input] = Utils.GetEntityIdentifier(value);
|
||||
if (!InputHasChanged(input)) {
|
||||
if (InputIsNotDefault(input)) {
|
||||
ControlUtils.SetInputNotDefault(input);
|
||||
@ -278,39 +278,21 @@ namespace Elwig.Windows {
|
||||
|
||||
protected bool InputHasChanged(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
if (!OriginalValues.ContainsKey(input)) {
|
||||
if (!OriginalValues.TryGetValue(input, out int? original)) {
|
||||
return false;
|
||||
} else if (input is TextBox tb) {
|
||||
return OriginalValues[tb] != Utils.GetEntityIdentifier(tb.Text);
|
||||
} else if (input is ComboBox sb) {
|
||||
return OriginalValues[sb] != Utils.GetEntityIdentifier(sb.SelectedItem);
|
||||
} else if (input is CheckComboBox ccb) {
|
||||
return OriginalValues[ccb] != Utils.GetEntityIdentifier(ccb.SelectedItems);
|
||||
} else if (input is CheckBox cb) {
|
||||
return OriginalValues[cb] != Utils.GetEntityIdentifier(cb.IsChecked);
|
||||
} else if (input is RadioButton rb) {
|
||||
return OriginalValues[rb] != Utils.GetEntityIdentifier(rb.IsChecked);
|
||||
} else {
|
||||
return false;
|
||||
var current = ControlUtils.GetInputHashCode(input);
|
||||
return original != current;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool InputIsNotDefault(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
if (!DefaultValues.ContainsKey(input)) {
|
||||
if (!DefaultValues.TryGetValue(input, out int? defaultValue)) {
|
||||
return false;
|
||||
} else if (input is TextBox tb) {
|
||||
return DefaultValues[tb] != Utils.GetEntityIdentifier(tb.Text);
|
||||
} else if (input is ComboBox sb) {
|
||||
return DefaultValues[sb] != Utils.GetEntityIdentifier(sb.SelectedItem);
|
||||
} else if (input is CheckComboBox ccb) {
|
||||
return DefaultValues[ccb] != Utils.GetEntityIdentifier(ccb.SelectedItems);
|
||||
} else if (input is CheckBox cb) {
|
||||
return DefaultValues[cb] != Utils.GetEntityIdentifier(cb.IsChecked);
|
||||
} else if (input is RadioButton rb) {
|
||||
return DefaultValues[rb] != Utils.GetEntityIdentifier(rb.IsChecked);
|
||||
} else {
|
||||
return false;
|
||||
var current = ControlUtils.GetInputHashCode(input);
|
||||
return defaultValue != current;
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +325,7 @@ namespace Elwig.Windows {
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
ControlUtils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
|
||||
ControlUtils.RenewItemsSource(ortInput, list);
|
||||
if (list != null && ortInput.SelectedItem == null && list.Count == 1)
|
||||
ortInput.SelectedItem = list[0];
|
||||
UpdateComboBox(ortInput);
|
||||
|
Reference in New Issue
Block a user