using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using System.Net.Http; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using MP.INVE; using MP.INVE.Shared; using MP.INVE.Components; using Blazored.LocalStorage; using MP.Data.DTO; using MP.Data; using MP.INVE.Data; using MP.Data.DatabaseModels; using Microsoft.AspNetCore.WebUtilities; namespace MP.INVE.Pages { public partial class Invio { [Inject] public MiDataService MIService { get; set; } = null!; protected SelectInvioParams invioParams = new SelectInvioParams(); protected SelectInveSessionParams sessParams = new SelectInveSessionParams(); private int totalCount { get => invioParams.TotCount; set { if (invioParams.TotCount != value) { invioParams.TotCount = value; } } } private int numRecord { get => invioParams.NumRec; set { if (invioParams.NumRec != value) { invioParams.NumRec = value; } } } private int currPage { get => invioParams.CurrPage; set { if (invioParams.CurrPage != value) { invioParams.CurrPage = value; } } } private string idOperatore { get => sessParams.idOperatore; set => sessParams.idOperatore = value; } private string authKey { get => sessParams.authKey; set => sessParams.authKey = value; } protected void ForceReload(int newNum) { numRecord = newNum; } protected void ForceReloadPage(int newNum) { currPage = newNum; } protected bool mostra = false; protected void mostraDati() { mostra = true; } protected async void chiudiSessione(int sessID) { var closed = await MIService.CloseOpenSessione(sessID, true); if (closed) { NavManager.NavigateTo(NavManager.Uri, true); } } protected async void apriSessione(int sessID) { var open = await MIService.CloseOpenSessione(sessID, false); if (open) { NavManager.NavigateTo(NavManager.Uri, true); } } protected async void trasfSessione(int sessID) { var trasf = await MIService.TransferSessione(sessID); if (trasf) { NavManager.NavigateTo(NavManager.Uri, true); } } 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 override 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}", rawCode); } } } } [Inject] private IConfiguration Configuration { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; [Inject] private NavigationManager NavManager { get; set; } = null!; [Inject] private ILocalStorageService localStorage { get; set; } = null!; protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrlJumper"]}"; } protected string rawCode { get { string answ = ""; answ = $"{BaseUrlTab}IdSessione={sessID}&IdMag={codMag}&MatrOpr={idOperatore}&UserAuthKey={authKey}"; return answ; } } private InventorySessionModel? sessione; protected bool isLoading = false; private async Task reloadData() { sessione = null; isLoading = true; sessione = MIService.InventSessByID(sessID); await Task.Delay(1); isLoading = false; } protected int sessID { get; set; } = 0; protected string codMag { get; set; } = ""; [Inject] protected MessageService MsgService { get; set; } = null!; protected async Task getId() { OperatoreDTO local = new OperatoreDTO(); local = await MsgService.getCurrOperDtoAsync(); if (local != null) { idOperatore = local.MatrOpr.ToString(); authKey = local.hashAuthKey; } } } }