Files

546 lines
16 KiB
C#

using EgwCoreLib.Razor;
using EgwCoreLib.Utils;
using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
using GPW.CORE.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NLog;
namespace GPW.CORE.ADM.Components.Compo
{
public partial class SpostaOreMan : IDisposable
{
#region Public Methods
public void Dispose()
{
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected MessageService AppMServ { get; set; } = null!;
[Inject]
protected AppAuthService AuthServ { get; set; } = null!;
[Inject]
protected GpwDataService GDataServ { get; set; } = null!;
protected bool HasRowSelected
{
get => ListRecords != null && ListRecords.Where(x => x.Selected).Count() > 0;
}
protected int IdxCliSelFrom
{
get => idxCliFrom;
set
{
if (idxCliFrom != value)
{
idxCliFrom = value;
idxProjFrom = 0;
idxFaseFrom = 0;
}
}
}
protected int IdxCliSelTo
{
get => idxCliTo;
set
{
if (idxCliTo != value)
{
idxCliTo = value;
idxProjTo = 0;
idxFaseTo = 0;
}
}
}
protected int IdxDipSel
{
get => idxDipendente;
set => idxDipendente = value;
}
protected int IdxFaseSelFrom
{
get => idxFaseFrom;
set => idxFaseFrom = value;
}
protected int IdxFaseSelTo
{
get => idxFaseTo;
set => idxFaseTo = value;
}
protected int IdxProjSelFrom
{
get => idxProjFrom;
set
{
if (idxProjFrom != value)
{
idxProjFrom = value;
idxFaseFrom = 0;
}
}
}
protected int IdxProjSelTo
{
get => idxProjTo;
set
{
if (idxProjTo != value)
{
idxProjTo = value;
idxFaseTo = 0;
}
}
}
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected List<AnagClientiModel> ListClientiFiltFrom
{
get
{
List<AnagClientiModel> answ = new List<AnagClientiModel>();
if (ShowCliInattFrom)
{
answ = ListClienti;
}
else
{
answ = ListClienti.Where(x => x.Attivo).ToList();
}
return answ;
}
}
protected List<AnagClientiModel> ListClientiFiltTo
{
get
{
List<AnagClientiModel> answ = new List<AnagClientiModel>();
if (ShowCliInattTo)
{
answ = ListClienti;
}
else
{
answ = ListClienti.Where(x => x.Attivo).ToList();
}
return answ;
}
}
protected List<DipendentiModel> ListDipendentiFilt
{
get
{
List<DipendentiModel> answ = new List<DipendentiModel>();
if (ShowDipInatt)
{
answ = ListDipendenti;
}
else
{
answ = ListDipendenti.Where(x => (x.Attivo ?? false)).ToList();
}
return answ;
}
}
protected List<AnagFasiModel> ListFasiFiltFrom
{
get
{
List<AnagFasiModel> answ = new List<AnagFasiModel>();
if (idxProjFrom > 0)
{
answ = ListFasi
.Where(x => x.IdxProgetto == IdxProjSelFrom && (x.Attivo || ShowFaseInattFrom))
.OrderBy(x => x.CodFase)
.ToList();
}
return answ;
}
}
protected List<AnagFasiModel> ListFasiFiltTo
{
get
{
List<AnagFasiModel> answ = new List<AnagFasiModel>();
if (idxProjTo > 0)
{
answ = ListFasi
.Where(x => x.IdxProgetto == IdxProjSelTo && (x.Attivo || ShowFaseInattTo))
.OrderBy(x => x.CodFase)
.ToList();
}
return answ;
}
}
protected List<AnagProgettiModel> ListProgettiFiltFrom
{
get
{
List<AnagProgettiModel> answ = new List<AnagProgettiModel>();
if (idxCliFrom > 0)
{
answ = ListProgetti.Where(x => x.IdxCliente == IdxCliSelFrom && ((x.Attivo ?? false) || ShowProjInattFrom)).ToList();
}
return answ;
}
}
protected List<AnagProgettiModel> ListProgettiFiltTo
{
get
{
List<AnagProgettiModel> answ = new List<AnagProgettiModel>();
if (idxCliTo > 0)
{
answ = ListProgetti.Where(x => x.IdxCliente == IdxCliSelTo && ((x.Attivo ?? false) || ShowProjInattTo)).ToList();
}
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
protected string CssCheckSel(RegAttDayExpDTO currRec)
{
bool isSel = SelRecord != null && SelRecord.IdxDipendente == currRec.IdxDipendente;
return isSel ? "table-info" : "";
}
protected async Task ForceReload()
{
currPage = 1;
SelRecord = null;
await ReloadData();
}
protected async Task ForceReloadList()
{
await ReloadBaseData();
}
protected override async Task OnInitializedAsync()
{
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
await ReloadBaseData();
}
protected async void Recalc()
{
await Task.Delay(200);
}
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
await AppMServ.NumRowGridSet(gridKey, newNum);
await InvokeAsync(ReloadData);
}
protected async Task SetPage(int newNum)
{
currPage = newNum;
allSel = false;
await InvokeAsync(ReloadData);
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
/// <summary>
/// Effettua spostamento degli item selezionati verso la fase di destinazione
/// </summary>
protected async Task SpostaSel()
{
var cliente = ListClienti.FirstOrDefault(x => x.IdxCliente == IdxCliSelTo);
var progetto = ListProgetti.FirstOrDefault(x => x.IdxProgetto == IdxProjSelTo);
var fase = ListFasi.FirstOrDefault(x => x.IdxFase == IdxFaseSelTo);
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler spostare i record selezionati?{Environment.NewLine}{Environment.NewLine}Cliente: {cliente.RagSociale}{Environment.NewLine}Progetto: {progetto.NomeProj} | {progetto.DescrProj}{Environment.NewLine}Fase: {fase.DescrizioneFase}"))
return;
// solo se ho una fase dest selezionata
if (IdxFaseSelTo > 0)
{
Dictionary<int, int> list2move = new Dictionary<int, int>();
foreach (var item in ListRecords)
{
if (item.Selected)
{
// inserisco in dizionario la riga da spostare
list2move.Add(item.IdxRA, IdxFaseSelTo);
}
}
// sposto righe!
await GDataServ.RegAttUpdateFase(list2move);
await ReloadData();
}
}
/// <summary>
/// Effettua toggle selezione globale delle righe mostrateGpwDataService gDataServprivate async Task ReloadData
/// </summary>
protected void ToggleSelection()
{
allSel = !allSel;
foreach (var item in ListRecords)
{
item.Selected = allSel;
}
}
protected string Traduci(string lemma)
{
return AuthServ.Traduci(lemma, AppMServ.UserLang);
}
#endregion Protected Methods
#region Private Fields
private static Logger Log = LogManager.GetCurrentClassLogger();
private bool allSel = false;
private int currPage = 1;
private string gridKey = "TimbMan";
private int idxCliFrom = 0;
private int idxCliTo = 0;
private int idxDipendente = 0;
private int idxFaseFrom = 0;
private int idxFaseTo = 0;
private int idxProjFrom = 0;
private int idxProjTo = 0;
private bool isAncest = false;
private bool isLoading = false;
private int numRecord = 10;
private bool ShowCliInattFrom = false;
private bool ShowCliInattTo = false;
private bool ShowDipInatt = false;
private bool ShowFaseInattFrom = false;
private bool ShowFaseInattTo = false;
private bool ShowProjInattFrom = false;
private bool ShowProjInattTo = false;
private bool sortAsc = true;
private string sortField = "";
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
private DtUtils.Periodo CurrPeriodo { get; set; } = new DtUtils.Periodo(DtUtils.PeriodSet.ThisMonth);
private List<AnagClientiModel> ListClienti { get; set; } = new List<AnagClientiModel>();
private List<DipendentiModel> ListDipendenti { get; set; } = new List<DipendentiModel>();
private List<AnagFasiModel> ListFasi { get; set; } = new List<AnagFasiModel>();
private List<AnagProgettiModel> ListProgetti { get; set; } = new List<AnagProgettiModel>();
private List<RegAttDayExpDTO>? ListRecords { get; set; } = null;
private string mainDivCss
{
get => SelRecord == null ? "col-12" : "col-12 col-lg-9";
}
private List<RegAttDayExpDTO>? SearchRecords { get; set; } = null;
private RegAttDayExpDTO? SelRecord { get; set; } = null;
#endregion Private Properties
#region Private Methods
private async void AppMServ_EA_SearchUpdated()
{
await ReloadData();
}
/// <summary>
/// Caricamento dati "statici" dei selettori
/// </summary>
/// <returns></returns>
private async Task ReloadBaseData()
{
ListDipendenti = await GDataServ.DipendentiGetAll();
ListClienti = await GDataServ.AnagClientiAllAsync();
ListProgetti = await GDataServ.AnagProjAll();
ListFasi = await GDataServ.AnagFasiAll();
}
private async Task ReloadData()
{
isLoading = true;
await InvokeAsync(StateHasChanged);
// tolgo selezione toggle
allSel = false;
// carico i dati della tabella
List<RegAttivitaDayExplModel> rawData = await GDataServ.RegAttDayExplList(idxDipendente, CurrPeriodo.Inizio, CurrPeriodo.Fine, idxCliFrom, idxProjFrom, idxFaseFrom, isAncest);
// se ho ricerca filtro (descrizione)
if (!string.IsNullOrWhiteSpace(AppMServ.SearchVal))
{
rawData = rawData
.Where(x => x.Descrizione.Contains(AppMServ.SearchVal, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
// converto da model a DTO...
SearchRecords = rawData
.Select(x => new RegAttDayExpDTO(x))
.ToList();
totalCount = SearchRecords.Count;
// paginazione e sorting
SortTable();
isLoading = false;
await InvokeAsync(StateHasChanged);
}
private async Task SavePeriodo(DtUtils.Periodo newPeiodo)
{
CurrPeriodo = newPeiodo;
await ReloadData();
}
private void SortTable()
{
if (SearchRecords != null)
{
if (!string.IsNullOrEmpty(sortField))
{
switch (sortField)
{
case "CognomeNome":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.CognomeNome).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.CognomeNome).ToList();
}
break;
case "OreTot":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.OreTot).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.OreTot).ToList();
}
break;
case "Periodo":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.Inizio).ThenBy(x => x.Fine).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.Inizio).ThenBy(x => x.Fine).ToList();
}
break;
case "Gruppo":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.Gruppo).ThenBy(x => x.RagSociale).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.Gruppo).ThenBy(x => x.RagSociale).ToList();
}
break;
case "Progetto":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.NomeProj).ThenBy(x => x.NomeFase).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.NomeProj).ThenBy(x => x.NomeFase).ToList();
}
break;
case "Descrizione":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.Descrizione).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.Descrizione).ToList();
}
break;
default:
break;
}
}
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
}
#endregion Private Methods
}
}