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 MP.Data.DatabaseModels; using MP.INVE.Data; using MP.Data.DTO; using Blazored.LocalStorage; namespace MP.INVE.Pages { public partial class Session { [Inject] private MiDataService MIDataservice { get; set; } = null!; private List? elencoSessioni; private List? elencoOperatori; private List? elencoMagazzini; protected override async Task OnInitializedAsync() { //await FilterChanged.InvokeAsync(actFilter); await getId(); await Task.Delay(1); await reloadData(); } private bool inCorso { get; set; } = true; protected async Task toggle() { inCorso = !inCorso; await reloadData(); } protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrlJumper"]}"; } private string idOperatore { get; set; } = ""; private int currIdSess { get; set; } = 0; private string authKey { get; set; } = ""; private DateTime dtStart { get; set; } = DateTime.Now.AddMonths(-1); private DateTime dtEnd { get; set; } = DateTime.Now; protected string rawCode { get { string answ = ""; answ = $"{BaseUrlTab}IdSessione={currIdSess}&MatrOpr={idOperatore}&UserAuthKey={authKey}"; return answ; } } private bool reqNew { get; set; } = false; private void openNew() { reqNew = true; elencoOperatori = MIDataservice.ElencoOperatori(0, ""); elencoMagazzini = MIDataservice.ElencoMagazzini(); } private void closeNew() { reqNew = false; elencoOperatori = new List(); elencoMagazzini = new List(); } private async Task insertNewSession() { var alert = await JSRuntime.InvokeAsync("confirm", "Confermi di voler creare una nuova sessione per il magazzino selezionato?"); if (alert) { InventorySessionModel newSess = new InventorySessionModel() { UserCrea = idOperatore, Description = desc, DtStart = DateTime.Parse(DateTime.Now.ToString("yyyy/MM/dd HH:mm")), DtEnd = null, Transferred = false, MagID = magazzino }; await MIDataservice.InsertNewSessione(newSess); NavManager.NavigateTo("Session", true); await reloadData(); } else { closeNew(); } } private async Task deleteSession(InventorySessionModel session) { var alert = await JSRuntime.InvokeAsync("confirm", "Confermi di voler creare una nuova sessione per il magazzino selezionato?"); if (alert) { await MIDataservice.deleteSessione(session); NavManager.NavigateTo("Session", true); await reloadData(); } } private bool isLoading { get; set; } = false; private int magazzino { get; set; } = 0; private string matrOpr { get; set; } = ""; private string desc { get; set; } = ""; private async Task reloadData() { await Task.Delay(1); elencoSessioni = null; isLoading = true; if (inCorso) { elencoSessioni = MIDataservice.InventSessCurrList(); } else { elencoSessioni = MIDataservice.InventSessHistList(dtStart, dtEnd); } isLoading = false; } protected async Task getCurrSess(int idSess) { currIdSess = idSess; await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}"); await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", rawCode); } [Inject] private IConfiguration Configuration { get; set; } = null!; [Inject] protected ILocalStorageService localStorage { get; set; } = null!; [Inject] protected NavigationManager NavManager { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected async Task getId() { OperatoreDTO local = new OperatoreDTO(); local = await localStorage.GetItemAsync("MatrOpr"); if (local != null) { idOperatore = local.MatrOpr.ToString(); authKey = local.hashAuthKey; } } } }