255 lines
7.4 KiB
C#
255 lines
7.4 KiB
C#
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this
|
|
// file to you under the MIT license.
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MagMan.Data.Tenant.DbModels;
|
|
using MagMan.Data.Tenant.Services;
|
|
using MagMan.Core.Services;
|
|
|
|
namespace MagMan.UI.Components
|
|
{
|
|
public partial class CodeReader : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool IsDeposit { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool IsPickup { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public string Title { get; set; } = "Pickup/Deposit";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMService.EA_CustomerSel -= AppMService_EA_CustomerSel;
|
|
AppMService.EA_KeySel -= AppMService_EA_KeySel;
|
|
}
|
|
|
|
public async Task SetFocusAsync()
|
|
{
|
|
await Task.Delay(50);
|
|
await CodeInput.FocusAsync(true);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMService { get; set; } = null!;
|
|
|
|
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 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 TService.ItemModQty(KeyNum, currRecord, qtyMov, currUserId, "M06+: Deposito Risorsa (Deposit)", "M06-: Prelievo Risorsa (Pickup)");
|
|
alertMessage = "";
|
|
lastCmd = "";
|
|
if (currRecord.MaterialNav != null)
|
|
{
|
|
lastMessage = $"<h4>Operation Confirmed!</h4><b>{qtyMov} x {currRecord.MaterialNav.MatCode}</b> {currRecord.MaterialNav.MatDesc} <div class=\"small\">{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.HMm: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.HMm:N3}</div>";
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
StateHasChanged();
|
|
await Task.Delay(scanOpDelay);
|
|
await ReloadData();
|
|
await SetFocusAsync();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await SetFocusAsync();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
string rawConf = Configuration["OptConf:ScanOpDelay"];
|
|
if (rawConf != null)
|
|
{
|
|
int.TryParse(rawConf, out scanOpDelay);
|
|
}
|
|
KeyNum = AppMService.KeyNum;
|
|
AppMService.EA_CustomerSel += AppMService_EA_CustomerSel;
|
|
AppMService.EA_KeySel += AppMService_EA_KeySel;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task processInput(string newVal)
|
|
{
|
|
processing = true;
|
|
alertMessage = "";
|
|
lastMessage = "";
|
|
var remnRecord = await TService.ItemGetByQr(KeyNum, newVal);
|
|
if (remnRecord != null && remnRecord.MatId > 0 && remnRecord.ItemDtmx == newVal)
|
|
{
|
|
currRecord = remnRecord;
|
|
lastCmd = newVal;
|
|
if (remnRecord.MaterialNav != null)
|
|
{
|
|
lastMessage = $"<b>{remnRecord.MaterialNav.MatCode}</b> {remnRecord.MaterialNav.MatDesc} <div class=\"small\">{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.HMm:N3}</div>";
|
|
}
|
|
else
|
|
{
|
|
lastMessage = $"<b>ND</b> ??? <div class=\"small\">{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.HMm: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 Private Fields
|
|
|
|
private string alertMessage = "";
|
|
|
|
private ElementReference CodeInput;
|
|
|
|
private RawItemModel? currRecord = null;
|
|
|
|
private string lastCmd = "";
|
|
|
|
private string lastMessage = "";
|
|
|
|
private bool processing = false;
|
|
|
|
private int scanOpDelay = 5000;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private MarkupString alertMsg { get => (MarkupString)alertMessage; }
|
|
|
|
[Inject]
|
|
private AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IConfiguration Configuration { get; set; } = null!;
|
|
|
|
private int CustomerID { get; set; } = 0;
|
|
|
|
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 int KeyNum { get; set; } = 0;
|
|
|
|
private MarkupString lastMsg { get => (MarkupString)lastMessage; }
|
|
|
|
[Inject]
|
|
private TenantService TService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void AppMService_EA_CustomerSel()
|
|
{
|
|
CustomerID = AppMService.CustomerID;
|
|
//await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async void AppMService_EA_KeySel()
|
|
{
|
|
KeyNum = AppMService.KeyNum;
|
|
//await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
currRecord = null;
|
|
alertMessage = "";
|
|
lastMessage = "";
|
|
lastCmd = "";
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |