ChartWindow: Load GraphEntries correctly from EditBillingData
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return new(ParseJson(json), attributeVariants);
|
return new(ParseJson(json), attributeVariants);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries() {
|
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext context) {
|
||||||
Dictionary<int, List<string>> dict1 = [];
|
Dictionary<int, List<string>> dict1 = [];
|
||||||
Dictionary<decimal, List<string>> dict2 = [];
|
Dictionary<decimal, List<string>> dict2 = [];
|
||||||
var p = GetPaymentEntry();
|
var p = GetPaymentEntry();
|
||||||
@ -40,22 +41,38 @@ namespace Elwig.Helpers.Billing {
|
|||||||
dict2[idx].Add("default");
|
dict2[idx].Add("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var virtOffset = dict1.Count;
|
||||||
Dictionary<int, Curve> curves = GetCurves();
|
Dictionary<int, Curve> curves = GetCurves();
|
||||||
decimal[] virtCurves = [.. dict2.Keys.Order()];
|
decimal[] virtCurves = [.. dict2.Keys.Order()];
|
||||||
for (int i = 0; i < virtCurves.Length; i++) {
|
for (int i = 0; i < virtCurves.Length; i++) {
|
||||||
var idx = virtCurves[i];
|
var idx = virtCurves[i];
|
||||||
dict1[1000 + i] = dict2[idx];
|
dict1[i + virtOffset] = dict2[idx];
|
||||||
curves[1000 + i] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
curves[i + virtOffset] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<int, List<string>> dict3 = [];
|
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
|
||||||
|
foreach (var (selector, value) in GetSelection(p, AttributeVariants)) {
|
||||||
|
int? idx = null;
|
||||||
|
if (value.TryGetValue<decimal>(out var val)) {
|
||||||
|
idx = Array.IndexOf(virtCurves, val) + virtOffset;
|
||||||
|
} else if (value.TryGetValue<string>(out var str)) {
|
||||||
|
idx = int.Parse(str.Split(":")[1]);
|
||||||
|
}
|
||||||
|
if (idx != null)
|
||||||
|
dict3[(int)idx].Add(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
var vars = context.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||||
|
var attrs = context.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||||
|
|
||||||
|
return dict3
|
||||||
return dict3.Select(e => new GraphEntry(e.Key, curves[e.Key], 50, 120)).ToList();
|
.Select(e => new GraphEntry(e.Key, curves[e.Key], e.Value
|
||||||
|
.Select(s => new ContractSelection(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null))
|
||||||
|
.ToList(), 50, 120))
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<GraphEntry> GetQualityGraphEntries() {
|
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext context) {
|
||||||
Dictionary<int, List<string>> dict1 = [];
|
Dictionary<int, List<string>> dict1 = [];
|
||||||
Dictionary<decimal, List<string>> dict2 = [];
|
Dictionary<decimal, List<string>> dict2 = [];
|
||||||
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
||||||
|
@ -31,11 +31,12 @@ namespace Elwig.Helpers.Billing {
|
|||||||
if (gebunden != null) GebundenGraph = new Graph(gebunden, minX, maxX);
|
if (gebunden != null) GebundenGraph = new Graph(gebunden, minX, maxX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphEntry(int id, BillingData.Curve curve, int minX, int maxX) :
|
public GraphEntry(int id, BillingData.Curve curve, List<ContractSelection> contracts, int minX, int maxX) :
|
||||||
this(id, curve.Mode, minX, maxX) {
|
this(id, curve.Mode, minX, maxX) {
|
||||||
DataGraph = new Graph(curve.Normal, minX, maxX);
|
DataGraph = new Graph(curve.Normal, minX, maxX);
|
||||||
if (curve.Gebunden != null)
|
if (curve.Gebunden != null)
|
||||||
GebundenGraph = new Graph(curve.Gebunden, minX, maxX);
|
GebundenGraph = new Graph(curve.Gebunden, minX, maxX);
|
||||||
|
Contracts = contracts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphEntry(int id, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
|
private GraphEntry(int id, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
|
||||||
|
@ -58,10 +58,7 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private async Task RefreshGraphList() {
|
private async Task RefreshGraphList() {
|
||||||
await Context.PaymentVariants.LoadAsync();
|
await Context.PaymentVariants.LoadAsync();
|
||||||
await RefreshGraphListQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task RefreshGraphListQuery() {
|
|
||||||
var attrVariants = Context.DeliveryParts
|
var attrVariants = Context.DeliveryParts
|
||||||
.Where(d => d.Year == Year)
|
.Where(d => d.Year == Year)
|
||||||
.Select(d => $"{d.SortId}{d.AttrId}")
|
.Select(d => $"{d.SortId}{d.AttrId}")
|
||||||
@ -71,37 +68,18 @@ namespace Elwig.Windows {
|
|||||||
.Order()
|
.Order()
|
||||||
.ToList();
|
.ToList();
|
||||||
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
|
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
|
||||||
GraphEntries.AddRange(data.GetPaymentGraphEntries());
|
GraphEntries = [ ..data.GetPaymentGraphEntries(Context), ..data.GetQualityGraphEntries(Context)];
|
||||||
GraphEntries.AddRange(data.GetQualityGraphEntries());
|
|
||||||
|
|
||||||
//var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
|
var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
|
||||||
//ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as GraphEntry)?.Id);
|
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.ToString());
|
||||||
|
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.First);
|
||||||
ControlUtils.RenewItemsSource(ContractInput, attrVariants, g => g);
|
|
||||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.IfOnly);
|
|
||||||
|
|
||||||
RefreshInputs();
|
RefreshInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ParseContracts(JsonObject auszahlungsSorten, int num) {
|
private void RefreshInputs() {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RefreshInputs(bool validate = false) {
|
|
||||||
ResetPlot();
|
ResetPlot();
|
||||||
if (!PaymentVar.TestVariant) {
|
if (SelectedGraphEntry != null) {
|
||||||
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) {
|
|
||||||
CopyButton.IsEnabled = true;
|
CopyButton.IsEnabled = true;
|
||||||
DeleteButton.IsEnabled = true;
|
DeleteButton.IsEnabled = true;
|
||||||
//EnableUnitTextBox(OechsleInput);
|
//EnableUnitTextBox(OechsleInput);
|
||||||
@ -117,21 +95,31 @@ namespace Elwig.Windows {
|
|||||||
DisableUnitTextBox(OechsleInput);
|
DisableUnitTextBox(OechsleInput);
|
||||||
DisableOptionButtons();
|
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() {
|
private void FillInputs() {
|
||||||
GraphNum.Text = SelectedGraphEntry.Id.ToString();
|
GraphNum.Text = SelectedGraphEntry?.Id.ToString();
|
||||||
|
|
||||||
if (SelectedGraphEntry.GebundenFlatBonus != null) {
|
if (SelectedGraphEntry?.GebundenFlatBonus != null) {
|
||||||
GebundenTypeFixed.IsChecked = true;
|
GebundenTypeFixed.IsChecked = true;
|
||||||
} else if (SelectedGraphEntry.GebundenGraph != null) {
|
} else if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||||
GebundenTypeGraph.IsChecked = true;
|
GebundenTypeGraph.IsChecked = true;
|
||||||
} else {
|
} else {
|
||||||
GebundenTypeNone.IsChecked = true; ;
|
GebundenTypeNone.IsChecked = true; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry.Contracts, i => (i as ContractSelection)?.Listing);
|
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry?.Contracts ?? [], i => (i as ContractSelection)?.Listing);
|
||||||
|
|
||||||
InitPlot();
|
InitPlot();
|
||||||
OechslePricePlot.IsEnabled = true;
|
OechslePricePlot.IsEnabled = true;
|
||||||
@ -149,13 +137,13 @@ namespace Elwig.Windows {
|
|||||||
GebundenPlot.MarkerSize = 9;
|
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.LineColor = Color.Blue;
|
||||||
DataPlot.MarkerColor = Color.Blue;
|
DataPlot.MarkerColor = Color.Blue;
|
||||||
DataPlot.MarkerSize = 9;
|
DataPlot.MarkerSize = 9;
|
||||||
|
|
||||||
if (SelectedGraphEntry.GebundenGraph == null) {
|
if (SelectedGraphEntry?.GebundenGraph == null) {
|
||||||
ChangeActiveGraph(SelectedGraphEntry.DataGraph);
|
ChangeActiveGraph(SelectedGraphEntry?.DataGraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
OechslePricePlot.RightClicked -= OechslePricePlot.DefaultRightClickEvent;
|
OechslePricePlot.RightClicked -= OechslePricePlot.DefaultRightClickEvent;
|
||||||
@ -470,7 +458,7 @@ namespace Elwig.Windows {
|
|||||||
HighlightedPointPlot.IsVisible = true;
|
HighlightedPointPlot.IsVisible = true;
|
||||||
HoverChanged = true ^ HoverActive;
|
HoverChanged = true ^ HoverActive;
|
||||||
HoverActive = true;
|
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 {
|
} else {
|
||||||
ChangeMarker(HighlightedPointPlot, false);
|
ChangeMarker(HighlightedPointPlot, false);
|
||||||
HoverChanged = false ^ HoverActive;
|
HoverChanged = false ^ HoverActive;
|
||||||
@ -604,7 +592,7 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||||
SelectedGraphEntry = (GraphEntry)GraphList.SelectedItem;
|
SelectedGraphEntry = GraphList.SelectedItem as GraphEntry;
|
||||||
RefreshInputs();
|
RefreshInputs();
|
||||||
|
|
||||||
//var x = OechslePricePlot.Plot.GetPlottables().OfType<ScatterPlot>();
|
//var x = OechslePricePlot.Plot.GetPlottables().OfType<ScatterPlot>();
|
||||||
@ -629,6 +617,7 @@ namespace Elwig.Windows {
|
|||||||
private void ContractInput_Changed(object sender, RoutedEventArgs e) {
|
private void ContractInput_Changed(object sender, RoutedEventArgs e) {
|
||||||
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
|
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
|
||||||
SelectedGraphEntry!.Contracts = r.ToList();
|
SelectedGraphEntry!.Contracts = r.ToList();
|
||||||
|
// FIXME when using arrow keys, selection does not work nicely
|
||||||
GraphList.Items.Refresh();
|
GraphList.Items.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user