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 fasiList { get; set; } = new List(); [Inject] protected GpwDataService GDataServ { get; set; } protected List gruppiList { get; set; } = new List(); protected List projList { get; set; } = new List(); #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 ItemReset { get; set; } [Parameter] public EventCallback 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); } /// /// Verifico coerenza date (inizio < fine) /// /// indica se la data modificata sia l'inizio 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 /// /// Salvo in MService record clonato /// protected async void DoClone() { AppMServ.clonedRA = currRecord; await ItemReset.InvokeAsync(true); } /// /// Elimino record /// protected async void DoDelete() { // chiedo verifica if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record selezionato??")) return; // aggiorno await GDataServ.RegAttDelete(currRecord); // registro fatto await ItemUpdated.InvokeAsync(true); } /// /// Indico item selezionato /// protected async void DoReset() { await ItemReset.InvokeAsync(true); } /// /// Aggiorno e riporto update /// 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 } }