235 lines
6.4 KiB
C#
235 lines
6.4 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 CalAzMan
|
|
{
|
|
#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()
|
|
{
|
|
ListGiust = await GDataServ.AnagGiust();
|
|
// 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 = "CalChiusura";
|
|
|
|
private bool isSendingData = false;
|
|
|
|
private List<CalFesteFerieModel>? ListRecords = null;
|
|
private List<CalFesteFerieModel>? 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 CalFesteFerieModel currRecord { get; set; } = new CalFesteFerieModel();
|
|
|
|
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 void DoEdit(CalFesteFerieModel 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);
|
|
await Task.Delay(1);
|
|
// effettuo insert...
|
|
sendDataVal = 5;
|
|
sendDataNextVal = 90;
|
|
await Task.Delay(1);
|
|
await GDataServ.CalFestFerieUpsert(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.CalFestFeriePeriodo(DtStart, DtEnd);
|
|
// conteggio!
|
|
totalCount = SearchRecords.Count;
|
|
// paginazione
|
|
ListRecords = SearchRecords
|
|
.OrderByDescending(x => x.data)
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private void ToggleEdit()
|
|
{
|
|
showAdd = !showAdd;
|
|
}
|
|
|
|
private void AddNew()
|
|
{
|
|
showAdd = true;
|
|
currRecord = new CalFesteFerieModel()
|
|
{
|
|
data = DateTime.Today,
|
|
codGiust = "FER",
|
|
descrizione = "CHIUSURA UFFICIO"
|
|
};
|
|
}
|
|
|
|
private List<AnagGiustModel>? ListGiust = null;
|
|
|
|
private async Task DoDelete(CalFesteFerieModel selItem)
|
|
{
|
|
// chiedo verifica
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record selezionato??"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
isSendingData = true;
|
|
sendDataVal = 0;
|
|
sendDataNextVal = 90;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
await GDataServ.CalFestFerieDelete(selItem);
|
|
sendDataVal = 100;
|
|
sendDataNextVal = 100;
|
|
await Task.Delay(1);
|
|
await ReloadData();
|
|
await ReportUpdate.InvokeAsync(true);
|
|
isSendingData = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |