[#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:
@ -292,6 +292,10 @@ namespace Elwig {
|
||||
return w;
|
||||
}
|
||||
|
||||
public static DeliveryScheduleAdminWindow FocusDeliverySchedule() {
|
||||
return FocusWindow<DeliveryScheduleAdminWindow>(() => new());
|
||||
}
|
||||
|
||||
public static PaymentVariantsWindow FocusPaymentVariants(int year) {
|
||||
return FocusWindow<PaymentVariantsWindow>(() => new(year), w => w.Year == year);
|
||||
}
|
||||
|
@ -20,6 +20,12 @@ namespace Elwig.Controls {
|
||||
set => SetValue(DelimiterProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ListDisplayMemberPathProperty = DependencyProperty.Register(nameof(ListDisplayMemberPath), typeof(string), typeof(CheckComboBox), new FrameworkPropertyMetadata(null));
|
||||
public string ListDisplayMemberPath {
|
||||
get => (string)GetValue(ListDisplayMemberPathProperty);
|
||||
set => SetValue(ListDisplayMemberPathProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AllItemsSelectedContentProperty = DependencyProperty.Register(nameof(AllItemsSelectedContent), typeof(string), typeof(CheckComboBox), new FrameworkPropertyMetadata("All"));
|
||||
public string AllItemsSelectedContent {
|
||||
get => (string)GetValue(AllItemsSelectedContentProperty);
|
||||
@ -116,7 +122,7 @@ namespace Elwig.Controls {
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
SelectItemsReverse();
|
||||
var dmp = DisplayMemberPath != null && DisplayMemberPath != "" ? DisplayMemberPath : null;
|
||||
var dmp = !string.IsNullOrEmpty(ListDisplayMemberPath) ? ListDisplayMemberPath : !string.IsNullOrEmpty(DisplayMemberPath) ? DisplayMemberPath : null;
|
||||
if (SelectedItems.Count == ItemsSource.Cast<object>().Count() && AllItemsSelectedContent != null) {
|
||||
_textBox.Text = AllItemsSelectedContent;
|
||||
AllItemsSelected = true;
|
||||
|
@ -239,6 +239,13 @@ namespace Elwig.Helpers {
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
public async Task<int> NextDsNr(int year) {
|
||||
int c = 0;
|
||||
(await DeliverySchedules.Where(s => s.Year == year).Select(s => s.DsNr).ToListAsync())
|
||||
.ForEach(a => { if (a <= c + 100) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
public async Task<WineQualLevel> GetWineQualityLevel(double kmw) {
|
||||
return await WineQualityLevels
|
||||
.Where(q => !q.IsPredicate && (q.MinKmw == null || q.MinKmw <= kmw))
|
||||
@ -269,6 +276,31 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDeliveryScheduleWineVarieties(DeliverySchedule schedule, IEnumerable<(WineVar, int)> oldVarieties, IEnumerable<(WineVar, int)> newVarieties) {
|
||||
foreach (var v in WineVarieties) {
|
||||
var e = new DeliveryScheduleWineVar {
|
||||
Year = schedule.Year,
|
||||
DsNr = schedule.DsNr,
|
||||
SortId = v.SortId,
|
||||
Priority = 1,
|
||||
};
|
||||
var o = oldVarieties.Where(x => x.Item1.SortId == e.SortId).Select(x => x.Item2).FirstOrDefault(-1);
|
||||
var n = newVarieties.Where(x => x.Item1.SortId == e.SortId).Select(x => x.Item2).FirstOrDefault(-1);
|
||||
if (n != -1) {
|
||||
e.Priority = n;
|
||||
if (o == -1) {
|
||||
Add(e);
|
||||
} else {
|
||||
Update(e);
|
||||
}
|
||||
} else {
|
||||
if (o != -1) {
|
||||
Remove(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task FetchMemberAreaCommitmentBuckets(int year, SqliteConnection? cnx = null) {
|
||||
var ownCnx = cnx == null;
|
||||
cnx ??= await ConnectAsync();
|
||||
|
183
Elwig/Services/DeliveryScheduleService.cs
Normal file
183
Elwig/Services/DeliveryScheduleService.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.ViewModels;
|
||||
using LinqKit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class DeliveryScheduleService {
|
||||
|
||||
public static void InitInputs(this DeliveryScheduleAdminViewModel vm) {
|
||||
if (vm.BranchSource.Count() == 1)
|
||||
vm.Branch = vm.BranchSource.First();
|
||||
vm.AncmtFromTimeString = "00:00";
|
||||
vm.AncmtToTimeString = "23:59";
|
||||
}
|
||||
|
||||
public static void ClearInputs(this DeliveryScheduleAdminViewModel vm) {
|
||||
}
|
||||
|
||||
public static async Task FillInputs(this DeliveryScheduleAdminViewModel vm, DeliverySchedule s) {
|
||||
vm.Date = s.Date;
|
||||
vm.Branch = (Branch?)ControlUtils.GetItemFromSourceWithPk(vm.BranchSource, s.ZwstId);
|
||||
vm.Description = s.Description;
|
||||
vm.MaxWeight = s.MaxWeight;
|
||||
vm.MainVarieties.Clear();
|
||||
foreach (var v in s.Varieties.Where(v => v.Priority == 1)) {
|
||||
vm.MainVarieties.Add((WineVar)ControlUtils.GetItemFromSourceWithPk(vm.MainVarietiesSource, v.SortId)!);
|
||||
}
|
||||
vm.OtherVarieties.Clear();
|
||||
foreach (var v in s.Varieties.Where(v => v.Priority != 1)) {
|
||||
vm.OtherVarieties.Add((WineVar)ControlUtils.GetItemFromSourceWithPk(vm.OtherVarietiesSource, v.SortId)!);
|
||||
}
|
||||
vm.AncmtFrom = s.AncmtFrom;
|
||||
vm.AncmtTo = s.AncmtTo?.AddSeconds(-1);
|
||||
}
|
||||
|
||||
public static async Task<(List<string>, IQueryable<DeliverySchedule>, List<string>)> GetFilters(this DeliveryScheduleAdminViewModel vm, AppDbContext ctx) {
|
||||
List<string> filterNames = [];
|
||||
IQueryable<DeliverySchedule> deliveryScheduleQuery = ctx.DeliverySchedules;
|
||||
if (vm.FilterSeason != null) {
|
||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.Year == vm.FilterSeason);
|
||||
filterNames.Add($"{vm.FilterSeason}");
|
||||
}
|
||||
if (vm.FilterOnlyUpcoming) {
|
||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0);
|
||||
filterNames.Add($"ab {Utils.Today:dd.MM.yyyy}");
|
||||
}
|
||||
|
||||
var filterVar = new List<string>();
|
||||
var filterNotVar = new List<string>();
|
||||
var filterZwst = new List<string>();
|
||||
var filterDate = new List<(string?, string?)>();
|
||||
|
||||
var filter = vm.TextFilter;
|
||||
if (filter.Count > 0) {
|
||||
var var = await ctx.WineVarieties.ToDictionaryAsync(v => v.SortId, v => v);
|
||||
var zwst = await ctx.Branches.ToDictionaryAsync(b => b.Name.ToLower().Split(" ")[0], b => b);
|
||||
|
||||
for (int i = 0; i < filter.Count; i++) {
|
||||
var e = filter[i];
|
||||
if (e.ToLower() is "r" or "rot") {
|
||||
filterVar.AddRange(var.Values.Where(v => v.IsRed).Select(v => v.SortId));
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add("Rotweinsorten");
|
||||
} else if (e.ToLower() is "w" or "weiß" or "weiss") {
|
||||
filterVar.AddRange(var.Values.Where(v => v.IsWhite).Select(v => v.SortId));
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add("Weißweinsorten");
|
||||
} else if (e.Length == 2 && var.ContainsKey(e.ToUpper())) {
|
||||
filterVar.Add(e.ToUpper());
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add(var[e.ToUpper()].Name);
|
||||
} else if (e.Length == 3 && e[0] == '!' && var.ContainsKey(e[1..].ToUpper())) {
|
||||
filterNotVar.Add(e[1..].ToUpper());
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add("außer " + var[e[1..].ToUpper()].Name);
|
||||
} else if (zwst.ContainsKey(e.ToLower())) {
|
||||
var b = zwst[e.ToLower()];
|
||||
filterZwst.Add(b.ZwstId);
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add($"Zweigstelle {b.Name}");
|
||||
} else if (DateOnly.TryParse(e, out var date)) {
|
||||
var s = date.ToString("yyyy-MM-dd");
|
||||
filterDate.Add((s, s));
|
||||
filter.RemoveAt(i--);
|
||||
if (filterNames.Contains($"{vm.FilterSeason}") && vm.FilterSeason == date.Year)
|
||||
filterNames.Remove($"{vm.FilterSeason}");
|
||||
filterNames.Add(date.ToString("dd.MM.yyyy"));
|
||||
} else if (Utils.DateFromToRegex.IsMatch(e)) {
|
||||
var parts = e.Split("-");
|
||||
if (parts.Length == 1) {
|
||||
// single date
|
||||
var dParts = parts[0].Split('.');
|
||||
var s = $"{dParts[2]}-{dParts[1].PadLeft(2, '0')}-{dParts[0].PadLeft(2, '0')}";
|
||||
filterDate.Add((s, s));
|
||||
filter.RemoveAt(i--);
|
||||
var n = string.Join('.', s.Split('-').Reverse());
|
||||
if (dParts[2] == "") {
|
||||
filterNames.Remove($"{vm.FilterSeason}");
|
||||
filterNames.Add(n + $"{vm.FilterSeason}");
|
||||
} else {
|
||||
if ($"{vm.FilterSeason}" == dParts[2])
|
||||
filterNames.Remove($"{vm.FilterSeason}");
|
||||
filterNames.Add(n);
|
||||
}
|
||||
} else if (parts.Length == 2) {
|
||||
// from/to date
|
||||
var d1Parts = parts[0].Split('.');
|
||||
var d2Parts = parts[1].Split('.');
|
||||
var s1 = d1Parts.Length < 2 ? null : $"{d1Parts.ElementAtOrDefault(2)}-{d1Parts[1].PadLeft(2, '0')}-{d1Parts[0].PadLeft(2, '0')}";
|
||||
var s2 = d2Parts.Length < 2 ? null : $"{d2Parts.ElementAtOrDefault(2)}-{d2Parts[1].PadLeft(2, '0')}-{d2Parts[0].PadLeft(2, '0')}";
|
||||
filterDate.Add((s1, s2));
|
||||
filter.RemoveAt(i--);
|
||||
var n1 = s1 == null ? null : string.Join('.', s1.Split('-').Reverse());
|
||||
var n2 = s2 == null ? null : string.Join('.', s2.Split('-').Reverse());
|
||||
if (n1 != null && n2 != null) {
|
||||
filterNames.Add($"{n1}–{n2}");
|
||||
} else if (n1 != null) {
|
||||
filterNames.Add($"ab dem {n1}");
|
||||
} else if (n2 != null) {
|
||||
filterNames.Add($"bis zum {n2}");
|
||||
}
|
||||
}
|
||||
} else if (e.Length > 2 && e.StartsWith('"') && e.EndsWith('"')) {
|
||||
filter[i] = e[1..^1];
|
||||
} else if (e.Length <= 2) {
|
||||
filter.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
|
||||
if (filterDate.Count > 0) {
|
||||
var pr = PredicateBuilder.New<DeliverySchedule>(false);
|
||||
foreach (var (d1, d2) in filterDate)
|
||||
pr.Or(p => (d1 == null || d1.CompareTo(p.DateString.Substring(10 - d1.Length)) <= 0) && (d2 == null || d2.CompareTo(p.DateString.Substring(10 - d2.Length)) >= 0));
|
||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(pr);
|
||||
}
|
||||
if (filterVar.Count > 0) deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.Varieties.Any(v => filterVar.Contains(v.SortId)));
|
||||
if (filterNotVar.Count > 0) deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.Varieties.All(v => !filterNotVar.Contains(v.SortId)));
|
||||
if (filterZwst.Count > 0) deliveryScheduleQuery = deliveryScheduleQuery.Where(s => filterZwst.Contains(s.Branch.ZwstId));
|
||||
}
|
||||
|
||||
return (filterNames, deliveryScheduleQuery, filter);
|
||||
}
|
||||
|
||||
public static async Task UpdateDeliverySchedule(this DeliveryScheduleAdminViewModel vm, int? oldYear, int? oldDsNr) {
|
||||
int year = vm.Date!.Value.Year;
|
||||
|
||||
using (var ctx = new AppDbContext()) {
|
||||
var s = new DeliverySchedule {
|
||||
Year = oldYear ?? year,
|
||||
DsNr = oldDsNr ?? await ctx.NextDsNr(year),
|
||||
DateString = $"{vm.Date:yyyy-MM-dd}",
|
||||
ZwstId = vm.Branch!.ZwstId,
|
||||
Description = vm.Description,
|
||||
MaxWeight = vm.MaxWeight,
|
||||
AncmtFrom = vm.AncmtFrom,
|
||||
AncmtTo = vm.AncmtTo?.AddMinutes(1),
|
||||
};
|
||||
|
||||
if (oldDsNr != null) {
|
||||
ctx.Update(s);
|
||||
} else {
|
||||
ctx.Add(s);
|
||||
}
|
||||
|
||||
ctx.UpdateDeliveryScheduleWineVarieties(s, (await ctx.DeliveryScheduleWineVarieties
|
||||
.Where(v => v.Year == s.Year && v.DsNr == s.DsNr)
|
||||
.Select(v => new { v.Variety, v.Priority })
|
||||
.ToListAsync())
|
||||
.Select(v => (v.Variety, v.Priority))
|
||||
.ToList(), vm.MainVarieties.Select(v => (v, 1)).Union(vm.OtherVarieties.Select(v => (v, 2))).ToList());
|
||||
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await App.HintContextChange();
|
||||
}
|
||||
}
|
||||
}
|
101
Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs
Normal file
101
Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace Elwig.ViewModels {
|
||||
public partial class DeliveryScheduleAdminViewModel : ObservableObject {
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _searchQuery = "";
|
||||
public List<string> TextFilter => [.. SearchQuery?.ToLower().Split(' ').ToList().FindAll(e => e.Length > 0)];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _filterOnlyUpcoming;
|
||||
[ObservableProperty]
|
||||
private string? _filterSeasonString;
|
||||
public int? FilterSeason {
|
||||
get => int.TryParse(FilterSeasonString, out var year) ? year : null;
|
||||
set => FilterSeasonString = $"{value}";
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private DeliverySchedule? _selectedDeliverySchedule;
|
||||
[ObservableProperty]
|
||||
private IEnumerable<DeliverySchedule> _deliverySchedules = [];
|
||||
[ObservableProperty]
|
||||
private bool _enableSearchInputs = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _dateString = "";
|
||||
public DateOnly? Date {
|
||||
get => DateOnly.TryParseExact(DateString, "dd.MM.yyyy", out var d) ? d : null;
|
||||
set => DateString = $"{value:dd.MM.yyyy}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private Branch? _branch;
|
||||
[ObservableProperty]
|
||||
private IEnumerable<Branch> _branchSource = [];
|
||||
[ObservableProperty]
|
||||
private string _description = "";
|
||||
[ObservableProperty]
|
||||
private string? _maxWeightString = "";
|
||||
public int? MaxWeight {
|
||||
get => int.TryParse(MaxWeightString, out var w) ? w : null;
|
||||
set => MaxWeightString = $"{value}";
|
||||
}
|
||||
public ObservableCollection<WineVar> MainVarieties { get; set; } = [];
|
||||
[ObservableProperty]
|
||||
private IEnumerable<WineVar> _mainVarietiesSource = [];
|
||||
public ObservableCollection<WineVar> OtherVarieties { get; set; } = [];
|
||||
[ObservableProperty]
|
||||
private IEnumerable<WineVar> _otherVarietiesSource = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private string _ancmtFromDateString = "";
|
||||
public DateOnly? AncmtFromDate {
|
||||
get => DateOnly.TryParseExact(AncmtFromDateString, "dd.MM.yyyy", out var d) ? d : null;
|
||||
set => AncmtFromDateString = $"{value:dd.MM.yyyy}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string _ancmtFromTimeString = "";
|
||||
public TimeOnly? AncmtFromTime {
|
||||
get => TimeOnly.TryParseExact(AncmtFromTimeString, "HH:mm", out var t) ? t : null;
|
||||
set => AncmtFromTimeString = $"{value:HH:mm}";
|
||||
}
|
||||
public DateTime? AncmtFrom {
|
||||
get => AncmtFromDate != null && AncmtFromTime != null ? AncmtFromDate.Value.ToDateTime(AncmtFromTime.Value) : null;
|
||||
set {
|
||||
AncmtFromDateString = $"{value:dd.MM.yyyy}";
|
||||
AncmtFromTimeString = $"{value:HH:mm}";
|
||||
}
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string _ancmtToDateString = "";
|
||||
public DateOnly? AncmtToDate {
|
||||
get => DateOnly.TryParseExact(AncmtToDateString, "dd.MM.yyyy", out var d) ? d : null;
|
||||
set => AncmtToDateString = $"{value:dd.MM.yyyy}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string _ancmtToTimeString = "";
|
||||
public TimeOnly? AncmtToTime {
|
||||
get => TimeOnly.TryParseExact(AncmtToTimeString, "HH:mm", out var t) ? t : null;
|
||||
set => AncmtToTimeString = $"{value:HH:mm}";
|
||||
}
|
||||
public DateTime? AncmtTo {
|
||||
get => AncmtToDate != null && AncmtToTime != null ? AncmtToDate.Value.ToDateTime(AncmtToTime.Value) : null;
|
||||
set {
|
||||
AncmtToDateString = $"{value:dd.MM.yyyy}";
|
||||
AncmtToTimeString = $"{value:HH:mm}";
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private Visibility _controlButtonsVisibility = Visibility.Visible;
|
||||
[ObservableProperty]
|
||||
private Visibility _editingButtonsVisibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
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