Files
samuele b1afa82a91 Continuo spostamento servizi in Data:
- GpwDataSrvice
- MessageService
- ogni dipendenza (aggiunti using, in _import non basta...)
2024-09-07 11:40:28 +02:00

225 lines
5.8 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace GPW.CORE.WRKLOG.Components.Compo
{
public partial class DettAtt : IDisposable
{
#region Public Properties
[Parameter]
public RegAttivitaModel CurrData { get; set; } = null!;
[Parameter]
public string FontSizeBig { get; set; } = "1.4rem";
[Parameter]
public string FontSizeSmall { get; set; } = "1.1rem";
[Parameter]
public int IdxDipSel { get; set; } = 0;
[Parameter]
public EventCallback<RegAttivitaModel> ItemDeleted { get; set; }
[Parameter]
public EventCallback<RegAttivitaModel> ItemSelected { get; set; }
[Parameter]
public List<AnagFasiModel> ListFasi { get; set; } = null!;
[Parameter]
public int MaxChar { get; set; } = 100;
[Parameter]
public double Periodo { get; set; } = 1;
[Parameter]
public bool ShowDate { get; set; } = false;
#endregion Public Properties
#region Public Methods
public void Dispose()
{
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
}
#endregion Public Methods
#region Protected Fields
protected bool isSelected = false;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService AppMServ { get; set; } = null!;
protected string blockClass
{
get
{
string btnClass = "";
bool highlight = false;
// recupero search
string SearchVal = AppMServ.SearchVal;
// calcolo valore highlight
if (!string.IsNullOrEmpty(SearchVal))
{
highlight = (CurrData.Descrizione.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase));
}
btnClass = highlight ? "bg-success bg-opacity-25" : "bg-light";
return btnClass;
}
}
protected string cssSelected
{
get => isSelected ? "table-info" : "";
}
protected string cssTrim
{
get
{
string answ = "max100Char";
if (50 <= MaxChar && MaxChar < 100)
{
answ = "max50Char";
}
else if (20 <= MaxChar && MaxChar < 50)
{
answ = "max30Char";
}
else if (MaxChar < 20)
{
answ = "max20Char";
}
else
{
answ = "max100Char";
}
return answ;
}
}
[Inject]
protected GpwDataService GDataServ { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Clono item selezionato
/// </summary>
protected async void Clone()
{
var newData = CurrData.Clone();
newData.IdxRa = 0;
AppMServ.clonedRA = newData;
await ItemSelected.InvokeAsync(null);
}
/// <summary>
/// Elimino item selezionato
/// </summary>
protected async void Delete()
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record selezionato??"))
return;
// aggiorno
await GDataServ.RegAttDelete(CurrData);
// registro fatto
await ItemDeleted.InvokeAsync(null);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void Edit()
{
isSelected = true;
await ItemSelected.InvokeAsync(CurrData);
}
protected override void OnInitialized()
{
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
isSelected = false;
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void ReportSelect(RegAttivitaModel selRecord)
{
await ItemSelected.InvokeAsync(selRecord);
}
/// <summary>
/// Trim linea di testo secondo regole
/// </summary>
/// <param name="stringOrig">Stringa origiale</param>
/// <param name="multFact">Fattore di moltiplicazione (std: 130)</param>
/// <returns></returns>
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
#region Private Properties
private string blockCss
{
get
{
string answ = CurrData.IdxFase == 0 ? "" : " border border-dark rounded";
return answ;
}
}
private bool VetoInsert
{
get => GDataServ.VetoInsert;
}
#endregion Private Properties
#region Private Methods
private void AppMServ_EA_SearchUpdated()
{
InvokeAsync(StateHasChanged);
}
#endregion Private Methods
}
}