302 lines
7.4 KiB
C#
302 lines
7.4 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using GPW.CORE.Data;
|
|
using GPW.CORE.Data.DbModels;
|
|
|
|
namespace GPW.CORE.Smart.Data
|
|
{
|
|
public class MessageService
|
|
{
|
|
#region Public Fields
|
|
|
|
public int orarioDip = 0;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore)
|
|
{
|
|
localStorage = genLocalStorage;
|
|
sessionStore = sessStore;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Events
|
|
|
|
public event Action EA_HideSearch = null!;
|
|
|
|
public event Action EA_PageUpdated = null!;
|
|
|
|
public event Action EA_DipUpdated = null!;
|
|
|
|
public event Action EA_TimbUpd = null!;
|
|
|
|
#endregion Public Events
|
|
|
|
//public EventCallback<int> ReportIdxDip { get; set; }
|
|
|
|
#region Public Properties
|
|
|
|
public RegAttivitaModel? clonedRA { get; set; } = null;
|
|
|
|
/// <summary>
|
|
/// Calcola HASH del codice impiego = payload utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string HashDip
|
|
{
|
|
get
|
|
{
|
|
DataValidator cDV = new DataValidator(_rigaDip);
|
|
string hash = cDV.HashDip;
|
|
return hash;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Indica se il prossimo stato timbratura sia entrata
|
|
/// </summary>
|
|
public bool NextIsEntrata {
|
|
get => nextIsEntrata;
|
|
set
|
|
{
|
|
if (nextIsEntrata != value)
|
|
{
|
|
nextIsEntrata = value;
|
|
ReportEntrata();
|
|
}
|
|
}
|
|
}
|
|
private bool nextIsEntrata { get; set; } = true;
|
|
|
|
public int IdxDipendente
|
|
{
|
|
get
|
|
{
|
|
int answ = -1;
|
|
if (_rigaDip != null)
|
|
{
|
|
answ = _rigaDip.IdxDipendente;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public bool IsActive
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (_rigaDip != null && _rigaDip.Attivo != null)
|
|
{
|
|
answ = (bool)_rigaDip.Attivo;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public string PageIcon
|
|
{
|
|
get => _pageIcon;
|
|
set
|
|
{
|
|
if (_pageIcon != value)
|
|
{
|
|
_pageIcon = value;
|
|
ReportPageUpd();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PageName
|
|
{
|
|
get => _pageName;
|
|
set
|
|
{
|
|
if (_pageName != value)
|
|
{
|
|
_pageName = value;
|
|
ReportPageUpd();
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool PayloadOk { get; set; } = false;
|
|
public RegAttivitaModel? recordRA { get; set; } = null;
|
|
|
|
public DipendentiModel? RigaDip
|
|
{
|
|
get => _rigaDip;
|
|
set
|
|
{
|
|
// salvo
|
|
_rigaDip = value;
|
|
if (EA_DipUpdated != null)
|
|
{
|
|
EA_DipUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string SearchVal
|
|
{
|
|
get => _searchVal;
|
|
set
|
|
{
|
|
if (_searchVal != value)
|
|
{
|
|
_searchVal = value;
|
|
|
|
if (EA_DipUpdated != null)
|
|
{
|
|
EA_DipUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public int selWeekNum { get; set; } = 0;
|
|
public int selYear { get; set; } = DateTime.Today.Year;
|
|
|
|
public bool ShowSearch
|
|
{
|
|
get => showSearch;
|
|
set
|
|
{
|
|
if (showSearch != value)
|
|
{
|
|
showSearch = value;
|
|
if (showSearch)
|
|
{
|
|
if (EA_TimbUpd != null)
|
|
{
|
|
EA_TimbUpd?.Invoke();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (EA_HideSearch != null)
|
|
{
|
|
EA_HideSearch?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime targetDate { get; set; } = DateTime.Today;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce il valore di DeviceSecret da localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<string> getDevSecretAsync()
|
|
{
|
|
string answ = "";
|
|
var result = await localStorage.GetItemAsync<string>("DevSec");
|
|
if (result != null)
|
|
{
|
|
answ = result;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Restituisce il valore di idxDip da localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<int> getIdxDipAsync()
|
|
{
|
|
int answ = -2;
|
|
var result = await sessionStore.GetItemAsync<int>("idxDip");
|
|
if (result != null)
|
|
{
|
|
answ = result;
|
|
}
|
|
return answ;
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Scrive il valore di DeviceSecret nel localstoragee
|
|
/// </summary>
|
|
/// <param name="devSec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> setDevSecretAsync(string devSec)
|
|
{
|
|
bool answ = false;
|
|
await localStorage.SetItemAsync("DevSec", devSec);
|
|
answ = true;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scrive il valore di idxDip nel localstoragee
|
|
/// </summary>
|
|
/// <param name="devSec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> setIdxDipAsync(int idxDip)
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
await sessionStore.SetItemAsync("idxDip", idxDip);
|
|
#endif
|
|
answ = true;
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected ILocalStorageService localStorage { get; set; } = null!;
|
|
protected ISessionStorageService sessionStore { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
private string _pageIcon = "";
|
|
|
|
private string _pageName = "";
|
|
|
|
private DipendentiModel? _rigaDip;
|
|
private string _searchVal = "";
|
|
private bool showSearch;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void ReportPageUpd()
|
|
{
|
|
if (EA_PageUpdated != null)
|
|
{
|
|
EA_PageUpdated?.Invoke();
|
|
}
|
|
}
|
|
private void ReportEntrata()
|
|
{
|
|
if (EA_TimbUpd != null)
|
|
{
|
|
EA_TimbUpd?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void ReportSearch()
|
|
{
|
|
if (EA_DipUpdated != null)
|
|
{
|
|
EA_DipUpdated?.Invoke();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |