Skip to content

Commit 630b94b

Browse files
committed
UPDATE: view of NettoWeight - DeviceControl
1 parent 5195069 commit 630b94b

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

Src/Apps/Desktop/ScalesDesktop/Source/Features/LabelPrint.razor.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private async Task PrintLabelAsync()
7070
{
7171
Kneading = LabelContext.KneadingModel.KneadingCount,
7272
ProductDt = GetProductDt(LabelContext.KneadingModel.ProductDate),
73-
WeightNet = (decimal)LabelContext.KneadingModel.NetWeightG / 1000,
73+
WeightNet = LabelContext.KneadingModel.NetWeight,
7474
WeightTare = LabelContext.Plu?.TareWeight ?? 0
7575
};
7676

@@ -123,13 +123,9 @@ private bool ValidateScalesStatus()
123123
return false;
124124
}
125125

126-
if (((decimal)LabelContext.KneadingModel.NetWeightG / 1000 - LabelContext.Plu?.TareWeight ?? 0) < 0)
127-
{
128-
ToastService.ShowWarning(Localizer["ScalesStatusTooLight"]);
129-
return false;
130-
}
131-
132-
return true;
126+
if (LabelContext.KneadingModel.NetWeight >= 0) return true;
127+
ToastService.ShowWarning(Localizer["ScalesStatusTooLight"]);
128+
return false;
133129
}
134130

135131
private static DateTime GetProductDt(DateTime time) =>

Src/Apps/Desktop/ScalesDesktop/Source/Shared/Models/WeightKneadingModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace ScalesDesktop.Source.Shared.Models;
22

33
public class WeightKneadingModel
44
{
5-
public int NetWeightG { get; set; }
5+
public decimal NetWeight { get; set; }
66
public DateTime ProductDate { get; set; } = DateTime.Now;
77
public ushort KneadingCount { get; set; } = 1;
88
}

Src/Apps/Desktop/ScalesDesktop/Source/Widgets/LabelDisplay/LabelDisplayNetWeight.razor

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using MassaK.Plugin.Abstractions.Enums
2+
@using Ws.Shared.Extensions
23

34
<LabelDisplayItem Label="@WsDataLocalizer["ColNetWeight"]">
45
@if (ScalesService.Status == MassaKStatus.Initializing)
@@ -10,14 +11,9 @@
1011
<div class="text-[2rem] flex items-end mx-auto px-4 text-center rounded-lg overflow-hidden xl:text-[2.5rem]
1112
@(!ScalesService.IsStable || GetNetWeight <= 0 ? "text-destructive" : "text-green-400")">
1213
<span class="w-5 flex justify-center xl:w-6">@Sign</span>
13-
@foreach (char intChar in IntegerPart)
14+
@foreach (char i in NetWeightAbsStr)
1415
{
15-
<span class="w-5 flex justify-center xl:w-6">@intChar</span>
16-
}
17-
<span>,</span>
18-
@foreach (char decChar in DecimalPart)
19-
{
20-
<span class="w-5 flex justify-center xl:w-6">@decChar</span>
16+
<span class="@(i.ToString().IsDigitsOnly() ? "w-5 flex justify-center xl:w-6" : string.Empty)">@i</span>
2117
}
2218
<span>@WsDataLocalizer["MeasureKg"]</span>
2319
</div>

Src/Apps/Desktop/ScalesDesktop/Source/Widgets/LabelDisplay/LabelDisplayNetWeight.razor.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Ws.Shared.Extensions;
2+
13
namespace ScalesDesktop.Source.Widgets.LabelDisplay;
24

35
public sealed partial class LabelDisplayNetWeight : ComponentBase, IDisposable
@@ -12,28 +14,26 @@ public sealed partial class LabelDisplayNetWeight : ComponentBase, IDisposable
1214

1315
private Action? StableStatusChangedHandler { get; set; }
1416

17+
#region Weight
18+
19+
private string Sign => GetNetWeight >= 0 ? string.Empty : "-";
20+
private decimal GetNetWeight => LabelContext.KneadingModel.NetWeight;
21+
private string NetWeightAbsStr => Math.Abs(GetNetWeight).ToSepStr(',').PadLeft(8, '0');
22+
23+
#endregion
24+
1525
protected override void OnInitialized()
1626
{
1727
StableStatusChangedHandler = () =>
1828
{
19-
LabelContext.KneadingModel.NetWeightG = ScalesService.CurrentWeight;
29+
LabelContext.KneadingModel.NetWeight = (decimal)ScalesService.CurrentWeight / 1000 - LabelContext.Plu?.TareWeight ?? 0;
2030
StateHasChanged();
2131
};
2232
LabelContext.StateChanged += StateHasChanged;
2333
ScalesService.WeightChanged += StableStatusChangedHandler;
2434
ScalesService.StartPolling();
2535
}
2636

27-
private decimal GetNetWeight => (decimal)LabelContext.KneadingModel.NetWeightG / 1000 - GetTareWeight;
28-
29-
private decimal GetTareWeight => LabelContext.Plu?.TareWeight ?? 0;
30-
31-
private string Sign => GetNetWeight >= 0 ? string.Empty : "-";
32-
33-
private string IntegerPart => $"{Math.Truncate(Math.Abs(GetNetWeight)):0000}";
34-
35-
private string DecimalPart => Math.Abs(GetNetWeight % 1).ToString(".000")[1..];
36-
3737
public void Dispose()
3838
{
3939
ScalesService.StopPolling();

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Plu/Impl/Weight/PluWeightService.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public List<PluWeight> GetAllWeightByArm(Guid uid)
5555

5656
#region Commands
5757

58-
// FIX: dto naming
5958
public WeightLabel GenerateLabel(Guid armId, Guid pluId, CreateWeightLabelDto dto)
6059
{
6160
Arm line = armService.GetItemByUid(armId);
@@ -64,7 +63,7 @@ public WeightLabel GenerateLabel(Guid armId, Guid pluId, CreateWeightLabelDto dt
6463
{
6564
Plu = pluService.GetItemByUid(pluId),
6665
Line = line,
67-
Weight = dto.WeightNet-dto.WeightTare,
66+
Weight = dto.WeightNet,
6867
Kneading = (short)dto.Kneading,
6968
ProductDt = dto.ProductDt
7069
};

0 commit comments

Comments
 (0)