Files
limanapp/LiMan.UI/Components/StatsCallList.razor.cs
Samuele Locatelli 5d72d21fb1 Stat installazioni:
Update gestione paginazione (visibile solo dove serve) + fix calcolo di alcuni intems male filtrati
2025-04-03 17:47:31 +02:00

190 lines
4.2 KiB
C#

using LiMan.DB.DBModels;
using LiMan.UI.Data;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LiMan.UI.Components
{
public partial class StatsCallList
{
#region Public Methods
public string checkSelect(StatsCallModel testRec)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.CodInst == testRec.CodInst && currRecord.YearRef == testRec.YearRef) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
#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; }
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
}
protected async Task SetNumRec(int newNum)
{
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 void Select(StatsCallModel selRecord)
{
currRecord = selRecord;
}
protected async Task UpdateData()
{
await FullReload();
}
#endregion Protected Methods
#region Private Fields
private StatsCallModel currRecord = null;
private DateTime dtFrom = DateTime.Today.AddMonths(-12);
private DateTime dtTo = DateTime.Today.AddDays(1);
private List<StatsCallModel> ListRecords;
private List<StatsCallModel> SearchRecords;
private string searchVal = "";
#endregion Private Fields
#region Private Properties
private int currPage
{
get
{
return AppMService.PageNum;
}
set
{
AppMService.PageNum = value;
}
}
private DateTime DtFrom
{
get => dtFrom;
set
{
if (dtFrom != value)
{
dtFrom = value;
ForceReload();
}
}
}
private DateTime DtTo
{
get => dtTo;
set
{
if (dtTo != value)
{
dtTo = value;
ForceReload();
}
}
}
private bool isLoading { get; set; } = false;
private int numRecord
{
get
{
return AppMService.PageSize;
}
set
{
AppMService.PageSize = value;
}
}
#endregion Private Properties
#region Private Methods
private void ForceReload()
{
var pUpd = Task.Run(async () =>
{
await FullReload();
});
pUpd.Wait();
}
private async Task FullReload()
{
currRecord = null;
await DataService.FlushRedisCache();
await ReloadAllData();
}
private async Task ReloadAllData()
{
isLoading = true;
await Task.Delay(1);
//SearchRecords = null;
SearchRecords = await DataService.StatsLogCallGetFilt(dtFrom, dtTo, searchVal);
totalCount = SearchRecords.Count();
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
isLoading = false;
}
#endregion Private Methods
}
}