OK deposito e pickup

This commit is contained in:
Samuele Locatelli
2021-11-22 19:49:59 +01:00
parent dcedf03d2c
commit c9cd2b2df1
4 changed files with 205 additions and 211 deletions
+202
View File
@@ -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
<PageTitle>@Title</PageTitle>
<div class="card">
<div class="card-header table-primary pb-0 mb-0">
<div class="d-flex justify-content-between">
<div class="px-2">
<h2>@Title</h2>
</div>
<div class="px-2">
@if (processing)
{
<span class="spinner-border"></span> <i>...working...</i>
}
<button @onclick="() => Reset()" class="btn btn-primary"><i class="fas fa-sync-alt"></i></button>
</div>
</div>
</div>
<div class="card-body p-1">
<div class="row">
<div class="col-12 form-group">
<input @ref="CodeInput" @bind="@inputValue" class="form-control" autofocus="true"></input>
</div>
@if (!string.IsNullOrEmpty(lastCmd))
{
<div class="col-12 my-1">
<button class="btn btn-lg btn-block btn-success" @onclick="() => ConfirmOperation()">
@if (IsPickup)
{
<i class="fas fa-download pr-2" aria-hidden="true"></i>
}
else
{
<i class="fas fa-upload pr-2" aria-hidden="true"></i>
}
Confirm @Title</button>
</div>
}
<div class="col-12">
@if (!string.IsNullOrEmpty(alertMessage))
{
<div class="alert alert-danger text-center fade show">
@alertMsg
</div>
}
@if (!string.IsNullOrEmpty(lastMessage))
{
<div class="alert alert-success text-center fade show">
@lastMsg
</div>
}
</div>
</div>
</div>
</div>
@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 = $"<b>{remnRecord.MaterialNav.MatExtCode}</b> {remnRecord.MaterialNav.MatDesc} <div class=\"small\">{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}</div>";
}
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<bool>("confirm", "Confirm operation?"))
// return;
int qtyMov = IsPickup ? -1 : 1;
await DataService.RemnantsMovMag(currRecord, currUserId, qtyMov);
alertMessage = "";
lastCmd = "";
lastMessage = $"<h4>Operation Confirmed!</h4><b>{qtyMov} x {currRecord.MaterialNav.MatExtCode}</b> {currRecord.MaterialNav.MatDesc} <div class=\"small\">{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}</div>";
await Task.Delay(1);
StateHasChanged();
await Task.Delay(3000);
await ReloadData();
await SetFocusAsync();
}
}
+1 -1
View File
@@ -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();
}
+1 -24
View File
@@ -1,27 +1,4 @@
@page "/Deposit"
@using REMAN.Components
<PageTitle>Deposit</PageTitle>
<div class="card">
<div class="card-header table-primary pb-0 mb-0">
<div class="d-flex justify-content-between">
<div class="px-2">
<h2>Deposit</h2>
</div>
<div class="px-2">
@* @if (processing)
{
<span class="spinner-border"></span> <i>...working...</i>
}
*@ </div>
</div>
</div>
<div class="card-body">
</div>
</div>
@code {
}
<CodeReader IsPickup="false" Title="Deposit"></CodeReader>
+1 -186
View File
@@ -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
<PageTitle>PickUp</PageTitle>
<div class="card">
<div class="card-header table-primary pb-0 mb-0">
<div class="d-flex justify-content-between">
<div class="px-2">
<h2>PickUp</h2>
</div>
<div class="px-2">
@if (processing)
{
<span class="spinner-border"></span> <i>...working...</i>
}
</div>
</div>
</div>
<div class="card-body p-1">
<div class="row">
<div class="col-12 form-group">
<input @ref="CodeInput" @bind="@inputValue" class="form-control" autofocus="true"></input>
</div>
@if (!string.IsNullOrEmpty(lastCmd))
{
<div class="col-12 my-1">
<button class="btn btn-lg btn-block btn-success" @onclick="() => ConfirmPickup()"><i class="fas fa-download pr-2" aria-hidden="true"></i> Confirm Pickup</button>
</div>
}
<div class="col-12">
@if (!string.IsNullOrEmpty(alertMessage))
{
<div class="alert alert-danger text-center fade show">
@alertMsg
</div>
}
@if (!string.IsNullOrEmpty(lastMessage))
{
<div class="alert alert-success text-center fade show">
@lastMsg
</div>
}
</div>
</div>
</div>
</div>
@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 = $"<b>{remnRecord.MaterialNav.MatExtCode}</b> {remnRecord.MaterialNav.MatDesc} <div class=\"small\">{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}</div>";
}
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<bool>("confirm", "Confirm item pickup?"))
return;
await DataService.RemnantsMovMag(currRecord, currUserId, -1);
alertMessage = "";
lastCmd = "";
lastMessage = $"<h4>PickUp Confirmed!</h4><b>{currRecord.MaterialNav.MatExtCode}</b> {currRecord.MaterialNav.MatDesc} <div class=\"small\">{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}</div>";
await Task.Delay(1);
StateHasChanged();
await Task.Delay(3000);
await ReloadData();
}
}
<CodeReader IsPickup="true" Title="PickUp"></CodeReader>