[#46] PaymentAdjustmentWindow: Refine DataGrid
All checks were successful
Test / Run tests (push) Successful in 1m55s

This commit is contained in:
2024-06-17 11:03:32 +02:00
parent 66eb177fbf
commit c1903b1f36
2 changed files with 86 additions and 25 deletions

View File

@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Elwig.Windows" xmlns:local="clr-namespace:Elwig.Windows"
xmlns:ctrl="clr-namespace:Elwig.Controls" xmlns:ctrl="clr-namespace:Elwig.Controls"
Title="Auszahlung anpassen - Elwig" Height="500" Width="800" MinHeight="400" MinWidth="700"> Title="Auszahlung anpassen - Elwig" Height="500" Width="850" MinHeight="400" MinWidth="850">
<Window.Resources> <Window.Resources>
<Style TargetType="Label"> <Style TargetType="Label">
<Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="HorizontalAlignment" Value="Left"/>
@ -44,7 +44,7 @@
<RowDefinition Height="24"/> <RowDefinition Height="24"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/> <ColumnDefinition Width="450"/>
<ColumnDefinition Width="2.5*"/> <ColumnDefinition Width="2.5*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
@ -52,18 +52,41 @@
</Menu> </Menu>
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<ListBox x:Name="MemberList" Margin="10,10,10,10"> <DataGrid x:Name="MemberList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
<ListBox.ItemTemplate> CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False" Margin="10,10,10,10">
<DataTemplate> <DataGrid.Columns>
<StackPanel Orientation="Horizontal"> <DataGridTextColumn Header="MgNr." Binding="{Binding MgNr, StringFormat='{}{0} '}" Width="45">
<TextBlock Text="{Binding MgNr}" Width="30" TextAlignment="Right" Margin="0,0,10,0"/> <DataGridTextColumn.CellStyle>
<TextBlock Text="{Binding FamilyName}" Width="100"/> <Style>
<TextBlock Text="{Binding GivenName}" Width="60"/> <Setter Property="TextBlock.TextAlignment" Value="Right"/>
<TextBlock Text="{Binding BusinessShares}" Width="40" TextAlignment="Right"/> </Style>
</StackPanel> </DataGridTextColumn.CellStyle>
</DataTemplate> </DataGridTextColumn>
</ListBox.ItemTemplate> <DataGridTextColumn Header="Nachname" Binding="{Binding FamilyName}" Width="100"/>
</ListBox> <DataGridTextColumn Header="Vorname" Binding="{Binding GivenName}" Width="100"/>
<DataGridTextColumn Header="GA" Binding="{Binding BusinessShares, StringFormat='{}{0} '}" Width="35">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Ü.-/U.-Lfrg." Binding="{Binding OverUnder, StringFormat='{}{0} kg '}" Width="70">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Nachz." Binding="{Binding Adjust, StringFormat='{}{0} '}" Width="45">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid> </Grid>
<Grid Grid.Column="1" Grid.Row="1"> <Grid Grid.Column="1" Grid.Row="1">
@ -86,7 +109,7 @@
<ctrl:UnitTextBox x:Name="MinBsInput" Unit="GA" Margin="140,70,10,10" Width="50" <ctrl:UnitTextBox x:Name="MinBsInput" Unit="GA" Margin="140,70,10,10" Width="50"
TextChanged="BsInput_TextChanged"/> TextChanged="BsInput_TextChanged"/>
<Button x:Name="SeasonButton" Content="GA-Wert" Margin="10,10,10,40" Width="120" <Button x:Name="SeasonButton" Content="GA-Wert" Margin="10,10,10,42" Width="120"
HorizontalAlignment="Right" VerticalAlignment="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Click="SeasonButton_Click"/> Click="SeasonButton_Click"/>
<Button x:Name="AutoAdjustBsButton" Content="Nachzeichnen" Margin="10,10,135,10" Width="120" <Button x:Name="AutoAdjustBsButton" Content="Nachzeichnen" Margin="10,10,135,10" Width="120"

View File

@ -1,7 +1,9 @@
using Elwig.Helpers; using Elwig.Helpers;
using Elwig.Helpers.Billing; using Elwig.Helpers.Billing;
using Elwig.Models.Dtos;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@ -24,19 +26,55 @@ namespace Elwig.Windows {
} }
protected override async Task OnRenewContext(AppDbContext ctx) { protected override async Task OnRenewContext(AppDbContext ctx) {
MemberList.ItemsSource = await ctx.MemberHistory var members = await ctx.Members
.Select(m => new {
m.MgNr,
m.FamilyName,
m.GivenName,
m.BusinessShares,
})
.OrderBy(m => m.FamilyName)
.ThenBy(m => m.GivenName)
.ThenBy(m => m.MgNr)
.ToListAsync();
var season = (await ctx.Seasons.FindAsync(Year))!;
var tbl = await OverUnderDeliveryData.ForSeason(ctx.OverUnderDeliveryRows, Year);
var weight = tbl.Rows.ToDictionary(r => r.MgNr, r => r.Weight);
var history = await ctx.MemberHistory
.Where(h => h.DateString.CompareTo($"{Year}-01-01") >= 0 && h.DateString.CompareTo($"{Year}-12-31") <= 0 && h.Type == "auto" && h.BusinessShares > 0) .Where(h => h.DateString.CompareTo($"{Year}-01-01") >= 0 && h.DateString.CompareTo($"{Year}-12-31") <= 0 && h.Type == "auto" && h.BusinessShares > 0)
.GroupBy(h => h.Member) .GroupBy(h => h.Member)
.Select(h => new { .ToDictionaryAsync(h => h.Key.MgNr, h => h.Sum(g => g.BusinessShares));
h.Key.MgNr,
h.Key.FamilyName, var list = members
h.Key.GivenName, .Select(m => new {
BusinessShares = h.Sum(g => g.BusinessShares), m.MgNr,
m.FamilyName,
m.GivenName,
BusinessShares = m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0),
DeliveryObligation = (m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0)) * season.MinKgPerBusinessShare,
DeliveryRight = (m.BusinessShares - history.GetValueOrDefault(m.MgNr, 0)) * season.MaxKgPerBusinessShare,
}) })
.OrderBy(h => h.FamilyName) .Select(m => new {
.ThenBy(h => h.GivenName) m.MgNr,
.ThenBy(h => h.MgNr) m.FamilyName,
.ToListAsync(); m.GivenName,
m.BusinessShares,
OverUnder = weight.TryGetValue(m.MgNr, out int v1) ?
(v1 < m.DeliveryObligation ? (int?)v1 - m.DeliveryObligation :
v1 > m.DeliveryRight ? (int?)v1 - m.DeliveryRight : null)
: null,
Adjust = history.TryGetValue(m.MgNr, out int v2) ? (int?)v2 : null
})
.Where(m => m.OverUnder != null || m.Adjust != null)
.OrderByDescending(m => m.OverUnder)
.ThenBy(m => m.FamilyName)
.ThenBy(m => m.GivenName)
.ThenBy(m => m.MgNr)
.ToList();
MemberList.ItemsSource = list;
} }
private async void AutoAdjustBsButton_Click(object sender, RoutedEventArgs evt) { private async void AutoAdjustBsButton_Click(object sender, RoutedEventArgs evt) {