Files
mapo-core/MP.SPEC/Components/ListDossiers.razor.cs

478 lines
14 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Core.DTO;
using MP.Data.DbModels;
using MP.SPEC.Data;
using Newtonsoft.Json;
namespace MP.SPEC.Components
{
public partial class ListDossiers : IDisposable
{
#region Public Properties
[Parameter]
public EventCallback<DossierModel> RecordSel { get; set; }
[Parameter]
public EventCallback<FluxLogDTO> RecordSelFlux { get; set; }
[Parameter]
public SelectDossierParams SelFilter { get; set; } = null!;
[Parameter]
public EventCallback<int> TotRecordChanged { get; set; }
#endregion Public Properties
#region Public Methods
public string checkSelect(DossierModel recordSel)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.IdxMacchina == recordSel.IdxMacchina && currRecord.DtRif == recordSel.DtRif) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
public string checkSelPar(FluxLogDTO recordSel)
{
string answ = "";
if (currFluxLogDto != null)
{
try
{
answ = (currFluxLogDto.CodFlux == recordSel.CodFlux && currFluxLogDto.dtEvento == recordSel.dtEvento) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
public void Dispose()
{
currRecord = null;
SearchRecords = null;
ListRecords = null;
GC.Collect();
}
public async Task flushCache()
{
await Task.Delay(1);
await MDService.FlushRedisCache();
await Task.Delay(1);
// rimando a pagina corrente
NavManager.NavigateTo(NavManager.Uri, true);
}
#endregion Public Methods
#region Protected Fields
protected string selAzienda = "*";
protected string giacenzeConf = "false";
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MpDataService MDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task cancel()
{
var alert = await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler annullare TUTTE le modifiche? i dati saranno ricaricati.");
if (alert)
{
currFluxLogDto = null;
isEditing = false;
await Task.Delay(1);
if (currRecord != null)
{
listaFlux = MDService.FluxLogDtoGetByFlux(currRecord.Valore);
}
StateHasChanged();
}
}
protected async Task cancelNewDoss()
{
var alert = await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler annullare l'aggiunta di un nuovo dossier? i dati saranno ricaricati.");
if (alert)
{
currRecordClone = null;
isEditing = false;
await Task.Delay(1);
StateHasChanged();
}
}
protected async Task cloneRecord(DossierModel selRec)
{
// creo record duplicato...
DossierModel newRec = new DossierModel()
{
//IdxDossier = 0,
DataType = selRec.DataType,
KeyRichiesta = selRec.KeyRichiesta,
DtRif = DateTime.Now,
IdxMacchina = selRec.IdxMacchina,
CodArticolo = selRec.CodArticolo,
IdxODL = 0,
Valore = selRec.Valore
};
currRecordClone = newRec;
await Task.Delay(1);
}
/// <summary>
/// Eliminazione record selezionato (previa conferma)
/// </summary>
/// <param name="selRec"></param>
/// <returns></returns>
protected async Task deleteRecord(DossierModel selRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Eliminazione Dossier: sei sicuro di voler procedere?"))
return;
await Task.Delay(1);
var done = await MDService.DossiersDeleteRecord(selRec);
currRecord = null;
await ReloadData(true);
visualizzaFlux = true;
await Task.Delay(1);
}
protected async Task editRecord(FluxLogDTO selRec)
{
currFluxLogDto = selRec;
// indico record selezionato
await RecordSelFlux.InvokeAsync(selRec);
}
protected async Task newDossier(DossierModel selRec)
{
var alert = await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler creare un nuovo Dossier per l'impianto/articolo selezionato?");
if (alert)
{
await Task.Delay(1);
if (currRecordClone != null)
{
// serializzo valore x flux log...
DossierFluxLogDTO? valoreDeserializzato = JsonConvert.DeserializeObject<DossierFluxLogDTO>(selRec.Valore);
if (valoreDeserializzato != null)
{
listaFlux = valoreDeserializzato
.ODL
.OrderBy(x => x.CodFlux)
.ToList();
}
if (listaFlux != null)
{
foreach (var item in listaFlux)
{
item.IdxMacchina = selRec.IdxMacchina;
item.Valore = "0";
item.ValoreEdit = "0";
item.dtEvento = DateTime.Now;
}
}
DossierFluxLogDTO updatedResult = new DossierFluxLogDTO() { ODL = listaFlux };
string newVal = JsonConvert.SerializeObject(updatedResult);
// preparo x insert
currRecordClone.DtRif = DateTime.Now;
currRecordClone.IdxMacchina = selRec.IdxMacchina;
currRecordClone.CodArticolo = selRec.CodArticolo;
currRecordClone.KeyRichiesta = selRec.KeyRichiesta;
currRecordClone.Valore = newVal;
// METODO PER INSERT DOSSIER + FLUX
await MDService.DossiersInsert(currRecordClone);
//await ReloadDataAsync(true);
currRecordClone = null;
isEditing = false;
await Task.Delay(1);
await flushCache();
}
return;
}
else
{
currRecordClone = null;
await Task.Delay(1);
NavManager.NavigateTo(NavManager.Uri, true);
}
}
//prtected bool hasLic
//{
// get => selAzienda == "GIACOVELLI";
//}
protected override async Task OnInitializedAsync()
{
await MDService.ConfigResetCache();
ListGruppiFase = MDService.ElencoGruppiFase();
ListStati = await MDService.AnagStatiComm();
selAzienda = await MDService.ConfigTryGetAsync("AZIENDA");
giacenzeConf = await MDService.ConfigTryGetAsync("SPEC_ShowGiacenze");
ListArticoli = await MDService.ArticoliGetSearch(100000, selAzienda, "");
ListMacchine = MDService.MacchineGetFilt("*");
await ReloadData(true);
}
protected override async Task OnParametersSetAsync()
{
if (!lastFilter.Equals(SelFilter))
{
lastFilter = SelFilter.clone();
await ReloadData(true);
}
}
protected async void OnSeachUpdated()
{
await InvokeAsync(() =>
{
currPage = 1;
StateHasChanged();
});
}
protected async Task selRecord(DossierModel selRec)
{
currRecord = selRec;
await RecordSel.InvokeAsync(selRec);
listaFlux = MDService.FluxLogDtoGetByFlux(selRec.Valore);
await toggleTableFlux();
}
protected async Task update(FluxLogDTO selRec)
{
var alert = await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler salvare TUTTE le modifiche? queste saranno parte del dossier inviato all'impianto");
if (alert)
{
await Task.Delay(1);
if (currRecord != null)
{
// serializzo valore x flux log...
DossierFluxLogDTO updatedResult = new DossierFluxLogDTO() { ODL = listaFlux };
string newVal = JsonConvert.SerializeObject(updatedResult);
currRecord.Valore = newVal;
// METODO PER UPDATE FLUX
await MDService.DossiersUpdateValore(currRecord);
currFluxLogDto = null;
isEditing = false;
await Task.Delay(1);
StateHasChanged();
}
return;
}
else
{
currFluxLogDto = null;
await Task.Delay(1);
// rimando a pagina corrente
NavManager.NavigateTo(NavManager.Uri, true);
}
}
protected async Task UpdateData()
{
currRecord = null;
await ReloadData(true);
}
#endregion Protected Methods
#region Private Fields
private int _totalCount = 0;
private FluxLogDTO? currFluxLogDto = null;
private DossierModel? currRecord = null;
private DossierModel? currRecordClone = null;
private List<AnagArticoliModel>? ListArticoli;
private List<AnagGruppiModel>? ListGruppiFase;
private List<MacchineModel>? ListMacchine;
private List<DossierModel>? ListRecords;
private List<ListValuesModel>? ListStati;
private List<DossierModel>? SearchRecords;
#endregion Private Fields
#region Private Properties
private int currPage
{
get => SelFilter.CurrPage;
set => SelFilter.CurrPage = value;
}
private bool isEditing
{
get => SelFilter.isEditing;
set => SelFilter.isEditing = value;
}
private bool isLoading { get; set; } = false;
private SelectDossierParams lastFilter { get; set; } = new SelectDossierParams() { CurrPage = -1 };
private List<FluxLogDTO>? listaFlux { get; set; } = null;
private int MaxRecord
{
get => SelFilter.MaxRecord;
}
[Inject]
private NavigationManager NavManager { get; set; } = null!;
private int numRecord
{
get => SelFilter.NumRec;
set => SelFilter.NumRec = value;
}
private string SelArticolo
{
get => SelFilter.CodArticolo;
}
private DateTime SelDtEnd
{
get => SelFilter.DtEnd;
}
private DateTime SelDtStart
{
get => SelFilter.DtStart;
}
private string SelMacchina
{
get => SelFilter.IdxMacchina;
}
private int MaxRec
{
get => SelFilter.MaxRecord;
}
private int totalCount
{
get => _totalCount;
set
{
if (_totalCount != value)
{
_totalCount = value;
TotRecordChanged.InvokeAsync(value);
}
}
}
private bool visualizzaFlux { get; set; } = true;
#endregion Private Properties
#region Private Methods
private async Task closeTableFlux()
{
currFluxLogDto = null;
currRecord = null;
currRecordClone = null;
visualizzaFlux = true;
isEditing = false;
await RecordSelFlux.InvokeAsync(currFluxLogDto);
await Task.Delay(1);
}
private string css()
{
string answ = "";
if (isEditing)
{
answ = "visible";
}
else
{
answ = "hidden";
}
return answ;
}
private void enableEditing()
{
isEditing = true;
}
private async Task ReloadData(bool setChanged)
{
isLoading = true;
SearchRecords = await MDService.DossiersGetLastFilt(SelMacchina, SelArticolo, SelDtStart, SelDtEnd, MaxRec);
totalCount = SearchRecords.Count;
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
await Task.Delay(1);
if (setChanged)
{
await InvokeAsync(() => StateHasChanged());
}
isLoading = false;
}
private async Task toggleTableFlux()
{
visualizzaFlux = false;
await Task.Delay(1);
}
private string tradFase(string codFase)
{
string answ = codFase;
if (ListStati != null && ListStati.Count > 0)
{
var recSel = ListStati.FirstOrDefault(x => x.value == codFase);
if (recSel != null)
{
answ = recSel.label;
}
}
return answ;
}
private string traduci(string lemma)
{
var answ = MDService.Traduci(lemma, "IT");
return answ;
}
#endregion Private Methods
}
}