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.Pages { public partial class LicenseManager : ComponentBase, IDisposable { #region Private Fields private LicenzeAttive currRecord = null; private List ListRecords; private List SearchRecords; #endregion Private Fields #region Protected Fields protected int totalCount = 0; #endregion Protected 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; } } #endregion Private Properties #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 Private Methods private async Task ReloadAllData() { isLoading = true; await Task.Delay(1); //SearchRecords = null; SearchRecords = await DataService.LicenzeGLSGetAll(); totalCount = SearchRecords.Count(); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } #endregion Private Methods #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 SetCurrPage(int newNum) { currPage = newNum; await ReloadAllData(); isLoading = false; } protected void ResetData() { } #endregion Protected Methods #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 } }