Update DeliveryAdminWindow

This commit is contained in:
2023-08-14 20:09:53 +02:00
parent f8af155c60
commit 99a6f53307
5 changed files with 149 additions and 78 deletions

View File

@ -3,12 +3,15 @@ using Elwig.Models;
namespace Elwig.Helpers { namespace Elwig.Helpers {
public class ClientParameters { public class ClientParameters {
public enum Type { Matzen, GWK };
public string NameToken; public string NameToken;
public string NameShort; public string NameShort;
public string NameShortened; public string NameShortened;
public string Name; public string Name;
public string NameSuffix; public string NameSuffix;
public string NameFull => $"{Name} {NameSuffix}"; public string NameFull => $"{Name} {NameSuffix}";
public Type? Client;
public PostalDest PostalDest { public PostalDest PostalDest {
set { set {
@ -40,6 +43,7 @@ namespace Elwig.Helpers {
NameShortened = "Winzergenossenschaft f. Matzen u. Umgebung"; NameShortened = "Winzergenossenschaft f. Matzen u. Umgebung";
Name = "Winzergenossenschaft für Matzen und Umgebung"; Name = "Winzergenossenschaft für Matzen und Umgebung";
NameSuffix = "reg. Gen.m.b.H."; NameSuffix = "reg. Gen.m.b.H.";
Client = Type.Matzen;
Plz = 2243; Plz = 2243;
Ort = "Matzen"; Ort = "Matzen";
Address = "Schloßstraße 6"; Address = "Schloßstraße 6";

View File

@ -161,16 +161,19 @@ namespace Elwig.Helpers.Weighing {
var terminalNr = line[49..52].Trim(); var terminalNr = line[49..52].Trim();
var crc16 = line[52..60].Trim(); var crc16 = line[52..60].Trim();
if (Utils.CalcCrc16Modbus(record[..54]).ToString() != crc16) { if (Utils.CalcCrc16Modbus(record[..54]) != ushort.Parse(crc16)) {
throw new IOException($"Invalid response from scale: Invalid CRC16 checksum ({crc16} != {Utils.CalcCrc16Modbus(record[..54]).ToString()})"); throw new IOException($"Invalid response from scale: Invalid CRC16 checksum ({crc16} != {Utils.CalcCrc16Modbus(record[..54]).ToString()})");
} else if (unit != "kg") { } else if (unit != "kg") {
throw new IOException($"Unsupported unit in weighing response: '{unit}'"); throw new IOException($"Unsupported unit in weighing response: '{unit}'");
} }
identNr = identNr.Length > 0 && identNr != "0" ? identNr : null;
var parsedDate = DateOnly.Parse(date);
return new() { return new() {
Weight = int.TryParse(netto, out int w) ? w : null, Weight = int.Parse(netto),
WeighingId = identNr.Length > 0 && identNr != "0" ? identNr : null, WeighingId = identNr,
Date = DateOnly.Parse(date), FullWeighingId = identNr != null ? $"{parsedDate:yyyy-MM-dd}/{identNr}" : null,
Date = parsedDate,
Time = TimeOnly.Parse(time), Time = TimeOnly.Parse(time),
}; };
} }
@ -195,10 +198,10 @@ namespace Elwig.Helpers.Weighing {
p.DtrEnable = false; p.DtrEnable = false;
} else if (EmptyMode == Output.OUT1 || EmptyMode == Output.OUT2) { } else if (EmptyMode == Output.OUT1 || EmptyMode == Output.OUT2) {
int output = EmptyMode == Output.OUT1 ? 1 : 2; int output = EmptyMode == Output.OUT1 ? 1 : 2;
await SendCommand($"OS{output:02i}"); await SendCommand($"OS{output:00}");
await ReceiveResponse(); await ReceiveResponse();
await Task.Delay(EmptyDelay); await Task.Delay(EmptyDelay);
await SendCommand($"OC{output:02i}"); await SendCommand($"OC{output:00}");
await ReceiveResponse(); await ReceiveResponse();
} }
} }
@ -212,7 +215,7 @@ namespace Elwig.Helpers.Weighing {
} else if (FillingClearanceMode == Output.OUT1 || FillingClearanceMode == Output.OUT2) { } else if (FillingClearanceMode == Output.OUT1 || FillingClearanceMode == Output.OUT2) {
string cmd = status ? "OS" : "OC"; string cmd = status ? "OS" : "OC";
int output = FillingClearanceMode == Output.OUT1 ? 1 : 2; int output = FillingClearanceMode == Output.OUT1 ? 1 : 2;
await SendCommand($"{cmd}{output:02i}"); await SendCommand($"{cmd}{output:00}");
await ReceiveResponse(); await ReceiveResponse();
} }
} }

View File

@ -15,6 +15,11 @@ namespace Elwig.Helpers.Weighing {
/// </summary> /// </summary>
public string? WeighingId = null; public string? WeighingId = null;
/// <summary>
/// Wheighing id (or IdentNr) provided by the scale optionally combined with the current date
/// </summary>
public string? FullWeighingId = null;
/// <summary> /// <summary>
/// Date string provided by the scale /// Date string provided by the scale
/// </summary> /// </summary>

View File

@ -266,12 +266,16 @@
Click="WeighingManualButton_Click" Click="WeighingManualButton_Click"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,10,10,10" Grid.Column="2"/> VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,10,10,10" Grid.Column="2"/>
<Button x:Name="WeighingAButton" Content="Wiegen A" Width="120" <Button x:Name="WeighingAButton" Content="Wiegen A" Width="120"
Click="WeighingButton_Click"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,42,10,10" Grid.Column="2"/> VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,42,10,10" Grid.Column="2"/>
<Button x:Name="WeighingBButton" Content="Wiegen B" Width="120" <Button x:Name="WeighingBButton" Content="Wiegen B" Width="120"
Click="WeighingButton_Click"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,74,10,10" Grid.Column="2"/> VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,74,10,10" Grid.Column="2"/>
<Button x:Name="WeighingCButton" Content="Wiegen C" Width="120" <Button x:Name="WeighingCButton" Content="Wiegen C" Width="120"
Click="WeighingButton_Click"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,106,10,10" Grid.Column="2"/> VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,106,10,10" Grid.Column="2"/>
<Button x:Name="WeighingDButton" Content="Wiegen D" Width="120" <Button x:Name="WeighingDButton" Content="Wiegen D" Width="120"
Click="WeighingButton_Click"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,138,10,10" Grid.Column="2"/> VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,138,10,10" Grid.Column="2"/>
</Grid> </Grid>

View File

@ -24,6 +24,9 @@ namespace Elwig.Windows {
private readonly RoutedCommand CtrlF = new(); private readonly RoutedCommand CtrlF = new();
private string? ManualWeighingReason = null; private string? ManualWeighingReason = null;
private string? ScaleId = null;
private string? WeighingId = null;
private Button[] WeighingButtons;
public DeliveryAdminWindow(bool receipt = false) { public DeliveryAdminWindow(bool receipt = false) {
InitializeComponent(); InitializeComponent();
@ -42,6 +45,9 @@ namespace Elwig.Windows {
DeliveryList, DeliveryPartList, DeliveryList, DeliveryPartList,
MemberAddressField, MemberAddressField,
}; };
WeighingButtons = new Button[] {
WeighingAButton, WeighingBButton, WeighingCButton, WeighingDButton,
};
IsReceipt = receipt; IsReceipt = receipt;
Timer = new DispatcherTimer(); Timer = new DispatcherTimer();
@ -111,8 +117,13 @@ namespace Elwig.Windows {
private void InitialInputs() { private void InitialInputs() {
HandPickedInput.IsChecked = null; HandPickedInput.IsChecked = null;
// FIXME if Matzen if (App.Client.Client == ClientParameters.Type.Matzen) {
GerebeltGewogenInput.IsChecked = true; GerebeltGewogenInput.IsChecked = true;
GerebeltGewogenInput.IsEnabled = false;
} else {
GerebeltGewogenInput.IsChecked = false;
GerebeltGewogenInput.IsEnabled = true;
}
ClearOriginalValues(); ClearOriginalValues();
ValidateRequiredInputs(); ValidateRequiredInputs();
} }
@ -311,7 +322,6 @@ namespace Elwig.Windows {
d.Comment = (CommentInput.Text == "") ? null : CommentInput.Text; d.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
p.SortId = (WineVarietyInput.SelectedItem as WineVar)?.SortId; p.SortId = (WineVarietyInput.SelectedItem as WineVar)?.SortId;
p.Weight = int.Parse(WeightInput.Text.Replace("\u202f", ""));
p.Kmw = double.Parse(GradationKmwInput.Text); p.Kmw = double.Parse(GradationKmwInput.Text);
p.QualId = (WineQualityLevelInput.SelectedItem as WineQualLevel)?.QualId; p.QualId = (WineQualityLevelInput.SelectedItem as WineQualLevel)?.QualId;
p.HkId = (WineOriginInput.SelectedItem as WineOrigin)?.HkId; p.HkId = (WineOriginInput.SelectedItem as WineOrigin)?.HkId;
@ -319,16 +329,18 @@ namespace Elwig.Windows {
p.RdNr = (WineRdInput.SelectedItem as WbRd)?.RdNr; p.RdNr = (WineRdInput.SelectedItem as WbRd)?.RdNr;
p.IsGerebelt = GerebeltGewogenInput.IsChecked ?? false; p.IsGerebelt = GerebeltGewogenInput.IsChecked ?? false;
p.ManualWeighing = ManualWeighingInput.IsChecked ?? false;
p.IsHandPicked = HandPickedInput.IsChecked; p.IsHandPicked = HandPickedInput.IsChecked;
p.IsLesewagen = LesewagenInput.IsChecked; p.IsLesewagen = LesewagenInput.IsChecked;
p.Temperature = (TemperatureInput.Text == "") ? null : double.Parse(TemperatureInput.Text); p.Temperature = (TemperatureInput.Text == "") ? null : double.Parse(TemperatureInput.Text);
p.Acid = (TemperatureInput.Text == "") ? null : double.Parse(AcidInput.Text); p.Acid = (AcidInput.Text == "") ? null : double.Parse(AcidInput.Text);
p.Comment = (PartCommentInput.Text == "") ? null : PartCommentInput.Text; p.Comment = (PartCommentInput.Text == "") ? null : PartCommentInput.Text;
// TODO weighing/scale id p.Weight = int.Parse(WeightInput.Text.Replace("\u202f", ""));
// p.ScaleId p.ManualWeighing = ManualWeighingInput.IsChecked ?? false;
// p.WeighingId p.ScaleId = ScaleId;
p.WeighingId = WeighingId;
if (ManualWeighingReason != null)
p.Comment = (p.Comment != null ? $"{p.Comment} / " : "") + $"Begründung Handwiegung: {ManualWeighingReason}";
// TODO update KgNr when MgNr changes (if default is selected) // TODO update KgNr when MgNr changes (if default is selected)
@ -401,6 +413,39 @@ namespace Elwig.Windows {
return p; return p;
} }
private void WeighingButton_Click(object sender, RoutedEventArgs evt) {
int index = Array.IndexOf(WeighingButtons, sender as Button);
if (index >= 0) WeighingButton_Click(index);
}
private async void WeighingButton_Click(int index) {
DisableWeighingButtons();
FinishButton.IsEnabled = false;
NewDeliveryPartButton.IsEnabled = false;
CancelCreatingButton.IsEnabled = false;
try {
var s = App.Scales[index];
var res = await s.Weigh();
if ((res.Weight ?? 0) > 0 && res.FullWeighingId != null) {
WeightInput.Text = $"{res.Weight:N0}";
ScaleId = s.ScaleId;
WeighingId = res.FullWeighingId;
s.Empty();
} else {
WeightInput.Text = "";
ScaleId = null;
WeighingId = null;
}
ManualWeighingReason = null;
ManualWeighingInput.IsChecked = false;
} catch (Exception e) {
MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler",
MessageBoxButton.OK, MessageBoxImage.Error);
}
EnableWeighingButtons();
UpdateButtons();
}
private async void SearchInput_TextChanged(object sender, RoutedEventArgs evt) { private async void SearchInput_TextChanged(object sender, RoutedEventArgs evt) {
TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(e => e.Length > 0); TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(e => e.Length > 0);
await RefreshDeliveryListQuery(true); await RefreshDeliveryListQuery(true);
@ -500,11 +545,7 @@ namespace Elwig.Windows {
IsEditing = false; IsEditing = false;
DeliveryList.IsEnabled = true; DeliveryList.IsEnabled = true;
DeliveryPartList.IsEnabled = true; DeliveryPartList.IsEnabled = true;
WeighingManualButton.IsEnabled = false; DisableWeighingButtons();
WeighingAButton.IsEnabled = false;
WeighingBButton.IsEnabled = false;
WeighingCButton.IsEnabled = false;
WeighingDButton.IsEnabled = false;
HideFinishNewPartDeliveryCancelButtons(); HideFinishNewPartDeliveryCancelButtons();
ShowNewEditDeleteButtons(); ShowNewEditDeleteButtons();
RefreshInputs(); RefreshInputs();
@ -522,11 +563,7 @@ namespace Elwig.Windows {
IsCreating = true; IsCreating = true;
DeliveryList.IsEnabled = false; DeliveryList.IsEnabled = false;
DeliveryPartList.IsEnabled = false; DeliveryPartList.IsEnabled = false;
WeighingManualButton.IsEnabled = true; EnableWeighingButtons();
WeighingAButton.IsEnabled = true;
WeighingBButton.IsEnabled = true;
WeighingCButton.IsEnabled = true;
WeighingDButton.IsEnabled = true;
DeliveryList.SelectedItem = null; DeliveryList.SelectedItem = null;
HideNewEditDeleteButtons(); HideNewEditDeleteButtons();
ShowFinishNewPartDeliveryCancelButtons(); ShowFinishNewPartDeliveryCancelButtons();
@ -545,6 +582,8 @@ namespace Elwig.Windows {
WeightInput.Text = $"{res?.Item1:N0}"; WeightInput.Text = $"{res?.Item1:N0}";
ManualWeighingInput.IsChecked = true; ManualWeighingInput.IsChecked = true;
ManualWeighingReason = res?.Item2; ManualWeighingReason = res?.Item2;
ScaleId = null;
WeighingId = null;
} }
private void EditDeliveryButton_Click(object sender, RoutedEventArgs evt) { private void EditDeliveryButton_Click(object sender, RoutedEventArgs evt) {
@ -733,6 +772,22 @@ namespace Elwig.Windows {
BranchInput.IsEnabled = false; BranchInput.IsEnabled = false;
} }
private void DisableWeighingButtons() {
WeighingManualButton.IsEnabled = false;
WeighingAButton.IsEnabled = false;
WeighingBButton.IsEnabled = false;
WeighingCButton.IsEnabled = false;
WeighingDButton.IsEnabled = false;
}
private void EnableWeighingButtons() {
WeighingManualButton.IsEnabled = true;
WeighingAButton.IsEnabled = true;
WeighingBButton.IsEnabled = true;
WeighingCButton.IsEnabled = true;
WeighingDButton.IsEnabled = true;
}
private async Task UpdateLsNr() { private async Task UpdateLsNr() {
if (DateInput.Text == "" || BranchInput.SelectedItem == null) { if (DateInput.Text == "" || BranchInput.SelectedItem == null) {
LsNrInput.Text = ""; LsNrInput.Text = "";