From c9cd2b2df1c119f6b8dc1f3fd97e9f543d307670 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 22 Nov 2021 19:49:59 +0100 Subject: [PATCH] OK deposito e pickup --- REMAN/REMAN/Components/CodeReader.razor | 202 ++++++++++++++++++++++++ REMAN/REMAN/Data/RDataService.cs | 2 +- REMAN/REMAN/Pages/Deposit.razor | 25 +-- REMAN/REMAN/Pages/PickUp.razor | 187 +--------------------- 4 files changed, 205 insertions(+), 211 deletions(-) create mode 100644 REMAN/REMAN/Components/CodeReader.razor diff --git a/REMAN/REMAN/Components/CodeReader.razor b/REMAN/REMAN/Components/CodeReader.razor new file mode 100644 index 0000000..0738cd1 --- /dev/null +++ b/REMAN/REMAN/Components/CodeReader.razor @@ -0,0 +1,202 @@ + +@using Microsoft.AspNetCore.Components.Authorization +@using NKC.Data.DbModels +@using REMAN.Components +@using REMAN.Data +@using static JsFunctions + +@inject AuthenticationStateProvider AuthStateProvider +@inject IJSRuntime JSRuntime +@inject RDataService DataService + +@Title + + +
+
+
+
+

@Title

+
+
+ @if (processing) + { + ...working... + } + +
+
+
+
+
+
+ +
+ @if (!string.IsNullOrEmpty(lastCmd)) + { +
+ +
+ } +
+ @if (!string.IsNullOrEmpty(alertMessage)) + { +
+ @alertMsg +
+ } + @if (!string.IsNullOrEmpty(lastMessage)) + { +
+ @lastMsg +
+ } +
+
+
+
+ +@code { + + [Parameter] + public string Title { get; set; } = "Pick/Deposit"; + + [Parameter] + public bool IsPickup { get; set; } = true; + + private ElementReference CodeInput; + + private bool processing = false; + private string alertMessage = ""; + private string lastMessage = ""; + private MarkupString alertMsg + { + get => (MarkupString)alertMessage; + } + private MarkupString lastMsg + { + get => (MarkupString)lastMessage; + } + + private RemnantsModel currRecord = null; + + private string lastCmd = ""; + + private string inputValue + { + get + { + return ""; + } + set + { + var pUpd = Task.Run(async () => + { + await processInput(value.Trim()); + }); + pUpd.Wait(); + } + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + protected async override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await SetFocusAsync(); + } + } + + public async Task SetFocusAsync() + { + await CodeInput.FocusAsync(JSRuntime); + } + + protected async Task processInput(string newVal) + { + processing = true; + alertMessage = ""; + lastMessage = ""; + var remnRecord = await DataService.SearchQrRemnant(newVal); + if (remnRecord != null && remnRecord.MatID > 0 && remnRecord.RemDtmx == newVal) + { + currRecord = remnRecord; + lastCmd = newVal; + lastMessage = $"{remnRecord.MaterialNav.MatExtCode} {remnRecord.MaterialNav.MatDesc}
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}
"; + } + else + { + alertMessage = $"Error: code {newVal} not valid / not found"; + lastCmd = ""; + } + processing = false; + } + + + + private async Task ReloadData() + { + currRecord = null; + alertMessage = ""; + lastMessage = ""; + lastCmd = ""; + await Task.Delay(1); + } + + protected string currUserId + { + get + { + string userName = ""; + var authState = AuthStateProvider.GetAuthenticationStateAsync().Result; + var user = authState.User; + if (user != null && user.Identity != null) + { + if (user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "N.A."; + } + } + return userName; + } + } + + protected async Task Reset() + { + await ReloadData(); + await SetFocusAsync(); + } + protected async Task ConfirmOperation() + { + //if (!await JSRuntime.InvokeAsync("confirm", "Confirm operation?")) + // return; + + int qtyMov = IsPickup ? -1 : 1; + await DataService.RemnantsMovMag(currRecord, currUserId, qtyMov); + alertMessage = ""; + lastCmd = ""; + lastMessage = $"

Operation Confirmed!

{qtyMov} x {currRecord.MaterialNav.MatExtCode} {currRecord.MaterialNav.MatDesc}
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}
"; + await Task.Delay(1); + StateHasChanged(); + await Task.Delay(3000); + await ReloadData(); + await SetFocusAsync(); + } +} diff --git a/REMAN/REMAN/Data/RDataService.cs b/REMAN/REMAN/Data/RDataService.cs index 7adacf9..b0d881d 100644 --- a/REMAN/REMAN/Data/RDataService.cs +++ b/REMAN/REMAN/Data/RDataService.cs @@ -199,7 +199,7 @@ namespace REMAN.Data // modifico qty entro limiti >=0.. if (currRecord.QtyAvail + deltaQty >= 0) { - currRecord.QtyAvail += deltaQty; + currRecord.QtyAvail = currRecord.QtyAvail+ deltaQty; done = dbController.RemnantsUpsert(currRecord, userId); await InvalidateAllCache(); } diff --git a/REMAN/REMAN/Pages/Deposit.razor b/REMAN/REMAN/Pages/Deposit.razor index 224b8dd..cbf036c 100644 --- a/REMAN/REMAN/Pages/Deposit.razor +++ b/REMAN/REMAN/Pages/Deposit.razor @@ -1,27 +1,4 @@ @page "/Deposit" @using REMAN.Components -Deposit - - -
-
-
-
-

Deposit

-
-
-@* @if (processing) - { - ...working... - } -*@
-
-
-
-
-
- -@code { - -} + diff --git a/REMAN/REMAN/Pages/PickUp.razor b/REMAN/REMAN/Pages/PickUp.razor index 2839458..e9e6edb 100644 --- a/REMAN/REMAN/Pages/PickUp.razor +++ b/REMAN/REMAN/Pages/PickUp.razor @@ -1,190 +1,5 @@ @page "/PickUp" - -@using Microsoft.AspNetCore.Components.Authorization -@using NKC.Data.DbModels @using REMAN.Components -@using REMAN.Data -@using static JsFunctions - -@inject AuthenticationStateProvider AuthStateProvider -@inject IJSRuntime JSRuntime -@inject RDataService DataService - -PickUp -
-
-
-
-

PickUp

-
-
- @if (processing) - { - ...working... - } -
-
-
-
-
-
- -
- @if (!string.IsNullOrEmpty(lastCmd)) - { -
- -
- } -
- @if (!string.IsNullOrEmpty(alertMessage)) - { -
- @alertMsg -
- } - @if (!string.IsNullOrEmpty(lastMessage)) - { -
- @lastMsg -
- } -
-
-
-
- -@code { - - private ElementReference CodeInput; - - private bool processing = false; - private string alertMessage = ""; - private string lastMessage = ""; - private MarkupString alertMsg - { - get => (MarkupString)alertMessage; - } - private MarkupString lastMsg - { - get => (MarkupString)lastMessage; - } - - private RemnantsModel currRecord = null; - - private string lastCmd = ""; - - private string inputValue - { - get - { - return ""; - } - set - { - var pUpd = Task.Run(async () => - { - await processInput(value); - }); - pUpd.Wait(); - } - } - - protected override async Task OnInitializedAsync() - { - await ReloadData(); - } - - protected async override Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - await SetFocusAsync(); - } - } - - public async Task SetFocusAsync() - { - await CodeInput.FocusAsync(JSRuntime); - } - - protected async Task processInput(string inputVal) - { - inputVal = inputVal.Trim(); - processing = true; - alertMessage = ""; - lastMessage = ""; - var remnRecord = await DataService.SearchQrRemnant(inputVal); - if (remnRecord != null && remnRecord.MatID > 0 && remnRecord.RemDtmx == inputVal) - { - currRecord = remnRecord; - lastCmd = inputVal; - lastMessage = $"{remnRecord.MaterialNav.MatExtCode} {remnRecord.MaterialNav.MatDesc}
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}
"; - } - else - { - alertMessage = $"Error: code {inputVal} not valid / not found"; - lastCmd = ""; - await waitResetAlerts(); - } - processing = false; - } - - private async Task waitResetAlerts() - { - //await Task.Delay(1); - //await InvokeAsync(StateHasChanged); - //await Task.Delay(1); - //await Task.Delay(3000); - //await ReloadData(); - } - - private async Task ReloadData() - { - currRecord = null; - alertMessage = ""; - lastMessage = ""; - lastCmd = ""; - await Task.Delay(1); - //await Focus("CodeInput"); - } - - protected string currUserId - { - get - { - string userName = ""; - var authState = AuthStateProvider.GetAuthenticationStateAsync().Result; - var user = authState.User; - if (user != null && user.Identity != null) - { - if (user.Identity.IsAuthenticated) - { - userName = $"{user.Identity.Name}"; - } - else - { - userName = "N.A."; - } - } - return userName; - } - } - - protected async Task ConfirmPickup() - { - if (!await JSRuntime.InvokeAsync("confirm", "Confirm item pickup?")) - return; - - await DataService.RemnantsMovMag(currRecord, currUserId, -1); - alertMessage = ""; - lastCmd = ""; - lastMessage = $"

PickUp Confirmed!

{currRecord.MaterialNav.MatExtCode} {currRecord.MaterialNav.MatDesc}
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}
"; - await Task.Delay(1); - StateHasChanged(); - await Task.Delay(3000); - await ReloadData(); - } -} + \ No newline at end of file