Files
gpw_next/GPW.CORE.UI/Components/RegAttEditor.razor.cs
T
2022-01-26 14:38:18 +01:00

211 lines
5.9 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.UI.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace GPW.CORE.UI.Components
{
public partial class RegAttEditor
{
#region Protected Fields
protected string _gruppoSel = "";
protected int _idxProj = 0;
protected bool vetoUpd = false;
#endregion Protected Fields
#region Private Properties
[Inject]
private MessageService AppMServ { get; set; }
[Inject]
private IJSRuntime JSRuntime { get; set; }
private bool VetoInsert
{
get => GDataServ.VetoInsert;
}
#endregion Private Properties
#region Protected Properties
protected List<AnagFasiModel> fasiList { get; set; } = new List<AnagFasiModel>();
[Inject]
protected GpwDataService GDataServ { get; set; }
protected List<AnagGruppiModel> gruppiList { get; set; } = new List<AnagGruppiModel>();
protected List<AnagProgettiModel> projList { get; set; } = new List<AnagProgettiModel>();
#endregion Protected Properties
#region Public Properties
[Parameter]
public RegAttivitaModel currRecord
{
get
{
return AppMServ.recordRA;
}
set
{
AppMServ.recordRA = value;
vetoUpd = true;
if (value.FasiNav != null && value.FasiNav.ProgettoNav != null)
{
gruppoSel = value.FasiNav.ProgettoNav.Gruppo;
idxProj = value.FasiNav.IdxProgetto != null ? (int)value.FasiNav.IdxProgetto : 0;
}
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
vetoUpd = false;
}
}
public string gruppoSel
{
get
{
return _gruppoSel;
}
set
{
_gruppoSel = value;
if (!vetoUpd)
{
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
public int idxProj
{
get
{
return _idxProj;
}
set
{
_idxProj = value;
if (!vetoUpd)
{
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
[Parameter]
public EventCallback<bool> ItemReset { get; set; }
[Parameter]
public EventCallback<bool> ItemUpdated { get; set; }
#endregion Public Properties
#region Private Methods
private void arrotondaMinuti()
{
// arrotondo ai 5 min...
currRecord.Inizio = CORE.Data.Utils.DateRounded(currRecord.Inizio.AddMinutes(2), 5, true);
// arrotondo ai 5 min...
currRecord.Fine = CORE.Data.Utils.DateRounded(currRecord.Fine.AddMinutes(2), 5, true);
checkCoerenzaDate(true);
}
/// <summary>
/// Verifico coerenza date (inizio < fine)
/// </summary>
/// <param name="modInizio">indica se la data modificata sia l'inizio</param>
private void checkCoerenzaDate(bool modInizio)
{
// verifica presenza errori
bool inError = currRecord.Inizio >= currRecord.Fine;
if (inError)
{
// se ho mod inizio --> tengo ferma fine, inizio 1/2 h prima
if (modInizio)
{
currRecord.Inizio = currRecord.Fine.AddMinutes(-30);
}
else
{
currRecord.Fine = currRecord.Inizio.AddMinutes(30);
}
}
}
#endregion Private Methods
#region Protected Methods
/// <summary>
/// Salvo in MService record clonato
/// </summary>
protected async void DoClone()
{
AppMServ.clonedRA = currRecord;
await ItemReset.InvokeAsync(true);
}
/// <summary>
/// Elimino record
/// </summary>
protected async void DoDelete()
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record selezionato??"))
return;
// aggiorno
await GDataServ.RegAttDelete(currRecord);
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void DoReset()
{
await ItemReset.InvokeAsync(true);
}
/// <summary>
/// Aggiorno e riporto update
/// </summary>
protected async void DoUpdate()
{
arrotondaMinuti();
// aggiorno
await GDataServ.RegAttUpdate(currRecord);
// resetto clone e record corrente...
AppMServ.clonedRA = null;
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
protected async Task ReloadData()
{
gruppiList = await GDataServ.AnagGruppiAll();
var allProj = await GDataServ.AnagProjAll();
projList = allProj
.Where(x => x.Attivo == true && x.Gruppo == gruppoSel)
.OrderBy(x => x.ClienteNav.RagSociale)
.ThenBy(x => x.NomeProj)
.ToList();
var allFasi = await GDataServ.AnagFasiAll();
fasiList = allFasi
.Where(x => x.IdxProgetto == idxProj)
.ToList();
}
#endregion Protected Methods
}
}