Files
mapo-core/MP.SPEC/Pages/RepOper.razor.cs
T
2026-06-08 16:59:53 +02:00

133 lines
3.7 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Core.DTO;
using MP.Data.DbModels;
using MP.SPEC.Data;
namespace MP.SPEC.Pages
{
public partial class RepOper
{
#region Protected Fields
protected List<MacchineModel>? ListMacchine = null;
protected List<MacchineModel>? ListMacchineAll = null;
protected List<AnagOperatoriModel>? ListOperatori = null;
protected List<AnagOperatoriModel>? ListOperatoriAll = null;
protected List<RepartiDTO>? ListReparti = null;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MpDataService MDService { get; set; } = null!;
protected string SearchVal
{
get => searchVal;
set
{
if (searchVal != value)
{
searchVal = value;
}
}
}
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadBaseDataAsync();
await ReloadDataAsync();
}
#endregion Protected Methods
#region Private Fields
private string CodGruppo = "";
private bool isLoading = false;
private string searchVal = "";
#endregion Private Fields
#region Private Properties
private string btnSearchCss => string.IsNullOrWhiteSpace(SearchVal) ? "btn-secondary" : "btn-primary";
private string CssMain => ShowDetail ? "col-4" : "col-12";
private bool ShowDetail => !string.IsNullOrEmpty(CodGruppo);
#endregion Private Properties
#region Private Methods
private async Task ForceReload(bool doForce)
{
if (doForce)
{
CodGruppo = "";
}
await ReloadDataAsync();
}
private async Task ReloadBaseDataAsync()
{
ListMacchineAll = await MDService.MacchineGetFiltAsync("*");
var listRaw = await MDService.OperatoriGetFiltAsync("*");
ListOperatoriAll = listRaw.Where(x => x.isEnabled).ToList();
}
private async Task ReloadDataAsync()
{
isLoading = true;
if (string.IsNullOrEmpty(CodGruppo))
{
ListReparti?.Clear();
var rawList = await MDService.ElencoRepartiDtoAsync();
if (string.IsNullOrEmpty(SearchVal))
{
ListReparti = rawList;
}
else
{
ListReparti = rawList.Where(x => x.CodGruppo.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.DescrGruppo.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)).ToList();
}
}
if (!string.IsNullOrEmpty(CodGruppo))
{
await ReloadDetailAsync();
}
isLoading = false;
}
private async Task ReloadDetailAsync()
{
if (!string.IsNullOrEmpty(CodGruppo))
{
ListMacchine = await MDService.MacchineGetFiltAsync(CodGruppo);
ListOperatori = (await MDService.OperatoriGetFiltAsync(CodGruppo))
.Where(x => x.isEnabled).ToList();
}
}
private async Task ResetSearch()
{
SearchVal = "";
await ReloadDataAsync();
}
private async Task SetCodGruppo(string CodGruppoSel)
{
CodGruppo = CodGruppoSel;
await ReloadDetailAsync();
}
#endregion Private Methods
}
}