212 lines
5.8 KiB
C#
212 lines
5.8 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.JSInterop;
|
|
using NKC.Data.DbModels;
|
|
using REMAN.Data;
|
|
|
|
namespace REMAN.Components
|
|
{
|
|
public partial class CodeReader
|
|
{
|
|
#region Private Fields
|
|
|
|
private string alertMessage = "";
|
|
|
|
private ElementReference CodeInput;
|
|
|
|
private RemnantsModel? currRecord = null;
|
|
|
|
private string lastCmd = "";
|
|
|
|
private string lastMessage = "";
|
|
|
|
private bool processing = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private MarkupString alertMsg { get => (MarkupString)alertMessage; }
|
|
|
|
[Inject]
|
|
private AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private RDataService DataService { get; set; } = null!;
|
|
|
|
private string inputValue
|
|
{
|
|
get
|
|
{
|
|
return "";
|
|
}
|
|
|
|
set
|
|
{
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await processInput(value.Trim());
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
private MarkupString lastMsg { get => (MarkupString)lastMessage; }
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool IsPickup { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool IsDeposit { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public string Title { get; set; } = "Pick/Deposit";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
currRecord = null;
|
|
alertMessage = "";
|
|
lastMessage = "";
|
|
lastCmd = "";
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task ConfirmOperation()
|
|
{
|
|
//if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confirm operation?"))
|
|
// return;
|
|
|
|
int qtyMov = 0;
|
|
if (IsPickup)
|
|
{
|
|
qtyMov = -1;
|
|
}
|
|
else if (IsDeposit)
|
|
{
|
|
qtyMov = 1;
|
|
}
|
|
if (qtyMov != 0)
|
|
{
|
|
if (currRecord != null)
|
|
{
|
|
await DataService.RemnantsMovMag(currRecord, currUserId, qtyMov);
|
|
alertMessage = "";
|
|
lastCmd = "";
|
|
if (currRecord.MaterialNav != null)
|
|
{
|
|
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>";
|
|
}
|
|
else
|
|
{
|
|
lastMessage = $"<h4>Operation Confirmed!</h4><b>{qtyMov} x ND</b> ??? <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();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await SetFocusAsync();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
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;
|
|
if (remnRecord.MaterialNav != null)
|
|
{
|
|
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
|
|
{
|
|
lastMessage = $"<b>ND</b> ??? <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;
|
|
}
|
|
|
|
protected async Task Reset()
|
|
{
|
|
await ReloadData();
|
|
await SetFocusAsync();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public async Task SetFocusAsync()
|
|
{
|
|
await CodeInput.FocusAsync(JSRuntime);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |