Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70e1e7c73a |
@@ -2,26 +2,6 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
[v1.1.1.2][v1.1.1.2] (2026-08-25) {#v1.1.1.2}
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
### Sonstiges {#v1.1.1.2-misc}
|
|
||||||
|
|
||||||
* In Matzen werden für Planenw./Kipper und Lesewagen die Klassen automatisch gesetzt. (3366cc25eb)
|
|
||||||
* Im Lieferungen-Fenster (`DeliveryAdminWindow`) wird für "Nur heute" nicht mehr nur das Datum, sondern die letzten zusammenhängenden Lieferungen verwendet. (46e596ae23)
|
|
||||||
* Für Pamhagen wird als standard Wiege-Methode "brutto" verwendet. (0c4611024f)
|
|
||||||
* Für Waagen kann das automatische setzen von Datum und Uhrzeit nun per Opt-out ausgeschalten werden (Konfigurationsdatei -> `[scale.X]` -> `synctime = false`). (f450dc35b1)
|
|
||||||
|
|
||||||
### Behobene Fehler {#v1.1.1.2-bugfixes}
|
|
||||||
|
|
||||||
* Auf Lieferscheinen (`DeliveryNote`) waren die Mengenangaben nicht rechtsbündig. (ff71e9fb7f)
|
|
||||||
* Beim Importieren von Mitgliedern mit Stamm-KG ohne Großlage kam es zu einem Fehler, obwohl die Großlage automatisch hätte zugewiesen werden müssen. (edf3678154)
|
|
||||||
|
|
||||||
[v1.1.1.2]: https://git.necronda.net/winzer/elwig/releases/tag/v1.1.1.2
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[v1.1.1.1][v1.1.1.1] (2026-08-24) {#v1.1.1.1}
|
[v1.1.1.1][v1.1.1.1] (2026-08-24) {#v1.1.1.1}
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
||||||
|
|||||||
+18
-2
@@ -28,6 +28,8 @@ namespace Elwig {
|
|||||||
public static bool ForceShutdown { get; private set; } = false;
|
public static bool ForceShutdown { get; private set; } = false;
|
||||||
|
|
||||||
private readonly DispatcherTimer _autoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
private readonly DispatcherTimer _autoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||||
|
private readonly DispatcherTimer _autoBackupTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||||
|
private DatabaseBackupService? _databaseBackupService;
|
||||||
public readonly SerialPortWatcher SerialPortWatcher = new();
|
public readonly SerialPortWatcher SerialPortWatcher = new();
|
||||||
|
|
||||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Elwig");
|
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Elwig");
|
||||||
@@ -101,6 +103,13 @@ namespace Elwig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Config.DatabaseBackup) {
|
||||||
|
_databaseBackupService = new DatabaseBackupService(Config.DatabaseFile);
|
||||||
|
await _databaseBackupService.RunIfNeededAsync();
|
||||||
|
_autoBackupTimer.Tick += OnAutoBackupTimer;
|
||||||
|
_autoBackupTimer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
LastChanged = CurrentLastWrite;
|
LastChanged = CurrentLastWrite;
|
||||||
ContextTimer.Start();
|
ContextTimer.Start();
|
||||||
|
|
||||||
@@ -146,7 +155,7 @@ namespace Elwig {
|
|||||||
foreach (var s in Config.Scales) {
|
foreach (var s in Config.Scales) {
|
||||||
try {
|
try {
|
||||||
var scale = Scale.FromConfig(s);
|
var scale = Scale.FromConfig(s);
|
||||||
if (s.SyncTime && scale is ICommandScale cmd) {
|
if (scale is ICommandScale cmd) {
|
||||||
try {
|
try {
|
||||||
await cmd.SetDateAndTime(DateTime.Now);
|
await cmd.SetDateAndTime(DateTime.Now);
|
||||||
} catch { }
|
} catch { }
|
||||||
@@ -179,7 +188,7 @@ namespace Elwig {
|
|||||||
Config.WeighingMode = WeighingMode.Net;
|
Config.WeighingMode = WeighingMode.Net;
|
||||||
} else if (Client.IsHaugsdorf || Client.IsSitzendorf) {
|
} else if (Client.IsHaugsdorf || Client.IsSitzendorf) {
|
||||||
Config.WeighingMode = WeighingMode.Box;
|
Config.WeighingMode = WeighingMode.Box;
|
||||||
} else if (Client.IsBaden || Client.IsGrInzersdorf || Client.IsPamhagen) {
|
} else if (Client.IsBaden || Client.IsGrInzersdorf) {
|
||||||
Config.WeighingMode = WeighingMode.Gross;
|
Config.WeighingMode = WeighingMode.Gross;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,6 +200,7 @@ namespace Elwig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async void Application_Exit(object sender, ExitEventArgs evt) {
|
private async void Application_Exit(object sender, ExitEventArgs evt) {
|
||||||
|
_autoBackupTimer.Stop();
|
||||||
SerialPortWatcher.Dispose();
|
SerialPortWatcher.Dispose();
|
||||||
foreach (var s in EventScales) {
|
foreach (var s in EventScales) {
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
@@ -198,6 +208,12 @@ namespace Elwig {
|
|||||||
await Pdf.Cleanup();
|
await Pdf.Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void OnAutoBackupTimer(object? sender, EventArgs evt) {
|
||||||
|
if (_databaseBackupService != null) {
|
||||||
|
await _databaseBackupService.RunIfNeededAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetBranch(Branch b) {
|
public static void SetBranch(Branch b) {
|
||||||
SetBranch((b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr));
|
SetBranch((b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace Elwig.Documents {
|
|||||||
.AddCell(NewDeliveryMainTd(part.Quality.Name))
|
.AddCell(NewDeliveryMainTd(part.Quality.Name))
|
||||||
.AddCell(NewDeliveryMainTd($"{part.Oe:N0}", center: true))
|
.AddCell(NewDeliveryMainTd($"{part.Oe:N0}", center: true))
|
||||||
.AddCell(NewDeliveryMainTd($"{part.Kmw:N1}", center: true))
|
.AddCell(NewDeliveryMainTd($"{part.Kmw:N1}", center: true))
|
||||||
.AddCell(NewDeliveryMainTd($"{part.Weight:N0}", right: true));
|
.AddCell(NewDeliveryMainTd($"{part.Weight:N0}", center: true));
|
||||||
|
|
||||||
if (part.Cultivation != null) {
|
if (part.Cultivation != null) {
|
||||||
var cult = new KernedParagraph(8);
|
var cult = new KernedParagraph(8);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Elwig.Documents {
|
|||||||
public Document(string title) {
|
public Document(string title) {
|
||||||
Title = title;
|
Title = title;
|
||||||
Author = App.Client.NameFull;
|
Author = App.Client.NameFull;
|
||||||
Date = DateOnly.FromDateTime(DateTime.Today);
|
Date = DateOnly.FromDateTime(Utils.Today);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Document() {
|
~Document() {
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||||
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
|
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
|
||||||
<Version>1.1.1.2</Version>
|
<Version>1.1.1.1</Version>
|
||||||
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<ApplicationManifest>App.manifest</ApplicationManifest>
|
<ApplicationManifest>App.manifest</ApplicationManifest>
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ namespace Elwig.Helpers {
|
|||||||
public string? Filling;
|
public string? Filling;
|
||||||
public string? Limit;
|
public string? Limit;
|
||||||
public bool Required;
|
public bool Required;
|
||||||
public bool SyncTime;
|
|
||||||
public string? Log;
|
public string? Log;
|
||||||
public string? _Log;
|
public string? _Log;
|
||||||
|
|
||||||
public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, bool? required, bool? syncTime, string? log) {
|
public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, bool? required, string? log) {
|
||||||
Id = id;
|
Id = id;
|
||||||
Type = type;
|
Type = type;
|
||||||
Model = model;
|
Model = model;
|
||||||
@@ -30,7 +29,6 @@ namespace Elwig.Helpers {
|
|||||||
Filling = filling;
|
Filling = filling;
|
||||||
Limit = limit;
|
Limit = limit;
|
||||||
Required = required ?? true;
|
Required = required ?? true;
|
||||||
SyncTime = syncTime ?? true;
|
|
||||||
_Log = log;
|
_Log = log;
|
||||||
Log = log != null ? Path.Combine(App.DataPath, log) : null;
|
Log = log != null ? Path.Combine(App.DataPath, log) : null;
|
||||||
}
|
}
|
||||||
@@ -39,12 +37,12 @@ namespace Elwig.Helpers {
|
|||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
private static readonly string[] TrueValues = ["1", "true", "yes", "on"];
|
private static readonly string[] TrueValues = ["1", "true", "yes", "on"];
|
||||||
private static readonly string[] FalseValues = ["0", "false", "no", "off"];
|
|
||||||
|
|
||||||
private readonly string FileName;
|
private readonly string FileName;
|
||||||
|
|
||||||
public bool Debug;
|
public bool Debug;
|
||||||
public string DatabaseFile = Path.Combine(App.DataPath, "database.sqlite3");
|
public string DatabaseFile = App.DataPath + "database.sqlite3";
|
||||||
|
public bool DatabaseBackup = true;
|
||||||
public string? DatabaseLog = null;
|
public string? DatabaseLog = null;
|
||||||
public string? Branch = null;
|
public string? Branch = null;
|
||||||
public WeighingMode? WeighingMode;
|
public WeighingMode? WeighingMode;
|
||||||
@@ -79,6 +77,8 @@ namespace Elwig.Helpers {
|
|||||||
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
||||||
|
|
||||||
DatabaseFile = Path.Combine(Path.GetDirectoryName(FileName) ?? App.DataPath, config["database:file"] ?? "database.sqlite3");
|
DatabaseFile = Path.Combine(Path.GetDirectoryName(FileName) ?? App.DataPath, config["database:file"] ?? "database.sqlite3");
|
||||||
|
var backup = config["database:backup"];
|
||||||
|
DatabaseBackup = backup == null || TrueValues.Contains(backup.ToLower());
|
||||||
var log = config["database:log"];
|
var log = config["database:log"];
|
||||||
DatabaseLog = log != null ? Path.Combine(Path.GetDirectoryName(FileName) ?? App.DataPath, log) : null;
|
DatabaseLog = log != null ? Path.Combine(Path.GetDirectoryName(FileName) ?? App.DataPath, log) : null;
|
||||||
Branch = config["general:branch"];
|
Branch = config["general:branch"];
|
||||||
@@ -108,7 +108,6 @@ namespace Elwig.Helpers {
|
|||||||
s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"],
|
s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"],
|
||||||
config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"],
|
config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"],
|
||||||
config[$"scale.{s}:required"] != null ? TrueValues.Contains(config[$"scale.{s}:required"]?.ToLower()) : null,
|
config[$"scale.{s}:required"] != null ? TrueValues.Contains(config[$"scale.{s}:required"]?.ToLower()) : null,
|
||||||
config[$"scale.{s}:synctime"] != null ? !FalseValues.Contains(config[$"scale.{s}:synctime"]?.ToLower()) : null,
|
|
||||||
config[$"scale.{s}:log"]
|
config[$"scale.{s}:log"]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Elwig.Helpers {
|
||||||
|
internal sealed class DatabaseBackupService {
|
||||||
|
|
||||||
|
private const int DailyBackupCount = 7;
|
||||||
|
private const int WeeklyBackupCount = 5;
|
||||||
|
|
||||||
|
private readonly string DatabaseFile;
|
||||||
|
private readonly string BackupDirectory;
|
||||||
|
private readonly string DatabaseName;
|
||||||
|
private readonly string BackupPrefix;
|
||||||
|
private readonly string LockFile;
|
||||||
|
private readonly Func<DateTime> Now;
|
||||||
|
private readonly SemaphoreSlim Gate = new(1, 1);
|
||||||
|
|
||||||
|
internal DatabaseBackupService(string databaseFile, Func<DateTime>? now = null) {
|
||||||
|
DatabaseFile = Path.GetFullPath(databaseFile);
|
||||||
|
BackupDirectory = Path.Combine(Path.GetDirectoryName(DatabaseFile)!, "backup");
|
||||||
|
DatabaseName = Path.GetFileNameWithoutExtension(DatabaseFile);
|
||||||
|
BackupPrefix = $"{DatabaseName}_";
|
||||||
|
LockFile = Path.Combine(BackupDirectory, $".{DatabaseName}.backup.lock");
|
||||||
|
Now = now ?? (() => DateTime.Now);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task RunIfNeededAsync() {
|
||||||
|
if (!await Gate.WaitAsync(0)) return;
|
||||||
|
try {
|
||||||
|
var slotDate = GetSlotDate(Now());
|
||||||
|
await Task.Run(() => Run(slotDate));
|
||||||
|
} catch {
|
||||||
|
// Automatic backups dont prevent Elwig from starting or running.
|
||||||
|
} finally {
|
||||||
|
Gate.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Run(DateOnly slotDate) {
|
||||||
|
Directory.CreateDirectory(BackupDirectory);
|
||||||
|
|
||||||
|
FileStream lockStream;
|
||||||
|
try {
|
||||||
|
lockStream = new FileStream(LockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||||
|
} catch (IOException) {
|
||||||
|
// Another Elwig instance is currently creating/pruning backups.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (lockStream) {
|
||||||
|
CleanupTemporaryFiles();
|
||||||
|
|
||||||
|
var backupFile = GetBackupFile(slotDate);
|
||||||
|
if (!File.Exists(backupFile)) {
|
||||||
|
CreateBackup(backupFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(backupFile)) {
|
||||||
|
PruneBackups(slotDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateBackup(string backupFile) {
|
||||||
|
var id = Guid.NewGuid().ToString("N");
|
||||||
|
var temporaryDatabase = Path.Combine(BackupDirectory, $".{DatabaseName}.backup-{id}.sqlite3.tmp");
|
||||||
|
var temporaryArchive = Path.Combine(BackupDirectory, $".{DatabaseName}.backup-{id}.zip.tmp");
|
||||||
|
|
||||||
|
try {
|
||||||
|
var sourceConnectionString = new SqliteConnectionStringBuilder {
|
||||||
|
DataSource = DatabaseFile,
|
||||||
|
Mode = SqliteOpenMode.ReadOnly,
|
||||||
|
Cache = SqliteCacheMode.Default,
|
||||||
|
Pooling = false,
|
||||||
|
}.ToString();
|
||||||
|
var destinationConnectionString = new SqliteConnectionStringBuilder {
|
||||||
|
DataSource = temporaryDatabase,
|
||||||
|
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||||
|
Cache = SqliteCacheMode.Default,
|
||||||
|
Pooling = false,
|
||||||
|
}.ToString();
|
||||||
|
|
||||||
|
using (var source = new SqliteConnection(sourceConnectionString))
|
||||||
|
using (var destination = new SqliteConnection(destinationConnectionString)) {
|
||||||
|
source.Open();
|
||||||
|
destination.Open();
|
||||||
|
source.BackupDatabase(destination);
|
||||||
|
|
||||||
|
using var check = destination.CreateCommand();
|
||||||
|
check.CommandText = "PRAGMA quick_check";
|
||||||
|
if (!string.Equals(check.ExecuteScalar()?.ToString(), "ok", StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
throw new InvalidDataException("The automatic database backup failed its SQLite integrity check.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var archive = ZipFile.Open(temporaryArchive, ZipArchiveMode.Create)) {
|
||||||
|
archive.CreateEntryFromFile(temporaryDatabase, "database.sqlite3", CompressionLevel.SmallestSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File.Move(temporaryArchive, backupFile, false);
|
||||||
|
} catch (IOException) when (File.Exists(backupFile)) {
|
||||||
|
// A completed backup won a publish race. Its time slot is satisfied.
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
DeleteFile(temporaryDatabase);
|
||||||
|
DeleteFile(temporaryArchive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CleanupTemporaryFiles() {
|
||||||
|
foreach (var file in Directory.EnumerateFiles(BackupDirectory, $".{DatabaseName}.backup-*.tmp")) {
|
||||||
|
DeleteFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void PruneBackups(DateOnly slotDate) {
|
||||||
|
var backups = GetManagedBackups().ToArray();
|
||||||
|
var retained = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
var dailyStart = slotDate.AddDays(-(DailyBackupCount - 1));
|
||||||
|
foreach (var backup in backups.Where(b => b.Date >= dailyStart && b.Date <= slotDate)) {
|
||||||
|
retained.Add(backup.File);
|
||||||
|
}
|
||||||
|
|
||||||
|
var daysSinceMonday = ((int)slotDate.DayOfWeek + 6) % 7;
|
||||||
|
var currentWeekStart = slotDate.AddDays(-daysSinceMonday);
|
||||||
|
for (var i = 1; i <= WeeklyBackupCount; i++) {
|
||||||
|
var weekStart = currentWeekStart.AddDays(-7 * i);
|
||||||
|
RetainNewest(backups, retained, weekStart, weekStart.AddDays(7));
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentMonthStart = new DateOnly(slotDate.Year, slotDate.Month, 1);
|
||||||
|
foreach (var month in backups
|
||||||
|
.Where(b => b.Date < currentMonthStart)
|
||||||
|
.GroupBy(b => (b.Date.Year, b.Date.Month))) {
|
||||||
|
retained.Add(month.OrderByDescending(b => b.Date).First().File);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clock corrections should not cause future-dated backups to be deleted.
|
||||||
|
foreach (var backup in backups.Where(b => b.Date > slotDate)) {
|
||||||
|
retained.Add(backup.File);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var backup in backups.Where(b => !retained.Contains(b.File))) {
|
||||||
|
DeleteFile(backup.File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RetainNewest(
|
||||||
|
IEnumerable<(string File, DateOnly Date)> backups,
|
||||||
|
ISet<string> retained,
|
||||||
|
DateOnly start,
|
||||||
|
DateOnly end
|
||||||
|
) {
|
||||||
|
var newest = backups
|
||||||
|
.Where(b => b.Date >= start && b.Date < end)
|
||||||
|
.OrderByDescending(b => b.Date)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (newest.File != null) retained.Add(newest.File);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<(string File, DateOnly Date)> GetManagedBackups() {
|
||||||
|
foreach (var file in Directory.EnumerateFiles(BackupDirectory, $"{BackupPrefix}*.sqlite3.zip")) {
|
||||||
|
var name = Path.GetFileName(file);
|
||||||
|
if (!name.StartsWith(BackupPrefix, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
!name.EndsWith(".sqlite3.zip", StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dateText = name[BackupPrefix.Length..^".sqlite3.zip".Length];
|
||||||
|
if (DateOnly.TryParseExact(dateText, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date)) {
|
||||||
|
yield return (file, date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetBackupFile(DateOnly date) {
|
||||||
|
return Path.Combine(BackupDirectory, $"{BackupPrefix}{date:yyyy-MM-dd}.sqlite3.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DeleteFile(string file) {
|
||||||
|
try {
|
||||||
|
File.Delete(file);
|
||||||
|
} catch {
|
||||||
|
// Cleanup and retention are best-effort and will be retried later.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static DateOnly GetSlotDate(DateTime timestamp) {
|
||||||
|
return DateOnly.FromDateTime(timestamp.Hour >= 3 ? timestamp : timestamp.AddDays(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ using System.IO.Compression;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace Elwig.Helpers.Export {
|
namespace Elwig.Helpers.Export {
|
||||||
public static class ElwigData {
|
public static class ElwigData {
|
||||||
@@ -35,16 +36,14 @@ namespace Elwig.Helpers.Export {
|
|||||||
public static async Task Import(IEnumerable<string> filenames, ImportMode mode) {
|
public static async Task Import(IEnumerable<string> filenames, ImportMode mode) {
|
||||||
try {
|
try {
|
||||||
Dictionary<string, Branch> branches;
|
Dictionary<string, Branch> branches;
|
||||||
Dictionary<int, AT_Kg> kgs;
|
|
||||||
Dictionary<int, int> currentDids;
|
Dictionary<int, int> currentDids;
|
||||||
Dictionary<string, int> currentLsNrs;
|
Dictionary<string, int> currentLsNrs;
|
||||||
Dictionary<int, List<WbRd>> currentWbRde;
|
Dictionary<int, List<WbRd>> currentWbRde;
|
||||||
Dictionary<int, WbKg> currentWbKgs;
|
Dictionary<int, AT_Kg> kgs;
|
||||||
List<WbGl> currentWbGls;
|
List<WbGl> currentWbGls;
|
||||||
|
|
||||||
using (var ctx = new AppDbContext()) {
|
using (var ctx = new AppDbContext()) {
|
||||||
branches = await ctx.FetchBranches().ToDictionaryAsync(b => b.ZwstId);
|
branches = await ctx.FetchBranches().ToDictionaryAsync(b => b.ZwstId);
|
||||||
kgs = await ctx.Katastralgemeinden.ToDictionaryAsync(k => k.KgNr);
|
|
||||||
currentDids = await ctx.Deliveries
|
currentDids = await ctx.Deliveries
|
||||||
.GroupBy(d => d.Year)
|
.GroupBy(d => d.Year)
|
||||||
.ToDictionaryAsync(g => g.Key, g => g.Max(d => d.DId));
|
.ToDictionaryAsync(g => g.Key, g => g.Max(d => d.DId));
|
||||||
@@ -53,8 +52,8 @@ namespace Elwig.Helpers.Export {
|
|||||||
currentWbRde = await ctx.WbRde
|
currentWbRde = await ctx.WbRde
|
||||||
.GroupBy(r => r.KgNr)
|
.GroupBy(r => r.KgNr)
|
||||||
.ToDictionaryAsync(g => g.Key, g => g.ToList());
|
.ToDictionaryAsync(g => g.Key, g => g.ToList());
|
||||||
currentWbKgs = await ctx.WbKgs.ToDictionaryAsync(k => k.KgNr);
|
|
||||||
currentWbGls = await ctx.WbGls.ToListAsync();
|
currentWbGls = await ctx.WbGls.ToListAsync();
|
||||||
|
kgs = await ctx.Katastralgemeinden.Include(k => k.WbKg).ToDictionaryAsync(k => k.KgNr);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = new List<(
|
var data = new List<(
|
||||||
@@ -123,7 +122,6 @@ namespace Elwig.Helpers.Export {
|
|||||||
var obj = JsonNode.Parse(line)!.AsObject();
|
var obj = JsonNode.Parse(line)!.AsObject();
|
||||||
var (k, g) = obj.ToWbKg(currentWbGls);
|
var (k, g) = obj.ToWbKg(currentWbGls);
|
||||||
r.WbKgs.Add(k);
|
r.WbKgs.Add(k);
|
||||||
currentWbKgs[k.KgNr] = k;
|
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
currentWbGls[g.GlNr] = g;
|
currentWbGls[g.GlNr] = g;
|
||||||
r.WbGls.Add(g);
|
r.WbGls.Add(g);
|
||||||
@@ -137,7 +135,7 @@ namespace Elwig.Helpers.Export {
|
|||||||
string? line;
|
string? line;
|
||||||
while ((line = await reader.ReadLineAsync()) != null) {
|
while ((line = await reader.ReadLineAsync()) != null) {
|
||||||
var obj = JsonNode.Parse(line)!.AsObject();
|
var obj = JsonNode.Parse(line)!.AsObject();
|
||||||
var (m, b, telNrs, emailAddrs, timestamps) = obj.ToMember(kgs, currentWbKgs);
|
var (m, b, telNrs, emailAddrs, timestamps) = obj.ToMember(kgs);
|
||||||
r.Members.Add(m);
|
r.Members.Add(m);
|
||||||
if (b != null) r.BillingAddresses.Add(b);
|
if (b != null) r.BillingAddresses.Add(b);
|
||||||
r.TelephoneNumbers.AddRange(telNrs);
|
r.TelephoneNumbers.AddRange(telNrs);
|
||||||
@@ -165,7 +163,7 @@ namespace Elwig.Helpers.Export {
|
|||||||
string? line;
|
string? line;
|
||||||
while ((line = await reader.ReadLineAsync()) != null) {
|
while ((line = await reader.ReadLineAsync()) != null) {
|
||||||
var obj = JsonNode.Parse(line)!.AsObject();
|
var obj = JsonNode.Parse(line)!.AsObject();
|
||||||
var (contract, areaCom, wbrd, timestamps) = obj.ToAreaCom(kgs, currentWbKgs, currentWbRde);
|
var (contract, areaCom, wbrd, timestamps) = obj.ToAreaCom(currentWbRde);
|
||||||
r.Contracts.Add(contract);
|
r.Contracts.Add(contract);
|
||||||
r.AreaCommitments.Add(areaCom);
|
r.AreaCommitments.Add(areaCom);
|
||||||
if (wbrd != null) {
|
if (wbrd != null) {
|
||||||
@@ -184,7 +182,7 @@ namespace Elwig.Helpers.Export {
|
|||||||
string? line;
|
string? line;
|
||||||
while ((line = await reader.ReadLineAsync()) != null) {
|
while ((line = await reader.ReadLineAsync()) != null) {
|
||||||
var obj = JsonNode.Parse(line)!.AsObject();
|
var obj = JsonNode.Parse(line)!.AsObject();
|
||||||
var (contract, areaComs, wbrd, timestamps) = obj.ToAreaComContract(kgs, currentWbKgs, currentWbRde);
|
var (contract, areaComs, wbrd, timestamps) = obj.ToAreaComContract(currentWbRde);
|
||||||
r.Contracts.Add(contract);
|
r.Contracts.Add(contract);
|
||||||
r.AreaCommitments.AddRange(areaComs.Select(v => v.Item1));
|
r.AreaCommitments.AddRange(areaComs.Select(v => v.Item1));
|
||||||
if (wbrd != null) {
|
if (wbrd != null) {
|
||||||
@@ -205,7 +203,7 @@ namespace Elwig.Helpers.Export {
|
|||||||
string? line;
|
string? line;
|
||||||
while ((line = await reader.ReadLineAsync()) != null) {
|
while ((line = await reader.ReadLineAsync()) != null) {
|
||||||
var obj = JsonNode.Parse(line)!.AsObject();
|
var obj = JsonNode.Parse(line)!.AsObject();
|
||||||
var (d, parts, mods, rde, timestamps) = obj.ToDelivery(currentLsNrs, currentDids, kgs, currentWbKgs, currentWbRde);
|
var (d, parts, mods, rde, timestamps) = obj.ToDelivery(currentLsNrs, currentDids, kgs, currentWbRde);
|
||||||
r.Deliveries.Add(d);
|
r.Deliveries.Add(d);
|
||||||
r.DeliveryParts.AddRange(parts.Select(p => p.Item1));
|
r.DeliveryParts.AddRange(parts.Select(p => p.Item1));
|
||||||
r.Modifiers.AddRange(mods);
|
r.Modifiers.AddRange(mods);
|
||||||
@@ -682,11 +680,11 @@ namespace Elwig.Helpers.Export {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (Member, BillingAddr?, List<MemberTelNr>, List<MemberEmailAddr>, (DateTime CreatedAt, DateTime ModifiedAt)?) ToMember(this JsonNode json, Dictionary<int, AT_Kg> kgs, Dictionary<int, WbKg> currentWbKgs) {
|
public static (Member, BillingAddr?, List<MemberTelNr>, List<MemberEmailAddr>, (DateTime CreatedAt, DateTime ModifiedAt)?) ToMember(this JsonNode json, Dictionary<int, AT_Kg> kgs) {
|
||||||
var mgnr = json["mgnr"]!.AsValue().GetValue<int>();
|
var mgnr = json["mgnr"]!.AsValue().GetValue<int>();
|
||||||
var kgnr = json["default_kgnr"]?.AsValue().GetValue<int>();
|
var kgnr = json["default_kgnr"]?.AsValue().GetValue<int>();
|
||||||
if (kgnr != null && !currentWbKgs.Values.Any(k => k.KgNr == kgnr)) {
|
if (kgnr != null && !kgs.Values.Any(k => k.WbKg?.KgNr == kgnr)) {
|
||||||
throw new KeyNotFoundException($"Für KG {(kgs.TryGetValue(kgnr.Value, out var k) ? k.Name : "?")} ({kgnr:00000}) ist noch keine Großlage festgelegt!\n(Stammdaten \u2192 Herkunftshierarchie)");
|
throw new ArgumentException($"Für KG {(kgs.TryGetValue(kgnr.Value, out var k) ? k.Name : "?")} ({kgnr:00000}) ist noch keine Großlage festgelegt!\n(Stammdaten → Herkunftshierarchie)");
|
||||||
}
|
}
|
||||||
var createdAt = json["created_at"]?.AsValue().GetValue<string>();
|
var createdAt = json["created_at"]?.AsValue().GetValue<string>();
|
||||||
var modifiedAt = json["modified_at"]?.AsValue().GetValue<string>();
|
var modifiedAt = json["modified_at"]?.AsValue().GetValue<string>();
|
||||||
@@ -817,13 +815,10 @@ namespace Elwig.Helpers.Export {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (AreaComContract, List<(AreaCom, (DateTime CreatedAt, DateTime ModifiedAt)?)>, WbRd?, (DateTime CreatedAt, DateTime ModifiedAt)?) ToAreaComContract(this JsonNode json, Dictionary<int, AT_Kg> kgs, Dictionary<int, WbKg> currentWbKgs, Dictionary<int, List<WbRd>> riede) {
|
public static (AreaComContract, List<(AreaCom, (DateTime CreatedAt, DateTime ModifiedAt)?)>, WbRd?, (DateTime CreatedAt, DateTime ModifiedAt)?) ToAreaComContract(this JsonNode json, Dictionary<int, List<WbRd>> riede) {
|
||||||
var kgnr = json["kgnr"]!.AsValue().GetValue<int>();
|
var kgnr = json["kgnr"]!.AsValue().GetValue<int>();
|
||||||
var ried = json["ried"]?.AsValue().GetValue<string>();
|
var ried = json["ried"]?.AsValue().GetValue<string>();
|
||||||
var fbnr = json["fbnr"]!.AsValue()!.GetValue<int>();
|
var fbnr = json["fbnr"]!.AsValue()!.GetValue<int>();
|
||||||
if (!currentWbKgs.Values.Any(k => k.KgNr == kgnr)) {
|
|
||||||
throw new KeyNotFoundException($"Für KG {(kgs.TryGetValue(kgnr, out var k) ? k.Name : "?")} ({kgnr:00000}) ist noch keine Großlage festgelegt!\n(Stammdaten \u2192 Herkunftshierarchie)");
|
|
||||||
}
|
|
||||||
WbRd? rd = null;
|
WbRd? rd = null;
|
||||||
bool newRd = false;
|
bool newRd = false;
|
||||||
if (ried != null) {
|
if (ried != null) {
|
||||||
@@ -871,12 +866,9 @@ namespace Elwig.Helpers.Export {
|
|||||||
DateTime.ParseExact(modifiedAt, "yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture, DateTimeStyles.None)));
|
DateTime.ParseExact(modifiedAt, "yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture, DateTimeStyles.None)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (AreaComContract, AreaCom, WbRd?, (DateTime CreatedAt, DateTime ModifiedAt)?) ToAreaCom(this JsonNode json, Dictionary<int, AT_Kg> kgs, Dictionary<int, WbKg> currentWbKgs, Dictionary<int, List<WbRd>> riede) {
|
public static (AreaComContract, AreaCom, WbRd?, (DateTime CreatedAt, DateTime ModifiedAt)?) ToAreaCom(this JsonNode json, Dictionary<int, List<WbRd>> riede) {
|
||||||
var kgnr = json["kgnr"]!.AsValue().GetValue<int>();
|
var kgnr = json["kgnr"]!.AsValue().GetValue<int>();
|
||||||
var ried = json["ried"]?.AsValue().GetValue<string>();
|
var ried = json["ried"]?.AsValue().GetValue<string>();
|
||||||
if (!currentWbKgs.Values.Any(k => k.KgNr == kgnr)) {
|
|
||||||
throw new KeyNotFoundException($"Für KG {(kgs.TryGetValue(kgnr, out var k) ? k.Name : "?")} ({kgnr:00000}) ist noch keine Großlage festgelegt!\n(Stammdaten \u2192 Herkunftshierarchie)");
|
|
||||||
}
|
|
||||||
WbRd? rd = null;
|
WbRd? rd = null;
|
||||||
bool newRd = false;
|
bool newRd = false;
|
||||||
if (ried != null) {
|
if (ried != null) {
|
||||||
@@ -965,7 +957,7 @@ namespace Elwig.Helpers.Export {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (Delivery, List<(DeliveryPart, (DateTime CreatedAt, DateTime ModifiedAt)?)>, List<DeliveryPartModifier>, List<WbRd>, (DateTime CreatedAt, DateTime ModifiedAt)?) ToDelivery(this JsonNode json, Dictionary<string, int> currentLsNrs, Dictionary<int, int> currentDids, Dictionary<int, AT_Kg> kgs, Dictionary<int, WbKg> currentWbKgs, Dictionary<int, List<WbRd>> riede) {
|
public static (Delivery, List<(DeliveryPart, (DateTime CreatedAt, DateTime ModifiedAt)?)>, List<DeliveryPartModifier>, List<WbRd>, (DateTime CreatedAt, DateTime ModifiedAt)?) ToDelivery(this JsonNode json, Dictionary<string, int> currentLsNrs, Dictionary<int, int> currentDids, Dictionary<int, AT_Kg> kgs, Dictionary<int, List<WbRd>> riede) {
|
||||||
var year = json["year"]!.AsValue().GetValue<int>();
|
var year = json["year"]!.AsValue().GetValue<int>();
|
||||||
var lsnr = json["lsnr"]!.AsValue().GetValue<string>();
|
var lsnr = json["lsnr"]!.AsValue().GetValue<string>();
|
||||||
var did = currentLsNrs.GetValueOrDefault(lsnr, -1);
|
var did = currentLsNrs.GetValueOrDefault(lsnr, -1);
|
||||||
@@ -991,9 +983,6 @@ namespace Elwig.Helpers.Export {
|
|||||||
}, [.. json["parts"]!.AsArray().Select(p => p!.AsObject()).Select<JsonObject, (DeliveryPart, (DateTime, DateTime)?)>(p => {
|
}, [.. json["parts"]!.AsArray().Select(p => p!.AsObject()).Select<JsonObject, (DeliveryPart, (DateTime, DateTime)?)>(p => {
|
||||||
var kgnr = p["kgnr"]?.AsValue().GetValue<int>();
|
var kgnr = p["kgnr"]?.AsValue().GetValue<int>();
|
||||||
var ried = p["ried"]?.AsValue().GetValue<string>();
|
var ried = p["ried"]?.AsValue().GetValue<string>();
|
||||||
if (kgnr != null && !currentWbKgs.Values.Any(k => k.KgNr == kgnr)) {
|
|
||||||
throw new KeyNotFoundException($"Für KG {(kgs.TryGetValue(kgnr.Value, out var k) ? k.Name : "?")} ({kgnr:00000}) ist noch keine Großlage festgelegt!\n(Stammdaten \u2192 Herkunftshierarchie)");
|
|
||||||
}
|
|
||||||
WbRd? rd = null;
|
WbRd? rd = null;
|
||||||
if (ried != null && kgnr != null) {
|
if (ried != null && kgnr != null) {
|
||||||
var rde = riede.GetValueOrDefault(kgnr.Value, []);
|
var rde = riede.GetValueOrDefault(kgnr.Value, []);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace Elwig.Helpers {
|
|||||||
public static int CurrentNextSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0);
|
public static int CurrentNextSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0);
|
||||||
public static int CurrentLastSeason => DateTime.Now.Year - (DateTime.Now.Month <= 6 ? 1 : 0);
|
public static int CurrentLastSeason => DateTime.Now.Year - (DateTime.Now.Month <= 6 ? 1 : 0);
|
||||||
public static int FollowingSeason => DateTime.Now.Year + (DateTime.Now.Month >= 11 ? 1 : 0);
|
public static int FollowingSeason => DateTime.Now.Year + (DateTime.Now.Month >= 11 ? 1 : 0);
|
||||||
|
public static DateTime Today => (DateTime.Now.Hour >= 3) ? DateTime.Today : DateTime.Today.AddDays(-1);
|
||||||
|
|
||||||
[GeneratedRegex("^serial://([A-Za-z0-9]+):([0-9]+)(,([5-9]),([NOEMSnoems]),(0|1|1\\.5|2|))?$", RegexOptions.Compiled)]
|
[GeneratedRegex("^serial://([A-Za-z0-9]+):([0-9]+)(,([5-9]),([NOEMSnoems]),(0|1|1\\.5|2|))?$", RegexOptions.Compiled)]
|
||||||
private static partial Regex GeneratedSerialRegex();
|
private static partial Regex GeneratedSerialRegex();
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Elwig.Services {
|
|||||||
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == s.Year && a.DsNr == s.DsNr);
|
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == s.Year && a.DsNr == s.DsNr);
|
||||||
filterNames.Add($"{s.Date:dd.MM.yyyy} – {s.Branch.Name} – {s.Description}");
|
filterNames.Add($"{s.Date:dd.MM.yyyy} – {s.Branch.Name} – {s.Description}");
|
||||||
} else {
|
} else {
|
||||||
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == vm.FilterSeason && (!vm.FilterOnlyUpcoming || a.Schedule.DateString.CompareTo(DateTime.Today.ToString("yyyy-MM-dd")) >= 0));
|
deliveryAncmtQuery = deliveryAncmtQuery.Where(a => a.Year == vm.FilterSeason && (!vm.FilterOnlyUpcoming || a.Schedule.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0));
|
||||||
filterNames.Add($"{vm.FilterSeason}");
|
filterNames.Add($"{vm.FilterSeason}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ namespace Elwig.Services {
|
|||||||
filterNames.Add($"{vm.FilterSeason}");
|
filterNames.Add($"{vm.FilterSeason}");
|
||||||
}
|
}
|
||||||
if (vm.FilterOnlyUpcoming) {
|
if (vm.FilterOnlyUpcoming) {
|
||||||
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.DateString.CompareTo(DateTime.Today.ToString("yyyy-MM-dd")) >= 0);
|
deliveryScheduleQuery = deliveryScheduleQuery.Where(s => s.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0);
|
||||||
filterNames.Add($"ab {DateTime.Today:dd.MM.yyyy}");
|
filterNames.Add($"ab {Utils.Today:dd.MM.yyyy}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var filterVar = new List<string>();
|
var filterVar = new List<string>();
|
||||||
|
|||||||
@@ -72,31 +72,6 @@ namespace Elwig.Services {
|
|||||||
vm.ManualWeighingReason = p.WeighingReason;
|
vm.ManualWeighingReason = p.WeighingReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<(Expression<Func<Delivery, bool>>, string)> GetFilterToday(AppDbContext ctx) {
|
|
||||||
var today = DateTime.Today;
|
|
||||||
var timestamps = (await ctx.Deliveries
|
|
||||||
.Where(d => d.DateString.CompareTo(today.AddDays(-1).ToString("yyyy-MM-dd")) >= 0)
|
|
||||||
.OrderBy(d => d.DateString).ThenBy(d => d.TimeString)
|
|
||||||
.Select(d => d.DateString + " " + d.TimeString)
|
|
||||||
.ToListAsync())
|
|
||||||
.Select(s => DateTime.TryParseExact(s, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt) ? (DateTime?)dt : null)
|
|
||||||
.Where(t => t.HasValue)
|
|
||||||
.Cast<DateTime>()
|
|
||||||
.ToArray();
|
|
||||||
if (timestamps.Length > 0) {
|
|
||||||
var latest = timestamps.Last();
|
|
||||||
var since = timestamps.Cast<DateTime>().Reverse().Aggregate(latest, (s, c) => s.Subtract(c).TotalHours <= 6 ? c : s);
|
|
||||||
latest += new TimeSpan(0, 1, -latest.Minute, -latest.Second, -latest.Millisecond, -latest.Microsecond);
|
|
||||||
since += new TimeSpan(0, 0, -since.Minute, -since.Second, -since.Millisecond, -since.Microsecond);
|
|
||||||
|
|
||||||
return (d => (d.DateString == since.ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo(since.ToString("HH:mm:ss")) >= 0)) ||
|
|
||||||
(d.DateString.CompareTo(since.ToString("yyyy-MM-dd")) > 0),
|
|
||||||
since.Date == latest.Date ? since.ToString("dd.MM.yyyy") : $"{since:dd.MM.yyyy \\a\\b HH:mm} / {latest:dd.MM.yyyy \\b\\i\\s HH:mm}");
|
|
||||||
} else {
|
|
||||||
return (_ => false, today.ToString("dd.MM.yyyy"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<(List<string>, IQueryable<Delivery>, IQueryable<DeliveryPart>, Predicate<DeliveryPart>, List<string>)> GetFilters(this DeliveryAdminViewModel vm, AppDbContext ctx) {
|
public static async Task<(List<string>, IQueryable<Delivery>, IQueryable<DeliveryPart>, Predicate<DeliveryPart>, List<string>)> GetFilters(this DeliveryAdminViewModel vm, AppDbContext ctx) {
|
||||||
List<string> filterNames = [];
|
List<string> filterNames = [];
|
||||||
IQueryable<Delivery> deliveryQuery = ctx.Deliveries;
|
IQueryable<Delivery> deliveryQuery = ctx.Deliveries;
|
||||||
@@ -109,9 +84,10 @@ namespace Elwig.Services {
|
|||||||
filterNames.Add(vm.FilterMember.AdministrativeName);
|
filterNames.Add(vm.FilterMember.AdministrativeName);
|
||||||
}
|
}
|
||||||
if (vm.FilterTodayOnly) {
|
if (vm.FilterTodayOnly) {
|
||||||
var (pred, name) = await GetFilterToday(ctx);
|
deliveryQuery = deliveryQuery
|
||||||
deliveryQuery = deliveryQuery.Where(pred);
|
.Where(d => (d.DateString == Utils.Today.ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo("03:00:00") > 0)) ||
|
||||||
filterNames.Add(name);
|
(d.DateString == Utils.Today.AddDays(1).ToString("yyyy-MM-dd") && (d.TimeString == null || d.TimeString.CompareTo("03:00:00") <= 0)));
|
||||||
|
filterNames.Add(Utils.Today.ToString("dd.MM.yyyy"));
|
||||||
} else if (!vm.FilterAllSeasons) {
|
} else if (!vm.FilterAllSeasons) {
|
||||||
deliveryQuery = deliveryQuery.Where(d => d.Year == vm.FilterSeason);
|
deliveryQuery = deliveryQuery.Where(d => d.Year == vm.FilterSeason);
|
||||||
filterNames.Add($"{vm.FilterSeason}");
|
filterNames.Add($"{vm.FilterSeason}");
|
||||||
@@ -754,9 +730,10 @@ namespace Elwig.Services {
|
|||||||
query = q;
|
query = q;
|
||||||
filterNames.AddRange(f);
|
filterNames.AddRange(f);
|
||||||
} else if (subject == ExportSubject.FromToday) {
|
} else if (subject == ExportSubject.FromToday) {
|
||||||
var (pred, name) = await GetFilterToday(ctx);
|
var date = $"{Utils.Today:yyyy-MM-dd}";
|
||||||
query = ctx.Deliveries.Where(pred).SelectMany(d => d.Parts);
|
query = ctx.DeliveryParts
|
||||||
filterNames.Add(name);
|
.Where(p => p.Delivery.DateString == date);
|
||||||
|
filterNames.Add($"{Utils.Today:dd.MM.yyyy}");
|
||||||
} else if (subject == ExportSubject.FromSeasonAndBranch) {
|
} else if (subject == ExportSubject.FromSeasonAndBranch) {
|
||||||
query = ctx.DeliveryParts
|
query = ctx.DeliveryParts
|
||||||
.Where(p => p.Year == Utils.CurrentLastSeason && p.Delivery.ZwstId == App.ZwstId);
|
.Where(p => p.Year == Utils.CurrentLastSeason && p.Delivery.ZwstId == App.ZwstId);
|
||||||
@@ -828,9 +805,10 @@ namespace Elwig.Services {
|
|||||||
query = q;
|
query = q;
|
||||||
filterNames.AddRange(f);
|
filterNames.AddRange(f);
|
||||||
} else if (subject == ExportSubject.FromToday) {
|
} else if (subject == ExportSubject.FromToday) {
|
||||||
var (pred, name) = await GetFilterToday(ctx);
|
var date = $"{Utils.Today:yyyy-MM-dd}";
|
||||||
query = ctx.Deliveries.Where(pred).SelectMany(d => d.Parts);
|
query = ctx.DeliveryParts
|
||||||
filterNames.Add(name);
|
.Where(p => p.Delivery.DateString == date);
|
||||||
|
filterNames.Add($"{Utils.Today:dd.MM.yyyy}");
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentException("Invalid value for ExportSubject");
|
throw new ArgumentException("Invalid value for ExportSubject");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Elwig.Models;
|
|||||||
using Elwig.Models.Entities;
|
using Elwig.Models.Entities;
|
||||||
using Elwig.ViewModels;
|
using Elwig.ViewModels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -12,7 +11,7 @@ namespace Elwig.Services {
|
|||||||
|
|
||||||
public static async Task InitInputs(this MemberBusinessSharesViewModel vm) {
|
public static async Task InitInputs(this MemberBusinessSharesViewModel vm) {
|
||||||
using var ctx = new AppDbContext();
|
using var ctx = new AppDbContext();
|
||||||
vm.DateNoticeString = $"{DateTime.Today:dd.MM.yyyy}";
|
vm.DateNoticeString = $"{Utils.Today:dd.MM.yyyy}";
|
||||||
vm.ValuePerShare = (await ctx.Seasons.OrderBy(s => s.Year).LastOrDefaultAsync())?.BusinessShareValue;
|
vm.ValuePerShare = (await ctx.Seasons.OrderBy(s => s.Year).LastOrDefaultAsync())?.BusinessShareValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ namespace Elwig.Windows {
|
|||||||
if (await ctx.FetchSeasons(Utils.CurrentYear).SingleOrDefaultAsync() == null) {
|
if (await ctx.FetchSeasons(Utils.CurrentYear).SingleOrDefaultAsync() == null) {
|
||||||
InteractionService.ShowWarning("Saison noch nicht erstellt",
|
InteractionService.ShowWarning("Saison noch nicht erstellt",
|
||||||
"Die Saison für das aktuelle Jahr wurde noch nicht erstellt. Neue Lieferungen können nicht abgespeichert werden.\n\n" +
|
"Die Saison für das aktuelle Jahr wurde noch nicht erstellt. Neue Lieferungen können nicht abgespeichert werden.\n\n" +
|
||||||
"(Stammdaten \u2192 Saisons \u2192 Neu anlegen...)");
|
"(Stammdaten -> Saisons -> Neu anlegen...)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -685,7 +685,7 @@ namespace Elwig.Windows {
|
|||||||
private async void TodayOnlyInput_Changed(object sender, RoutedEventArgs evt) {
|
private async void TodayOnlyInput_Changed(object sender, RoutedEventArgs evt) {
|
||||||
if (!HasContextLoaded) return;
|
if (!HasContextLoaded) return;
|
||||||
if (TodayOnlyInput.IsChecked == true && AllSeasonsInput.IsChecked == false) {
|
if (TodayOnlyInput.IsChecked == true && AllSeasonsInput.IsChecked == false) {
|
||||||
ViewModel.FilterSeason = DateTime.Today.Year;
|
ViewModel.FilterSeason = Utils.Today.Year;
|
||||||
ViewModel.FilterTodayOnly = true;
|
ViewModel.FilterTodayOnly = true;
|
||||||
}
|
}
|
||||||
await RefreshList();
|
await RefreshList();
|
||||||
@@ -1379,7 +1379,7 @@ namespace Elwig.Windows {
|
|||||||
var kl = mod.Where(m => m.Name.StartsWith("Klasse ")).Select(m => m.ModId).LastOrDefault("_")[0];
|
var kl = mod.Where(m => m.Name.StartsWith("Klasse ")).Select(m => m.ModId).LastOrDefault("_")[0];
|
||||||
if (ViewModel.IsUnloadingPumped && (kl == 'A' || kl == '_')) {
|
if (ViewModel.IsUnloadingPumped && (kl == 'A' || kl == '_')) {
|
||||||
kl = 'B';
|
kl = 'B';
|
||||||
} else if (ViewModel.IsUnloadingDumper && (kl == 'B' || kl == '_')) {
|
} else if (ViewModel.IsUnloadingDumper && kl == '_') {
|
||||||
kl = 'A';
|
kl = 'A';
|
||||||
} else {
|
} else {
|
||||||
kl = '_';
|
kl = '_';
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Elwig.Windows {
|
|||||||
list.ForEach(v => v.Schedule.AnnouncedWeightOverride = v.AnnouncedWeight);
|
list.ForEach(v => v.Schedule.AnnouncedWeightOverride = v.AnnouncedWeight);
|
||||||
var deliverySchedules = list.Select(v => v.Schedule).ToList();
|
var deliverySchedules = list.Select(v => v.Schedule).ToList();
|
||||||
ControlUtils.RenewItemsSource(DeliveryScheduleList, deliverySchedules
|
ControlUtils.RenewItemsSource(DeliveryScheduleList, deliverySchedules
|
||||||
.Where(s => !ViewModel.FilterOnlyUpcoming || s.DateString.CompareTo(DateTime.Today.ToString("yyyy-MM-dd")) >= 0)
|
.Where(s => !ViewModel.FilterOnlyUpcoming || s.DateString.CompareTo(Utils.Today.ToString("yyyy-MM-dd")) >= 0)
|
||||||
.ToList(), DeliveryScheduleList_SelectionChanged, ViewModel.FilterFromAllSchedules ? ControlUtils.RenewSourceDefault.None : ControlUtils.RenewSourceDefault.First);
|
.ToList(), DeliveryScheduleList_SelectionChanged, ViewModel.FilterFromAllSchedules ? ControlUtils.RenewSourceDefault.None : ControlUtils.RenewSourceDefault.First);
|
||||||
ControlUtils.RenewItemsSource(DeliveryScheduleInput, deliverySchedules, DeliveryScheduleInput_SelectionChanged);
|
ControlUtils.RenewItemsSource(DeliveryScheduleInput, deliverySchedules, DeliveryScheduleInput_SelectionChanged);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace Elwig.Windows {
|
|||||||
public MailWindow(int? year = null) {
|
public MailWindow(int? year = null) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
using (var ctx = new AppDbContext()) {
|
using (var ctx = new AppDbContext()) {
|
||||||
Year = year ?? ctx.Seasons.OrderByDescending(s => s.Year).FirstOrDefault()?.Year ?? DateTime.Today.Year;
|
Year = year ?? ctx.Seasons.OrderByDescending(s => s.Year).FirstOrDefault()?.Year ?? Utils.Today.Year;
|
||||||
Title = $"Rundschreiben - Lese {Year} - Elwig";
|
Title = $"Rundschreiben - Lese {Year} - Elwig";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ namespace Elwig.Windows {
|
|||||||
PostalSender1.Text = App.Client.Sender1;
|
PostalSender1.Text = App.Client.Sender1;
|
||||||
PostalSender2.Text = App.Client.Sender2;
|
PostalSender2.Text = App.Client.Sender2;
|
||||||
PostalLocation.Text = App.BranchLocation;
|
PostalLocation.Text = App.BranchLocation;
|
||||||
PostalDate.Text = $"{DateTime.Today:dd.MM.yyyy}";
|
PostalDate.Text = $"{Utils.Today:dd.MM.yyyy}";
|
||||||
EmailSubjectInput.Text = App.Client.TextEmailSubject ?? "Rundschreiben";
|
EmailSubjectInput.Text = App.Client.TextEmailSubject ?? "Rundschreiben";
|
||||||
EmailBodyInput.Text = App.Client.TextEmailBody ?? "Sehr geehrtes Mitglied,\n\nim Anhang finden Sie das aktuelle Rundschreiben.\n\nIhre Winzergenossenschaft\n";
|
EmailBodyInput.Text = App.Client.TextEmailBody ?? "Sehr geehrtes Mitglied,\n\nim Anhang finden Sie das aktuelle Rundschreiben.\n\nIhre Winzergenossenschaft\n";
|
||||||
}
|
}
|
||||||
@@ -438,7 +438,7 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private void Date_LostFocus(object sender, RoutedEventArgs evt) {
|
private void Date_LostFocus(object sender, RoutedEventArgs evt) {
|
||||||
var res = Validator.CheckDate((TextBox)sender, true);
|
var res = Validator.CheckDate((TextBox)sender, true);
|
||||||
if (!res.IsValid) ((TextBox)sender).Text = $"{DateTime.Today:dd.MM.yyyy}";
|
if (!res.IsValid) ((TextBox)sender).Text = $"{Utils.Today:dd.MM.yyyy}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateRecipients(AppDbContext ctx) {
|
private async Task UpdateRecipients(AppDbContext ctx) {
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private async void Menu_Database_Backup_Click(object sender, RoutedEventArgs evt) {
|
private async void Menu_Database_Backup_Click(object sender, RoutedEventArgs evt) {
|
||||||
try {
|
try {
|
||||||
var filename = InteractionService.SaveFile("Datenbank-Sicherung", $"database_{DateTime.Today:yyyy-MM-dd}", "sql.zip");
|
var filename = InteractionService.SaveFile("Datenbank-Sicherung", $"database_{Utils.Today:yyyy-MM-dd}", "sql.zip");
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
if (!filename.EndsWith(".sql.zip")) filename += ".sql.zip";
|
if (!filename.EndsWith(".sql.zip")) filename += ".sql.zip";
|
||||||
Mouse.OverrideCursor = Cursors.Wait;
|
Mouse.OverrideCursor = Cursors.Wait;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
int mgnr;
|
int mgnr;
|
||||||
try {
|
try {
|
||||||
mgnr = await ViewModel.UpdateMemberHistory(ViewModel.SelectedHistoryEntry?.HistNr, IsEditing || ViewModel.DateNotice >= DateOnly.FromDateTime(DateTime.Today).AddDays(-14));
|
mgnr = await ViewModel.UpdateMemberHistory(ViewModel.SelectedHistoryEntry?.HistNr, IsEditing || ViewModel.DateNotice >= DateOnly.FromDateTime(Utils.Today).AddDays(-14));
|
||||||
App.HintContextChange();
|
App.HintContextChange();
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
InteractionService.ShowDbException("Geschäftsanteilbewegung aktualisieren", exc);
|
InteractionService.ShowDbException("Geschäftsanteilbewegung aktualisieren", exc);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
[database]
|
[database]
|
||||||
; Relative or absolute path to database file
|
; Relative or absolute path to database file
|
||||||
file = database.sqlite3
|
file = database.sqlite3
|
||||||
|
; Enables automatic compressed database backups
|
||||||
|
backup = true
|
||||||
; Enables database logging
|
; Enables database logging
|
||||||
;log = db.log
|
;log = db.log
|
||||||
|
|
||||||
@@ -38,8 +40,6 @@ auto = true
|
|||||||
;limit = 3500
|
;limit = 3500
|
||||||
; Enables scale logging
|
; Enables scale logging
|
||||||
;log = waage.log
|
;log = waage.log
|
||||||
; Opt-out of auto time synchronization at startup
|
|
||||||
;synctime = false
|
|
||||||
|
|
||||||
;[scale.B]
|
;[scale.B]
|
||||||
;type = Avery-Async
|
;type = Avery-Async
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ About
|
|||||||
**Product:** Elwig
|
**Product:** Elwig
|
||||||
**Description:** Electronic Management for Vintners' Cooperatives
|
**Description:** Electronic Management for Vintners' Cooperatives
|
||||||
**Type:** ERP system
|
**Type:** ERP system
|
||||||
**Version:** 1.1.1.2 ([Changelog](./CHANGELOG.md))
|
**Version:** 1.1.1.1 ([Changelog](./CHANGELOG.md))
|
||||||
**License:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
**License:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||||
**Website:** https://elwig.at/
|
**Website:** https://elwig.at/
|
||||||
**Source code:** https://git.necronda.net/winzer/elwig
|
**Source code:** https://git.necronda.net/winzer/elwig
|
||||||
@@ -33,7 +33,7 @@ Packaging: [WiX Toolset](https://www.firegiant.com/wixtoolset/)
|
|||||||
**Produkt:** Elwig
|
**Produkt:** Elwig
|
||||||
**Beschreibung:** Elektronische Winzergenossenschaftsverwaltung
|
**Beschreibung:** Elektronische Winzergenossenschaftsverwaltung
|
||||||
**Typ:** Warenwirtschaftssystem (ERP-System)
|
**Typ:** Warenwirtschaftssystem (ERP-System)
|
||||||
**Version:** 1.1.1.2 ([Änderungsprotokoll](./CHANGELOG.md))
|
**Version:** 1.1.1.1 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||||
**Lizenz:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
**Lizenz:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||||
**Website:** https://elwig.at/
|
**Website:** https://elwig.at/
|
||||||
**Quellcode:** https://git.necronda.net/winzer/elwig
|
**Quellcode:** https://git.necronda.net/winzer/elwig
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Tests.E2ETests {
|
|||||||
Session.App.FindElement(By.Name("Rundschreiben")).Click();
|
Session.App.FindElement(By.Name("Rundschreiben")).Click();
|
||||||
Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
|
Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
|
||||||
var window = Session.CreateWindowDriver("MailWindow");
|
var window = Session.CreateWindowDriver("MailWindow");
|
||||||
Assert.That(window.Title, Is.EqualTo($"Rundschreiben - Lese {DateTime.Today.Year} - Elwig"));
|
Assert.That(window.Title, Is.EqualTo($"Rundschreiben - Lese {Elwig.Helpers.Utils.Today.Year} - Elwig"));
|
||||||
window.Close();
|
window.Close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Tests.UnitTests.DocumentTests {
|
|||||||
"""));
|
"""));
|
||||||
Assert.That(text, Contains.Substring("0123463")); // Betriebsnummer
|
Assert.That(text, Contains.Substring("0123463")); // Betriebsnummer
|
||||||
Assert.That(text, Contains.Substring("pauschaliert"));
|
Assert.That(text, Contains.Substring("pauschaliert"));
|
||||||
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Today:dd.MM.yyyy}"));
|
Assert.That(text, Contains.Substring($"Wolkersdorf, am {Elwig.Helpers.Utils.Today:dd.MM.yyyy}"));
|
||||||
Assert.That(text, Contains.Substring("Traubengutschrift Max Mustermann – Probevariante"));
|
Assert.That(text, Contains.Substring("Traubengutschrift Max Mustermann – Probevariante"));
|
||||||
Assert.That(text, Contains.Substring("AT81 1234 5678 9012 3457"));
|
Assert.That(text, Contains.Substring("AT81 1234 5678 9012 3457"));
|
||||||
Assert.That(text, Contains.Substring("""
|
Assert.That(text, Contains.Substring("""
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Tests.UnitTests.DocumentTests {
|
|||||||
"""));
|
"""));
|
||||||
Assert.That(text, Contains.Substring("0123463")); // Betriebsnummer
|
Assert.That(text, Contains.Substring("0123463")); // Betriebsnummer
|
||||||
Assert.That(text, Contains.Substring("pauschaliert"));
|
Assert.That(text, Contains.Substring("pauschaliert"));
|
||||||
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Today:dd.MM.yyyy}"));
|
Assert.That(text, Contains.Substring($"Wolkersdorf, am {Elwig.Helpers.Utils.Today:dd.MM.yyyy}"));
|
||||||
Assert.That(text, Contains.Substring("Anlieferungsbestätigung 2020"));
|
Assert.That(text, Contains.Substring("Anlieferungsbestätigung 2020"));
|
||||||
Assert.That(text, Contains.Substring("""
|
Assert.That(text, Contains.Substring("""
|
||||||
20201001X001 1 Grüner Veltliner QUW 73 15,0 ungeb.: 3 219 3 219 ☑
|
20201001X001 1 Grüner Veltliner QUW 73 15,0 ungeb.: 3 219 3 219 ☑
|
||||||
|
|||||||
Reference in New Issue
Block a user