Decodifica PLU dai barcode CODE128 a 7 cifre
Oltre alle etichette a peso variabile (EAN13/CODE128 a 13 cifre), ora vengono riconosciuti i CODE128 di 7 cifre che iniziano con '2': si scarta il prefisso e restano le 6 cifre del PLU, come per DecodeEanPeso.
This commit is contained in:
@@ -26,6 +26,8 @@ public class BarcodeManager(
|
||||
|
||||
if (IsEanPeso(dto))
|
||||
stringValue = DecodeEanPeso(stringValue);
|
||||
else if (IsPlu(dto))
|
||||
stringValue = DecodePlu(stringValue);
|
||||
|
||||
messenger.Send(new NewScannerMessage(stringValue));
|
||||
},
|
||||
@@ -39,14 +41,29 @@ public class BarcodeManager(
|
||||
(IsEtichetta128(barcodeScan) || IsEan13(barcodeScan)) && barcodeScan.StringValue is { Length: 13 } &&
|
||||
barcodeScan.StringValue.StartsWith('2');
|
||||
|
||||
private static bool IsPlu(BarcodeScanDto barcodeScan) =>
|
||||
IsCode128(barcodeScan) && barcodeScan.StringValue is { Length: 7 } && barcodeScan.StringValue.StartsWith('2');
|
||||
|
||||
private static bool IsEtichetta128(BarcodeScanDto barcodeScan) =>
|
||||
barcodeScan.Type is BarcodeType.CODE128 or BarcodeType.EAN128;
|
||||
|
||||
private static bool IsCode128(BarcodeScanDto barcodeScan) =>
|
||||
barcodeScan.Type == BarcodeType.CODE128;
|
||||
|
||||
private static bool IsEan13(BarcodeScanDto barcodeScan) =>
|
||||
barcodeScan.Type == BarcodeType.EAN13;
|
||||
|
||||
private static string DecodeEanPeso(string? barcode)
|
||||
{
|
||||
return barcode is not { Length: 13 } ? throw new Exception("Errore durante il parse del barcode (" + barcode + ")") : barcode.Substring(1, 6);
|
||||
return barcode is not { Length: 13 }
|
||||
? throw new Exception("Errore durante il parse del barcode (" + barcode + ")")
|
||||
: barcode.Substring(1, 6);
|
||||
}
|
||||
|
||||
private static string DecodePlu(string? barcode)
|
||||
{
|
||||
return barcode is not { Length: 7 }
|
||||
? throw new Exception("Errore durante il parse del barcode (" + barcode + ")")
|
||||
: barcode.Substring(1, 6);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user