using Blazored.LocalStorage; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.Data.DbModels; using MP.INVE.Data; namespace MP.INVE.Components { public partial class InveSessionList : IDisposable { #region Public Properties public string currIdMag { get; set; } public int currIdSess { get; set; } [Parameter] public SelectInveSessionParams currParams { get; set; } = null!; [Parameter] public bool isLoading { get; set; } #endregion Public Properties #region Public Methods public void Dispose() { elencoSessioni = null; ElencoMagazzini = null; elencoOperatori = null; SearchRecords = null; GC.Collect(); } #endregion Public Methods #region Protected Properties protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrlJumper"]}"; } [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; [Inject] protected ILocalStorageService localStorage { get; set; } = null!; [Inject] protected NavigationManager NavManager { get; set; } = null!; protected string rawCode { get { string answ = ""; answ = $"{BaseUrlTab}IdSessione={currIdSess}&IdMag={currIdMag}&MatrOpr={idOperatore}&UserAuthKey={authKey}"; return answ; } } #endregion Protected Properties #region Protected Methods protected async Task getCurrSess(int idSess, string idMag) { currIdSess = idSess; currIdMag = idMag; await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}"); await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", rawCode); } protected override async Task OnParametersSetAsync() { await reloadData(); await popola(); } protected async Task popola() { await Task.Delay(1); if (reqNew) { elencoOperatori = MIDataservice.ElencoOperatori(); ElencoMagazzini = MIDataservice.MagazziniList(); } } #endregion Protected Methods #region Private Fields private List? ElencoMagazzini; private List? elencoOperatori; private List? elencoSessioni; private List? SearchRecords; #endregion Private Fields #region Private Properties private string authKey { get => currParams.authKey; set => currParams.authKey = value; } private string searchVal { get => currParams.searchVal; set => currParams.searchVal = value; } [Inject] private IConfiguration Configuration { get; set; } = null!; private string desc { get; set; } = ""; private DateTime dtEnd { get; set; } = DateTime.Now; private DateTime dtStart { get; set; } = DateTime.Now.AddMonths(-1); private string idOperatore { get => currParams.idOperatore; set => currParams.idOperatore = value; } private bool inCorso { get => currParams.inCorso; set => currParams.inCorso = value; } private int magazzino { get; set; } = 0; [Inject] private MiDataService MIDataservice { get; set; } = null!; private bool reqNew { get => currParams.reqNew; set => currParams.reqNew = value; } private int numRecord { get => currParams.NumRec; set { currParams.NumRec = value; StateHasChanged(); } } private int currPage { get => currParams.CurrPage; set { currParams.CurrPage = value; StateHasChanged(); } } private int totalCount { get => currParams.TotCount; set => currParams.TotCount = value; } #endregion Private Properties #region Private Methods private void closeNew() { reqNew = false; elencoOperatori = new List(); ElencoMagazzini = new List(); } 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(NavManager.Uri, true); await reloadData(); } } 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(NavManager.Uri, true); await reloadData(); } else { closeNew(); } } private async Task reloadData() { elencoSessioni = null; isLoading = true; if (inCorso) { SearchRecords = MIDataservice.InventSessCurrList(); } else { SearchRecords = MIDataservice.InventSessHistList(); } //verifico filtro ricerca mag if (!string.IsNullOrEmpty(searchVal)) { StringComparison strComp = StringComparison.CurrentCultureIgnoreCase; SearchRecords = SearchRecords.Where(x => x.AnagMagNav.DescMag.Contains(searchVal, strComp) || x.Description.Contains(searchVal, strComp)).ToList(); } totalCount = SearchRecords.Count; elencoSessioni = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); await Task.Delay(1); await InvokeAsync(() => StateHasChanged()); await Task.Delay(1); isLoading = false; } #endregion Private Methods } }