From df83430c35ced1d65b67b661830221c093aca764 Mon Sep 17 00:00:00 2001 From: Thomas Hilscher Date: Thu, 25 Jan 2024 00:36:36 +0100 Subject: [PATCH] ChartWindow: Add MessageBox when removing contract from other graph --- Elwig/Helpers/Billing/GraphEntry.cs | 2 +- Elwig/Windows/ChartWindow.xaml.cs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Elwig/Helpers/Billing/GraphEntry.cs b/Elwig/Helpers/Billing/GraphEntry.cs index b76d776..e1098a2 100644 --- a/Elwig/Helpers/Billing/GraphEntry.cs +++ b/Elwig/Helpers/Billing/GraphEntry.cs @@ -39,7 +39,7 @@ namespace Elwig.Helpers.Billing { public List Contracts { get; set; } public string ContractsStringSimple => (Abgewertet ? "Abgew.: " : "") + (Contracts.Count != 0 ? (Contracts.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Contracts.Select(c => c.Listing))) : "-"); public string ContractsString => Contracts.Count != 0 ? string.Join("\n", Contracts.Select(c => c.FullName)) : "-"; - + public string ContractsStringChange => (Abgewertet ? "A." : "") + string.Join(",", Contracts.Select(c => c.Listing)); private readonly int Precision; public GraphEntry(int id, int precision, BillingData.CurveMode mode) { diff --git a/Elwig/Windows/ChartWindow.xaml.cs b/Elwig/Windows/ChartWindow.xaml.cs index 798cb72..c4639a2 100644 --- a/Elwig/Windows/ChartWindow.xaml.cs +++ b/Elwig/Windows/ChartWindow.xaml.cs @@ -95,7 +95,7 @@ namespace Elwig.Windows { FillingInputs = true; ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing); FillingInputs = false; - ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.ContractsStringSimple, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First); + ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.ContractsStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First); RefreshInputs(); } @@ -718,7 +718,10 @@ namespace Elwig.Windows { private void ContractInput_Changed(object sender, ItemSelectionChangedEventArgs e) { if (FillingInputs) return; if (e.IsSelected == true) { - RemoveContractFromOtherGraphEntries(e.Item.ToString()); + bool success = RemoveContractFromOtherGraphEntries(e.Item.ToString()); + if (!success) { + ContractInput.SelectedItems.Remove(e.Item); + } } var r = ContractInput.SelectedItems.Cast(); SelectedGraphEntry!.Contracts = r.ToList(); @@ -726,13 +729,21 @@ namespace Elwig.Windows { GraphList.Items.Refresh(); } - private void RemoveContractFromOtherGraphEntries(string? contract) { - if (contract == null) return; + private bool RemoveContractFromOtherGraphEntries(string? contract) { + if (contract == null) return true; foreach (var ge in GraphEntries) { if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) { + var toRemove = ge.Contracts.Where(c => c.Listing.Equals(contract)).ToList(); + if (toRemove.Count == 0) continue; + var r = MessageBox.Show($"Achtung: {string.Join(", ", toRemove)} ist bereits in Graph {ge.Id} in Verwendung!\nSoll die Zuweisung dort entfernt werden?", "Entfernen bestätigen", + MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); + if (r != MessageBoxResult.Yes) { + return false; + } ge.Contracts.RemoveAll(c => c.Listing.Equals(contract)); } } + return true; } private void AbgewertetInput_Changed(object sender, RoutedEventArgs e) {