Files
mapo-core/MP-TAB3/Components/DeclarMan.razor.cs
T
2023-12-19 08:32:07 +01:00

168 lines
4.6 KiB
C#

using global::Microsoft.AspNetCore.Components;
using MP.Data.DatabaseModels;
using MP.Data.Services;
using NLog;
using Org.BouncyCastle.Asn1.IsisMtt.X509;
using static EgwCoreLib.Utils.DtUtils;
namespace MP_TAB3.Components
{
public partial class DeclarMan
{
#region Public Properties
[Parameter]
public MappaStatoExpl? RecMSE { get; set; } = null;
#endregion Public Properties
#region Public Methods
/// <summary>
/// Aggiorno valori produzione alla data richiesta...
/// </summary>
/// <param name="newDate"></param>
public async Task doUpdate()
{
isProcessing = true;
await Task.Delay(1);
if (!string.IsNullOrEmpty(IdxMaccSel))
{
ListComplete = await TabDServ.RegDichiarGetFilt(IdxMaccSel, "", 0, IdxOdl, CurrPeriodo.Inizio, CurrPeriodo.Fine);
TotalCount = ListComplete.Count;
// esegue paginazione
UpdateTable();
}
isProcessing = false;
await Task.Delay(1);
}
#endregion Public Methods
#region Protected Properties
protected List<RegistroDichiarazioniModel> ListComplete { get; set; } = new List<RegistroDichiarazioniModel>();
protected List<RegistroDichiarazioniModel> ListPaged { get; set; } = new List<RegistroDichiarazioniModel>();
protected void SetEdit(RegistroDichiarazioniModel selRec)
{
CurrRec = selRec;
}
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected MessageService MServ { get; set; } = null!;
[Inject]
protected TabDataService TabDServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
if (RecMSE != null)
{
IdxMaccSel = RecMSE.IdxMacchina;
bool isMulti = SMServ.DictMacchMulti[IdxMaccSel] == 1;
if (isMulti)
{
var idxMSel = MServ.UserPrefGet(IdxMaccSel);
if (!string.IsNullOrEmpty(idxMSel))
{
IdxMaccSel = idxMSel;
}
}
DateTime fine = DateTime.Today.AddDays(1);
DateTime inizio = fine.AddDays(-8);
CurrPeriodo = new Periodo(inizio, fine);
await doUpdate();
}
}
protected void SaveNumRec(int newNum)
{
NumRecPage = newNum;
UpdateTable();
}
protected void SavePage(int newNum)
{
PageNum = newNum;
UpdateTable();
}
protected async Task SetMacc(string selIdxMacc)
{
isProcessing = true;
await Task.Delay(1);
IdxMaccSel = selIdxMacc;
await doUpdate();
isProcessing = false;
await Task.Delay(1);
}
protected async Task SetOdl(int selIdxOdl)
{
isProcessing = true;
await Task.Delay(1);
IdxOdl = selIdxOdl;
await doUpdate();
isProcessing = false;
await Task.Delay(1);
}
protected async Task SetPeriodo(Periodo newPeriodo)
{
CurrPeriodo = newPeriodo;
await doUpdate();
}
protected void UpdateTable()
{
// esegue paginazione
if (TotalCount > NumRecPage)
{
ListPaged = ListComplete.Skip((PageNum - 1) * NumRecPage).Take(NumRecPage).ToList();
}
else
{
ListPaged = ListComplete;
}
}
#endregion Protected Methods
#region Private Fields
private RegistroDichiarazioniModel? CurrRec { get; set; } = null;
private static Logger Log = LogManager.GetCurrentClassLogger();
private bool isProcessing = false;
private int NumRecPage = 10;
private int PageNum = 1;
private int TotalCount = 0;
private bool useOdl = false;
#endregion Private Fields
#region Private Properties
private Periodo CurrPeriodo { get; set; } = new Periodo();
private string IdxMaccSel { get; set; } = "";
private int IdxOdl { get; set; } = 0;
private string selMessage
{
get => useOdl ? "Periodo da ODL" : "Periodo Libero";
}
#endregion Private Properties
}
}