Files

224 lines
6.1 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NLog;
namespace GPW.CORE.ADM.Components.Compo
{
public partial class RegMalattia
{
#region Public Properties
[Parameter]
public DateTime DtEnd { get; set; } = new DateTime(DateTime.Today.Year + 1, 1, 1);
[Parameter]
public DateTime DtStart { get; set; } = new DateTime(DateTime.Today.Year, 1, 1);
[Parameter]
public bool isLoading { get; set; }
[Parameter]
public EventCallback<bool> ReportUpdate { get; set; }
#endregion Public Properties
#region Protected Fields
protected List<int> PageSizeListSpec = new List<int>() { 5, 10, 15, 20 };
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService AppMServ { get; set; } = null!;
[Inject]
protected GpwDataService GDataServ { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
// recupero preferenze utente...
await InitUserPref();
}
protected override async Task OnParametersSetAsync()
{
currPage = 1;
await ReloadData();
}
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
await AppMServ.NumRowGridSet(gridKey, newNum);
await InvokeAsync(ReloadData);
}
protected async Task SetPage(int newNum)
{
currPage = newNum;
await InvokeAsync(ReloadData);
}
#endregion Protected Methods
#region Private Fields
private static Logger Log = LogManager.GetCurrentClassLogger();
private string gridKey = "RegMalattie";
private bool isSendingData = false;
private List<RegMalattieModel>? ListRecords = null;
private List<RegMalattieModel>? SearchRecords = null;
private int sendDataMaxVal = 100;
private int sendDataNextVal = 0;
private int sendDataVal = 0;
private bool showAdd = false;
#endregion Private Fields
#region Private Properties
private int currPage { get; set; } = 1;
private RegMalattieModel currRecord { get; set; } = new RegMalattieModel();
private string NomeDip
{
get
{
string answ = "per cortesia";
if (AppMServ != null && AppMServ.RigaDip != null)
{
answ = $"{AppMServ.RigaDip.Nome}";
}
return answ;
}
}
private int numRecord { get; set; } = 10;
private int totalCount { get; set; } = 0;
#endregion Private Properties
#region Private Methods
private async Task DoApprove(RegMalattieModel selItem)
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi approvazione?"))
return;
await Task.Delay(1);
isSendingData = true;
sendDataVal = 0;
sendDataNextVal = 5;
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
// effettuo insert...
sendDataVal = 5;
sendDataNextVal = 90;
await Task.Delay(1);
await GDataServ.RegMalattieApprova(selItem);
sendDataVal = 100;
sendDataNextVal = 100;
await ReloadData();
await Task.Delay(1);
await ReportUpdate.InvokeAsync(true);
isSendingData = false;
}
private void DoEdit(RegMalattieModel selItem)
{
currRecord = selItem;
showAdd = true;
}
/// <summary>
/// Registra il record
/// </summary>
/// <returns></returns>
private async Task DoSave()
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi modifica record?"))
return;
isSendingData = true;
sendDataVal = 0;
sendDataNextVal = 5;
await Task.Delay(1);
// effettuo insert...
sendDataVal = 5;
sendDataNextVal = 90;
await Task.Delay(1);
await GDataServ.RegMalattieAppRif(currRecord);
// effettuo insert...
sendDataVal = 100;
sendDataNextVal = 100;
// aggiorno display...
await Task.Delay(1);
showAdd = false;
await ReloadData();
await ReportUpdate.InvokeAsync(true);
isSendingData = false;
}
/// <summary>
/// Init preferenze utente
/// </summary>
/// <returns></returns>
private async Task InitUserPref()
{
try
{
numRecord = await AppMServ.NumRowGridGet(gridKey);
}
catch (Exception exc)
{
Log.Error($"Eccezione in InitUserPref{Environment.NewLine}{exc}");
}
}
private async Task ReloadData()
{
SearchRecords = null;
await Task.Delay(1);
SearchRecords = GDataServ.RegMalattieGetByPeriod(DtStart, DtEnd);
// conteggio!
totalCount = SearchRecords.Count;
// paginazione
ListRecords = SearchRecords
.OrderByDescending(x => x.DtInizio)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
private void ToggleEdit()
{
showAdd = !showAdd;
}
#endregion Private Methods
}
}