ChartWindow/Billing: Misc improvements
This commit is contained in:
@ -15,6 +15,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using ScottPlot;
|
||||
using ScottPlot.Plottable;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class ChartWindow : ContextWindow {
|
||||
@ -24,6 +25,7 @@ namespace Elwig.Windows {
|
||||
|
||||
public readonly int Year;
|
||||
public readonly int AvNr;
|
||||
public readonly Season Season;
|
||||
private readonly PaymentVar PaymentVar;
|
||||
|
||||
private ScatterPlot DataPlot;
|
||||
@ -43,6 +45,7 @@ namespace Elwig.Windows {
|
||||
private bool FillingInputs = false;
|
||||
|
||||
private const int MinOechsle = 50;
|
||||
private const int MinOechsleGebunden = 73;
|
||||
private const int MaxOechsle = 140;
|
||||
|
||||
private List<GraphEntry> GraphEntries = [];
|
||||
@ -52,6 +55,7 @@ namespace Elwig.Windows {
|
||||
InitializeComponent();
|
||||
Year = year;
|
||||
AvNr = avnr;
|
||||
Season = Context.Seasons.Find(year) ?? throw new ArgumentException("Season not found");
|
||||
PaymentVar = Context.PaymentVariants.Find(year, avnr) ?? throw new ArgumentException("PaymentVar not found");
|
||||
Title = $"{PaymentVar?.Name} - Lese {year} - Elwig";
|
||||
}
|
||||
@ -72,7 +76,7 @@ namespace Elwig.Windows {
|
||||
.Order()
|
||||
.ToList();
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
|
||||
GraphEntries = [ ..data.GetPaymentGraphEntries(Context), ..data.GetQualityGraphEntries(Context)];
|
||||
GraphEntries = [ ..data.GetPaymentGraphEntries(Context, Season), ..data.GetQualityGraphEntries(Context, Season)];
|
||||
|
||||
var contracts = ContractSelection.GetContractsForYear(Context, Year);
|
||||
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing);
|
||||
@ -91,6 +95,7 @@ namespace Elwig.Windows {
|
||||
GebundenTypeGraph.IsEnabled = true;
|
||||
GebundenTypeNone.IsEnabled = true;
|
||||
ContractInput.IsEnabled = true;
|
||||
AbgewertetInput.IsEnabled = true;
|
||||
EnableOptionButtons();
|
||||
FillInputs();
|
||||
} else {
|
||||
@ -109,13 +114,13 @@ namespace Elwig.Windows {
|
||||
GebundenTypeGraph.IsEnabled = false;
|
||||
GebundenTypeNone.IsEnabled = false;
|
||||
ContractInput.IsEnabled = false;
|
||||
AbgewertetInput.IsEnabled = false;
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void FillInputs() {
|
||||
FillingInputs = true;
|
||||
GraphNum.Text = SelectedGraphEntry?.Id.ToString();
|
||||
|
||||
if (SelectedGraphEntry?.GebundenFlatBonus != null) {
|
||||
GebundenTypeFixed.IsChecked = true;
|
||||
@ -138,13 +143,13 @@ namespace Elwig.Windows {
|
||||
|
||||
private void InitPlot() {
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.GebundenGraph.DataX, SelectedGraphEntry.GebundenGraph.DataY);
|
||||
GebundenPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.GebundenGraph.DataX, SelectedGraphEntry.GebundenGraph.DataY, label: "Gebunden");
|
||||
GebundenPlot.LineColor = ColorGebunden;
|
||||
GebundenPlot.MarkerColor = ColorGebunden;
|
||||
GebundenPlot.MarkerSize = 9;
|
||||
}
|
||||
|
||||
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
|
||||
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY, label: "Ungebunden");
|
||||
DataPlot.LineColor = ColorUngebunden;
|
||||
DataPlot.MarkerColor = ColorUngebunden;
|
||||
DataPlot.MarkerSize = 9;
|
||||
@ -157,7 +162,7 @@ namespace Elwig.Windows {
|
||||
OechslePricePlot.Configuration.DoubleClickBenchmark = false;
|
||||
//OechslePricePlot.Plot.XAxis.ManualTickSpacing(1);
|
||||
OechslePricePlot.Plot.YAxis.ManualTickSpacing(0.1);
|
||||
OechslePricePlot.Plot.SetAxisLimits(MinOechsle - 1, MaxOechsle + 1, -0.1, 2);
|
||||
OechslePricePlot.Plot.SetAxisLimits(Math.Min(MinOechsle, MinOechsleGebunden) - 1, MaxOechsle + 1, -0.1, 2);
|
||||
|
||||
OechslePricePlot.Plot.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.XAxis2.Layout(padding: 0);
|
||||
@ -291,15 +296,15 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void ShowLegend() {
|
||||
OechslePricePlot.Plot.Legend(true, Alignment.UpperRight);
|
||||
OechslePricePlot.Plot.Legend(true, Alignment.UpperLeft);
|
||||
}
|
||||
|
||||
private void HideLegend() {
|
||||
OechslePricePlot.Plot.Legend(false, Alignment.UpperRight);
|
||||
OechslePricePlot.Plot.Legend(false, Alignment.UpperLeft);
|
||||
}
|
||||
|
||||
private void OechsleInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (ActiveGraph == null) {
|
||||
if (ActiveGraph == null || SelectedGraphEntry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -308,9 +313,9 @@ namespace Elwig.Windows {
|
||||
SecondaryMarkedPoint = -1;
|
||||
ChangeMarker(SecondaryMarkedPointPlot, false);
|
||||
|
||||
if (success) {
|
||||
if (oechsle >= MinOechsle && oechsle <= MaxOechsle) {
|
||||
PrimaryMarkedPoint = oechsle - MinOechsle;
|
||||
if (success) {
|
||||
if (oechsle >= ActiveGraph.MinX && oechsle <= ActiveGraph.MaxX) {
|
||||
PrimaryMarkedPoint = oechsle - ActiveGraph.MinX;
|
||||
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
||||
|
||||
PriceInput.Text = ActiveGraph.GetPriceAt(PrimaryMarkedPoint).ToString();
|
||||
@ -479,7 +484,7 @@ namespace Elwig.Windows {
|
||||
if (LastHighlighted != Highlighted || HoverChanged) {
|
||||
OechslePricePlot.Plot.Remove(TooltipPlot);
|
||||
if (TooltipInput.IsChecked == true) {
|
||||
TooltipPlot = OechslePricePlot.Plot.AddTooltip($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, 4)}€/kg)", pointX, pointY);
|
||||
TooltipPlot = OechslePricePlot.Plot.AddTooltip($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)}€/kg)", pointX, pointY);
|
||||
}
|
||||
LastHighlighted = (g, pointIndex);
|
||||
HoverChanged = false;
|
||||
@ -492,7 +497,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e) {
|
||||
GraphEntry newGraphEntry = new(GetMaxGraphId() + 1, BillingData.CurveMode.Oe, MinOechsle, MaxOechsle);
|
||||
GraphEntry newGraphEntry = new(GetMaxGraphId() + 1, Season, BillingData.CurveMode.Oe, MinOechsle, MinOechsleGebunden, MaxOechsle);
|
||||
GraphEntries.Add(newGraphEntry);
|
||||
GraphList.Items.Refresh();
|
||||
GraphList.SelectedItem = newGraphEntry;
|
||||
@ -545,6 +550,7 @@ namespace Elwig.Windows {
|
||||
|
||||
MessageBox.Show(data.ToJsonString());
|
||||
|
||||
/*
|
||||
EntityEntry<PaymentVar>? tr = null;
|
||||
try {
|
||||
PaymentVar.Data = data.ToJsonString();
|
||||
@ -552,12 +558,14 @@ namespace Elwig.Windows {
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
await App.HintContextChange();
|
||||
await RefreshGraphList();
|
||||
} catch (Exception exc) {
|
||||
if (tr != null) await tr.ReloadAsync();
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank gespeichert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Graph speichern", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void EnableUnitTextBox(UnitTextBox u) {
|
||||
@ -618,13 +626,30 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
private void ContractInput_Changed(object sender, RoutedEventArgs e) {
|
||||
private void ContractInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (e.IsSelected == true) {
|
||||
RemoveContractFromOtherGraphEntries(e.Item.ToString());
|
||||
}
|
||||
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
|
||||
SelectedGraphEntry!.Contracts = r.ToList();
|
||||
GraphList.Items.Refresh();
|
||||
}
|
||||
|
||||
private void RemoveContractFromOtherGraphEntries(string? contract) {
|
||||
if (contract == null) return;
|
||||
foreach (var ge in GraphEntries) {
|
||||
if (ge != SelectedGraphEntry) {
|
||||
ge.Contracts.RemoveAll(c => c.Listing.Equals(contract));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AbgewertetInput_Changed(object sender, RoutedEventArgs e) {
|
||||
if (SelectedGraphEntry == null) return;
|
||||
SelectedGraphEntry.Abgewertet = AbgewertetInput.IsChecked == true;
|
||||
}
|
||||
|
||||
private void GebundenType_Checked(object sender, RoutedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (SelectedGraphEntry == null) {
|
||||
|
Reference in New Issue
Block a user