Improve DeliveryAdminWindow
This commit is contained in:
@ -2,9 +2,12 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Elwig"
|
||||
xmlns:controls="clr-namespace:Elwig.Controls"
|
||||
StartupUri="Windows\MainWindow.xaml"
|
||||
xmlns:ui="http://schemas.modernwpf.com/2019">
|
||||
<Application.Resources>
|
||||
<controls:BoolToStringConverter x:Key="BoolToStarConverter" FalseValue="" TrueValue="*"/>
|
||||
|
||||
<DataTemplate x:Key="PostalDestTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Dest}"/>
|
||||
@ -63,6 +66,7 @@
|
||||
</ControlTemplate>
|
||||
<ControlTemplate x:Key="WineQualityLevelTemplateExtended">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding IsPredicate, Converter={StaticResource BoolToStarConverter}}" MinWidth="6"/>
|
||||
<TextBlock Text="{Binding Name}" MinWidth="100" Margin="0,0,10,0"/>
|
||||
<TextBlock Text="{Binding MinKmwStr}"/>
|
||||
</StackPanel>
|
||||
|
@ -15,6 +15,8 @@ namespace Elwig {
|
||||
public static readonly string DataPath = @"C:\ProgramData\Elwig\";
|
||||
public static readonly string ExePath = @"C:\Program Files\Elwig\";
|
||||
public static readonly Config Config = new(DataPath + "config.ini");
|
||||
|
||||
public static string ZwstId { get; private set; }
|
||||
public static IEnumerable<IScale> Scales { get; private set; }
|
||||
public static ClientParameters Client { get; private set; }
|
||||
|
||||
@ -30,10 +32,13 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs evt) {
|
||||
IEnumerable<string> branches = Array.Empty<string>();
|
||||
using (var ctx = new AppDbContext()) {
|
||||
if (!ctx.Database.CanConnect()) {
|
||||
MessageBox.Show($"Invalid Database:\n\n{Config.DatabaseFile}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Shutdown();
|
||||
} else {
|
||||
branches = ctx.Branches.Select(b => b.ZwstId).ToList();
|
||||
}
|
||||
}
|
||||
Utils.RunBackground("HTML Initialization", () => Documents.Html.Init(PrintingReadyChanged));
|
||||
@ -62,6 +67,20 @@ namespace Elwig {
|
||||
}
|
||||
Scales = list;
|
||||
|
||||
if (Config.ZwstId != null) {
|
||||
if (!branches.Contains(Config.ZwstId)) {
|
||||
MessageBox.Show("Invalid branch id in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Shutdown();
|
||||
} else {
|
||||
ZwstId = Config.ZwstId;
|
||||
}
|
||||
} else if (branches.Count() == 1) {
|
||||
ZwstId = branches.First();
|
||||
} else {
|
||||
MessageBox.Show("Unable to determine local branch!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
base.OnStartup(evt);
|
||||
}
|
||||
|
||||
|
@ -100,5 +100,13 @@ namespace Elwig.Helpers {
|
||||
.ForEach(a => { if (a <= c + 100) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
public async Task<int> NextLNr(DateOnly date) {
|
||||
var dateStr = date.ToString("yyyy-MM-dd");
|
||||
int c = 0;
|
||||
(await Deliveries.Where(d => d.DateString == dateStr).Select(d => d.LNr).ToListAsync())
|
||||
.ForEach(a => { if (a <= c + 10) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace Elwig.Helpers {
|
||||
private readonly string FileName;
|
||||
public string DatabaseFile = App.DataPath + "database.sqlite3";
|
||||
public string? DatabaseLog = null;
|
||||
public string? ZwstId = null;
|
||||
public IEnumerable<string[]> Scales;
|
||||
private readonly LinkedList<string[]> ScaleList = new();
|
||||
|
||||
@ -43,6 +44,12 @@ namespace Elwig.Helpers {
|
||||
DatabaseLog = App.DataPath + log;
|
||||
}
|
||||
|
||||
if (ini == null || !ini.TryGetKey("general.branch", out string branch)) {
|
||||
ZwstId = null;
|
||||
} else {
|
||||
ZwstId = branch;
|
||||
}
|
||||
|
||||
ScaleList.Clear();
|
||||
Scales = ScaleList;
|
||||
if (ini != null) {
|
||||
|
5
Elwig/Helpers/NullItem.cs
Normal file
5
Elwig/Helpers/NullItem.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Elwig.Helpers {
|
||||
public class NullItem {
|
||||
public static string Name => "- Keine Angabe -";
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ using System.Diagnostics;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO.Ports;
|
||||
using PdfSharp.Charting;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
|
@ -23,6 +23,6 @@ namespace Elwig.Models {
|
||||
[Column("name")]
|
||||
public string Name { get; private set; }
|
||||
|
||||
public string MinKmwStr => (MinKmw == null) ? "" : $"(mind. {MinKmw:#.0} °KMW)";
|
||||
public string MinKmwStr => (MinKmw == null) ? "" : $"(mind. {MinKmw:#.0}°)";
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,30 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Lieferung" Grid.Column="1" Grid.Row="2" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="LieferscheinNr.:" Margin="10,10,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="LsNrInput" Width="125" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,0,0"
|
||||
IsEnabled="False"/>
|
||||
|
||||
<Label Content="Datum/Uhrzeit:" Margin="10,40,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="DateInput" Width="76" Grid.Column="1" HorizontalAlignment="Left" Margin="0,40,0,0"
|
||||
IsEnabled="False"
|
||||
TextChanged="DateInput_TextChanged"/>
|
||||
<TextBox x:Name="TimeInput" Width="44" Grid.Column="1" HorizontalAlignment="Left" Margin="81,40,0,0"
|
||||
IsEnabled="False"/>
|
||||
|
||||
<Label Content="Zweigstelle:" Margin="10,70,0,0" Grid.Column="0"/>
|
||||
<ComboBox x:Name="BranchInput" Width="125" Margin="0,70,10,0" Grid.Column="1" HorizontalAlignment="Left"
|
||||
DisplayMemberPath="Name" TextSearch.TextPath="Name"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Sorte" Grid.Column="2" Grid.Row="1" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -112,27 +136,39 @@
|
||||
|
||||
<GroupBox Header="Gradation" Grid.Column="2" Grid.Row="2" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Width="56" Height="25" Margin="10,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="GradationOeInput" TextAlignment="Right" Padding="2,1,25,2"
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Content="Gradation:" Margin="10,10,10,10"/>
|
||||
<Grid Grid.Column="1" Width="56" Height="25" Margin="0,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="GradationOeInput" TextAlignment="Right" Padding="2,2,25,2"
|
||||
IsReadOnly="False" IsEnabled="True"
|
||||
TextChanged="GradationOeInput_TextChanged" LostFocus="GradationOeInput_LostFocus"/>
|
||||
<Label Content="°Oe" Margin="0,1,3,0" HorizontalAlignment="Right"/>
|
||||
<Label Content="°Oe" Margin="0,2,3,0" HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
<Label Content="=" Margin="72,10,10,10"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Width="72" Height="25" Margin="90,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="GradationKmwInput" TextAlignment="Right" Padding="2,1,38,2"
|
||||
<Label Content="=" Margin="62,10,10,10" Grid.Column="1"/>
|
||||
<Grid Grid.Column="1" Width="72" Height="25" Margin="80,10,10,10" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="GradationKmwInput" TextAlignment="Right" Padding="2,2,39,2" SnapsToDevicePixels="True"
|
||||
IsReadOnly="False" IsEnabled="True"
|
||||
TextChanged="GradationKmwInput_TextChanged" LostFocus="GradationKmwInput_LostFocus"/>
|
||||
<Label Content="°KMW" Margin="0,1,3,0" HorizontalAlignment="Right"/>
|
||||
<Label Content="°KMW" Margin="0,2,3,0" HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
|
||||
<Label Content="Qualitätsstufe:" Margin="10,40,10,10"/>
|
||||
<ComboBox x:Name="WineQualityLevelInput" IsEnabled="True" Margin="100,40,10,10"
|
||||
ItemTemplate="{StaticResource WineQualityLevelTemplate}"/>
|
||||
<ComboBox x:Name="WineQualityLevelInput" IsEnabled="True" Width="152" Margin="0,40,10,10" Grid.Column="1" HorizontalAlignment="Left"
|
||||
ItemTemplate="{StaticResource WineQualityLevelTemplate}"
|
||||
SelectionChanged="WineQualityLevelInput_SelectionChanged"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Zu-/Abschläge" Grid.Column="2" Grid.Row="3" Margin="5,5,5,5">
|
||||
<GroupBox Header="Gewicht" Grid.Column="2" Grid.Row="3" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Zu-/Abschläge" Grid.Column="2" Grid.Row="4" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<xctk:CheckComboBox x:Name="ModifiersInput" IsEnabled="True" Margin="10,10,10,10"
|
||||
ItemTemplate="{StaticResource ModifierTemplate}" Delimiter=", " AllItemsSelectedContent="Alle"
|
||||
@ -140,10 +176,25 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Herkunft" Grid.Column="2" Grid.Row="4" Margin="5,5,5,5">
|
||||
<GroupBox Header="Herkunft" Grid.Column="1" Grid.Row="4" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<ComboBox x:Name="WineOriginInput" IsEnabled="True" Margin="10,10,10,10"
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="Weinbaugebiet:" Margin="10,10,0,10" Grid.Column="0"/>
|
||||
<ComboBox x:Name="WineOriginInput" IsEnabled="True" Margin="0,10,10,10" Grid.Column="1"
|
||||
ItemTemplate="{StaticResource WineOriginTemplate}"/>
|
||||
|
||||
<Label Content="Weinbau-KG:" Margin="10,40,0,10" Grid.Column="0"/>
|
||||
<ComboBox x:Name="WineKgInput" IsEnabled="True" Margin="0,40,10,10" Grid.Column="1"
|
||||
DisplayMemberPath="Name"
|
||||
SelectionChanged="WineKgInput_SelectionChanged"/>
|
||||
|
||||
<Label Content="Ried:" Margin="10,70,0,10" Grid.Column="0"/>
|
||||
<ComboBox x:Name="WineRdInput" IsEnabled="True" Margin="0,70,10,10" Grid.Column="1"
|
||||
DisplayMemberPath="Name"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
@ -1,8 +1,11 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
@ -10,6 +13,8 @@ namespace Elwig.Windows {
|
||||
|
||||
private bool IsUpdatingGradation = false;
|
||||
|
||||
private DispatcherTimer dispatcherTimer;
|
||||
|
||||
public DeliveryAdminWindow() {
|
||||
InitializeComponent();
|
||||
RequiredInputs = new Control[] {
|
||||
@ -17,21 +22,35 @@ namespace Elwig.Windows {
|
||||
SortIdInput, WineVarietyInput,
|
||||
GradationOeInput, GradationKmwInput,
|
||||
WineQualityLevelInput,
|
||||
WineOriginInput,
|
||||
WineOriginInput, WineKgInput
|
||||
};
|
||||
ExemptInputs = new Control[] {
|
||||
MgNrInput, MemberInput,
|
||||
MemberAddressField
|
||||
};
|
||||
|
||||
dispatcherTimer = new DispatcherTimer();
|
||||
dispatcherTimer.Tick += new EventHandler(OnSecondPassed);
|
||||
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
|
||||
dispatcherTimer.Start();
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
MemberInput.ItemsSource = Context.Members.OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToList();
|
||||
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
|
||||
BranchInput.SelectedItem = BranchInput.ItemsSource.Cast<Branch>().Where(b => b.ZwstId == App.ZwstId).First();
|
||||
WineVarietyInput.ItemsSource = Context.WineVarieties.OrderBy(v => v.Name).ToList();
|
||||
AttributesInput.ItemsSource = Context.WineAttributes.OrderBy(a => a.Name).ToList();
|
||||
WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.ToList();
|
||||
ModifiersInput.ItemsSource = Context.Modifiers.Where(m => m.Season.Year == 2022).OrderBy(m => m.Name).ToList();
|
||||
WineOriginInput.ItemsSource = Context.WineOrigins.ToList().OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId);
|
||||
WineKgInput.ItemsSource = Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToList();
|
||||
}
|
||||
|
||||
private void OnSecondPassed(object? sender, EventArgs evt) {
|
||||
var now = DateTime.Now;
|
||||
TimeInput.Text = now.ToString("HH:mm");
|
||||
DateInput.Text = now.ToString("dd.MM.yyyy");
|
||||
}
|
||||
|
||||
protected override void UpdateButtons() {
|
||||
@ -52,6 +71,14 @@ namespace Elwig.Windows {
|
||||
var m = MemberInput.SelectedItem as Member;
|
||||
if (m != null) MgNrInput.Text = m.MgNr.ToString();
|
||||
MemberAddressField.Text = m?.FullAddress;
|
||||
WineKgInput.SelectedItem = m?.DefaultKg;
|
||||
}
|
||||
|
||||
private void DateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
var branch = (Branch)BranchInput.SelectedItem;
|
||||
var date = DateOnly.ParseExact(DateInput.Text, "dd.MM.yyyy");
|
||||
var lnr = Context.NextLNr(date).GetAwaiter().GetResult();
|
||||
LsNrInput.Text = $"{date.ToString("yyyyMMdd")}{branch.ZwstId}{lnr:000}";
|
||||
}
|
||||
|
||||
private void UpdateWineVariety(bool valid) {
|
||||
@ -135,5 +162,31 @@ namespace Elwig.Windows {
|
||||
private void ModifiersInput_SelectionChanged(object sender, ItemSelectionChangedEventArgs evt) {
|
||||
|
||||
}
|
||||
|
||||
private void UpdateWineOrigin() {
|
||||
var qual = (WineQualLevel)WineQualityLevelInput.SelectedItem;
|
||||
var kg = ((AT_Kg)WineKgInput.SelectedItem)?.WbKg;
|
||||
if (qual == null || kg == null) return;
|
||||
var o = kg.Origin;
|
||||
while (o != null && o.Level > qual.OriginLevel) o = o.Parent;
|
||||
WineOriginInput.SelectedItem = o;
|
||||
}
|
||||
|
||||
private void WineQualityLevelInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
UpdateWineOrigin();
|
||||
}
|
||||
|
||||
private void WineKgInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
UpdateWineOrigin();
|
||||
var kg = (AT_Kg)WineKgInput.SelectedItem;
|
||||
if (kg != null) {
|
||||
var list = Context.WbRde.Where(r => r.KgNr == kg.KgNr).OrderBy(r => r.Name).Cast<object>().ToList();
|
||||
list.Insert(0, new NullItem());
|
||||
WineRdInput.ItemsSource = list;
|
||||
WineRdInput.SelectedIndex = 0;
|
||||
} else {
|
||||
WineRdInput.ItemsSource = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user