Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
9172222307 | |||
05a75a52cc | |||
8732141e6b | |||
99ca12b276 | |||
7ff069d068 | |||
583d5b4e3e | |||
3f2b5b684c | |||
5db14c09ad |
@ -63,7 +63,7 @@ namespace Elwig {
|
||||
Directory.CreateDirectory(TempPath);
|
||||
Directory.CreateDirectory(DataPath);
|
||||
MainDispatcher = Dispatcher;
|
||||
Scales = Array.Empty<IScale>();
|
||||
Scales = [];
|
||||
CurrentApp = this;
|
||||
OverrideCulture();
|
||||
}
|
||||
@ -96,7 +96,7 @@ namespace Elwig {
|
||||
return;
|
||||
}
|
||||
|
||||
Dictionary<string, (string, string, int?, string?, string?, string?, string?, string?)> branches = new();
|
||||
Dictionary<string, (string, string, int?, string?, string?, string?, string?, string?)> branches = [];
|
||||
using (var ctx = new AppDbContext()) {
|
||||
branches = ctx.Branches.ToDictionary(b => b.Name.ToLower(), b => (b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr));
|
||||
try {
|
||||
@ -115,23 +115,11 @@ namespace Elwig {
|
||||
|
||||
var list = new List<IScale>();
|
||||
foreach (var s in Config.Scales) {
|
||||
var id = s[0];
|
||||
try {
|
||||
var type = s[1]?.ToLower();
|
||||
var model = s[2];
|
||||
var cnx = s[3];
|
||||
var empty = s[4];
|
||||
var filling = s[5];
|
||||
int? limit = s[6] == null ? null : int.Parse(s[6]);
|
||||
var log = s[7];
|
||||
if (type == "systec") {
|
||||
list.Add(new SystecScale(id, model, cnx, empty, filling, limit, log));
|
||||
} else {
|
||||
throw new ArgumentException($"Invalid scale type: \"{type}\"");
|
||||
}
|
||||
list.Add(Scale.FromConfig(s));
|
||||
} catch (Exception e) {
|
||||
list.Add(new InvalidScale(id));
|
||||
MessageBox.Show($"Unable to create scale {s[0]}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
list.Add(new InvalidScale(s.Id));
|
||||
MessageBox.Show($"Unable to create scale {s.Id}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
Scales = list;
|
||||
|
@ -15,7 +15,7 @@ namespace Elwig.Documents {
|
||||
public MemberDataSheet(Member m, AppDbContext ctx) : base($"{Name} {m.AdministrativeName}", m) {
|
||||
DocumentId = $"{Name} {m.MgNr}";
|
||||
Season = ctx.Seasons.ToList().MaxBy(s => s.Year) ?? throw new ArgumentException("invalid season");
|
||||
MemberBuckets = ctx.GetMemberBuckets(Season.Year, m.MgNr).GetAwaiter().GetResult();
|
||||
MemberBuckets = ctx.GetMemberBuckets(Utils.CurrentYear, m.MgNr).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<ApplicationIcon>Resources\Images\Elwig.ico</ApplicationIcon>
|
||||
<Version>0.6.6</Version>
|
||||
<Version>0.6.7</Version>
|
||||
<SatelliteResourceLanguages>de-AT</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace Elwig.Helpers {
|
||||
public static class AppDbUpdater {
|
||||
|
||||
// Don't forget to update value in Tests/fetch-resources.bat!
|
||||
public static readonly int RequiredSchemaVersion = 16;
|
||||
public static readonly int RequiredSchemaVersion = 17;
|
||||
|
||||
private static int VersionOffset = 0;
|
||||
|
||||
|
@ -7,20 +7,20 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Helpers {
|
||||
public class ClientParameters {
|
||||
|
||||
public enum Type { Matzen, Winzerkeller };
|
||||
public enum Type { Matzen, Winzerkeller, Weinland, Baden };
|
||||
|
||||
public bool IsMatzen => Client == Type.Matzen;
|
||||
public bool IsWinzerkeller => Client == Type.Winzerkeller;
|
||||
public bool IsWolkersdorf => Client == Type.Winzerkeller && App.ZwstId == "W";
|
||||
public bool IsHaugsdorf => Client == Type.Winzerkeller && App.ZwstId == "H";
|
||||
public bool IsSitzendorf => Client == Type.Winzerkeller && App.ZwstId == "S";
|
||||
public bool IsWeinland => Client == Type.Weinland;
|
||||
public bool IsBaden => Client == Type.Baden;
|
||||
public bool IsWolkersdorf => IsWinzerkeller && App.ZwstId == "W";
|
||||
public bool IsHaugsdorf => IsWinzerkeller && App.ZwstId == "H";
|
||||
public bool IsSitzendorf => IsWinzerkeller && App.ZwstId == "S";
|
||||
public bool IsGrInzersdorf => IsWeinland;
|
||||
|
||||
public bool HasRebler(string? zwstId) => IsMatzen || (IsWinzerkeller && zwstId == "W");
|
||||
public bool HasRebler(Branch? b) => HasRebler(b?.ZwstId);
|
||||
public bool HasRebler() => HasRebler(App.ZwstId);
|
||||
public bool HasKisten(string? zwstId) => IsWinzerkeller && (zwstId == "H" || zwstId == "S");
|
||||
public bool HasKisten(Branch? b) => HasKisten(b?.ZwstId);
|
||||
public bool HasKisten() => HasKisten(App.ZwstId);
|
||||
public bool HasNetWeighing(string? zwstId) => IsMatzen || (IsWinzerkeller && zwstId == "W");
|
||||
public bool HasNetWeighing(Branch? b) => HasNetWeighing(b?.ZwstId);
|
||||
public bool HasNetWeighing() => HasNetWeighing(App.ZwstId);
|
||||
|
||||
public string NameToken;
|
||||
public string NameShort;
|
||||
@ -36,8 +36,8 @@ namespace Elwig.Helpers {
|
||||
|
||||
public PostalDest PostalDest {
|
||||
set {
|
||||
Plz = value.AtPlz.Plz;
|
||||
Ort = value.AtPlz.Ort.Name;
|
||||
Plz = value.AtPlz!.Plz;
|
||||
Ort = value.AtPlz!.Ort.Name;
|
||||
}
|
||||
}
|
||||
public int Plz;
|
||||
@ -72,8 +72,14 @@ namespace Elwig.Helpers {
|
||||
NameSuffix = parameters.GetValueOrDefault("CLIENT_NAME_SUFFIX");
|
||||
NameType = parameters["CLIENT_NAME_TYPE"] ?? throw new KeyNotFoundException();
|
||||
switch (Name) {
|
||||
case "Winzergenossenschaft für Matzen und Umgebung": Client = Type.Matzen; break;
|
||||
case "Winzerkeller im Weinviertel": Client = Type.Winzerkeller; break;
|
||||
case "Winzergenossenschaft für Matzen und Umgebung":
|
||||
Client = Type.Matzen; break;
|
||||
case "Winzerkeller im Weinviertel":
|
||||
Client = Type.Winzerkeller; break;
|
||||
case "Winzergenossenschaft Weinland":
|
||||
Client = Type.Weinland; break;
|
||||
case "Winzergenossenschaft Baden - Bad Vöslau":
|
||||
Client = Type.Baden; break;
|
||||
};
|
||||
|
||||
Plz = int.Parse(parameters["CLIENT_PLZ"] ?? "");
|
||||
@ -115,7 +121,7 @@ namespace Elwig.Helpers {
|
||||
case 2: deliveryNoteStats = "SHORT"; break;
|
||||
case 3: deliveryNoteStats = "FULL"; break;
|
||||
}
|
||||
return new (string, string?)[] {
|
||||
return [
|
||||
("CLIENT_NAME_TOKEN", NameToken),
|
||||
("CLIENT_NAME_SHORT", NameShort),
|
||||
("CLIENT_NAME", Name),
|
||||
@ -137,7 +143,7 @@ namespace Elwig.Helpers {
|
||||
("TEXT_DELIVERYNOTE", TextDeliveryNote),
|
||||
("TEXT_DELIVERYCONFIRMATION", TextDeliveryConfirmation),
|
||||
("TEXT_CREDITNOTE", TextCreditNote),
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
public async Task UpdateValues() {
|
||||
|
@ -4,6 +4,31 @@ using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
|
||||
public record struct ScaleConfig {
|
||||
public string Id;
|
||||
public string? Type;
|
||||
public string? Model;
|
||||
public string? Connection;
|
||||
public string? Empty;
|
||||
public string? Filling;
|
||||
public string? Limit;
|
||||
public string? Log;
|
||||
public string? _Log;
|
||||
|
||||
public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, string? log) {
|
||||
Id = id;
|
||||
Type = type;
|
||||
Model = model;
|
||||
Connection = cnx;
|
||||
Empty = empty;
|
||||
Filling = filling;
|
||||
Limit = limit;
|
||||
_Log = log;
|
||||
Log = log != null ? Path.Combine(App.DataPath, log) : null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Config {
|
||||
|
||||
private readonly string FileName;
|
||||
@ -11,8 +36,8 @@ namespace Elwig.Helpers {
|
||||
public string DatabaseFile = App.DataPath + "database.sqlite3";
|
||||
public string? DatabaseLog = null;
|
||||
public string? Branch = null;
|
||||
public IList<string?[]> Scales;
|
||||
private readonly List<string?[]> ScaleList = [];
|
||||
public IList<ScaleConfig> Scales;
|
||||
private readonly List<ScaleConfig> ScaleList = [];
|
||||
private static readonly string[] trueValues = ["1", "true", "yes", "on"];
|
||||
|
||||
public Config(string filename) {
|
||||
@ -34,12 +59,10 @@ namespace Elwig.Helpers {
|
||||
ScaleList.Clear();
|
||||
Scales = ScaleList;
|
||||
foreach (var s in scales) {
|
||||
string? scaleLog = config[$"scale.{s}:log"];
|
||||
if (scaleLog != null) scaleLog = Path.Combine(App.DataPath, scaleLog);
|
||||
ScaleList.Add([
|
||||
ScaleList.Add(new(
|
||||
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"], scaleLog
|
||||
]);
|
||||
config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], config[$"scale.{s}:log"]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,11 +74,11 @@ namespace Elwig.Helpers {
|
||||
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
|
||||
if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
|
||||
foreach (var s in ScaleList) {
|
||||
file.Write($"\r\n[scale.{s[0]}]\r\ntype = {s[1]}\r\nmodel = {s[2]}\r\nconnection = {s[3]}\r\n");
|
||||
if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
|
||||
if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
|
||||
if (s[6] != null) file.Write($"limit = {s[6]}\r\n");
|
||||
if (s[7] != null) file.Write($"log = {s[7]}\r\n");
|
||||
file.Write($"\r\n[scale.{s.Id}]\r\ntype = {s.Type}\r\nmodel = {s.Model}\r\nconnection = {s.Connection}\r\n");
|
||||
if (s.Empty != null) file.Write($"empty = {s.Empty}\r\n");
|
||||
if (s.Filling != null) file.Write($"filling = {s.Filling}\r\n");
|
||||
if (s.Limit != null) file.Write($"limit = {s.Limit}\r\n");
|
||||
if (s._Log != null) file.Write($"log = {s._Log}\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
public class GassnerScale : IScale {
|
||||
|
||||
protected SerialPort Serial = null;
|
||||
protected StreamReader Reader;
|
||||
protected StreamWriter Writer;
|
||||
|
||||
public string Manufacturer => "Gassner";
|
||||
public int InternalScaleNr => 1;
|
||||
public string Model { get; private set; }
|
||||
public string ScaleId { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public bool HasFillingClearance { get; private set; }
|
||||
public int? WeightLimit { get; private set; }
|
||||
public string? LogPath { get; private set; }
|
||||
|
||||
public GassnerScale(string id, string model, string connection) {
|
||||
ScaleId = id;
|
||||
Model = model;
|
||||
IsReady = true;
|
||||
HasFillingClearance = false;
|
||||
|
||||
if (!connection.StartsWith("serial:"))
|
||||
throw new ArgumentException("Unsupported scheme");
|
||||
|
||||
Serial = Utils.OpenSerialConnection(connection);
|
||||
Writer = new(Serial.BaseStream, Encoding.ASCII, -1, true);
|
||||
Reader = new(Serial.BaseStream, Encoding.ASCII, false, -1, true);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Writer.Close();
|
||||
Reader.Close();
|
||||
Serial.Close();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public async Task<WeighingResult> Weigh(bool incIdentNr) {
|
||||
await Writer.WriteAsync(incIdentNr ? "\x05" : "?");
|
||||
// TODO receive response
|
||||
return new();
|
||||
}
|
||||
|
||||
public async Task<WeighingResult> GetCurrentWeight() {
|
||||
return await Weigh(false);
|
||||
}
|
||||
|
||||
public async Task<WeighingResult> Weigh() {
|
||||
return await Weigh(true);
|
||||
}
|
||||
|
||||
public async Task Empty() { }
|
||||
|
||||
public async Task GrantFillingClearance() { }
|
||||
|
||||
public async Task RevokeFillingClearance() { }
|
||||
}
|
||||
}
|
95
Elwig/Helpers/Weighing/Scale.cs
Normal file
95
Elwig/Helpers/Weighing/Scale.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.IO.Ports;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System;
|
||||
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
public abstract class Scale : IDisposable {
|
||||
|
||||
protected enum Output { RTS, DTR, OUT1, OUT2 };
|
||||
|
||||
protected SerialPort? Serial = null;
|
||||
protected SerialPort? ControlSerialEmpty = null, ControlSerialFilling = null;
|
||||
protected TcpClient? Tcp = null;
|
||||
protected Stream Stream;
|
||||
|
||||
protected readonly Output? EmptyMode = null;
|
||||
protected readonly Output? FillingClearanceMode = null;
|
||||
protected readonly int EmptyDelay;
|
||||
|
||||
public int? WeightLimit { get; private set; }
|
||||
public string? LogPath { get; private set; }
|
||||
|
||||
public static IScale FromConfig(ScaleConfig config) {
|
||||
int? limit = config.Limit != null ? int.Parse(config.Limit) : null;
|
||||
if (config.Type == "SysTec-IT") {
|
||||
return new SysTecITScale(config.Id, config.Model!, config.Connection!, config.Empty, config.Filling, limit, config.Log);
|
||||
} else if (config.Type == "Schember-evt") {
|
||||
return new SchemberEventScale(config.Id, config.Model!, config.Connection!, config.Empty, config.Filling, limit, config.Log);
|
||||
} else {
|
||||
throw new ArgumentException($"Invalid scale type: \"{config.Type}\"");
|
||||
}
|
||||
}
|
||||
|
||||
protected Scale(string cnx, string? empty, string? filling, int? limit, string? log) {
|
||||
if (cnx.StartsWith("serial:")) {
|
||||
Serial = Utils.OpenSerialConnection(cnx);
|
||||
Stream = Serial.BaseStream;
|
||||
} else if (cnx.StartsWith("tcp:")) {
|
||||
Tcp = Utils.OpenTcpConnection(cnx);
|
||||
Stream = Tcp.GetStream();
|
||||
} else {
|
||||
throw new ArgumentException("Unsupported scheme");
|
||||
}
|
||||
|
||||
LogPath = log;
|
||||
|
||||
if (empty != null) {
|
||||
var parts = empty.Split(':');
|
||||
if (parts.Length == 3) {
|
||||
if (parts[0] != Serial?.PortName)
|
||||
ControlSerialEmpty = Utils.OpenSerialConnection($"serial://{parts[0]}:9600");
|
||||
} else if (parts.Length != 2) {
|
||||
throw new ArgumentException("Invalid value for 'empty'");
|
||||
}
|
||||
EmptyMode = ConvertOutput(parts[^2]);
|
||||
EmptyDelay = int.Parse(parts[^1]);
|
||||
}
|
||||
|
||||
WeightLimit = limit;
|
||||
if (filling != null) {
|
||||
var parts = filling.Split(':');
|
||||
if (parts.Length == 2) {
|
||||
if (parts[0] != Serial?.PortName)
|
||||
ControlSerialFilling = parts[0] != ControlSerialEmpty?.PortName ? Utils.OpenSerialConnection($"serial://{parts[0]}:9600") : ControlSerialEmpty;
|
||||
} else if (parts.Length != 1) {
|
||||
throw new ArgumentException("Invalid value for 'filling'");
|
||||
}
|
||||
FillingClearanceMode = ConvertOutput(parts[^1]);
|
||||
}
|
||||
|
||||
if (FillingClearanceMode != null && WeightLimit == null)
|
||||
throw new ArgumentException("Weight limit has to be set, if filling clearance supervision is enabled");
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Stream.Close();
|
||||
Serial?.Close();
|
||||
ControlSerialEmpty?.Close();
|
||||
ControlSerialFilling?.Close();
|
||||
Tcp?.Close();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected static Output? ConvertOutput(string? value) {
|
||||
return value switch {
|
||||
null => null,
|
||||
"RTS" => Output.RTS,
|
||||
"DTR" => Output.DTR,
|
||||
"OUT1" => Output.OUT1,
|
||||
"OUT2" => Output.OUT2,
|
||||
_ => throw new ArgumentException($"Invalid value for argument: '{value}'"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
22
Elwig/Helpers/Weighing/SchemberEventScale.cs
Normal file
22
Elwig/Helpers/Weighing/SchemberEventScale.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
public class SchemberEventScale : Scale, IEventScale {
|
||||
|
||||
public string Manufacturer => "Schember";
|
||||
public int InternalScaleNr => 1;
|
||||
public string Model { get; private set; }
|
||||
public string ScaleId { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public bool HasFillingClearance { get; private set; }
|
||||
|
||||
public SchemberEventScale(string id, string model, string cnx, string? empty = null, string? filling = null, int? limit = null, string? log = null) :
|
||||
base(cnx, empty, filling, limit, log) {
|
||||
ScaleId = id;
|
||||
Model = model;
|
||||
IsReady = true;
|
||||
HasFillingClearance = false;
|
||||
Stream.WriteTimeout = 250;
|
||||
Stream.ReadTimeout = 6000;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
public class SchemberScale : IEventScale {
|
||||
|
||||
public string Manufacturer => "Schember";
|
||||
public string Model => throw new NotImplementedException();
|
||||
public string ScaleId => throw new NotImplementedException();
|
||||
public int InternalScaleNr => throw new NotImplementedException();
|
||||
public bool IsReady => throw new NotImplementedException();
|
||||
public bool HasFillingClearance => throw new NotImplementedException();
|
||||
public int? WeightLimit => throw new NotImplementedException();
|
||||
public string? LogPath => throw new NotImplementedException();
|
||||
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
public class SystecScale : ICommandScale {
|
||||
|
||||
protected enum Output { RTS, DTR, OUT1, OUT2 };
|
||||
|
||||
protected SerialPort? Serial = null;
|
||||
protected SerialPort? ControlSerialEmpty = null, ControlSerialFilling = null;
|
||||
protected TcpClient? Tcp = null;
|
||||
protected Stream Stream;
|
||||
|
||||
protected readonly Output? EmptyMode = null;
|
||||
protected readonly Output? FillingClearanceMode = null;
|
||||
protected readonly int EmptyDelay;
|
||||
public class SysTecITScale : Scale, ICommandScale {
|
||||
|
||||
public string Manufacturer => "SysTec";
|
||||
public int InternalScaleNr => 1;
|
||||
@ -25,74 +13,15 @@ namespace Elwig.Helpers.Weighing {
|
||||
public string ScaleId { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public bool HasFillingClearance { get; private set; }
|
||||
public int? WeightLimit { get; private set; }
|
||||
public string? LogPath { get; private set; }
|
||||
|
||||
public SystecScale(string id, string model, string connection, string? empty = null, string? filling = null, int? limit = null, string? log = null) {
|
||||
public SysTecITScale(string id, string model, string cnx, string? empty = null, string? filling = null, int? limit = null, string? log = null) :
|
||||
base(cnx, empty, filling, limit, log) {
|
||||
ScaleId = id;
|
||||
Model = model;
|
||||
IsReady = true;
|
||||
HasFillingClearance = false;
|
||||
LogPath = log;
|
||||
|
||||
if (connection.StartsWith("serial:")) {
|
||||
Serial = Utils.OpenSerialConnection(connection);
|
||||
Stream = Serial.BaseStream;
|
||||
} else if (connection.StartsWith("tcp:")) {
|
||||
Tcp = Utils.OpenTcpConnection(connection);
|
||||
Stream = Tcp.GetStream();
|
||||
} else {
|
||||
throw new ArgumentException("Unsupported scheme");
|
||||
}
|
||||
Stream.WriteTimeout = 250;
|
||||
Stream.ReadTimeout = 11000;
|
||||
|
||||
if (empty != null) {
|
||||
var parts = empty.Split(':');
|
||||
if (parts.Length == 3) {
|
||||
if (parts[0] != Serial?.PortName)
|
||||
ControlSerialEmpty = Utils.OpenSerialConnection($"serial://{parts[0]}:9600");
|
||||
} else if (parts.Length != 2) {
|
||||
throw new ArgumentException("Invalid value for 'empty'");
|
||||
}
|
||||
EmptyMode = ConvertOutput(parts[^2]);
|
||||
EmptyDelay = int.Parse(parts[^1]);
|
||||
}
|
||||
|
||||
WeightLimit = limit;
|
||||
if (filling != null) {
|
||||
var parts = filling.Split(':');
|
||||
if (parts.Length == 2) {
|
||||
if (parts[0] != Serial?.PortName)
|
||||
ControlSerialFilling = parts[0] != ControlSerialEmpty?.PortName ? Utils.OpenSerialConnection($"serial://{parts[0]}:9600") : ControlSerialEmpty;
|
||||
} else if (parts.Length != 1) {
|
||||
throw new ArgumentException("Invalid value for 'filling'");
|
||||
}
|
||||
FillingClearanceMode = ConvertOutput(parts[^1]);
|
||||
}
|
||||
|
||||
if (FillingClearanceMode != null && WeightLimit == null)
|
||||
throw new ArgumentException("Weight limit has to be set, if filling clearance supervision is enabled");
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Stream.Close();
|
||||
Serial?.Close();
|
||||
ControlSerialEmpty?.Close();
|
||||
ControlSerialFilling?.Close();
|
||||
Tcp?.Close();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected static Output? ConvertOutput(string? value) {
|
||||
return value switch {
|
||||
null => null,
|
||||
"RTS" => Output.RTS,
|
||||
"DTR" => Output.DTR,
|
||||
"OUT1" => Output.OUT1,
|
||||
"OUT2" => Output.OUT2,
|
||||
_ => throw new ArgumentException($"Invalid value for argument: '{value}'"),
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task SendCommand(string command) {
|
12
Elwig/Resources/Sql/16-17.sql
Normal file
12
Elwig/Resources/Sql/16-17.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- schema version 16 to 17
|
||||
|
||||
CREATE VIEW v_virtual_season AS
|
||||
SELECT year, max_kg_per_ha
|
||||
FROM season
|
||||
UNION
|
||||
SELECT strftime('%Y', date()) + 0, (SELECT max_kg_per_ha FROM season ORDER BY year DESC LIMIT 1);
|
||||
|
||||
PRAGMA writable_schema = ON;
|
||||
UPDATE sqlite_schema SET sql = REPLACE(sql, 'season s', 'v_virtual_season s')
|
||||
WHERE type = 'view' AND name = 'v_area_commitment_bucket_strict';
|
||||
PRAGMA writable_schema = OFF;
|
@ -16,21 +16,21 @@ namespace Elwig.Windows {
|
||||
public int MgNr => Member.MgNr;
|
||||
|
||||
private readonly Member Member;
|
||||
private List<string> TextFilter = new();
|
||||
private List<string> TextFilter = [];
|
||||
|
||||
public AreaComAdminWindow(int mgnr) {
|
||||
InitializeComponent();
|
||||
Member = Context.Members.Find(mgnr) ?? throw new ArgumentException("MgNr argument has invalid value");
|
||||
Title = $"Flächenbindungen - {Member.AdministrativeName} - Elwig";
|
||||
ExemptInputs = new Control[] {
|
||||
ExemptInputs = [
|
||||
MgNrInput, AreaCommitmentList, NewAreaCommitmentButton,
|
||||
EditAreaCommitmentButton, DeleteAreaCommitmentButton, AreaCommitmentSaveButton,
|
||||
AreaCommitmentResetButton, AreaCommitmentCancelButton, SearchInput, ActiveAreaCommitmentInput
|
||||
};
|
||||
RequiredInputs = new Control[] {
|
||||
];
|
||||
RequiredInputs = [
|
||||
FbNrInput, YearFromInput, KgInput, RdInput,
|
||||
GstNrInput, AreaInput.TextBox, AreaComTypeInput, WineCultivationInput
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
@ -76,10 +76,10 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async Task<(List<string>, IQueryable<AreaCom>, List<string>)> GetFilters() {
|
||||
List<string> filterNames = new();
|
||||
List<string> filterNames = [];
|
||||
IQueryable<AreaCom> areaComQuery = Context.AreaCommitments.Where(a => a.MgNr == Member.MgNr).OrderBy(a => a.FbNr);
|
||||
if (ActiveAreaCommitmentInput.IsChecked == true) {
|
||||
areaComQuery = areaComQuery.Where(a => (a.YearFrom <= Utils.CurrentNextSeason) && (a.YearTo == null || a.YearTo >= Utils.CurrentNextSeason));
|
||||
areaComQuery = areaComQuery.Where(a => (a.YearFrom <= Utils.CurrentYear) && (a.YearTo == null || a.YearTo >= Utils.CurrentYear));
|
||||
filterNames.Add("aktiv");
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ namespace Elwig.Windows {
|
||||
YearToInput.Text = a.YearTo.ToString();
|
||||
|
||||
KgInput.SelectedItem = a.Kg.AtKg;
|
||||
RdInput.SelectedItem = a.Rd;
|
||||
RdInput.SelectedItem = a.Rd ?? RdInput.Items[0];
|
||||
GstNrInput.Text = a.GstNr;
|
||||
AreaInput.Text = a.Area.ToString();
|
||||
|
||||
@ -230,8 +230,8 @@ namespace Elwig.Windows {
|
||||
a.RdNr = RdInput.SelectedItem.GetType() == typeof(NullItem) ? null : ((WbRd)RdInput.SelectedItem).RdNr;
|
||||
a.GstNr = GstNrInput.Text;
|
||||
a.Area = int.Parse(AreaInput.Text);
|
||||
a.VtrgId = (AreaComTypeInput.SelectedItem as AreaComType)?.VtrgId;
|
||||
a.CultId = (WineCultivationInput.SelectedItem as WineCult)?.CultId;
|
||||
a.VtrgId = (AreaComTypeInput.SelectedItem as AreaComType)!.VtrgId;
|
||||
a.CultId = (WineCultivationInput.SelectedItem as WineCult)!.CultId;
|
||||
a.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
|
||||
|
||||
EntityEntry<AreaCom>? tr = null;
|
||||
@ -275,7 +275,7 @@ namespace Elwig.Windows {
|
||||
MessageBox.Show(str, "Flächenbindung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
return a;
|
||||
return a!;
|
||||
}
|
||||
|
||||
private async void AreaCommitmentSaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -287,7 +287,7 @@ namespace Elwig.Windows {
|
||||
ShowAreaCommitmentNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
await RefreshAreaCommitmentList();
|
||||
await App.HintContextChange();
|
||||
AreaCommitmentList.SelectedItem = a;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void InitialDefaultInputs() {
|
||||
if (App.Client.HasRebler(BranchInput.SelectedValue as Branch)) {
|
||||
if (App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch)) {
|
||||
GerebeltGewogenInput.IsEnabled = false;
|
||||
SetDefaultValue(GerebeltGewogenInput, true);
|
||||
} else {
|
||||
@ -226,7 +226,7 @@ namespace Elwig.Windows {
|
||||
UnsetDefaultValue(GerebeltGewogenInput);
|
||||
}
|
||||
|
||||
if (App.Client.HasKisten(BranchInput.SelectedValue as Branch)) {
|
||||
if (!App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch)) {
|
||||
LesewagenInput.IsEnabled = false;
|
||||
SetDefaultValue(LesewagenInput, false);
|
||||
HandPickedInput.IsThreeState = false;
|
||||
@ -256,9 +256,9 @@ namespace Elwig.Windows {
|
||||
ClearOriginalValues();
|
||||
ClearDefaultValues();
|
||||
|
||||
GerebeltGewogenInput.IsChecked = App.Client.HasRebler(BranchInput.SelectedValue as Branch);
|
||||
GerebeltGewogenInput.IsChecked = App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch);
|
||||
LesewagenInput.IsChecked = false;
|
||||
HandPickedInput.IsChecked = App.Client.HasKisten(BranchInput.SelectedValue as Branch) ? true : null;
|
||||
HandPickedInput.IsChecked = !App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch) ? true : null;
|
||||
GebundenInput.IsChecked = null;
|
||||
InitialDefaultInputs();
|
||||
|
||||
@ -1731,14 +1731,14 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void GerebeltGewogenInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
if (App.Client.HasKisten(BranchInput.SelectedValue as Branch)) {
|
||||
if (!App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch)) {
|
||||
HandPickedInput.IsChecked = !GerebeltGewogenInput.IsChecked;
|
||||
}
|
||||
CheckBox_Changed(sender, evt);
|
||||
}
|
||||
|
||||
private void HandPickedInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
if (App.Client.HasKisten(BranchInput.SelectedValue as Branch)) {
|
||||
if (!App.Client.HasNetWeighing(BranchInput.SelectedValue as Branch)) {
|
||||
GerebeltGewogenInput.IsChecked = !HandPickedInput.IsChecked;
|
||||
}
|
||||
CheckBox_Changed(sender, evt);
|
||||
|
@ -9,6 +9,7 @@ namespace Elwig.Windows {
|
||||
InitializeComponent();
|
||||
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
VersionField.Text = "Version: " + (v == null ? "?" : $"{v.Major}.{v.Minor}.{v.Build}") + $" – {App.BranchName}";
|
||||
if (App.Client.Client == null) VersionField.Text += " (Unbekannt)";
|
||||
if (!App.Config.Debug) {
|
||||
TestWindowButton.Visibility = Visibility.Hidden;
|
||||
//QueryWindowButton.Visibility = Visibility.Hidden;
|
||||
|
@ -219,7 +219,7 @@ namespace Elwig.Windows {
|
||||
try {
|
||||
Context.Remove(v);
|
||||
await Context.SaveChangesAsync();
|
||||
await HintContextChange();
|
||||
await App.HintContextChange();
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
|
@ -133,6 +133,18 @@ namespace Tests.HelperTests {
|
||||
Assert.That(Utils.CalcCrc16Modbus("000004.09.2315:51 81 0 0 0kg B"), Is.EqualTo(40472));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000004.09.2315:51 91 0 0 0kg B"), Is.EqualTo(29465));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000004.09.2315:51 101 0 0 0kg B"), Is.EqualTo(29927));
|
||||
// Gr.Inzersdorf (L246/IT3)
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 11 0 0 0kg 001"), Is.EqualTo(27556));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 21 0 0 0kg 001"), Is.EqualTo(7332));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 31 0 0 0kg 001"), Is.EqualTo(61861));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 41 0 0 0kg 001"), Is.EqualTo(62116));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 51 0 0 0kg 001"), Is.EqualTo(8101));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 61 0 0 0kg 001"), Is.EqualTo(26789));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:49 71 50 0 50kg 001"), Is.EqualTo(16188));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:50 81 35 0 35kg 001"), Is.EqualTo(12015));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:50 91 40 0 40kg 001"), Is.EqualTo(60047));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:50 101 40 0 40kg 001"), Is.EqualTo(60785));
|
||||
Assert.That(Utils.CalcCrc16Modbus("000019.02.2410:50 111 45 0 45kg 001"), Is.EqualTo(35918));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
6
Tests/WeighingTests/ScaleTestGrInzersdorf.cs
Normal file
6
Tests/WeighingTests/ScaleTestGrInzersdorf.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Tests.WeighingTests {
|
||||
[TestFixture]
|
||||
public class ScaleTestGrInzersdorf {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace Tests.WeighingTests {
|
||||
class ScaleTestMatzen {
|
||||
|
||||
private MockScale? Mock;
|
||||
private SystecScale? Scale;
|
||||
private SysTecITScale? Scale;
|
||||
|
||||
private static (string, bool) ScaleHandler(string req, int weight, string? error, int identNr) {
|
||||
var modes = error?.Split(';') ?? [];
|
||||
@ -42,7 +42,7 @@ namespace Tests.WeighingTests {
|
||||
if (moving && incr)
|
||||
return ("<13>\r\n", false);
|
||||
|
||||
string data = $"00{(moving ? 1 : 0)}0{DateTime.Now:dd.MM.yyHH:mm}{(incr ? identNr : 0),4}1" +
|
||||
string data = $"00{(moving ? 1 : 0)}0{new DateTime(2020, 10, 15, 12, 34, 0):dd.MM.yyHH:mm}{(incr ? identNr : 0),4}1" +
|
||||
$"{weight,8}{0,8}{weight,8}{(unit ? "lb" : "kg")} {1,3}";
|
||||
ushort checksum = Elwig.Helpers.Utils.CalcCrc16Modbus(data);
|
||||
if (crc) checksum += 10;
|
||||
@ -72,15 +72,15 @@ namespace Tests.WeighingTests {
|
||||
public async Task Test_01_CurrentWeight() {
|
||||
Mock!.Weight = 1234;
|
||||
Assert.That(await Scale!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1234, Date = Utils.Today, Time = Utils.Time,
|
||||
Weight = 1234, Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
Mock!.Weight = 1235;
|
||||
Assert.That(await Scale!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1235, Date = Utils.Today, Time = Utils.Time,
|
||||
Weight = 1235, Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
Mock!.Weight = 1236;
|
||||
Assert.That(await Scale!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1236, Date = Utils.Today, Time = Utils.Time,
|
||||
Weight = 1236, Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
}
|
||||
|
||||
@ -89,20 +89,20 @@ namespace Tests.WeighingTests {
|
||||
Mock!.Weight = 1234;
|
||||
Assert.That(await Scale!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1234, WeighingId = "1",
|
||||
FullWeighingId = $"{DateTime.Today:yyyy-MM-dd}/1",
|
||||
Date = Utils.Today, Time = Utils.Time,
|
||||
FullWeighingId = $"2020-10-15/1",
|
||||
Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
Mock!.Weight = 3333;
|
||||
Assert.That(await Scale!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 3333, WeighingId = "2",
|
||||
FullWeighingId = $"{DateTime.Today:yyyy-MM-dd}/2",
|
||||
Date = Utils.Today, Time = Utils.Time,
|
||||
FullWeighingId = $"2020-10-15/2",
|
||||
Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
Mock!.Weight = 4321;
|
||||
Assert.That(await Scale!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 4321, WeighingId = "3",
|
||||
FullWeighingId = $"{DateTime.Today:yyyy-MM-dd}/3",
|
||||
Date = Utils.Today, Time = Utils.Time,
|
||||
FullWeighingId = $"2020-10-15/3",
|
||||
Date = new DateOnly(2020, 10, 15), Time = new TimeOnly(12, 34),
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
curl -s -L "https://www.necronda.net/elwig/files/create.sql?v=16" -u "elwig:ganzGeheim123!" -o "Resources\Sql\Create.sql"
|
||||
curl -s -L "https://www.necronda.net/elwig/files/create.sql?v=17" -u "elwig:ganzGeheim123!" -o "Resources\Sql\Create.sql"
|
||||
|
Reference in New Issue
Block a user