Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d80cca241 | |||
| 9dc225d3e4 | |||
| 0d513f7bff | |||
| b10c744bf9 | |||
| e6367da286 | |||
| 01f4480a08 | |||
| e9722c790c | |||
| af98c32026 | |||
| 7300b30cf5 | |||
| 428cd6ddc2 | |||
| 2de8af878b | |||
| 34d95eab9d | |||
| 548aeb2ce9 | |||
| 7edd888aa2 | |||
| a0d4f19f30 | |||
| 67ba342c28 |
64
CHANGELOG.md
64
CHANGELOG.md
@@ -2,6 +2,70 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
[v1.0.2.0][v1.0.2.0] (2025-11-10) {#v1.0.2.0}
|
||||
---------------------------------------------
|
||||
|
||||
### Neue Funktionen {#v1.0.2.0-features}
|
||||
|
||||
* Im Mitglieder-Fenster (`MemberAdminWindow`) können Kontaktdaten der Mitglieder als .vcf-Datei exportiert werden. (01f4480a08, 9dc225d3e4)
|
||||
|
||||
### Sonstiges {#v1.0.2.0-misc}
|
||||
|
||||
* Wenn ein Serial-/COM-Port-USB-Adapter an- oder abgesteckt wird, wird das nun automatisch erkannt. (e6367da286)
|
||||
* Abhängigkeiten aktualisiert. (b10c744bf9, 0d513f7bff)
|
||||
|
||||
[v1.0.2.0]: https://git.necronda.net/winzer/elwig/releases/tag/v1.0.2.0
|
||||
|
||||
|
||||
|
||||
|
||||
[v1.0.1.5][v1.0.1.5] (2025-10-29) {#v1.0.1.5}
|
||||
---------------------------------------------
|
||||
|
||||
### Behobene Fehler {#v1.0.1.5-bugfixes}
|
||||
|
||||
* Im Rundschreiben-Fenster (`MailWindow`) kam es zu einem Absturz, wenn man das Fenster über den "Anlieferungsbestätigung"-Knopf im Leseabschluss-Abschnitt geöffnet hat. (af98c32026)
|
||||
|
||||
[v1.0.1.5]: https://git.necronda.net/winzer/elwig/releases/tag/v1.0.1.5
|
||||
|
||||
|
||||
|
||||
|
||||
[v1.0.1.4][v1.0.1.4] (2025-10-28) {#v1.0.1.4}
|
||||
---------------------------------------------
|
||||
|
||||
### Behobene Fehler {#v1.0.1.4-bugfixes}
|
||||
|
||||
* Im Rundschreiben-Fenster (`MailWindow`) kam es zu einem Absturz, wenn man die Zustelloptionen "Post zusenden an Mitglieder, die keine E-Mail erhalten würden" und "E-Mail zusenden an niemanden" kombiniert hat. (2de8af878b)
|
||||
|
||||
### Sonstiges {#v1.0.1.4-misc}
|
||||
|
||||
* Im Auszahlungsvariante-Fenster (`ChartWindow`) gibt es keine Fehlermeldung mehr wenn nicht für alle Sorten ein Preis definiert ist, nur noch eine Warnung. (428cd6ddc2)
|
||||
|
||||
[v1.0.1.4]: https://git.necronda.net/winzer/elwig/releases/tag/v1.0.1.4
|
||||
|
||||
|
||||
|
||||
|
||||
[v1.0.1.3][v1.0.1.3] (2025-10-13) {#v1.0.1.3}
|
||||
---------------------------------------------
|
||||
|
||||
### Neue Funktionen {#v1.0.1.3-features}
|
||||
|
||||
* In der Liste des Lieferungen-Fenster (`DeliveryAdminWindow`) werden
|
||||
* statt ausschließlich der Sorte auch Attribut und Bewirtschaftungsart angezeigt. (a0d4f19f30)
|
||||
* Kommentare der Lieferungen (und Teillieferungen) angezeigt. (548aeb2ce9)
|
||||
|
||||
### Sonstiges {#v1.0.1.3-misc}
|
||||
|
||||
* Verzögerung der Überprüfung auf automatische Updates auf einige Sekunden verlängert. (67ba342c28)
|
||||
* Verbesserung der Ladezeiten im Anmeldungen-Fenster (`DeliveryAncmtAdminWindow`). (7edd888aa2)
|
||||
|
||||
[v1.0.1.3]: https://git.necronda.net/winzer/elwig/releases/tag/v1.0.1.3
|
||||
|
||||
|
||||
|
||||
|
||||
[v1.0.1.2][v1.0.1.2] (2025-09-25) {#v1.0.1.2}
|
||||
---------------------------------------------
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Elwig {
|
||||
public static bool ForceShutdown { get; private set; } = false;
|
||||
|
||||
private readonly DispatcherTimer _autoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||
public readonly SerialPortWatcher SerialPortWatcher = new();
|
||||
|
||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Elwig");
|
||||
public static readonly string MailsPath = Path.Combine(DataPath, "mails");
|
||||
@@ -48,9 +49,10 @@ namespace Elwig {
|
||||
public static string? BranchPhoneNr { get; private set; }
|
||||
public static string? BranchFaxNr { get; private set; }
|
||||
public static string? BranchMobileNr { get; private set; }
|
||||
public static IList<IScale> Scales { get; private set; }
|
||||
public static IList<ICommandScale> CommandScales => Scales.Where(s => s is ICommandScale).Cast<ICommandScale>().ToList();
|
||||
public static IList<IEventScale> EventScales => Scales.Where(s => s is IEventScale).Cast<IEventScale>().ToList();
|
||||
|
||||
public static IList<IScale> Scales { get; private set; } = [];
|
||||
public static IList<ICommandScale> CommandScales => [.. Scales.Where(s => s is ICommandScale).Cast<ICommandScale>()];
|
||||
public static IList<IEventScale> EventScales => [.. Scales.Where(s => s is IEventScale).Cast<IEventScale>()];
|
||||
public static ClientParameters Client { get; set; }
|
||||
|
||||
public static Dispatcher MainDispatcher { get; private set; }
|
||||
@@ -128,7 +130,7 @@ namespace Elwig {
|
||||
if (Config.UpdateAuto && Config.UpdateUrl != null) {
|
||||
if (Utils.HasInternetConnectivity()) {
|
||||
Utils.RunBackground("Auto Updater", async () => {
|
||||
await Task.Delay(500);
|
||||
await Task.Delay(1000);
|
||||
await CheckForUpdates();
|
||||
});
|
||||
}
|
||||
@@ -137,6 +139,9 @@ namespace Elwig {
|
||||
_autoUpdateTimer.Start();
|
||||
}
|
||||
|
||||
SerialPortWatcher.SerialPortConnected += OnSerialPortConnected;
|
||||
SerialPortWatcher.SerialPortDisconnected += OnSerialPortDisconnected;
|
||||
|
||||
var list = new List<IScale>();
|
||||
foreach (var s in Config.Scales) {
|
||||
try {
|
||||
@@ -144,7 +149,7 @@ namespace Elwig {
|
||||
} catch (Exception e) {
|
||||
list.Add(new InvalidScale(s.Id));
|
||||
if (s.Required)
|
||||
MessageBox.Show($"Unable to create scale {s.Id}:\n\n{e.Message}", "Scale Error",
|
||||
MessageBox.Show($"Verbindung zu Waage {s.Id} konnte nicht hergestellt werden:\n\n{e.Message}", "Waagen-Fehler",
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
@@ -152,7 +157,7 @@ namespace Elwig {
|
||||
|
||||
if (Config.Branch != null) {
|
||||
if (!branches.ContainsKey(Config.Branch.ToLower())) {
|
||||
MessageBox.Show("Invalid branch name in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
MessageBox.Show("Ungültige Zweigstelle in Konfigurationsdatei!", "Ungültige Zweigstelle", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Shutdown();
|
||||
} else {
|
||||
SetBranch(branches[Config.Branch.ToLower()]);
|
||||
@@ -160,7 +165,7 @@ namespace Elwig {
|
||||
} else if (branches.Count == 1) {
|
||||
SetBranch(branches.First().Value);
|
||||
} else {
|
||||
MessageBox.Show("Unable to determine local branch!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
MessageBox.Show("Erkennen der lokalen Zweigstelle nicht möglich!", "Ungültige Zweigstelle", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
@@ -181,6 +186,7 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
private async void Application_Exit(object sender, ExitEventArgs evt) {
|
||||
SerialPortWatcher.Dispose();
|
||||
foreach (var s in EventScales) {
|
||||
s.Dispose();
|
||||
}
|
||||
@@ -234,12 +240,53 @@ namespace Elwig {
|
||||
if (!evt.IsAvailable) return;
|
||||
if (Utils.HasInternetConnectivity()) {
|
||||
Utils.RunBackground("Auto Updater", async () => {
|
||||
await Task.Delay(500);
|
||||
await Task.Delay(2000);
|
||||
await CheckForUpdates();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSerialPortConnected(object? sender, string name) {
|
||||
for (var i = 0; i < Config.Scales.Count; i++) {
|
||||
var s = Config.Scales[i];
|
||||
if ((s.Connection?.StartsWith($"serial://{name}:") ?? false) && Scales[i] is InvalidScale) {
|
||||
try {
|
||||
Scales[i] = Scale.FromConfig(s);
|
||||
MessageBox.Show($"Verbindung zu Waage {s.Id} wieder hergestellt!", $"Waage {s.Id}", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
} catch (Exception e) {
|
||||
Scales[i] = new InvalidScale(s.Id);
|
||||
MessageBox.Show($"Verbindung zu Waage {s.Id} konnte nicht hergestellt werden:\n\n{e.Message}", "Waagen-Fehler",
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateScales();
|
||||
}
|
||||
|
||||
private void OnSerialPortDisconnected(object? sender, string name) {
|
||||
for (var i = 0; i < Config.Scales.Count; i++) {
|
||||
var s = Config.Scales[i];
|
||||
if ((s.Connection?.StartsWith($"serial://{name}:") ?? false) && Scales[i] is not InvalidScale) {
|
||||
MessageBox.Show($"Verbindung zu Waage {s.Id} unterbrochen!", $"Waagen {s.Id}", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
try {
|
||||
Scales[i].Dispose();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
Scales[i] = new InvalidScale(s.Id);
|
||||
}
|
||||
}
|
||||
UpdateScales();
|
||||
}
|
||||
|
||||
public static void UpdateScales() {
|
||||
foreach (Window w in CurrentApp.Windows) {
|
||||
if (w is DeliveryAdminWindow t && t.ViewModel.IsReceipt) {
|
||||
t.UpdateScales();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task CheckForUpdates(bool showAlert = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
var latest = await Utils.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
|
||||
<Version>1.0.1.2</Version>
|
||||
<Version>1.0.2.0</Version>
|
||||
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
@@ -23,21 +23,22 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageReference Include="LinqKit" Version="1.3.8" />
|
||||
<PackageReference Include="MailKit" Version="4.13.0" />
|
||||
<PackageReference Include="MailKit" Version="4.14.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.36" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3485.44" />
|
||||
<PackageReference Include="NJsonSchema" Version="11.4.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3595.46" />
|
||||
<PackageReference Include="NJsonSchema" Version="11.5.2" />
|
||||
<PackageReference Include="PdfiumViewer" Version="2.13.0" />
|
||||
<PackageReference Include="PdfiumViewer.Native.x86_64.no_v8-no_xfa" Version="2018.4.8.256" />
|
||||
<PackageReference Include="RazorLight" Version="2.3.1" />
|
||||
<PackageReference Include="ScottPlot.WPF" Version="5.0.56" />
|
||||
<PackageReference Include="ScottPlot.WPF" Version="5.1.57" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.2" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="9.0.9" />
|
||||
<PackageReference Include="System.IO.Ports" Version="9.0.9" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.9" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="9.0.10" />
|
||||
<PackageReference Include="System.IO.Ports" Version="9.0.10" />
|
||||
<PackageReference Include="System.Management" Version="9.0.10" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -20,13 +20,19 @@ namespace Elwig.Helpers.Billing {
|
||||
Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetVaributes(ctx, Year, onlyDelivered: false));
|
||||
}
|
||||
|
||||
public async Task Calculate(bool? honorGebunden = null, bool? allowAttrsIntoLower = null, bool? avoidUnderDeliveries = null) {
|
||||
public async Task Calculate(bool strictPrices = true, bool? honorGebunden = null, bool? allowAttrsIntoLower = null, bool? avoidUnderDeliveries = null) {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
using var tx = await cnx.BeginTransactionAsync();
|
||||
await CalculateBuckets(honorGebunden, allowAttrsIntoLower, avoidUnderDeliveries, cnx);
|
||||
await DeleteInDb(cnx);
|
||||
await SetCalcTime(cnx);
|
||||
await CalculatePrices(cnx);
|
||||
KeyNotFoundException? exception = null;
|
||||
try {
|
||||
await CalculatePrices(cnx, strictPrices);
|
||||
} catch (KeyNotFoundException e) {
|
||||
if (strictPrices) throw;
|
||||
exception = e;
|
||||
}
|
||||
if (Data.ConsiderDelieryModifiers) {
|
||||
await CalculateDeliveryModifiers(cnx);
|
||||
}
|
||||
@@ -34,6 +40,8 @@ namespace Elwig.Helpers.Billing {
|
||||
await CalculateMemberModifiers(cnx);
|
||||
}
|
||||
await tx.CommitAsync();
|
||||
if (exception != null)
|
||||
throw exception;
|
||||
}
|
||||
|
||||
public async Task Commit() {
|
||||
@@ -142,7 +150,8 @@ namespace Elwig.Helpers.Billing {
|
||||
""");
|
||||
}
|
||||
|
||||
protected async Task CalculatePrices(SqliteConnection cnx) {
|
||||
protected async Task CalculatePrices(SqliteConnection cnx, bool strict = true) {
|
||||
var invalid = new HashSet<string>();
|
||||
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string? AttrId, string? CultId, string Discr, int Value, double Oe, double Kmw, string QualId, bool AttrAreaCom)>();
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"""
|
||||
@@ -172,15 +181,25 @@ namespace Elwig.Helpers.Billing {
|
||||
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
|
||||
var attrId = part.AttrAreaCom ? payAttrId : part.AttrId;
|
||||
var geb = !ungeb && (payAttrId == attrId || !part.AttrAreaCom);
|
||||
var price = Data.CalculatePrice(part.SortId, attrId, part.CultId, part.QualId, geb, part.Oe, part.Kmw);
|
||||
decimal price = 0;
|
||||
try {
|
||||
price = Data.CalculatePrice(part.SortId, attrId, part.CultId, part.QualId, geb, part.Oe, part.Kmw);
|
||||
} catch (KeyNotFoundException e) {
|
||||
invalid.Add(e.Message.Split('\'')[1]);
|
||||
}
|
||||
var priceL = PaymentVariant.Season.DecToDb(price);
|
||||
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
|
||||
}
|
||||
|
||||
var msg = invalid.Count == 0 ? null : "Für folgende Sorten wurde noch keine Preiskurve festgelegt: " + string.Join(", ", invalid);
|
||||
if (msg != null && strict)
|
||||
throw new KeyNotFoundException(msg);
|
||||
await AppDbContext.ExecuteBatch(cnx, $"""
|
||||
INSERT INTO payment_delivery_part_bucket (year, did, dpnr, bktnr, avnr, price, amount)
|
||||
VALUES {string.Join(",\n ", inserts.Select(i => $"({i.Year}, {i.DId}, {i.DPNr}, {i.BktNr}, {AvNr}, {i.Price}, {i.Amount})"))};
|
||||
""");
|
||||
if (msg != null)
|
||||
throw new KeyNotFoundException(msg);
|
||||
}
|
||||
|
||||
protected async Task CalculateDeliveryModifiers(SqliteConnection cnx) {
|
||||
|
||||
69
Elwig/Helpers/Export/VCard.cs
Normal file
69
Elwig/Helpers/Export/VCard.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Export {
|
||||
public class VCard : IExporter<Member> {
|
||||
|
||||
public static string FileExtension => "vcf";
|
||||
|
||||
private readonly StreamWriter _writer;
|
||||
|
||||
public VCard(string filename) : this(filename, Utils.UTF8) { }
|
||||
|
||||
public VCard(string filename, Encoding encoding) {
|
||||
_writer = new StreamWriter(filename, false, encoding);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
_writer.Dispose();
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync() {
|
||||
GC.SuppressFinalize(this);
|
||||
return _writer.DisposeAsync();
|
||||
}
|
||||
|
||||
public async Task ExportAsync(IEnumerable<Member> data, IProgress<double>? progress = null) {
|
||||
progress?.Report(0.0);
|
||||
int count = data.Count() + 1, i = 0;
|
||||
|
||||
foreach (var row in data) {
|
||||
var billingAddr = row.BillingAddress != null ? $"ADR;TYPE=work;LANGUAGE=de;LABEL=\"{Escape(row.BillingAddress.FullName)}\\n{Escape(row.BillingAddress.Address)}\\n{row.BillingAddress.PostalDest.AtPlz?.Plz} {Escape(row.BillingAddress.PostalDest.AtPlz?.Ort.Name)}\\nÖsterreich\":;;{Escape(row.BillingAddress.Address)};{Escape(row.BillingAddress.PostalDest.AtPlz?.Ort.Name)};;{row.BillingAddress.PostalDest.AtPlz?.Plz};Österreich\r\n" : null;
|
||||
var tel = string.Join("", row.TelephoneNumbers
|
||||
.Where(n => n.Type != "fax")
|
||||
.Select(n => $"TEL;TYPE={(n.Type == "mobile" ? "cell" : "voice")}:{Escape(n.Number)}\r\n"));
|
||||
var email = string.Join("", row.EmailAddresses.Select(a => $"EMAIL:{Escape(a.Address)}\r\n"));
|
||||
await _writer.WriteLineAsync($"""
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
UID:mg{row.MgNr}@{App.Client.NameToken.ToLower()}.elwig.at
|
||||
NOTE:MgNr. {row.MgNr}
|
||||
FN:{Escape(row.AdministrativeName)}
|
||||
N:{Escape(row.Name)};{Escape(row.GivenName)};{Escape(row.MiddleName)};{Escape(row.Prefix)};{Escape(row.Suffix)}
|
||||
KIND:{(row.IsJuridicalPerson ? "org" : "individual")}
|
||||
ADR{(billingAddr == null ? "" : ";TYPE=home")};LANGUAGE=de;LABEL="{Escape(row.Address)}\n{row.PostalDest.AtPlz?.Plz} {Escape(row.PostalDest.AtPlz?.Ort.Name)}\nÖsterreich":;;{Escape(row.Address)};{Escape(row.PostalDest.AtPlz?.Ort.Name)};;{row.PostalDest.AtPlz?.Plz};Österreich
|
||||
{billingAddr}{tel}{email}REV:{row.ModifiedAt.ToUniversalTime():yyyyMMdd\THHmmss\Z}
|
||||
END:VCARD
|
||||
""");
|
||||
progress?.Report(100.0 * ++i / count);
|
||||
}
|
||||
|
||||
await _writer.FlushAsync();
|
||||
progress?.Report(100.0);
|
||||
}
|
||||
|
||||
public void Export(IEnumerable<Member> data, IProgress<double>? progress = null) {
|
||||
ExportAsync(data, progress).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private static string? Escape(string? text) {
|
||||
return text?.Replace("\\", "\\\\").Replace(",", "\\,").Replace(";", "\\;").Replace("\n", "\\n").Replace("\r", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Elwig.Helpers {
|
||||
public enum ExportMode {
|
||||
Show, SaveList, SavePdf, Print, Email, Export, Upload
|
||||
Show, SaveList, SavePdf, Print, Email, Vcf, Export, Upload
|
||||
}
|
||||
}
|
||||
|
||||
54
Elwig/Helpers/SerialPortWatcher.cs
Normal file
54
Elwig/Helpers/SerialPortWatcher.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public sealed class SerialPortWatcher : IDisposable {
|
||||
|
||||
private readonly ManagementEventWatcher _deviceArrivalWatcher;
|
||||
private readonly ManagementEventWatcher _deviceRemovalWatcher;
|
||||
|
||||
private string[] _knownPorts;
|
||||
|
||||
public event EventHandler<string>? SerialPortConnected;
|
||||
public event EventHandler<string>? SerialPortDisconnected;
|
||||
|
||||
public SerialPortWatcher() {
|
||||
_knownPorts = SerialPort.GetPortNames();
|
||||
_deviceArrivalWatcher = new ManagementEventWatcher("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
|
||||
_deviceArrivalWatcher.EventArrived += (s, e) => OnDeviceArrived();
|
||||
_deviceRemovalWatcher = new ManagementEventWatcher("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3");
|
||||
_deviceRemovalWatcher.EventArrived += (s, e) => OnDeviceRemoved();
|
||||
_deviceArrivalWatcher.Start();
|
||||
_deviceRemovalWatcher.Start();
|
||||
|
||||
}
|
||||
|
||||
private void OnDeviceArrived() {
|
||||
string[] currentPorts = SerialPort.GetPortNames();
|
||||
var newPorts = currentPorts.Except(_knownPorts).ToArray();
|
||||
foreach (var port in newPorts)
|
||||
SerialPortConnected?.Invoke(this, port);
|
||||
_knownPorts = currentPorts;
|
||||
}
|
||||
|
||||
private void OnDeviceRemoved() {
|
||||
string[] currentPorts = SerialPort.GetPortNames();
|
||||
var removedPorts = _knownPorts.Except(currentPorts).ToArray();
|
||||
foreach (var port in removedPorts)
|
||||
SerialPortDisconnected?.Invoke(this, port);
|
||||
_knownPorts = currentPorts;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
try {
|
||||
_deviceArrivalWatcher?.Stop();
|
||||
_deviceRemovalWatcher?.Stop();
|
||||
} finally {
|
||||
_deviceArrivalWatcher?.Dispose();
|
||||
_deviceRemovalWatcher?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -62,6 +63,11 @@ namespace Elwig.Models.Entities {
|
||||
[Column("comment")]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public string[] Comments => [.. Parts.Select(p => p.Comment).Prepend(Comment).Where(c => c != null).Cast<string>()];
|
||||
[NotMapped]
|
||||
public string CommentsString => string.Join(" / ", Comments);
|
||||
|
||||
[Column("ctime"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public long CTime { get; set; }
|
||||
[NotMapped]
|
||||
@@ -108,16 +114,16 @@ namespace Elwig.Models.Entities {
|
||||
public int Weight => Parts.Select(p => p.Weight).Sum();
|
||||
public int FilteredWeight => FilteredParts.Select(p => p.Weight).Sum();
|
||||
|
||||
public IEnumerable<string> SortIds => Parts
|
||||
.GroupBy(p => p.SortId)
|
||||
public IEnumerable<RawVaribute> Vaributes => Parts
|
||||
.GroupBy(p => (p.SortId, p.AttrId, p.CultId))
|
||||
.OrderByDescending(g => g.Select(p => p.Weight).Sum())
|
||||
.Select(g => g.Key);
|
||||
public IEnumerable<string> FilteredSortIds => FilteredParts
|
||||
.GroupBy(p => p.SortId)
|
||||
.Select(g => new RawVaribute(g.Key.SortId, g.Key.AttrId, g.Key.CultId));
|
||||
public IEnumerable<RawVaribute> FilteredVaributes => FilteredParts
|
||||
.GroupBy(p => (p.SortId, p.AttrId, p.CultId))
|
||||
.OrderByDescending(g => g.Select(p => p.Weight).Sum())
|
||||
.Select(g => g.Key);
|
||||
public string SortIdString => string.Join(", ", SortIds);
|
||||
public string FilteredSortIdString => string.Join(", ", FilteredSortIds);
|
||||
.Select(g => new RawVaribute(g.Key.SortId, g.Key.AttrId, g.Key.CultId));
|
||||
public string VaributeString => string.Join(", ", Vaributes);
|
||||
public string FilteredVaributeString => string.Join(", ", FilteredVaributes);
|
||||
|
||||
public Brush? Color => Parts.Select(p => p.Variety.Color).Distinct().SingleOrDefault();
|
||||
public Brush? FilteredColor => FilteredParts.Select(p => p.Variety.Color).Distinct().SingleOrDefault();
|
||||
|
||||
@@ -42,7 +42,9 @@ namespace Elwig.Models.Entities {
|
||||
[Column("max_weight")]
|
||||
public int? MaxWeight { get; set; }
|
||||
[NotMapped]
|
||||
public int AnnouncedWeight => Announcements.Sum(a => a.Weight);
|
||||
public int AnnouncedWeight => AnnouncedWeightOverride ?? Announcements.Sum(a => a.Weight);
|
||||
[NotMapped]
|
||||
public int? AnnouncedWeightOverride { get; set; }
|
||||
[NotMapped]
|
||||
public double? Percent => (double)AnnouncedWeight / MaxWeight * 100;
|
||||
|
||||
|
||||
@@ -493,6 +493,32 @@ namespace Elwig.Services {
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Vcf) {
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = "Mitglieder.vcf",
|
||||
DefaultExt = "vcf",
|
||||
Filter = "vCard-Datei (*.vcf)|*.vcf",
|
||||
Title = "Kontakte speichern unter - Elwig"
|
||||
};
|
||||
if (d.ShowDialog() == true) {
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
var members = await query
|
||||
.OrderBy(m => m.MgNr)
|
||||
.Include(m => m.BillingAddress)
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.AsSplitQuery()
|
||||
.ToListAsync();
|
||||
using var exporter = new VCard(d.FileName);
|
||||
await exporter.ExportAsync(members);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
});
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
} else if (mode == ExportMode.Export) {
|
||||
var d = new SaveFileDialog() {
|
||||
FileName = subject == ExportSubject.Selected ? $"Mitglied_{vm.SelectedMember?.MgNr}.elwig.zip" : $"Mitglieder_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip",
|
||||
|
||||
@@ -664,8 +664,10 @@ namespace Elwig.Windows {
|
||||
try {
|
||||
await Task.Run(async () => {
|
||||
var b = new BillingVariant(PaymentVar.Year, PaymentVar.AvNr);
|
||||
await b.Calculate();
|
||||
await b.Calculate(false);
|
||||
});
|
||||
} catch (KeyNotFoundException exc) {
|
||||
MessageBox.Show(exc.Message, "Noch nicht alle Preise festgelegt", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Berechnungsfehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
@@ -265,13 +265,18 @@
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding FilteredSortIdString}" Width="50">
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding FilteredVaributeString}" Width="60">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.Foreground" Value="{Binding FilteredColor}"/>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Menge" Binding="{Binding FilteredWeight, StringFormat='{}{0:N0} kg '}" Width="75">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
@@ -290,6 +295,7 @@
|
||||
<DataGridTextColumn Header="LsNr." Binding="{Binding LsNr}" Width="120"/>
|
||||
<DataGridTextColumn Header="Mitglied" Binding="{Binding Member.AdministrativeName}" Width="180"/>
|
||||
<DataGridTextColumn Header="Zu-/Abschläge" Binding="{Binding FilteredModifiersString}" Width="150"/>
|
||||
<DataGridTextColumn Header="Kommentar" Binding="{Binding CommentsString}" Width="150"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
||||
@@ -1168,6 +1168,19 @@ namespace Elwig.Windows {
|
||||
WeighingDButton.IsEnabled = n > 3 && App.CommandScales[3].IsReady;
|
||||
}
|
||||
|
||||
public void UpdateScales() {
|
||||
if (!ViewModel.IsReceipt) return;
|
||||
foreach (var s in App.EventScales) {
|
||||
s.WeighingEvent -= Scale_Weighing;
|
||||
s.WeighingEvent += Scale_Weighing;
|
||||
}
|
||||
if (WeighingManualButton.IsEnabled) {
|
||||
EnableWeighingButtons();
|
||||
} else {
|
||||
DisableWeighingButtons();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateLsNr() {
|
||||
if (string.IsNullOrEmpty(ViewModel.Date) || ViewModel.Branch == null) {
|
||||
ViewModel.LsNr = "";
|
||||
|
||||
@@ -83,14 +83,19 @@ namespace Elwig.Windows {
|
||||
|
||||
private async Task RefreshDeliveryScheduleList() {
|
||||
using var ctx = new AppDbContext();
|
||||
var deliverySchedules = await ctx.DeliverySchedules
|
||||
var list = await ctx.DeliverySchedules
|
||||
.Where(s => s.Year == ViewModel.FilterSeason)
|
||||
.Include(s => s.Branch)
|
||||
.Include(s => s.Announcements)
|
||||
.OrderBy(s => s.DateString)
|
||||
.ThenBy(s => s.Branch.Name)
|
||||
.ThenBy(s => s.Description)
|
||||
.Select(s => new {
|
||||
Schedule = s,
|
||||
AnnouncedWeight = s.Announcements.Sum(a => a.Weight)
|
||||
})
|
||||
.ToListAsync();
|
||||
list.ForEach(v => v.Schedule.AnnouncedWeightOverride = v.AnnouncedWeight);
|
||||
var deliverySchedules = list.Select(v => v.Schedule).ToList();
|
||||
ControlUtils.RenewItemsSource(DeliveryScheduleList, deliverySchedules
|
||||
.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);
|
||||
|
||||
@@ -738,7 +738,7 @@ namespace Elwig.Windows {
|
||||
PostalNoEmailInput.IsChecked == true ? 1 : 0;
|
||||
var emailMode = EmailAllInput.IsChecked == true ? 2 : EmailWishInput.IsChecked == true ? 1 : 0;
|
||||
|
||||
double printNum = printMode == 3 ? PostalAllCount : printMode == 2 ? PostalWishCount : printMode == 2 ? PostalNoEmailCount : 0;
|
||||
double printNum = printMode == 3 ? PostalAllCount : printMode == 2 ? PostalWishCount : printMode == 1 ? PostalNoEmailCount : 0;
|
||||
double emailNum = emailMode == 2 ? EmailAllCount : emailMode == 1 ? EmailWishCount : 0;
|
||||
double totalNum = printNum + emailNum;
|
||||
|
||||
@@ -954,7 +954,7 @@ namespace Elwig.Windows {
|
||||
AvaiableDocumentsList.SelectedIndex = 1;
|
||||
if (AvaiableDocumentsList.SelectedItem is not string s || SelectedDocs.Any(d => d.Type == DocType.DeliveryConfirmation))
|
||||
return;
|
||||
SelectedDocs.Add(new(DocType.DeliveryConfirmation, s, (Year, DocumentNonDeliverersInput.IsChecked == true)));
|
||||
SelectedDocs.Add(new(DocType.DeliveryConfirmation, s, Year));
|
||||
SelectedDocumentsList.SelectedIndex = SelectedDocs.Count - 1;
|
||||
RecipientsDeliveryMembersInput.IsChecked = true;
|
||||
}
|
||||
|
||||
@@ -164,6 +164,14 @@
|
||||
<MenuItem x:Name="Menu_Export_UploadAll" Header="...von allen Mitgliedern hochladen"
|
||||
Click="Menu_Export_UploadAll_Click"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Kontakte">
|
||||
<MenuItem x:Name="Menu_Contacts_Selected" Header="...von ausgewähltem Mitglied speichern..." IsEnabled="False"
|
||||
Click="Menu_Contacts_Selected_Click"/>
|
||||
<MenuItem x:Name="Menu_Contacts_Filters" Header="...aus Filtern speichern..."
|
||||
Click="Menu_Contacts_Filters_Click"/>
|
||||
<MenuItem x:Name="Menu_Contacts_All" Header="...von allen Mitgliedern speichern..."
|
||||
Click="Menu_Contacts_All_Click"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
<Grid Grid.Row="1" Margin="5,0,0,0">
|
||||
|
||||
@@ -319,9 +319,11 @@ namespace Elwig.Windows {
|
||||
if (MemberList.SelectedItem is Member m) {
|
||||
Menu_Export_ExportSelected.IsEnabled = !IsEditing && !IsCreating;
|
||||
Menu_Export_UploadSelected.IsEnabled = !IsEditing && !IsCreating && App.Config.SyncUrl != null;
|
||||
Menu_Contacts_Selected.IsEnabled = !IsEditing && !IsCreating;
|
||||
} else {
|
||||
Menu_Export_ExportSelected.IsEnabled = false;
|
||||
Menu_Export_UploadSelected.IsEnabled = false;
|
||||
Menu_Contacts_Selected.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,6 +651,13 @@ namespace Elwig.Windows {
|
||||
await ViewModel.GenerateMemberList(MemberService.ExportSubject.Selected, ExportMode.Upload);
|
||||
}
|
||||
|
||||
private async void Menu_Contacts_All_Click(object sender, RoutedEventArgs evt) =>
|
||||
await ViewModel.GenerateMemberList(MemberService.ExportSubject.All, ExportMode.Vcf);
|
||||
private async void Menu_Contacts_Filters_Click(object sender, RoutedEventArgs evt) =>
|
||||
await ViewModel.GenerateMemberList(MemberService.ExportSubject.FromFilters, ExportMode.Vcf);
|
||||
private async void Menu_Contacts_Selected_Click(object sender, RoutedEventArgs evt) =>
|
||||
await ViewModel.GenerateMemberList(MemberService.ExportSubject.Selected, ExportMode.Vcf);
|
||||
|
||||
private async void Menu_List_Order_Click(object sender, RoutedEventArgs evt) {
|
||||
Menu_List.IsSubmenuOpen = true;
|
||||
if (sender == Menu_List_OrderMgNr) {
|
||||
|
||||
@@ -13,7 +13,7 @@ About
|
||||
**Product:** Elwig
|
||||
**Description:** Electronic Management for Vintners' Cooperatives
|
||||
**Type:** ERP system
|
||||
**Version:** 1.0.1.2 ([Changelog](./CHANGELOG.md))
|
||||
**Version:** 1.0.2.0 ([Changelog](./CHANGELOG.md))
|
||||
**License:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Website:** https://elwig.at/
|
||||
**Source code:** https://git.necronda.net/winzer/elwig
|
||||
@@ -33,7 +33,7 @@ Packaging: [WiX Toolset](https://www.firegiant.com/wixtoolset/)
|
||||
**Produkt:** Elwig
|
||||
**Beschreibung:** Elektronische Winzergenossenschaftsverwaltung
|
||||
**Typ:** Warenwirtschaftssystem (ERP-System)
|
||||
**Version:** 1.0.1.2 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||
**Version:** 1.0.2.0 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||
**Lizenz:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Website:** https://elwig.at/
|
||||
**Quellcode:** https://git.necronda.net/winzer/elwig
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
|
||||
<PackageReference Include="Appium.WebDriver" Version="4.4.5" />
|
||||
<PackageReference Include="NReco.PdfRenderer" Version="1.6.0" />
|
||||
<PackageReference Include="NUnit" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.10.0">
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.11.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Tests.UnitTests.HelperTests {
|
||||
Assert.That(payment["GV"], Is.EqualTo(10_000));
|
||||
});
|
||||
|
||||
await b.Calculate(false, false, false);
|
||||
await b.Calculate(true, false, false, false);
|
||||
var prices = await GetMemberDeliveryPrices(year, mgnr);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(prices, Has.Count.EqualTo(7));
|
||||
@@ -234,7 +234,7 @@ namespace Tests.UnitTests.HelperTests {
|
||||
Assert.That(payment["GV"], Is.EqualTo(8_000));
|
||||
});
|
||||
|
||||
await b.Calculate(true, false, false);
|
||||
await b.Calculate(true, true, false, false);
|
||||
var prices = await GetMemberDeliveryPrices(year, mgnr);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(prices, Has.Count.EqualTo(6));
|
||||
|
||||
Reference in New Issue
Block a user