ChartWindow: Add MessageBox when removing contract from other graph

This commit is contained in:
2024-01-25 00:36:36 +01:00
parent d59a713a8c
commit df83430c35
2 changed files with 16 additions and 5 deletions

View File

@ -39,7 +39,7 @@ namespace Elwig.Helpers.Billing {
public List<ContractSelection> 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) {

View File

@ -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<ContractSelection>();
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) {