239 lines
5.8 KiB
C#
239 lines
5.8 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Stats.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Stats.Pages
|
|
{
|
|
public partial class Controlli : ComponentBase, IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private MP.Data.DbModels.ResControlli currRecord = null;
|
|
|
|
private string fileName = "Controlli.csv";
|
|
private List<MP.Data.DbModels.ResControlli> ListRecords;
|
|
private List<MP.Data.DbModels.ResControlli> SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
var pUpd = Task.Run(async () => await reloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string fullPath
|
|
{
|
|
get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}";
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
var pUpd = Task.Run(async () => await reloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; }
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; }
|
|
|
|
[Inject]
|
|
protected MpStatsService StatService { get; set; }
|
|
|
|
protected int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (SearchRecords != null)
|
|
{
|
|
answ = SearchRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelectData currFilter
|
|
{
|
|
get
|
|
{
|
|
return MessageService.DetailFilter;
|
|
}
|
|
set
|
|
{
|
|
MessageService.DetailFilter = value;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void clearFile()
|
|
{
|
|
await Task.Run(() => File.Delete(fullPath));
|
|
}
|
|
|
|
private async Task ExportCsv()
|
|
{
|
|
isLoading = true;
|
|
// salvo davvero!
|
|
await Egw.Core.Utils.SaveToCsv(SearchRecords, fullPath, ';');
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task reloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await StatService.StatControlliGetAll(currFilter, MessageService.SearchVal);
|
|
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task DoFilter(SelectData newFilter)
|
|
{
|
|
clearFile();
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
currFilter = newFilter;
|
|
await reloadData();
|
|
}
|
|
|
|
protected void ForceReload(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void ForceReloadPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
clearFile();
|
|
numRecord = 10;
|
|
MessageService.ShowSearch = false;
|
|
MessageService.PageName = "Registro Controlli";
|
|
MessageService.PageIcon = "fa fa-flask";
|
|
MessageService.EA_SearchUpdated += OnSeachUpdated;
|
|
await reloadData();
|
|
}
|
|
|
|
protected void ResetData()
|
|
{
|
|
clearFile();
|
|
StatService.rollBackEdit(currRecord);
|
|
currRecord = null;
|
|
}
|
|
|
|
protected async Task ResetFilter(SelectData newFilter)
|
|
{
|
|
clearFile();
|
|
currRecord = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
currFilter = SelectData.Init(5, 7);
|
|
await reloadData();
|
|
}
|
|
|
|
protected async Task ToggleChart(bool doShow)
|
|
{
|
|
ShowCharts = !ShowCharts;
|
|
if (ShowCharts)
|
|
{
|
|
await reloadData();
|
|
}
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
currRecord = null;
|
|
await reloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(int IdxControllo)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.IdxControllo == IdxControllo) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
MessageService.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |