using LiMan.GLS.DatabaseModels; using LiMan.UI.Data; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LiMan.UI.Components { public partial class ListLicenzeGLS : ComponentBase, IDisposable { #region Public Methods public string checkSelect(int IdxLic) { string answ = ""; if (currRecord != null) { try { answ = (currRecord.IdxLic == IdxLic) ? "table-info" : ""; } catch { } } return answ; } public void Dispose() { } #endregion Public Methods #region Protected Fields protected int totalCount = 0; #endregion Protected Fields #region Protected Properties [Inject] protected MessageService AppMService { get; set; } [Inject] protected LiManDataService DataService { get; set; } [Inject] protected IJSRuntime JSRuntime { get; set; } [Inject] protected NavigationManager NavManager { get; set; } protected bool showCamera { get; set; } = false; #endregion Protected Properties #region Protected Methods /// /// formatta testo secondo scadenza: /// scadenza > 60gg --> verde /// 0 < scadenza < 60 gg --> giallo /// scadenza < 0 --> rosso /// /// /// protected string cssScadenza(DateTime scadenza) { string answ = "text-dark"; double periodo = scadenza.Subtract(DateTime.Today).TotalDays; if (periodo > 60) { answ = "text-success"; } else if (periodo > 0) { answ = "text-warning"; } else { answ = "text-danger"; } return answ; } protected void Edit(LicenzeAttive selRecord) { currRecord = selRecord; } protected override async Task OnInitializedAsync() { await ReloadAllData(); } protected async Task SetNumRec(int newNum) { currPage = 1; numRecord = newNum; await ReloadAllData(); isLoading = false; } protected async Task SetNumPage(int newNum) { currPage = newNum; await ReloadAllData(); isLoading = false; } protected async Task ResetData() { await FullReload(); } protected async Task UpdateData() { await FullReload(); } #endregion Protected Methods #region Private Fields private LicenzeAttive currRecord = null; private List ListApp; private List ListInstall; private List ListRecords; private List SearchRecords; #endregion Private Fields #region Private Properties private int currPage { get { return AppMService.PageNum; } set { AppMService.PageNum = value; } } private bool isLoading { get; set; } = false; private int numRecord { get { return AppMService.PageSize; } set { AppMService.PageSize = value; } } private bool OnlyActive { get { bool answ = false; if (AppMService.DetailGLSFilter != null) { answ = AppMService.DetailGLSFilter.OnlyActive; } return answ; } set { if (!AppMService.DetailGLSFilter.OnlyActive.Equals(value)) { AppMService.DetailGLSFilter.OnlyActive = value; var pUpd = Task.Run(async () => await ReloadAllData()); pUpd.Wait(); } } } private bool OnlyUnlock { get { bool answ = false; if (AppMService.DetailGLSFilter != null) { answ = AppMService.DetailGLSFilter.OnlyUnlock; } return answ; } set { if (!AppMService.DetailGLSFilter.OnlyUnlock.Equals(value)) { AppMService.DetailGLSFilter.OnlyUnlock = value; var pUpd = Task.Run(async () => await ReloadAllData()); pUpd.Wait(); } } } private string SelApp { get { string answ = ""; if (AppMService.DetailGLSFilter != null) { answ = AppMService.DetailGLSFilter.ApplicazioneSel; } return answ; } set { if (!AppMService.DetailGLSFilter.ApplicazioneSel.Equals(value)) { AppMService.DetailGLSFilter.ApplicazioneSel = value; var pUpd = Task.Run(async () => await ReloadAllData()); pUpd.Wait(); } } } private string SelInst { get { string answ = ""; if (AppMService.DetailGLSFilter != null) { answ = AppMService.DetailGLSFilter.InstallazioneSel; } return answ; } set { if (!AppMService.DetailGLSFilter.InstallazioneSel.Equals(value)) { AppMService.DetailGLSFilter.InstallazioneSel = value; var pUpd = Task.Run(async () => await ReloadAllData()); pUpd.Wait(); } } } #endregion Private Properties #region Private Methods private async Task FullReload() { currRecord = null; await DataService.FlushRedisCache(); await ReloadAllData(); } private async Task ReloadAllData() { isLoading = true; ListRecords = null; ListApp = await DataService.ApplicazioniGLSGetAll(); ListInstall = await DataService.InstallazioniGLSGetAll(); await Task.Delay(1); SearchRecords = await DataService.LicenzeGLSGetFilt(AppMService.DetailGLSFilter); totalCount = SearchRecords.Count(); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } #endregion Private Methods } }