ChartWindow: Rework varibute selection

This commit is contained in:
2024-01-27 22:41:31 +01:00
parent d3aca196dd
commit 3a2bf81bd9
6 changed files with 80 additions and 41 deletions

View File

@ -61,14 +61,17 @@
</Grid.ColumnDefinitions>
<Label Content="Für:" Margin="10,-2,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/>
<xctk:CheckComboBox x:Name="VaributeInput" Margin="50,0,0,0" Grid.Column="0"
Delimiter=", " AllItemsSelectedContent="Alle" IsEnabled="False" ItemSelectionChanged="VaributeInput_Changed"
Width="500" Height="25" HorizontalAlignment="Left">
<xctk:CheckComboBox x:Name="VaributeInput" Margin="50,0,0,0" Grid.Column="0" Width="500" Height="25" HorizontalAlignment="Left"
IsSelectAllActive="True" SelectAllContent="Alle Sorten" Delimiter=", " AllItemsSelectedContent="Alle Sorten"
IsEnabled="False" ItemSelectionChanged="VaributeInput_Changed">
<xctk:CheckComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Variety.Name}" Width="150"/>
<TextBlock Text="{Binding Attribute.Name}"/>
<TextBlock Text="{Binding Variety.Type}" Width="30"/>
<TextBlock Text="{Binding Attribute.Name}" Width="120"/>
<TextBlock Text="{Binding AssignedGraphId}" Width="30"/>
<TextBlock Text="{Binding AssignedAbgewGraphId}" Width="30"/>
</StackPanel>
</DataTemplate>
</xctk:CheckComboBox.ItemTemplate>

View File

@ -35,9 +35,9 @@ namespace Elwig.Windows {
private Text TooltipPlot;
private LegendItem UngebundenLegend;
private LegendItem GebundenLegend;
private LegendItem LDWLegend;
private LegendItem QUWLegend;
private LegendItem KABLegend;
private LegendItem LdwLegend;
private LegendItem QuwLegend;
private LegendItem KabLegend;
private (Graph? Graph, int Index) LastHighlighted = (null, -1);
private (Graph? Graph, int Index) Highlighted = (null, -1);
@ -50,6 +50,9 @@ namespace Elwig.Windows {
private List<GraphEntry> GraphEntries = [];
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
private List<Varibute> Vaributes = [];
private bool AllVaributesAssigned => Vaributes.All(v => v.AssignedGraphId != null);
private bool AllVaributesAssignedAbgew => Vaributes.All(v => v.AssignedAbgewGraphId != null);
public ChartWindow(int year, int avnr) {
InitializeComponent();
@ -88,12 +91,22 @@ namespace Elwig.Windows {
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
GraphEntries = [
..paymentEntries,
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
];
Vaributes = Utils.GetVaributeList(Context, Year);
GraphEntries.ForEach(e => {
e.Vaributes.ForEach(v => {
var found = Vaributes.Find(a => a.Attribute?.AttrId == v.Attribute?.AttrId && a.Variety?.SortId == v.Variety?.SortId);
if (e.Abgewertet) {
found!.AssignedAbgewGraphId = e.Id;
} else {
found!.AssignedGraphId = e.Id;
}
});
});
var vaributes = Utils.GetVaributesForYear(Context, Year);
FillingInputs = true;
ControlUtils.RenewItemsSource(VaributeInput, vaributes, g => (g as Varibute)?.Listing);
ControlUtils.RenewItemsSource(VaributeInput, Vaributes, v => (v as Varibute)?.Listing);
FillingInputs = false;
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
@ -174,21 +187,21 @@ namespace Elwig.Windows {
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
};
LDWLegend = new LegendItem() {
LdwLegend = new LegendItem() {
Label = "68 °Oe (LDW)",
LineWidth = 2,
LineColor = Colors.Red,
Marker = MarkerStyle.None
};
QUWLegend = new LegendItem() {
QuwLegend = new LegendItem() {
Label = "73 °Oe (QUW)",
LineWidth = 2,
LineColor = Colors.Orange,
Marker = MarkerStyle.None
};
KABLegend = new LegendItem() {
KabLegend = new LegendItem() {
Label = "84 °Oe (KAB)",
LineWidth = 2,
LineColor = Colors.Green,
@ -372,9 +385,9 @@ namespace Elwig.Windows {
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
OechslePricePlot.Plot.Legend.IsVisible = true;
OechslePricePlot.Plot.Legend.ManualItems.Add(LDWLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(QUWLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(KABLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(LdwLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(QuwLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(KabLegend);
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
}
@ -635,7 +648,8 @@ namespace Elwig.Windows {
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
var origData = BillingData.FromJson(PaymentVar.Data);
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true));
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true),
AllVaributesAssigned, AllVaributesAssignedAbgew);
EntityEntry<PaymentVar>? tr = null;
try {
@ -716,20 +730,33 @@ namespace Elwig.Windows {
}
private void VaributeInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
if (FillingInputs) return;
if (e.IsSelected == true) {
bool success = RemoveVaributeFromOtherGraphEntries(e.Item.ToString());
if (!success) {
if (FillingInputs || e.Item is not Varibute v) return;
var isOpen = VaributeInput.IsDropDownOpen;
if (e.IsSelected) {
if (RemoveVaributeFromOthers(e.Item.ToString())) {
if (AbgewertetInput.IsChecked == true) {
v.AssignedAbgewGraphId = SelectedGraphEntry?.Id;
} else {
v.AssignedGraphId = SelectedGraphEntry?.Id;
}
} else {
VaributeInput.SelectedItems.Remove(e.Item);
}
} else {
if (AbgewertetInput.IsChecked == true) {
v.AssignedAbgewGraphId = null;
} else {
v.AssignedGraphId = null;
}
}
var r = VaributeInput.SelectedItems.Cast<Varibute>();
SelectedGraphEntry!.Vaributes = r.ToList();
SelectedGraphEntry!.Vaributes = VaributeInput.SelectedItems.Cast<Varibute>().ToList();
SetHasChanged();
GraphList.Items.Refresh();
VaributeInput.Items.Refresh();
VaributeInput.IsDropDownOpen = isOpen;
}
private bool RemoveVaributeFromOtherGraphEntries(string? varibute) {
private bool RemoveVaributeFromOthers(string? varibute) {
if (varibute == null) return true;
foreach (var ge in GraphEntries) {
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {

View File

@ -173,7 +173,7 @@ namespace Elwig.Windows {
v.Name = "Neue Auszahlungsvariante";
v.TestVariant = true;
v.DateString = $"{DateTime.Today:yyyy-MM-dd}";
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": 1.0, \"quality\": {\"WEI\": 0}, \"curves\": []}";
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": {}, \"curves\": []}";
await Context.AddAsync(v);
await Context.SaveChangesAsync();