using GPW.CORE.Data.DbModels; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace GPW.CORE.UI.Components { public partial class RegAtt { #region Protected Fields protected bool isSelected = false; #endregion Protected Fields #region Private Properties private string blockCss { get { string answ = CurrData.IdxFase == 0 ? "" : " border border-info rounded"; return answ; } } private bool dropActionTop { get { bool answ = false; switch (CurrData.Inizio.DayOfWeek) { case DayOfWeek.Sunday: case DayOfWeek.Saturday: case DayOfWeek.Friday: answ = true; break; default: break; } return answ; } } private string widthPerc { get { string answ = "1%"; if (CurrData != null) { double num = CurrData.OreTot != null ? (double)CurrData.OreTot : 0; answ = $"{num / Periodo:P2}".Replace(",", "."); } return answ; } } private bool VetoInsert { get => GDataServ.VetoInsert; } #endregion Private Properties #region Protected Properties protected string buttonCss { get => !IsClipboard ? "dropbtn" : ""; } protected string cssSelected { get => isSelected ? "table-info" : ""; } protected string cssDropContent { get => dropActionTop ? "dropdown-content-top" : "dropdown-content"; } #endregion Protected Properties #region Public Properties [Parameter] public RegAttivitaModel CurrData { get; set; } = null!; [Parameter] public bool EnableActionMenu { get; set; } = true; [Parameter] public int IdxDipSel { get; set; } = 0; [Parameter] public bool IsClipboard { get; set; } = false; [Parameter] public EventCallback ItemCloned { get; set; } [Parameter] public EventCallback ItemSelected { get; set; } [Parameter] public EventCallback ItemUpdated { get; set; } [Parameter] public List ListFasi { get; set; } = null!; [Parameter] public double Periodo { get; set; } = 1; #endregion Public Properties #region Private Methods /// /// Verifico coerenza date (inizio < fine) /// /// indica se la data modificata sia l'inizio private void checkCoerenzaDate(bool modInizio) { // verifica presenza errori bool inError = CurrData.Inizio >= CurrData.Fine; if (inError) { // se ho mod inizio --> tengo ferma fine, inizio 1/2 h prima if (modInizio) { CurrData.Inizio = CurrData.Fine.AddMinutes(-30); } else { CurrData.Fine = CurrData.Inizio.AddMinutes(30); } } } #endregion Private Methods #region Protected Methods protected async void AddTime(bool isEnd, int deltaMin) { // verifico checkbox IsEnd if (isEnd) { // modifico fine... CurrData.Fine = CurrData.Fine.AddMinutes(deltaMin); checkCoerenzaDate(false); } else { // modifico inizio... CurrData.Inizio = CurrData.Inizio.AddMinutes(deltaMin); checkCoerenzaDate(true); } // salvo await GDataServ.RegAttUpdate(CurrData); await ItemUpdated.InvokeAsync(CurrData); } /// /// Indico item selezionato /// protected async void Clone() { AppMServ.clonedRA = CurrData; await ItemCloned.InvokeAsync(CurrData); } /// /// Indico item selezionato /// protected async void Delete() { // chiedo verifica if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record selezionato??")) return; // aggiorno await GDataServ.RegAttDelete(CurrData); // registro fatto await ItemUpdated.InvokeAsync(null); } /// /// Indico item selezionato /// protected async void Edit() { // SOLO SE non è una copia clipboard... //if (!IsClipboard) //{ isSelected = true; await ItemSelected.InvokeAsync(CurrData); //} } protected override void OnInitialized() { isSelected = false; } /// /// Indico item selezionato /// protected async void ReportSelect(RegAttivitaModel selRecord) { await ItemSelected.InvokeAsync(selRecord); } /// /// Trim linea di testo secondo regole /// /// Stringa origiale /// Fattore di moltiplicazione (std: 130) /// protected string trimLine(object stringOrig, int multFact = 130) { double num = 1; if (CurrData.OreTot != null) { num = (double)CurrData.OreTot; } double perc = num / Periodo; int maxLenght = (int)(perc * multFact); string answ = $"{stringOrig}"; if (answ.Length > maxLenght) { answ = $"{answ.Substring(0, maxLenght)}..."; } return answ; } #endregion Protected Methods } }