243 lines
7.4 KiB
C#
243 lines
7.4 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Smart.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Smart.Components.Compo
|
|
{
|
|
public partial class CompProj
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DateTime DtRif { get; set; } = DateTime.Today;
|
|
|
|
public int EndHour { get; set; } = 16;
|
|
|
|
[Parameter]
|
|
public int IdxDipCurr { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public List<RegAttivitaModel>? ListProgetti
|
|
{
|
|
get => listRA;
|
|
set => listRA = value;
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> ReqReload { get; set; }
|
|
|
|
public int StartHour { get; set; } = 8;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Wrapper valori con calcolo la lista comprensiva di spazi vuoti da quella ricevuta...
|
|
/// </summary>
|
|
protected List<RegAttivitaModel>? listRA
|
|
{
|
|
get => _listRA;
|
|
set => _listRA = value != null ? ListRegAtt(value) : new List<RegAttivitaModel>();
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Aggiorno e riporto update
|
|
/// </summary>
|
|
protected async void DoUpdate(bool forceReload)
|
|
{
|
|
if (forceReload)
|
|
{
|
|
await ReloadData();
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
protected async Task EditItem(RegAttivitaModel selRec)
|
|
{
|
|
ClonedRA = null;
|
|
CurrRA = selRec;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue operazione Paste(incolla) del record attualmente in memoria
|
|
/// </summary>
|
|
/// <param name="pasteRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task ExecPaste(RegAttivitaModel pasteRec)
|
|
{
|
|
// usa i dati del record ricevuto x indicare inizio...
|
|
ClonedRA.Inizio = pasteRec.Inizio;
|
|
// fine e durata calcolate...
|
|
if (pasteRec.OreTot < ClonedRA.OreTot)
|
|
{
|
|
ClonedRA.Fine = pasteRec.Fine;
|
|
ClonedRA.OreTot = pasteRec.OreTot;
|
|
}
|
|
else
|
|
{
|
|
ClonedRA.Fine = pasteRec.Inizio.Add(ClonedRA.Durata);
|
|
}
|
|
// chiama insert ed invalida cache...
|
|
await CDService.RegAttUpdate(ClonedRA);
|
|
// svuota cache x copy/paste
|
|
ClonedRA = null;
|
|
await Task.Delay(1);
|
|
// richiesta rilettura dati...
|
|
await ReqReload.InvokeAsync(true);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task SaveCloned(RegAttivitaModel clonedRec)
|
|
{
|
|
ClonedRA = clonedRec;
|
|
textDtAct = $"{DateTime.Now:ddd dd.MM.yyyy}";
|
|
lastAction = $"Clonato Attivita";
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task UpdRegAttData()
|
|
{
|
|
isLoading = true;
|
|
CurrRA = null;
|
|
// richiesta rilettura dati...
|
|
await ReqReload.InvokeAsync(true);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string lastAction = "";
|
|
private string textDtAct = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private List<RegAttivitaModel>? _listRA { get; set; } = null;
|
|
|
|
[Inject]
|
|
private CoreSmartDataService CDService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gestione ricezione evento + record RA clonato
|
|
/// </summary>
|
|
/// <param name="clonedRec"></param>
|
|
/// <returns></returns>
|
|
private RegAttivitaModel? ClonedRA
|
|
{
|
|
get => MService.clonedRA;
|
|
set => MService.clonedRA = value;
|
|
}
|
|
|
|
private RegAttivitaModel? CurrRA { get; set; } = null;
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
[Inject]
|
|
private MessageService MService { get; set; } = null!;
|
|
|
|
private bool showToast
|
|
{
|
|
get => MService.clonedRA != null;
|
|
}
|
|
|
|
private string toastCss
|
|
{
|
|
get => showToast ? "show" : "";
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private List<RegAttivitaModel> ListRegAtt(List<RegAttivitaModel> ListOnlyRA)
|
|
{
|
|
// init
|
|
List<RegAttivitaModel> result = new List<RegAttivitaModel>();
|
|
if (ListOnlyRA != null && ListOnlyRA.Count > 0)
|
|
{
|
|
// prendo prima attivita...
|
|
var firstRA = ListOnlyRA[0];
|
|
DateTime currHour = firstRA.Inizio.Date.AddHours(StartHour);
|
|
DateTime lastHour = firstRA.Inizio.Date.AddHours(EndHour);
|
|
DateTime domani = firstRA.Inizio.Date.AddDays(1);
|
|
// ciclo partendo dal primo evento, aggiungendo eventuali periodi in testa / coda intermedi
|
|
foreach (var item in ListOnlyRA)
|
|
{
|
|
// se evento > ora corrente --> aggiungo vuoto...
|
|
if (item.Inizio > currHour)
|
|
{
|
|
RegAttivitaModel? newItem = new RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = item.Inizio,
|
|
OreTot = (decimal)item.Inizio.Subtract(currHour).TotalHours
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
|
|
// ...altrimenti parto con lui...
|
|
result.Add(item);
|
|
currHour = item.Fine;
|
|
}
|
|
// se non sono in fondo alla giornata --> aggiungo!
|
|
if (currHour < domani)
|
|
{
|
|
var oreTot = currHour < lastHour ? (decimal)lastHour.Subtract(currHour).TotalHours : 1;
|
|
var dtFine = currHour < lastHour ? lastHour : currHour.AddHours(1);
|
|
RegAttivitaModel? newItem = new RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = dtFine,
|
|
OreTot = oreTot
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
}
|
|
// altrimenti aggiunge comunque un attivita...
|
|
else
|
|
{
|
|
RegAttivitaModel? newItem = new RegAttivitaModel()
|
|
{
|
|
Inizio = DtRif.AddHours(StartHour),
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = DtRif.AddHours(StartHour + 1),
|
|
OreTot = 1
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
isLoading = true;
|
|
}
|
|
|
|
private async Task resetClone()
|
|
{
|
|
ClonedRA = null;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |