[#14] Windows: Add DeliveryScheduleAdminWindow
All checks were successful
Test / Run tests (push) Successful in 2m58s
All checks were successful
Test / Run tests (push) Successful in 2m58s
This commit is contained in:
284
Elwig/Windows/DeliveryScheduleAdminWindow.xaml
Normal file
284
Elwig/Windows/DeliveryScheduleAdminWindow.xaml
Normal file
@ -0,0 +1,284 @@
|
||||
<local:AdministrationWindow
|
||||
x:Class="Elwig.Windows.DeliveryScheduleAdminWindow"
|
||||
AutomationProperties.AutomationId="DeliveryScheduleAdminWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Elwig.Windows"
|
||||
xmlns:vm="clr-namespace:Elwig.ViewModels"
|
||||
xmlns:ctrl="clr-namespace:Elwig.Controls"
|
||||
Title="Leseplanung - Elwig" Height="600" Width="850" MinHeight="450" MinWidth="800"
|
||||
Loaded="Window_Loaded">
|
||||
<Window.DataContext>
|
||||
<vm:DeliveryScheduleAdminViewModel/>
|
||||
</Window.DataContext>
|
||||
<Window.Resources>
|
||||
<Style TargetType="Label">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="Padding" Value="2,4,2,4"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
</Style>
|
||||
<Style TargetType="TextBox">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="TextWrapping" Value="NoWrap"/>
|
||||
</Style>
|
||||
<Style TargetType="ctrl:UnitTextBox">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="TextWrapping" Value="NoWrap"/>
|
||||
</Style>
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Style>
|
||||
<Style TargetType="ctrl:CheckComboBox">
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="9,3"/>
|
||||
<Setter Property="Height" Value="27"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="19"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="24"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" MinWidth="350"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="1*" MinWidth="400"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Menu Grid.ColumnSpan="3" BorderThickness="0,0,0,1" BorderBrush="LightGray" Background="White">
|
||||
</Menu>
|
||||
|
||||
<Grid Grid.Row="1" Margin="5,0,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="42"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox x:Name="SearchInput" Text="{Binding SearchQuery, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding EnableSearchInputs}"
|
||||
Grid.ColumnSpan="3" Margin="5,5,174,0" IsReadOnly="False"
|
||||
TextChanged="SearchInput_TextChanged">
|
||||
<TextBox.ToolTip>
|
||||
<TextBlock>
|
||||
<Bold>Strg+F</Bold><LineBreak/><LineBreak/>
|
||||
Lesepläne filtern und durchsuchen. Die Filter sind beliebig kombinierbar.<LineBreak/>
|
||||
Groß- und Kleinschreibung ist in den meisten Fällen egal.<LineBreak/>
|
||||
<LineBreak/>
|
||||
Filtern nach:<LineBreak/>
|
||||
<Bold>Sorte</Bold>: z.B. GV, ZW, rr, sa, !gv (ausgenommen GV), ...<LineBreak/>
|
||||
<Bold>Rot/Weiß</Bold>: z.B. r, Rot, w, weiß, ...<LineBreak/>
|
||||
<Bold>Zweigstelle</Bold>: z.B. musterort, ...<LineBreak/>
|
||||
<Bold>Datum</Bold>: z.B. 1.9., 15.9.-10.10., -15.10.2020, ...<LineBreak/>
|
||||
<Bold>Beschreibung</Bold>: z.B. Bio, ...
|
||||
</TextBlock>
|
||||
</TextBox.ToolTip>
|
||||
</TextBox>
|
||||
<ctrl:IntegerUpDown x:Name="SeasonInput" Text="{Binding FilterSeasonString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding EnableSearchInputs}"
|
||||
Grid.ColumnSpan="3" Height="25" Width="56" FontSize="14" Minimum="1900" Maximum="9999"
|
||||
Margin="5,5,113,0" VerticalAlignment="Top" HorizontalAlignment="Right"
|
||||
TextChanged="SeasonInput_TextChanged"/>
|
||||
<CheckBox x:Name="OnlyUpcomingInput" Content="Nur zukünftige" IsChecked="{Binding FilterOnlyUpcoming, Mode=TwoWay}" IsEnabled="{Binding EnableSearchInputs}"
|
||||
HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Checked="OnlyUpcomingInput_Changed" Unchecked="OnlyUpcomingInput_Changed"/>
|
||||
|
||||
<DataGrid x:Name="DeliveryScheduleList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
|
||||
ItemsSource="{Binding DeliverySchedules, Mode=TwoWay}" SelectedItem="{Binding SelectedDeliverySchedule, Mode=TwoWay}"
|
||||
CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False"
|
||||
SelectionChanged="DeliveryScheduleList_SelectionChanged"
|
||||
Margin="5,0,5,0" Grid.Row="1" FontSize="14" Grid.ColumnSpan="3">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Datum" Binding="{Binding Date, StringFormat='dd.MM.yy'}" Width="70">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Z." Binding="{Binding ZwstId}" Width="25">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Beschreibung" Binding="{Binding Description}" Width="200"/>
|
||||
<DataGridTextColumn Header="Max. Gew." Binding="{Binding MaxWeight, StringFormat='{}{0:N0} kg'}" Width="80">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<Button x:Name="NewDeliveryScheduleButton" Content="Neu" Visibility="{Binding ControlButtonsVisibility}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2"
|
||||
Click="NewDeliveryScheduleButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Alt+Einfg</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
<Button x:Name="EditDeliveryScheduleButton" Content="Bearbeiten" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2"
|
||||
Click="EditDeliveryScheduleButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Strg+B</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
<Button x:Name="DeleteDeliveryScheduleButton" Content="Löschen" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2"
|
||||
Click="DeleteDeliveryScheduleButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Alt+Entf</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
|
||||
<Button x:Name="SaveButton" Content="Speichern" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2"
|
||||
Click="SaveButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Strg+S</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
<Button x:Name="ResetButton" Content="Zurücksetzen" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2"
|
||||
Click="ResetButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Strg+Z</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
<Button x:Name="CancelButton" Content="Abbrechen" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}" IsCancel="True"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2"
|
||||
Click="CancelButton_Click">
|
||||
<Button.ToolTip>
|
||||
<TextBlock FontWeight="Bold">Esc</TextBlock>
|
||||
</Button.ToolTip>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<GridSplitter Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
|
||||
<Grid Grid.Column="2" Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1.5*"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<GroupBox Header="Leseplan" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="110"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="Datum/Zwst.:" Margin="10,10,0,10"/>
|
||||
<TextBox x:Name="DateInput" Text="{Binding DateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="0,10,10,10" Width="77" Grid.Column="1" HorizontalAlignment="Left" TextAlignment="Right"
|
||||
TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
|
||||
<ComboBox x:Name="BranchInput" SelectedItem="{Binding Branch, Mode=TwoWay}" ItemsSource="{Binding BranchSource, Mode=TwoWay}"
|
||||
DisplayMemberPath="Name" TextSearch.TextPath="Name"
|
||||
Margin="82,10,10,10" Width="150" Grid.Column="1" HorizontalAlignment="Left"/>
|
||||
|
||||
<Label Content="Beschreibung:" Margin="10,40,0,10"/>
|
||||
<TextBox x:Name="DescriptionInput" Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="0,40,10,10" Grid.Column="1"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
|
||||
<Label Content="Max. Gewicht:" Margin="10,70,0,10"/>
|
||||
<ctrl:UnitTextBox x:Name="MaxWeightInput" Unit="kg" Text="{Binding MaxWeightString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="0,70,10,10" Grid.Column="1" Width="68" HorizontalAlignment="Left"
|
||||
TextChanged="MaxWeightInput_TextChanged"/>
|
||||
|
||||
<Label Content="Sorten:" Margin="10,100,0,10"/>
|
||||
<ctrl:CheckComboBox x:Name="MainWineVarietiesInput" SelectedItems="{Binding MainVarieties}" ItemsSource="{Binding MainVarietiesSource, Mode=TwoWay}"
|
||||
Grid.Column="1" Margin="0,100,10,10"
|
||||
Delimiter=", " AllItemsSelectedContent="Alle Sorten" ListDisplayMemberPath="SortId" TextSearch.TextPath="Name">
|
||||
<ctrl:CheckComboBox.ItemTemplateSelector>
|
||||
<ctrl:WineVarietyTemplateSelector/>
|
||||
</ctrl:CheckComboBox.ItemTemplateSelector>
|
||||
</ctrl:CheckComboBox>
|
||||
|
||||
<Label Content="Weitere Sorten:" Margin="10,130,0,10"/>
|
||||
<ctrl:CheckComboBox x:Name="OtherWineVarietiesInput" SelectedItems="{Binding OtherVarieties}" ItemsSource="{Binding OtherVarietiesSource, Mode=TwoWay}"
|
||||
Grid.Column="1" Margin="0,130,10,10"
|
||||
Delimiter=", " AllItemsSelectedContent="Alle Sorten" ListDisplayMemberPath="SortId" TextSearch.TextPath="Name">
|
||||
<ctrl:CheckComboBox.ItemTemplateSelector>
|
||||
<ctrl:WineVarietyTemplateSelector/>
|
||||
</ctrl:CheckComboBox.ItemTemplateSelector>
|
||||
</ctrl:CheckComboBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Anmeldungen" Margin="5,5,5,5" Grid.Row="1" Width="249" Height="98"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="ab frühestens:" Margin="10,10,0,10"/>
|
||||
<TextBox x:Name="AncmtFromDateInput" Text="{Binding AncmtFromDateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Width="77" Margin="0,10,10,10" Grid.Column="1" HorizontalAlignment="Left" TextAlignment="Right"
|
||||
TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
|
||||
<TextBox x:Name="AncmtFromTimeInput" Text="{Binding AncmtFromTimeString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Width="44" Margin="83,10,10,10" Grid.Column="1" HorizontalAlignment="Left"
|
||||
TextChanged="TimeInput_TextChanged" LostFocus="TimeInput_LostFocus"/>
|
||||
|
||||
<Label Content="bis spätestens:" Margin="10,40,0,10"/>
|
||||
<TextBox x:Name="AncmtToDateInput" Text="{Binding AncmtToDateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Width="77" Margin="0,40,10,10" Grid.Column="1" HorizontalAlignment="Left" TextAlignment="Right"
|
||||
TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
|
||||
<TextBox x:Name="AncmtToTimeInput" Text="{Binding AncmtToTimeString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Width="44" Margin="83,40,10,10" Grid.Column="1" HorizontalAlignment="Left"
|
||||
TextChanged="TimeInput_TextChanged" LostFocus="TimeInput_LostFocus"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
<StatusBar Grid.Row="2" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="Gray">
|
||||
<StatusBar.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
</Grid>
|
||||
</ItemsPanelTemplate>
|
||||
</StatusBar.ItemsPanel>
|
||||
<StatusBarItem>
|
||||
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</local:AdministrationWindow>
|
311
Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs
Normal file
311
Elwig/Windows/DeliveryScheduleAdminWindow.xaml.cs
Normal file
@ -0,0 +1,311 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.Services;
|
||||
using Elwig.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class DeliveryScheduleAdminWindow : AdministrationWindow {
|
||||
|
||||
public DeliveryScheduleAdminViewModel ViewModel => (DeliveryScheduleAdminViewModel)DataContext;
|
||||
|
||||
private readonly RoutedCommand CtrlF = new("CtrlF", typeof(DeliveryScheduleAdminWindow), [new KeyGesture(Key.F, ModifierKeys.Control)]);
|
||||
|
||||
public DeliveryScheduleAdminWindow() {
|
||||
InitializeComponent();
|
||||
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||
ExemptInputs = [
|
||||
SearchInput, SeasonInput, OnlyUpcomingInput, DeliveryScheduleList,
|
||||
];
|
||||
RequiredInputs = [
|
||||
DateInput, BranchInput, DescriptionInput, MainWineVarietiesInput,
|
||||
];
|
||||
|
||||
InitializeDelayTimer(SearchInput, SearchInput_TextChanged);
|
||||
SearchInput.TextChanged -= SearchInput_TextChanged;
|
||||
ViewModel.FilterSeason = Utils.CurrentLastSeason;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
ViewModel.FilterOnlyUpcoming = true;
|
||||
LockInputs();
|
||||
}
|
||||
|
||||
private async Task RefreshList(bool updateSort = false) {
|
||||
using var ctx = new AppDbContext();
|
||||
var (_, deliveryScheduleQuery, filter) = await ViewModel.GetFilters(ctx);
|
||||
var deliverySchedules = await deliveryScheduleQuery
|
||||
.Include(s => s.Varieties)
|
||||
.Include(s => s.Branch)
|
||||
.AsSplitQuery()
|
||||
.ToListAsync();
|
||||
|
||||
if (filter.Count > 0 && deliverySchedules.Count > 0) {
|
||||
var dict = deliverySchedules.AsParallel()
|
||||
.ToDictionary(s => s, s => s.SearchScore(filter))
|
||||
.OrderByDescending(a => a.Value)
|
||||
.ThenBy(a => a.Key.DateString)
|
||||
.ThenBy(a => a.Key.Branch.Name)
|
||||
.ThenBy(a => a.Key.Description);
|
||||
var threshold = dict.Select(a => a.Value).Max() * 3 / 4;
|
||||
deliverySchedules = dict
|
||||
.Where(a => a.Value > threshold)
|
||||
.Select(a => a.Key)
|
||||
.ToList();
|
||||
} else {
|
||||
deliverySchedules = deliverySchedules
|
||||
.OrderBy(s => s.DateString)
|
||||
.ThenBy(s => s.Branch.Name)
|
||||
.ThenBy(s => s.Description)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
ControlUtils.RenewItemsSource(DeliveryScheduleList, deliverySchedules,
|
||||
DeliveryScheduleList_SelectionChanged, ViewModel.TextFilter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
|
||||
if (updateSort && DeliveryScheduleList.SelectedItem != null)
|
||||
DeliveryScheduleList.ScrollIntoView(DeliveryScheduleList.SelectedItem);
|
||||
}
|
||||
|
||||
private async Task RefreshInputs(bool validate = false) {
|
||||
ClearInputStates();
|
||||
if (ViewModel.SelectedDeliverySchedule is DeliverySchedule s) {
|
||||
EditDeliveryScheduleButton.IsEnabled = true;
|
||||
DeleteDeliveryScheduleButton.IsEnabled = true;
|
||||
await FillInputs(s);
|
||||
} else {
|
||||
EditDeliveryScheduleButton.IsEnabled = false;
|
||||
DeleteDeliveryScheduleButton.IsEnabled = false;
|
||||
ClearOriginalValues();
|
||||
ClearDefaultValues();
|
||||
ClearInputs(validate);
|
||||
ClearInputStates();
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void InitInputs() {
|
||||
ClearOriginalValues();
|
||||
ClearDefaultValues();
|
||||
ViewModel.InitInputs();
|
||||
ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext(AppDbContext ctx) {
|
||||
await base.OnRenewContext(ctx);
|
||||
|
||||
ControlUtils.RenewItemsSource(BranchInput, await ctx.Branches.OrderBy(b => b.Name).ToListAsync());
|
||||
var varieties = await ctx.WineVarieties.OrderBy(v => v.Name).ToListAsync();
|
||||
ControlUtils.RenewItemsSource(MainWineVarietiesInput, varieties);
|
||||
ControlUtils.RenewItemsSource(OtherWineVarietiesInput, varieties);
|
||||
|
||||
await RefreshList();
|
||||
}
|
||||
|
||||
private async void DeliveryScheduleList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
await RefreshInputs();
|
||||
}
|
||||
|
||||
private async void OnlyUpcomingInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
await RefreshList();
|
||||
}
|
||||
|
||||
private async void SearchInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
await RefreshList(true);
|
||||
}
|
||||
|
||||
private async void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (ViewModel.FilterSeason == null) return;
|
||||
ViewModel.FilterOnlyUpcoming = false;
|
||||
await RefreshList();
|
||||
}
|
||||
|
||||
protected override void ShortcutNew() {
|
||||
if (!NewDeliveryScheduleButton.IsEnabled || NewDeliveryScheduleButton.Visibility != Visibility.Visible)
|
||||
return;
|
||||
NewDeliveryScheduleButton_Click(null, null);
|
||||
}
|
||||
|
||||
private void NewDeliveryScheduleButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
IsCreating = true;
|
||||
DeliveryScheduleList.IsEnabled = false;
|
||||
ViewModel.SelectedDeliverySchedule = null;
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
InitInputs();
|
||||
ViewModel.EnableSearchInputs = false;
|
||||
}
|
||||
|
||||
protected override void ShortcutEdit() {
|
||||
if (!EditDeliveryScheduleButton.IsEnabled || EditDeliveryScheduleButton.Visibility != Visibility.Visible)
|
||||
return;
|
||||
EditDeliveryScheduleButton_Click(null, null);
|
||||
}
|
||||
|
||||
private void EditDeliveryScheduleButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (ViewModel.SelectedDeliverySchedule == null) return;
|
||||
IsEditing = true;
|
||||
DeliveryScheduleList.IsEnabled = false;
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
ViewModel.EnableSearchInputs = false;
|
||||
}
|
||||
|
||||
protected override void ShortcutDelete() {
|
||||
if (!DeleteDeliveryScheduleButton.IsEnabled || DeleteDeliveryScheduleButton.Visibility != Visibility.Visible)
|
||||
return;
|
||||
DeleteDeliveryScheduleButton_Click(null, null);
|
||||
}
|
||||
|
||||
private async void DeleteDeliveryScheduleButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (ViewModel.SelectedDeliverySchedule is not DeliverySchedule s)
|
||||
return;
|
||||
var r = MessageBox.Show(
|
||||
$"Soll der Leseplan \"{s.Description}\" vom {s.Date:dd.MM.yyyy} wirklich unwiderruflich gelöscht werden?",
|
||||
"Leseplan löschen", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
|
||||
if (r == MessageBoxResult.OK) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ctx.Remove(s);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
await App.HintContextChange();
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Leseplan löschen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ShortcutSave() {
|
||||
if (!SaveButton.IsEnabled || SaveButton.Visibility != Visibility.Visible)
|
||||
return;
|
||||
SaveButton_Click(null, null);
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
await ViewModel.UpdateDeliverySchedule(ViewModel.SelectedDeliverySchedule?.Year, ViewModel.SelectedDeliverySchedule?.DsNr);
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Leseplan aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
DeliveryScheduleList.IsEnabled = true;
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
ViewModel.EnableSearchInputs = true;
|
||||
FinishInputFilling();
|
||||
await RefreshList();
|
||||
await RefreshInputs();
|
||||
ViewModel.SearchQuery = "";
|
||||
}
|
||||
|
||||
protected override void ShortcutReset() {
|
||||
if (!ResetButton.IsEnabled || ResetButton.Visibility != Visibility.Visible)
|
||||
return;
|
||||
ResetButton_Click(null, null);
|
||||
}
|
||||
|
||||
private async void ResetButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (IsEditing) {
|
||||
await RefreshInputs();
|
||||
} else if (IsCreating) {
|
||||
ClearInputs();
|
||||
InitInputs();
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private async void CancelButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
DeliveryScheduleList.IsEnabled = true;
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
await RefreshInputs();
|
||||
LockInputs();
|
||||
ViewModel.EnableSearchInputs = true;
|
||||
}
|
||||
|
||||
private async Task FillInputs(DeliverySchedule s) {
|
||||
ClearOriginalValues();
|
||||
ClearDefaultValues();
|
||||
await ViewModel.FillInputs(s);
|
||||
FinishInputFilling();
|
||||
}
|
||||
|
||||
new protected void ClearInputs(bool validate = false) {
|
||||
ViewModel.ClearInputs();
|
||||
base.ClearInputs(validate);
|
||||
}
|
||||
|
||||
protected override void UpdateButtons() {
|
||||
if (!IsEditing && !IsCreating) return;
|
||||
bool ch = HasChanged, v = IsValid;
|
||||
ResetButton.IsEnabled = ch;
|
||||
SaveButton.IsEnabled = v && ch;
|
||||
}
|
||||
|
||||
private void FocusSearchInput(object sender, RoutedEventArgs evt) {
|
||||
if (!IsEditing && !IsCreating) {
|
||||
SearchInput.Focus();
|
||||
SearchInput.SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = true;
|
||||
ViewModel.EditingButtonsVisibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = false;
|
||||
ViewModel.EditingButtonsVisibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void ShowNewEditDeleteButtons() {
|
||||
NewDeliveryScheduleButton.IsEnabled = true;
|
||||
EditDeliveryScheduleButton.IsEnabled = ViewModel.SelectedDeliverySchedule != null;
|
||||
DeleteDeliveryScheduleButton.IsEnabled = ViewModel.SelectedDeliverySchedule != null;
|
||||
ViewModel.ControlButtonsVisibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideNewEditDeleteButtons() {
|
||||
NewDeliveryScheduleButton.IsEnabled = false;
|
||||
EditDeliveryScheduleButton.IsEnabled = false;
|
||||
DeleteDeliveryScheduleButton.IsEnabled = false;
|
||||
ViewModel.ControlButtonsVisibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private new void DateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
base.DateInput_TextChanged(sender, evt);
|
||||
if (ViewModel.Date is DateOnly date) {
|
||||
ViewModel.AncmtToDate = date.AddDays(-2);
|
||||
}
|
||||
}
|
||||
|
||||
private void MaxWeightInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, Validator.CheckInteger((TextBox)sender, false, 6));
|
||||
}
|
||||
}
|
||||
}
|
@ -64,7 +64,7 @@
|
||||
Margin="205,210,0,0"/>
|
||||
<Button x:Name="BaseDataButton" Content="Stammdaten" Click="BaseDataButton_Click"
|
||||
Margin="0,250,205,0"/>
|
||||
<Button x:Name="RegistrationButton" Content="Anmeldungen" IsEnabled="False"
|
||||
<Button x:Name="DeliveryAncmtButton" Content="Anmeldungen" Click="DeliveryAncmtButton_Click"
|
||||
Margin="205,250,0,0"/>
|
||||
|
||||
<Button x:Name="DownloadButton" Click="DownloadButton_Click"
|
||||
|
@ -213,6 +213,10 @@ namespace Elwig.Windows {
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void DeliveryAncmtButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusDeliverySchedule();
|
||||
}
|
||||
|
||||
private void BaseDataButton_Click(object sender, RoutedEventArgs evt) {
|
||||
App.FocusBaseData();
|
||||
}
|
||||
|
Reference in New Issue
Block a user