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

244 lines
6.4 KiB
C#

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<RegAttivitaModel> ItemCloned { get; set; }
[Parameter]
public EventCallback<RegAttivitaModel> ItemSelected { get; set; }
[Parameter]
public EventCallback<RegAttivitaModel> ItemUpdated { get; set; }
[Parameter]
public List<AnagFasiModel> ListFasi { get; set; } = null!;
[Parameter]
public double Periodo { get; set; } = 1;
#endregion Public Properties
#region Private Methods
/// <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 = 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);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void Clone()
{
AppMServ.clonedRA = CurrData;
await ItemCloned.InvokeAsync(CurrData);
}
/// <summary>
/// Indico 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 ItemUpdated.InvokeAsync(null);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void Edit()
{
// SOLO SE non è una copia clipboard...
//if (!IsClipboard)
//{
isSelected = true;
await ItemSelected.InvokeAsync(CurrData);
//}
}
protected override void OnInitialized()
{
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
}
}