Files
NKC/REMAN/Pages/Remnants.razor.cs
2021-11-25 09:56:11 +01:00

306 lines
8.1 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.JSInterop;
using NKC.Data.DbModels;
using NKC.Data.DTO;
using REMAN.Data;
namespace REMAN.Pages
{
public partial class Remnants : ComponentBase, IDisposable
{
#region Private Fields
private RemnantsModel? currRecord = null;
private List<RemnantsModel> ListRecords = null!;
private List<MaterialDTO> MaterialsList = null!;
private List<RemnantsModel> SearchRecords = null!;
#endregion Private Fields
#region Protected Fields
protected int RemnIdSel = 0;
protected bool processing = false;
#endregion Protected Fields
#region Private Properties
private int _currPage { get; set; } = 1;
private int _numRecord { get; set; } = 10;
private int currPage
{
get => _currPage;
set
{
if (_currPage != value)
{
_currPage = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private bool showDetail
{
get
{
return RemnIdSel > 0;
}
}
private bool isLoading { get; set; } = false;
private int numRecord
{
get => _numRecord;
set
{
if (_numRecord != value)
{
_numRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
#endregion Private Properties
#region Protected Properties
protected MaterialDTO currMat
{
get
{
MaterialDTO answ = new MaterialDTO();
var selMat = MaterialsList
.Where(x => x.MatID == SelMatID)
.FirstOrDefault();
answ = selMat != null ? selMat : answ;
return answ;
}
}
[Inject]
protected RDataService DataService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MessageService AppMService { get; set; } = null!;
[Inject]
protected IConfiguration Configuration { get; set; } = null!;
[Inject]
AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
protected int SelMatID
{
get
{
return AppMService.MatIdSel;
}
set
{
AppMService.MatIdSel = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
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;
}
}
/// <summary>
/// Restituisce URL immagine QRCode
/// </summary>
/// <param name="QrValue">Parametro da renderizzare con QRCode</param>
/// <returns></returns>
protected string getImgUrl(object QrValue)
{
string baseUrl = $"{Configuration["ZCodeUrl"]}/HOME/QR_site/JSON?val=";
string payload = "{'baseUrl':'{0}','parameters':['" + $"{QrValue}" + "']}";
string answ = $"{baseUrl}{payload}";
return answ;
}
protected int totalCount
{
get
{
int answ = 0;
if (SearchRecords != null)
{
answ = SearchRecords.Count;
}
return answ;
}
}
#endregion Protected Properties
#region Private Methods
private async Task ReloadData()
{
isLoading = true;
MaterialsList = await DataService.MaterialsGetAll();
SearchRecords = await DataService.RemnantsGetFilt(SelMatID, 0);
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
isLoading = false;
}
#endregion Private Methods
#region Protected Methods
protected void AddNew()
{
if (currMat != null)
{
// creo record da materiale...
currRecord = new RemnantsModel()
{
MatID = currMat.MatID,
DtMod = DateTime.Now,
Location = "MAG",
QtyAvail = 0,
LMm = currMat.LMm,
TMm = currMat.TMm,
WMm = currMat.WMm,
Note = ""
};
}
}
protected async Task addQty(RemnantsModel selRecord)
{
//if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confirm qtantity increase?"))
// return;
await DataService.RemnantsMovMag(selRecord, currUserId, 1);
await ReloadData();
}
protected void Clone(RemnantsModel selRecord)
{
RemnIdSel = 0;
currRecord = new RemnantsModel()
{
MatID = selRecord.MatID,
DtMod = DateTime.Now,
Location = selRecord.Location,
QtyAvail = 0,
LMm = selRecord.LMm,
TMm = selRecord.TMm,
WMm = selRecord.WMm,
Note = selRecord.Note,
MaterialNav = selRecord.MaterialNav
};
}
protected void Edit(RemnantsModel selRecord)
{
RemnIdSel = 0;
currRecord = selRecord;
}
protected void ForceReload(int newNum)
{
numRecord = newNum;
}
protected void ForceReloadPage(int newNum)
{
currPage = newNum;
}
public string checkSelect(int RemnId)
{
string answ = "";
answ = (RemnIdSel == RemnId) ? "table-info" : "";
return answ;
}
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task Print(RemnantsModel selRecord)
{
processing = true;
// chiamata x registrare richiesta
await Task.Delay(150);
await DataService.AddPrintJob(selRecord.RemnID);
await Task.Delay(150);
processing = false;
}
protected async Task remQty(RemnantsModel selRecord)
{
//if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confirm qtantity decrease?"))
// return;
await DataService.RemnantsMovMag(selRecord, currUserId, -1);
await ReloadData();
}
protected void ResetData()
{
if (currRecord != null)
{
DataService.rollBackEdit(currRecord);
}
currRecord = null;
RemnIdSel = 0;
}
protected void Select(RemnantsModel selRecord)
{
RemnIdSel = selRecord.RemnID;
}
protected async Task UpdateData()
{
currRecord = null;
RemnIdSel = 0;
await ReloadData();
}
#endregion Protected Methods
#region Public Methods
public void Dispose()
{
//AppMService.EA_SearchUpdated -= OnSeachUpdated;
}
#endregion Public Methods
}
}