286 lines
7.3 KiB
C#
286 lines
7.3 KiB
C#
using Blazored.LocalStorage;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
using Microsoft.JSInterop;
|
|
using MP.Core.DTO;
|
|
using MP.Data.DbModels;
|
|
using MP.INVE.Data;
|
|
|
|
namespace MP.INVE.Pages
|
|
{
|
|
public partial class Invio
|
|
{
|
|
#region Public Properties
|
|
|
|
[Inject]
|
|
public MiDataService MIService { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected SelectInvioParams invioParams = new SelectInvioParams();
|
|
protected bool isLoading = false;
|
|
protected bool mostra = false;
|
|
protected SelectInveSessionParams sessParams = new SelectInveSessionParams();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrlJumper"]}"; }
|
|
|
|
protected string codMag { get; set; } = "";
|
|
|
|
[Inject]
|
|
protected MessageService MsgService { get; set; } = null!;
|
|
|
|
protected string rawCode
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
answ = $"{BaseUrlTab}IdSessione={sessID}&IdMag={codMag}";
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected string searchVal { get; set; } = "";
|
|
|
|
protected int sessID { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
/// <summary>
|
|
/// Effettua salvataggio su file CSV
|
|
/// </summary>
|
|
protected async void ExportCSV()
|
|
{
|
|
var fullData = MIService.ExportSessionDetail(sessID);
|
|
await Egw.Core.Utils.SaveToCsv(fullData, fullPath, ';');
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected bool fileExist
|
|
{
|
|
get
|
|
{
|
|
return File.Exists(fullPath);
|
|
}
|
|
}
|
|
|
|
protected string fullPath
|
|
{
|
|
get => $"{exportDir}\\{fileName}";
|
|
}
|
|
|
|
protected string exportDir = $"{Directory.GetCurrentDirectory()}\\temp";
|
|
|
|
protected string fileName
|
|
{
|
|
get => $"{sessID}.csv";
|
|
}
|
|
|
|
|
|
protected async void apriSessione(int sessID)
|
|
{
|
|
var open = await MIService.CloseOpenSessione(sessID, false);
|
|
await resetCacheSessInv();
|
|
if (open)
|
|
{
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
}
|
|
|
|
protected async void chiudiSessione(int sessID)
|
|
{
|
|
var closed = await MIService.CloseOpenSessione(sessID, true);
|
|
await resetCacheSessInv();
|
|
if (closed)
|
|
{
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
}
|
|
|
|
protected void ForceReload(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void ForceReloadPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected async Task getId()
|
|
{
|
|
OperatoreDTO local = new OperatoreDTO();
|
|
local = await MsgService.getCurrOperDtoAsync();
|
|
if (local != null)
|
|
{
|
|
idOperatore = local.MatrOpr.ToString();
|
|
authKey = local.hashAuthKey;
|
|
}
|
|
}
|
|
|
|
protected void mostraDati()
|
|
{
|
|
mostra = true;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
await Task.Delay(50);
|
|
if (firstRender)
|
|
{
|
|
if (sessione != null)
|
|
{
|
|
await getId();
|
|
if ((sessione.DtEnd == null) && (!sessione.Transferred))
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}");
|
|
await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", $"{sessione.InveSessID}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
|
|
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("sessID", out var _inveSessionId) && QueryHelpers.ParseQuery(uri.Query).TryGetValue("codMag", out var _idMag))
|
|
{
|
|
sessID = int.Parse(_inveSessionId);
|
|
codMag = _idMag;
|
|
}
|
|
|
|
await reloadData();
|
|
}
|
|
|
|
protected async Task returnToSessions()
|
|
{
|
|
// svuoto eventuale vecchio file
|
|
if (fileExist)
|
|
{
|
|
File.Delete(fullPath);
|
|
}
|
|
await resetCacheSessInv();
|
|
// ritorno pagina...
|
|
NavManager.NavigateTo("InveSession", true);
|
|
}
|
|
|
|
protected async void trasfSessione(int sessID)
|
|
{
|
|
var trasf = await MIService.TransferSessione(sessID);
|
|
await resetCacheSessInv();
|
|
if (trasf)
|
|
{
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
}
|
|
|
|
protected void UpdateTotCount(int newTotCount)
|
|
{
|
|
totalCount = newTotCount;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private InventorySessionModel? sessione;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _totalCount { get; set; } = 0;
|
|
|
|
private string authKey
|
|
{
|
|
get => sessParams.authKey;
|
|
set => sessParams.authKey = value;
|
|
}
|
|
|
|
[Inject]
|
|
private IConfiguration Configuration { get; set; } = null!;
|
|
|
|
private int currPage
|
|
{
|
|
get => invioParams.CurrPage;
|
|
set
|
|
{
|
|
if (invioParams.CurrPage != value)
|
|
{
|
|
invioParams.CurrPage = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private string idOperatore
|
|
{
|
|
get => sessParams.idOperatore;
|
|
set => sessParams.idOperatore = value;
|
|
}
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private ILocalStorageService localStorage { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private NavigationManager NavManager { get; set; } = null!;
|
|
|
|
private int numRecord
|
|
{
|
|
get => invioParams.NumRec;
|
|
set
|
|
{
|
|
if (invioParams.NumRec != value)
|
|
{
|
|
invioParams.NumRec = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private int totalCount
|
|
{
|
|
get => invioParams.TotCount;
|
|
set
|
|
{
|
|
if (invioParams.TotCount != value)
|
|
{
|
|
invioParams.TotCount = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task reloadData()
|
|
{
|
|
sessione = null;
|
|
isLoading = true;
|
|
sessione = MIService.InventSessByID(sessID);
|
|
await Task.Delay(1);
|
|
isLoading = false;
|
|
}
|
|
|
|
private void reset()
|
|
{
|
|
searchVal = "";
|
|
}
|
|
|
|
private async Task resetCacheSessInv()
|
|
{
|
|
await MIService.FlushSessInvCache();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
}
|
|
} |