ChartWindow: Load GraphEntries correctly from EditBillingData

This commit is contained in:
2024-01-20 01:53:27 +01:00
parent 75e9d756d2
commit 6a5676f916
3 changed files with 54 additions and 47 deletions

View File

@ -58,10 +58,7 @@ namespace Elwig.Windows {
private async Task RefreshGraphList() {
await Context.PaymentVariants.LoadAsync();
await RefreshGraphListQuery();
}
private async Task RefreshGraphListQuery() {
var attrVariants = Context.DeliveryParts
.Where(d => d.Year == Year)
.Select(d => $"{d.SortId}{d.AttrId}")
@ -71,37 +68,18 @@ namespace Elwig.Windows {
.Order()
.ToList();
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
GraphEntries.AddRange(data.GetPaymentGraphEntries());
GraphEntries.AddRange(data.GetQualityGraphEntries());
GraphEntries = [ ..data.GetPaymentGraphEntries(Context), ..data.GetQualityGraphEntries(Context)];
//var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
//ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as GraphEntry)?.Id);
ControlUtils.RenewItemsSource(ContractInput, attrVariants, g => g);
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.IfOnly);
var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.ToString());
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.First);
RefreshInputs();
}
private string ParseContracts(JsonObject auszahlungsSorten, int num) {
return "";
}
private void RefreshInputs(bool validate = false) {
private void RefreshInputs() {
ResetPlot();
if (!PaymentVar.TestVariant) {
AddButton.IsEnabled = false;
CopyButton.IsEnabled = false;
DeleteButton.IsEnabled = false;
DisableUnitTextBox(OechsleInput);
DisableUnitTextBox(PriceInput);
GebundenTypeFixed.IsEnabled = false;
GebundenTypeGraph.IsEnabled = false;
GebundenTypeNone.IsEnabled = false;
ContractInput.IsEnabled = false;
EnableOptionButtons();
FillInputs();
} else if (SelectedGraphEntry != null) {
if (SelectedGraphEntry != null) {
CopyButton.IsEnabled = true;
DeleteButton.IsEnabled = true;
//EnableUnitTextBox(OechsleInput);
@ -117,21 +95,31 @@ namespace Elwig.Windows {
DisableUnitTextBox(OechsleInput);
DisableOptionButtons();
}
GC.Collect();
if (!PaymentVar.TestVariant) {
AddButton.IsEnabled = false;
CopyButton.IsEnabled = false;
DeleteButton.IsEnabled = false;
DisableUnitTextBox(OechsleInput);
DisableUnitTextBox(PriceInput);
GebundenTypeFixed.IsEnabled = false;
GebundenTypeGraph.IsEnabled = false;
GebundenTypeNone.IsEnabled = false;
ContractInput.IsEnabled = false;
}
}
private void FillInputs() {
GraphNum.Text = SelectedGraphEntry.Id.ToString();
GraphNum.Text = SelectedGraphEntry?.Id.ToString();
if (SelectedGraphEntry.GebundenFlatBonus != null) {
if (SelectedGraphEntry?.GebundenFlatBonus != null) {
GebundenTypeFixed.IsChecked = true;
} else if (SelectedGraphEntry.GebundenGraph != null) {
} else if (SelectedGraphEntry?.GebundenGraph != null) {
GebundenTypeGraph.IsChecked = true;
} else {
GebundenTypeNone.IsChecked = true; ;
}
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry.Contracts, i => (i as ContractSelection)?.Listing);
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry?.Contracts ?? [], i => (i as ContractSelection)?.Listing);
InitPlot();
OechslePricePlot.IsEnabled = true;
@ -149,13 +137,13 @@ namespace Elwig.Windows {
GebundenPlot.MarkerSize = 9;
}
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.DataGraph.DataX, SelectedGraphEntry.DataGraph.DataY);
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
DataPlot.LineColor = Color.Blue;
DataPlot.MarkerColor = Color.Blue;
DataPlot.MarkerSize = 9;
if (SelectedGraphEntry.GebundenGraph == null) {
ChangeActiveGraph(SelectedGraphEntry.DataGraph);
if (SelectedGraphEntry?.GebundenGraph == null) {
ChangeActiveGraph(SelectedGraphEntry?.DataGraph);
}
OechslePricePlot.RightClicked -= OechslePricePlot.DefaultRightClickEvent;
@ -470,7 +458,7 @@ namespace Elwig.Windows {
HighlightedPointPlot.IsVisible = true;
HoverChanged = true ^ HoverActive;
HoverActive = true;
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph);
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph!);
} else {
ChangeMarker(HighlightedPointPlot, false);
HoverChanged = false ^ HoverActive;
@ -604,7 +592,7 @@ namespace Elwig.Windows {
}
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
SelectedGraphEntry = (GraphEntry)GraphList.SelectedItem;
SelectedGraphEntry = GraphList.SelectedItem as GraphEntry;
RefreshInputs();
//var x = OechslePricePlot.Plot.GetPlottables().OfType<ScatterPlot>();
@ -629,6 +617,7 @@ namespace Elwig.Windows {
private void ContractInput_Changed(object sender, RoutedEventArgs e) {
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
SelectedGraphEntry!.Contracts = r.ToList();
// FIXME when using arrow keys, selection does not work nicely
GraphList.Items.Refresh();
}