BaseDataWindow: Add fields for season

This commit is contained in:
2023-11-05 12:20:59 +01:00
parent 6435a649b4
commit 7fe2ea76c3
12 changed files with 244 additions and 57 deletions

View File

@ -4,7 +4,7 @@
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="25"> <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="25">
<TextBox x:Name="TextBox" TextAlignment="Right" FontSize="14" VerticalAlignment="Stretch" <TextBox x:Name="TextBox" TextAlignment="Right" FontSize="14" VerticalAlignment="Stretch"
Padding="{Binding ElementName=UnitBlock, Path=ActualWidth, Converter={StaticResource WidthToPaddingConverter}}" Padding="{Binding ElementName=UnitBlock, Path=ActualWidth, Converter={StaticResource WidthToPaddingConverter}}"
Text="{Binding Path=Text, Mode=TwoWay}" TextChanged="TextBox_TextChanged"/> Text="{Binding Path=Text}" TextChanged="TextBox_TextChanged"/>
<TextBlock x:Name="UnitBlock" Text="{Binding Path=Unit}" Margin="0,0,4,4" FontSize="10" <TextBlock x:Name="UnitBlock" Text="{Binding Path=Unit}" Margin="0,0,4,4" FontSize="10"
HorizontalAlignment="Right" VerticalAlignment="Bottom"/> HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
</Grid> </Grid>

View File

@ -1,6 +1,5 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
namespace Elwig.Controls { namespace Elwig.Controls {
public partial class UnitTextBox : UserControl { public partial class UnitTextBox : UserControl {
@ -10,22 +9,29 @@ namespace Elwig.Controls {
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UnitTextBox)); public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UnitTextBox));
public string Text { public string Text {
get => (string)GetValue(TextProperty); get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value); set => SetValue(TextProperty, value ?? "");
} }
public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(UnitTextBox)); public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(UnitTextBox));
public string Unit { public string Unit {
get => (string)GetValue(UnitProperty); get => (string)GetValue(UnitProperty);
set => SetValue(UnitProperty, value); set => SetValue(UnitProperty, value ?? "");
} }
public UnitTextBox() { public UnitTextBox() {
Text = "";
Unit = "";
InitializeComponent(); InitializeComponent();
DataContext = this; DataContext = this;
} }
private void TextBox_TextChanged(object sender, TextChangedEventArgs evt) { private void TextBox_TextChanged(object sender, TextChangedEventArgs evt) {
if (TextChanged != null) TextChanged(sender, evt); Text = TextBox.Text;
TextChanged?.Invoke(sender, evt);
}
public new void Focus() {
TextBox.Focus();
} }
} }
} }

View File

@ -63,13 +63,15 @@ namespace Elwig.Helpers {
return CheckDecimal(input, required, -1, -1); return CheckDecimal(input, required, -1, -1);
} }
public static ValidationResult CheckDecimal(TextBox input, bool required, int maxLen, int maxDecimal) { public static ValidationResult CheckDecimal(TextBox input, bool required, int maxLen, int maxDecimal, bool allowMinus = false) {
string text = ""; string text = "";
int pos = input.CaretIndex; int pos = input.CaretIndex;
int v1 = 0, v2 = -1; int v1 = 0, v2 = -1;
for (int i = 0; i < input.Text.Length; i++) { for (int i = 0; i < input.Text.Length; i++) {
char ch = input.Text[i]; char ch = input.Text[i];
if (char.IsAsciiDigit(ch)) { if (ch == '-' && i == 0 && allowMinus) {
text += ch;
} else if (char.IsAsciiDigit(ch)) {
if (v2 == -1 && (maxLen == -1 || v1 < maxLen)) { if (v2 == -1 && (maxLen == -1 || v1 < maxLen)) {
text += ch; v1++; text += ch; v1++;
} else if (v2 != -1 && (maxDecimal == -1 || v2 < maxDecimal)) { } else if (v2 != -1 && (maxDecimal == -1 || v2 < maxDecimal)) {

View File

@ -63,10 +63,12 @@ namespace Elwig.Windows {
OriginalValues = new(); OriginalValues = new();
DefaultValues = new(); DefaultValues = new();
Closing += OnClosing; Closing += OnClosing;
Loaded -= base.OnLoaded;
Loaded += OnLoaded; Loaded += OnLoaded;
Loaded += base.OnLoaded;
} }
private void OnLoaded(object sender, RoutedEventArgs evt) { private new void OnLoaded(object sender, RoutedEventArgs evt) {
TextBoxInputs = ControlUtils.FindAllChildren<TextBox>(this, ExemptInputs).ToArray(); TextBoxInputs = ControlUtils.FindAllChildren<TextBox>(this, ExemptInputs).ToArray();
ComboBoxInputs = ControlUtils.FindAllChildren<ComboBox>(this, ExemptInputs).ToArray(); ComboBoxInputs = ControlUtils.FindAllChildren<ComboBox>(this, ExemptInputs).ToArray();
CheckBoxInputs = ControlUtils.FindAllChildren<CheckBox>(this, ExemptInputs).ToArray(); CheckBoxInputs = ControlUtils.FindAllChildren<CheckBox>(this, ExemptInputs).ToArray();

View File

@ -1,11 +1,13 @@
<local:AdministrationWindow x:Class="Elwig.Windows.BaseDataWindow" <local:AdministrationWindow
x:Class="Elwig.Windows.BaseDataWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
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"
mc:Ignorable="d" mc:Ignorable="d"
Title="Stammdaten - Elwig" Height="500" MinHeight="400" Width="800" MinWidth="800" Title="Stammdaten - Elwig" Height="500" MinHeight="400" Width="850" MinWidth="810"
Loaded="Window_Loaded"> Loaded="Window_Loaded">
<Window.Resources> <Window.Resources>
<Style TargetType="Label"> <Style TargetType="Label">
@ -198,7 +200,7 @@
<TabItem Header="Sortenattribute"> <TabItem Header="Sortenattribute">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="260"/> <ColumnDefinition Width="280"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ListBox x:Name="WineAttributeList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,35,10" <ListBox x:Name="WineAttributeList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,35,10"
@ -242,11 +244,8 @@
<GroupBox Header="Auszahlung" Grid.ColumnSpan="2" Margin="10,100,10,10"> <GroupBox Header="Auszahlung" Grid.ColumnSpan="2" Margin="10,100,10,10">
<Grid> <Grid>
<Label Content="Max. Ertrag:" Margin="10,10,0,10"/> <Label Content="Max. Ertrag:" Margin="10,10,0,10"/>
<Grid Grid.Column="1" Width="80" Height="25" Margin="84,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"> <ctrl:UnitTextBox x:Name="WineAttributeMaxKgPerHaInput" Unit="kg/ha" TextChanged="WineAttributeMaxKgPerHaInput_TextChanged"
<TextBox x:Name="WineAttributeMaxKgPerHaInput" TextAlignment="Right" Padding="2,2,30,2" Grid.Column="1" Width="80" Margin="84,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
TextChanged="WineAttributeMaxKgPerHaInput_TextChanged"/>
<Label Content="kg/ha" Margin="0,4,3,0" HorizontalAlignment="Right" FontSize="10"/>
</Grid>
<CheckBox x:Name="WineAttributeStrictInput" Content="Strikte Trennung zu Flächenbindung ohne Attribut" <CheckBox x:Name="WineAttributeStrictInput" Content="Strikte Trennung zu Flächenbindung ohne Attribut"
Margin="10,50,10,10" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,50,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"
@ -315,7 +314,16 @@
<TabItem Header="Saisons"> <TabItem Header="Saisons">
<Grid> <Grid>
<ListBox x:Name="SeasonList" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="150" Margin="10,10,10,10" <Grid.ColumnDefinitions>
<ColumnDefinition Width="180"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="180"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox x:Name="SeasonList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" Grid.RowSpan="2"
SelectionChanged="SeasonList_SelectionChanged"> SelectionChanged="SeasonList_SelectionChanged">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -328,7 +336,56 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<GroupBox Header="Zu-/Abschläge" Margin="170,150,10,10" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid Grid.Column="1" Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Maximaler Ertrag:" Margin="10,10,0,10"/>
<ctrl:UnitTextBox x:Name="SeasonMaxKgPerHaInput" Unit="kg/ha" TextChanged="SeasonMinMaxKgInput_TextChanged"
Grid.Column="1" Width="80" Margin="0,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="MwSt. (buchführend):" Margin="10,40,0,10"/>
<ctrl:UnitTextBox x:Name="SeasonVatNormalInput" Unit="%" TextChanged="SeasonVatInput_TextChanged"
Grid.Column="1" Width="48" Margin="0,40,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="MwSt. (pauschaliert):" Margin="10,70,0,10"/>
<ctrl:UnitTextBox x:Name="SeasonVatFlatrateInput" Unit="%" TextChanged="SeasonVatInput_TextChanged"
Grid.Column="1" Width="48" Margin="0,70,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Übernahme-Beginn:" Margin="10,100,0,10"/>
<TextBox x:Name="SeasonStartInput" Grid.Column="1" Margin="0,100,10,10" Width="78" IsEnabled="False"
HorizontalAlignment="Left"/>
<Label Content="Übernahme-Ende:" Margin="10,130,0,10"/>
<TextBox x:Name="SeasonEndInput" Grid.Column="1" Margin="0,130,10,10" Width="78" IsEnabled="False"
HorizontalAlignment="Left"/>
<Label Content="Lieferpflicht:" Margin="10,10,0,10" Grid.Column="2"/>
<ctrl:UnitTextBox x:Name="SeasonMinKgPerBsInput" Unit="kg/GA" TextChanged="SeasonMinMaxKgInput_TextChanged"
Grid.Column="3" Width="80" Margin="0,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Lieferrecht:" Margin="10,40,0,10" Grid.Column="2"/>
<ctrl:UnitTextBox x:Name="SeasonMaxKgPerBsInput" Unit="kg/GA" TextChanged="SeasonMinMaxKgInput_TextChanged"
Grid.Column="3" Width="80" Margin="0,40,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Strafe (pro unterl. kg):" Margin="10,70,0,10" Grid.Column="2"/>
<ctrl:UnitTextBox x:Name="SeasonPenaltyPerKgInput" Unit="€/kg" TextChanged="SeasonPenaltyPerKgInput_TextChanged"
Grid.Column="3" Width="80" Margin="0,70,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Strafe (Unterlieferung):" Margin="10,100,0,10" Grid.Column="2"/>
<ctrl:UnitTextBox x:Name="SeasonPenaltyInput" Unit="€" TextChanged="SeasonMoneyInput_TextChanged"
Grid.Column="3" Width="68" Margin="0,100,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Strafe (Nicht-Lieferung):" Margin="10,130,0,10" Grid.Column="2"/>
<ctrl:UnitTextBox x:Name="SeasonPenaltyNoneInput" Unit="€" TextChanged="SeasonMoneyInput_TextChanged"
Grid.Column="3" Width="68" Margin="0,130,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
<GroupBox Grid.Column="1" Grid.Row="1" Header="Zu-/Abschläge" Margin="0,0,10,10" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/> <ColumnDefinition Width="400"/>
@ -369,12 +426,12 @@
TextChanged="SeasonModifier_Changed"/> TextChanged="SeasonModifier_Changed"/>
<Label Content="Relativ:" Grid.Column="1" Margin="10,70,10,10"/> <Label Content="Relativ:" Grid.Column="1" Margin="10,70,10,10"/>
<TextBox x:Name="SeasonModifierRelInput" Grid.Column="2" Margin="0,70,10,10" <ctrl:UnitTextBox x:Name="SeasonModifierRelInput" Unit="%" TextChanged="SeasonModifierRelInput_TextChanged"
TextChanged="SeasonModifierRelInput_TextChanged"/> Grid.Column="2" Width="68" Margin="0,70,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="Absolut:" Grid.Column="1" Margin="10,100,10,10"/> <Label Content="Absolut:" Grid.Column="1" Margin="10,100,10,10"/>
<TextBox x:Name="SeasonModifierAbsInput" Grid.Column="2" Margin="0,100,10,10" <ctrl:UnitTextBox x:Name="SeasonModifierAbsInput" Unit="€/kg" TextChanged="SeasonModifierAbsInput_TextChanged"
TextChanged="SeasonModifierAbsInput_TextChanged"/> Grid.Column="2" Width="86" Margin="0,100,10,10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
</Grid> </Grid>

View File

@ -23,6 +23,7 @@ namespace Elwig.Windows {
_branches = _branchList.ToDictionary(b => b.ZwstId, b => (string?)b.ZwstId); _branches = _branchList.ToDictionary(b => b.ZwstId, b => (string?)b.ZwstId);
_branchIds = _branchList.ToDictionary(b => b, b => b.ZwstId); _branchIds = _branchList.ToDictionary(b => b, b => b.ZwstId);
ControlUtils.RenewItemsSource(BranchList, _branchList, b => (b as Branch)?.ZwstId); ControlUtils.RenewItemsSource(BranchList, _branchList, b => (b as Branch)?.ZwstId);
BranchList_SelectionChanged(null, null);
} }
private void BranchesFinishEditing() { private void BranchesFinishEditing() {
@ -63,7 +64,7 @@ namespace Elwig.Windows {
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
private void BranchList_SelectionChanged(object sender, SelectionChangedEventArgs evt) { private void BranchList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
UpdateButtons(); UpdateButtons();
_branchUpdate = true; _branchUpdate = true;
if (BranchList.SelectedItem is not Branch branch) { if (BranchList.SelectedItem is not Branch branch) {

View File

@ -24,6 +24,7 @@ namespace Elwig.Windows {
_mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId); _mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId);
_modIds = _modList.ToDictionary(m => m, m => m.ModId); _modIds = _modList.ToDictionary(m => m, m => m.ModId);
ControlUtils.RenewItemsSource(SeasonModifierList, _modList, m => (m as Modifier)?.ModId); ControlUtils.RenewItemsSource(SeasonModifierList, _modList, m => (m as Modifier)?.ModId);
SeasonModifierList_SelectionChanged(null, null);
} }
private void ModifiersFinishEditing() { private void ModifiersFinishEditing() {
@ -117,7 +118,7 @@ namespace Elwig.Windows {
UpdateButtons(); UpdateButtons();
} }
private void SeasonModifierList_SelectionChanged(object sender, SelectionChangedEventArgs evt) { private void SeasonModifierList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
UpdateButtons(); UpdateButtons();
_modUpdate = true; _modUpdate = true;
if (SeasonModifierList.SelectedItem is not Modifier mod) { if (SeasonModifierList.SelectedItem is not Modifier mod) {
@ -128,25 +129,23 @@ namespace Elwig.Windows {
} else { } else {
SeasonModifierIdInput.Text = mod.ModId; SeasonModifierIdInput.Text = mod.ModId;
SeasonModifierNameInput.Text = mod.Name; SeasonModifierNameInput.Text = mod.Name;
SeasonModifierRelInput.Text = (mod.Rel * 100)?.ToString(); SeasonModifierRelInput.Text = (mod.Rel * 100)?.ToString() ?? "";
SeasonModifierAbsInput.Text = mod.Abs?.ToString(); SeasonModifierAbsInput.Text = mod.Abs?.ToString() ?? "";
} }
_modUpdate = false; _modUpdate = false;
} }
private void SeasonModifier_Changed(object? sender, RoutedEventArgs evt) { private void SeasonModifier_Changed(object? sender, RoutedEventArgs? evt) {
if (_modUpdate || (!IsEditing && !IsCreating) || SeasonModifierList.SelectedItem is not Modifier mod || SeasonList.SelectedItem is not Season s || _mods == null || _modIds == null) return; if (_modUpdate || (!IsEditing && !IsCreating) || SeasonModifierList.SelectedItem is not Modifier mod || SeasonList.SelectedItem is not Season s || _mods == null || _modIds == null) return;
_modChanged = _modChanged || _modChanged = true;
SeasonModifierIdInput.Text != mod.ModId;
var old = _modIds.GetValueOrDefault(mod); var old = _modIds.GetValueOrDefault(mod);
var id = SeasonModifierIdInput.Text ?? ""; var id = SeasonModifierIdInput.Text ?? "";
if (old != null) _mods[old] = id; if (old != null) _mods[old] = id;
mod.ModId = id; mod.ModId = id;
mod.Name = SeasonModifierNameInput.Text;
mod.Rel = decimal.TryParse(SeasonModifierRelInput.Text, out var vRel) ? vRel / 100 : null; mod.Rel = decimal.TryParse(SeasonModifierRelInput.Text, out var vRel) ? vRel / 100 : null;
if (mod.Rel != null) SeasonModifierAbsInput.Text = "";
mod.AbsValue = decimal.TryParse(SeasonModifierAbsInput.Text, out var vAbs) ? Utils.DecToDb(vAbs, s.Precision) : null; mod.AbsValue = decimal.TryParse(SeasonModifierAbsInput.Text, out var vAbs) ? Utils.DecToDb(vAbs, s.Precision) : null;
if (mod.AbsValue != null) SeasonModifierRelInput.Text = "";
CollectionViewSource.GetDefaultView(_modList).Refresh(); CollectionViewSource.GetDefaultView(_modList).Refresh();
UpdateButtons(); UpdateButtons();
@ -158,12 +157,17 @@ namespace Elwig.Windows {
} }
private void SeasonModifierRelInput_TextChanged(object sender, TextChangedEventArgs evt) { private void SeasonModifierRelInput_TextChanged(object sender, TextChangedEventArgs evt) {
// DecimalInput_TextChanged(sender, evt); FIXME '-' is ignored InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, false, 3, 2, true));
if (SeasonModifierRelInput.Text.Length > 0 && SeasonModifierAbsInput.Text.Length > 0)
SeasonModifierAbsInput.Text = "";
SeasonModifier_Changed(sender, evt); SeasonModifier_Changed(sender, evt);
} }
private void SeasonModifierAbsInput_TextChanged(object sender, TextChangedEventArgs evt) { private void SeasonModifierAbsInput_TextChanged(object sender, TextChangedEventArgs evt) {
// DecimalInput_TextChanged(sender, evt); FIXME '-' is ignored if (SeasonList.SelectedItem is not Season s) return;
InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, false, 2, s.Precision, true));
if (SeasonModifierAbsInput.Text.Length > 0 && SeasonModifierRelInput.Text.Length > 0)
SeasonModifierRelInput.Text = "";
SeasonModifier_Changed(sender, evt); SeasonModifier_Changed(sender, evt);
} }
} }

View File

@ -0,0 +1,111 @@
using Elwig.Helpers;
using Elwig.Models;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace Elwig.Windows {
public partial class BaseDataWindow {
private bool _seasonChanged = false;
private bool _seasonUpdate = false;
private void SeasonsInitEditing() {
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
SeasonList_SelectionChanged(null, null);
}
private void SeasonsFinishEditing() {
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
_seasonChanged = false;
}
private async Task SeasonsSave() {
if (!_seasonChanged || SeasonList.SelectedItem is not Season s)
return;
Context.Update(s);
await Context.SaveChangesAsync();
}
private async void SeasonList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
_seasonUpdate = true;
if (SeasonList.SelectedItem is Season s) {
SeasonModifierList.ItemsSource = await Context.Modifiers.Where(m => m.Year == s.Year).OrderBy(m => m.Ordering).ToListAsync();
SeasonMaxKgPerHaInput.Text = s.MaxKgPerHa.ToString();
SeasonVatNormalInput.Text = (s.VatNormal * 100).ToString();
SeasonVatFlatrateInput.Text = (s.VatFlatrate * 100).ToString();
SeasonStartInput.Text = $"{s.StartDate:dd.MM.yyyy}";
SeasonEndInput.Text = $"{s.EndDate:dd.MM.yyyy}";
SeasonMinKgPerBsInput.Text = s.MinKgPerBusinessShare.ToString();
SeasonMaxKgPerBsInput.Text = s.MaxKgPerBusinessShare.ToString();
SeasonPenaltyPerKgInput.Text = s.PenaltyPerKg?.ToString() ?? "";
SeasonPenaltyInput.Text = s.PenaltyAmount?.ToString() ?? "";
SeasonPenaltyNoneInput.Text = s.PenaltyNone?.ToString() ?? "";
var sym = s.Currency.Symbol ?? "";
SeasonModifierAbsInput.Unit = $"{sym}/kg";
SeasonPenaltyPerKgInput.Unit = $"{sym}/kg";
SeasonPenaltyInput.Unit = sym;
SeasonPenaltyNoneInput.Unit = sym;
} else {
SeasonModifierList.ItemsSource = null;
SeasonMaxKgPerHaInput.Text = "";
SeasonVatNormalInput.Text = "";
SeasonVatFlatrateInput.Text = "";
SeasonStartInput.Text = "";
SeasonEndInput.Text = "";
SeasonMinKgPerBsInput.Text = "";
SeasonMaxKgPerBsInput.Text = "";
SeasonPenaltyPerKgInput.Text = "";
SeasonPenaltyInput.Text = "";
SeasonPenaltyNoneInput.Text = "";
}
_seasonUpdate = false;
}
private void Season_Changed(object? sender, RoutedEventArgs? evt) {
if (_seasonUpdate || (!IsEditing && !IsCreating) || SeasonList.SelectedItem is not Season s) return;
_seasonChanged = true;
if (SeasonMaxKgPerHaInput.Text.Length > 0)
s.MaxKgPerHa = int.Parse(SeasonMaxKgPerHaInput.Text);
if (SeasonVatNormalInput.Text.Length > 0)
s.VatNormal = double.Parse(SeasonVatNormalInput.Text) / 100;
if (SeasonVatFlatrateInput.Text.Length > 0)
s.VatFlatrate = double.Parse(SeasonVatFlatrateInput.Text) / 100;
if (SeasonMinKgPerBsInput.Text.Length > 0)
s.MinKgPerBusinessShare = int.Parse(SeasonMinKgPerBsInput.Text);
if (SeasonMaxKgPerBsInput.Text.Length > 0)
s.MaxKgPerBusinessShare = int.Parse(SeasonMaxKgPerBsInput.Text);
s.PenaltyPerKg = (SeasonPenaltyPerKgInput.Text.Length > 0) ? decimal.Parse(SeasonPenaltyPerKgInput.Text) : null;
s.PenaltyAmount = (SeasonPenaltyInput.Text.Length > 0) ? decimal.Parse(SeasonPenaltyInput.Text) : null;
s.PenaltyNone = (SeasonPenaltyNoneInput.Text.Length > 0) ? decimal.Parse(SeasonPenaltyNoneInput.Text) : null;
UpdateButtons();
}
private void SeasonMinMaxKgInput_TextChanged(object sender, TextChangedEventArgs evt) {
InputTextChanged((TextBox)sender, Validator.CheckInteger((TextBox)sender, true, 5));
Season_Changed(sender, evt);
}
private void SeasonVatInput_TextChanged(object sender, TextChangedEventArgs evt) {
InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, true, 2, 1));
Season_Changed(sender, evt);
}
private void SeasonPenaltyPerKgInput_TextChanged(object sender, TextChangedEventArgs evt) {
if (SeasonList.SelectedItem is not Season s) return;
InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, false, 2, s.Precision));
Season_Changed(sender, evt);
}
private void SeasonMoneyInput_TextChanged(object sender, TextChangedEventArgs evt) {
InputTextChanged((TextBox)sender, Validator.CheckDecimal((TextBox)sender, false, 4, 2));
Season_Changed(sender, evt);
}
}
}

View File

@ -24,6 +24,7 @@ namespace Elwig.Windows {
_attrs = _attrList.ToDictionary(a => a.AttrId, a => (string?)a.AttrId); _attrs = _attrList.ToDictionary(a => a.AttrId, a => (string?)a.AttrId);
_attrIds = _attrList.ToDictionary(a => a, a => a.AttrId); _attrIds = _attrList.ToDictionary(a => a, a => a.AttrId);
ControlUtils.RenewItemsSource(WineAttributeList, _attrList, a => (a as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(WineAttributeList, _attrList, a => (a as WineAttr)?.AttrId);
WineAttributeList_SelectionChanged(null, null);
} }
private void WineAttributesFinishEditing() { private void WineAttributesFinishEditing() {
@ -65,7 +66,7 @@ namespace Elwig.Windows {
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
private void WineAttributeList_SelectionChanged(object sender, SelectionChangedEventArgs evt) { private void WineAttributeList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
UpdateButtons(); UpdateButtons();
_attrUpdate = true; _attrUpdate = true;
if (WineAttributeList.SelectedItem is not WineAttr attr) { if (WineAttributeList.SelectedItem is not WineAttr attr) {

View File

@ -23,6 +23,7 @@ namespace Elwig.Windows {
_cults = _cultList.ToDictionary(c => c.CultId, c => (string?)c.CultId); _cults = _cultList.ToDictionary(c => c.CultId, c => (string?)c.CultId);
_cultIds = _cultList.ToDictionary(c => c, c => c.CultId); _cultIds = _cultList.ToDictionary(c => c, c => c.CultId);
ControlUtils.RenewItemsSource(WineCultivationList, _cultList, c => (c as WineCult)?.CultId); ControlUtils.RenewItemsSource(WineCultivationList, _cultList, c => (c as WineCult)?.CultId);
WineCultivationList_SelectionChanged(null, null);
} }
private void WineCultivationsFinishEditing() { private void WineCultivationsFinishEditing() {
@ -63,7 +64,7 @@ namespace Elwig.Windows {
await Context.SaveChangesAsync(); await Context.SaveChangesAsync();
} }
private void WineCultivationList_SelectionChanged(object sender, SelectionChangedEventArgs evt) { private void WineCultivationList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
UpdateButtons(); UpdateButtons();
_cultUpdate = true; _cultUpdate = true;
if (WineCultivationList.SelectedItem is not WineCult cult) { if (WineCultivationList.SelectedItem is not WineCult cult) {

View File

@ -21,9 +21,11 @@ namespace Elwig.Windows {
BranchIdInput, BranchNameInput, BranchPlzInput, BranchOrtInput, BranchIdInput, BranchNameInput, BranchPlzInput, BranchOrtInput,
BranchAddressInput, BranchPhoneNrInput, BranchFaxNrInput, BranchMobileNrInput, BranchAddressInput, BranchPhoneNrInput, BranchFaxNrInput, BranchMobileNrInput,
WineAttributeIdInput, WineAttributeNameInput, WineAttributeActiveInput, WineAttributeIdInput, WineAttributeNameInput, WineAttributeActiveInput,
WineAttributeMaxKgPerHaInput, WineAttributeStrictInput, WineAttributeFillLowerInput, WineAttributeMaxKgPerHaInput.TextBox, WineAttributeStrictInput, WineAttributeFillLowerInput,
WineCultivationIdInput, WineCultivationNameInput, WineCultivationDescriptionInput, WineCultivationIdInput, WineCultivationNameInput, WineCultivationDescriptionInput,
SeasonModifierIdInput, SeasonModifierNameInput, SeasonModifierRelInput, SeasonModifierAbsInput, SeasonMaxKgPerHaInput.TextBox, SeasonVatNormalInput.TextBox, SeasonVatFlatrateInput.TextBox, SeasonStartInput, SeasonEndInput,
SeasonMinKgPerBsInput.TextBox, SeasonMaxKgPerBsInput.TextBox, SeasonPenaltyPerKgInput.TextBox, SeasonPenaltyInput.TextBox, SeasonPenaltyNoneInput.TextBox,
SeasonModifierIdInput, SeasonModifierNameInput, SeasonModifierRelInput.TextBox, SeasonModifierAbsInput.TextBox,
}; };
WineAttributeFillLowerInput.Visibility = Visibility.Hidden; WineAttributeFillLowerInput.Visibility = Visibility.Hidden;
WineAttributeFillLowerLabel.Visibility = Visibility.Hidden; WineAttributeFillLowerLabel.Visibility = Visibility.Hidden;
@ -44,7 +46,7 @@ namespace Elwig.Windows {
WineAttributeIdInput.IsReadOnly = true; WineAttributeIdInput.IsReadOnly = true;
WineAttributeNameInput.IsReadOnly = true; WineAttributeNameInput.IsReadOnly = true;
WineAttributeActiveInput.IsEnabled = false; WineAttributeActiveInput.IsEnabled = false;
WineAttributeMaxKgPerHaInput.IsReadOnly = true; WineAttributeMaxKgPerHaInput.TextBox.IsReadOnly = true;
WineAttributeStrictInput.IsEnabled = false; WineAttributeStrictInput.IsEnabled = false;
WineAttributeFillLowerInput.IsEnabled = false; WineAttributeFillLowerInput.IsEnabled = false;
@ -54,8 +56,8 @@ namespace Elwig.Windows {
SeasonModifierIdInput.IsReadOnly = true; SeasonModifierIdInput.IsReadOnly = true;
SeasonModifierNameInput.IsReadOnly = true; SeasonModifierNameInput.IsReadOnly = true;
SeasonModifierRelInput.IsReadOnly = true; SeasonModifierRelInput.TextBox.IsReadOnly = true;
SeasonModifierAbsInput.IsReadOnly = true; SeasonModifierAbsInput.TextBox.IsReadOnly = true;
} }
new protected void UnlockInputs() { new protected void UnlockInputs() {
@ -73,7 +75,7 @@ namespace Elwig.Windows {
WineAttributeIdInput.IsReadOnly = false; WineAttributeIdInput.IsReadOnly = false;
WineAttributeNameInput.IsReadOnly = false; WineAttributeNameInput.IsReadOnly = false;
WineAttributeActiveInput.IsEnabled = true; WineAttributeActiveInput.IsEnabled = true;
WineAttributeMaxKgPerHaInput.IsReadOnly = false; WineAttributeMaxKgPerHaInput.TextBox.IsReadOnly = false;
WineAttributeStrictInput.IsEnabled = true; WineAttributeStrictInput.IsEnabled = true;
WineAttributeFillLowerInput.IsEnabled = true; WineAttributeFillLowerInput.IsEnabled = true;
@ -83,28 +85,28 @@ namespace Elwig.Windows {
SeasonModifierIdInput.IsReadOnly = false; SeasonModifierIdInput.IsReadOnly = false;
SeasonModifierNameInput.IsReadOnly = false; SeasonModifierNameInput.IsReadOnly = false;
SeasonModifierRelInput.IsReadOnly = false; SeasonModifierRelInput.TextBox.IsReadOnly = false;
SeasonModifierAbsInput.IsReadOnly = false; SeasonModifierAbsInput.TextBox.IsReadOnly = false;
} }
private void Window_Loaded(object sender, RoutedEventArgs evt) { private void Window_Loaded(object sender, RoutedEventArgs evt) {
LockInputs(); LockInputs();
FillInputs(App.Client);
} }
protected override async Task OnRenewContext() { protected override async Task OnRenewContext() {
await base.OnRenewContext(); await base.OnRenewContext();
var year = (SeasonList.SelectedItem as Season)?.Year; FillInputs(App.Client);
ControlUtils.RenewItemsSource(SeasonList, await Context.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(SeasonList, await Context.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(BranchList, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), b => (b as Branch)?.ZwstId); var year = (SeasonList.SelectedItem as Season)?.Year;
ControlUtils.RenewItemsSource(WineAttributeList, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), a => (a as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(BranchList, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), b => (b as Branch)?.ZwstId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineCultivationList, await Context.WineCultivations.OrderBy(c => c.Name).ToListAsync(), c=> (c as WineCult)?.CultId); ControlUtils.RenewItemsSource(WineAttributeList, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), a => (a as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(SeasonModifierList, await Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId); ControlUtils.RenewItemsSource(WineCultivationList, await Context.WineCultivations.OrderBy(c => c.Name).ToListAsync(), c=> (c as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(SeasonModifierList, await Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId, null, ControlUtils.RenewSourceDefault.First);
} }
protected override void UpdateButtons() { protected override void UpdateButtons() {
if (!IsEditing && !IsCreating) return; if (!IsEditing && !IsCreating) return;
bool ch = _branchChanged || _attrChanged || _cultChanged || _modChanged || HasChanged, bool ch = _branchChanged || _attrChanged || _cultChanged || _seasonChanged || _modChanged || HasChanged,
v = IsValid; v = IsValid;
CancelButton.IsEnabled = true; CancelButton.IsEnabled = true;
ResetButton.IsEnabled = ch; ResetButton.IsEnabled = ch;
@ -131,6 +133,7 @@ namespace Elwig.Windows {
BranchesInitEditing(); BranchesInitEditing();
WineAttributesInitEditing(); WineAttributesInitEditing();
WineCultivationsInitEditing(); WineCultivationsInitEditing();
SeasonsInitEditing();
ModifiersInitEditing(); ModifiersInitEditing();
UnlockInputs(); UnlockInputs();
UpdateButtons(); UpdateButtons();
@ -149,6 +152,7 @@ namespace Elwig.Windows {
BranchesFinishEditing(); BranchesFinishEditing();
WineCultivationsFinishEditing(); WineCultivationsFinishEditing();
WineAttributesFinishEditing(); WineAttributesFinishEditing();
SeasonsFinishEditing();
ModifiersFinishEditing(); ModifiersFinishEditing();
ClearInputStates(); ClearInputStates();
@ -166,6 +170,7 @@ namespace Elwig.Windows {
BranchesInitEditing(); BranchesInitEditing();
WineAttributesInitEditing(); WineAttributesInitEditing();
WineCultivationsInitEditing(); WineCultivationsInitEditing();
SeasonsInitEditing();
ModifiersInitEditing(); ModifiersInitEditing();
ClearInputStates(); ClearInputStates();
@ -179,6 +184,7 @@ namespace Elwig.Windows {
await BranchesSave(); await BranchesSave();
await WineAttributesSave(); await WineAttributesSave();
await WineCultivationsSave(); await WineCultivationsSave();
await SeasonsSave();
await ModifiersSave(); await ModifiersSave();
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
@ -197,6 +203,7 @@ namespace Elwig.Windows {
BranchesFinishEditing(); BranchesFinishEditing();
WineAttributesFinishEditing(); WineAttributesFinishEditing();
WineCultivationsFinishEditing(); WineCultivationsFinishEditing();
SeasonsFinishEditing();
ModifiersFinishEditing(); ModifiersFinishEditing();
ClearInputStates(); ClearInputStates();
@ -267,10 +274,5 @@ namespace Elwig.Windows {
ClientNameFull.Text = $"{ClientNameInput.Text}{(suffix != null ? $", {suffix}," : "")} {ClientNameTypeInput.Text}"; ClientNameFull.Text = $"{ClientNameInput.Text}{(suffix != null ? $", {suffix}," : "")} {ClientNameTypeInput.Text}";
TextBox_TextChanged(sender, evt); TextBox_TextChanged(sender, evt);
} }
private async void SeasonList_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
var year = (SeasonList.SelectedItem as Season)?.Year;
SeasonModifierList.ItemsSource = await Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync();
}
} }
} }

View File

@ -31,8 +31,8 @@ namespace Elwig.Windows {
await RenewContext(); await RenewContext();
} }
private void OnLoaded(object sender, RoutedEventArgs evt) { protected async void OnLoaded(object sender, RoutedEventArgs evt) {
OnRenewContext().GetAwaiter().GetResult(); await OnRenewContext();
} }
protected override void OnClosed(EventArgs evt) { protected override void OnClosed(EventArgs evt) {