210 lines
5.0 KiB
C#
210 lines
5.0 KiB
C#
using Blazored.LocalStorage;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MP.Data.DTO;
|
|
using NLog;
|
|
using NLog.Fluent;
|
|
|
|
namespace MP.INVE.Data
|
|
{
|
|
public class MessageService
|
|
{
|
|
protected ILocalStorageService localStorage { get; set; } = null!;
|
|
|
|
public MessageService(ILocalStorageService genLocalStorage)
|
|
{
|
|
localStorage = genLocalStorage;
|
|
}
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Effettua pulizia localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> clearLocalStorageAsync()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
await localStorage.ClearAsync();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
//Log.Error($"Eccezione in clearLocalStorage{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il record OperatoreDTO da localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<OperatoreDTO> getCurrOperDtoAsync()
|
|
{
|
|
OperatoreDTO answ = new OperatoreDTO();
|
|
var result = await localStorage.GetItemAsync<OperatoreDTO>("Opr");
|
|
if (result != null)
|
|
{
|
|
answ = result;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// scrive il record OperatoreDTO nel localstorage
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> setCurrOperDtoAsync(OperatoreDTO opr)
|
|
{
|
|
bool answ = false;
|
|
await localStorage.SetItemAsync("Opr", opr);
|
|
answ = true;
|
|
return answ;
|
|
}
|
|
|
|
#if false
|
|
|
|
public event Action EA_PageUpdated = null!;
|
|
|
|
public event Action EA_SearchUpdated = null!;
|
|
|
|
public event Action EA_ShowSearch = null!;
|
|
|
|
public event Action EA_StatoSearch = null!;
|
|
|
|
public int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
if (EA_PageUpdated != null)
|
|
{
|
|
EA_PageUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
if (EA_PageUpdated != null)
|
|
{
|
|
EA_PageUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
//if (_nome != value)
|
|
//{
|
|
searchVal = value;
|
|
|
|
if (EA_SearchUpdated != null)
|
|
{
|
|
EA_SearchUpdated?.Invoke();
|
|
}
|
|
//}
|
|
}
|
|
}
|
|
|
|
public bool ShowSearch
|
|
{
|
|
get => showSearch;
|
|
set
|
|
{
|
|
if (showSearch != value)
|
|
{
|
|
showSearch = value;
|
|
if (EA_ShowSearch != null)
|
|
{
|
|
EA_ShowSearch?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string StateSel
|
|
{
|
|
get => stateSel;
|
|
set
|
|
{
|
|
stateSel = value;
|
|
|
|
if (EA_StatoSearch != null)
|
|
{
|
|
EA_StatoSearch?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string TipoSearch
|
|
{
|
|
get => tipoSearch;
|
|
set
|
|
{
|
|
if (tipoSearch != value)
|
|
{
|
|
tipoSearch = value;
|
|
if (EA_ShowSearch != null)
|
|
{
|
|
EA_ShowSearch?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public int totalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
if (_totalCount != value)
|
|
{
|
|
_totalCount = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void reportPaging()
|
|
{
|
|
if (EA_PageUpdated != null)
|
|
{
|
|
EA_PageUpdated?.Invoke();
|
|
}
|
|
}
|
|
|
|
protected void reportSearch()
|
|
{
|
|
if (EA_SearchUpdated != null)
|
|
{
|
|
EA_SearchUpdated?.Invoke();
|
|
}
|
|
}
|
|
|
|
private string searchVal = "";
|
|
private bool showSearch;
|
|
private string stateSel = "*";
|
|
private string tipoSearch = "";
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
private int _totalCount { get; set; } = 0;
|
|
#endif
|
|
}
|
|
} |