220 lines
7.3 KiB
C#
220 lines
7.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Core.DTO;
|
|
using MP.Data;
|
|
using MP.Data.DbModels;
|
|
using MP.Data.Services;
|
|
using MP.SPEC.Data;
|
|
using Newtonsoft.Json;
|
|
using static MP.Core.Objects.Enums;
|
|
|
|
namespace MP.SPEC.Pages
|
|
{
|
|
public partial class RepStop : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
TDFeeder.pauseTimers();
|
|
TDFeeder.dataPipe.EA_NewMessage -= DataPipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MsgServiceSpec MService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected SharedMemService SMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataService TabDServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataFeeder TDFeeder { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadData();
|
|
TDFeeder.dataPipe.EA_NewMessage += DataPipe_EA_NewMessage;
|
|
TDFeeder.resumeTimers();
|
|
}
|
|
|
|
protected async Task SaveData(List<MappaStatoExplModel> newList)
|
|
{
|
|
// salvo valori ricevuti
|
|
CurrMSE = newList;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<string> CurrMachSel = new List<string>();
|
|
|
|
private List<MappaStatoExplModel> CurrMSE = new();
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<vSelEventiBCodeModel> SearchFermate = new();
|
|
|
|
private bool showFermate = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void CheckSelection(List<string> listSelezione)
|
|
{
|
|
CurrMachSel = listSelezione;
|
|
// se c'è selezione mostro elenco fermate...
|
|
showFermate = listSelezione.Count > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricevuto nuovi dati da mostrare!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void DataPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly List<string> --> allarmi
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
List<MappaStatoExplModel>? dataList = JsonConvert.DeserializeObject<List<MappaStatoExplModel>>(currArgs.newMessage);
|
|
if (dataList != null)
|
|
{
|
|
InvokeAsync(() => SaveData(dataList));
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
private async Task DoReload(bool forceReload)
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(100);
|
|
CurrMSE = await MDService.MseGetAll(true);
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione ritorno a stato precedente, tramite stored
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task DoRestorePrevious()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Hai {CurrMachSel.Count} impianti selezionati.{Environment.NewLine}Confermi di voler registrare il ritorno all'ultimo stato precedente le dichiarazioni manuali?{Environment.NewLine}La procedura verificherà l'applicabilità per ogni impianto selezionato."))
|
|
return;
|
|
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// se conferma ciclo x ogni macchina e registro
|
|
foreach (var idxMacc in CurrMachSel)
|
|
{
|
|
DateTime adesso = DateTime.Now.Floor(TimeSpan.FromSeconds(1));
|
|
var rigaStato = MDService.StatoMacchina(idxMacc);
|
|
string valData = $"SPEC | FRep.Fine | {MService.DomainName}\\{MService.UserName}";
|
|
|
|
// chiamo stored
|
|
await TabDServ.RipristinaStatoPrec(idxMacc, adesso, valData, rigaStato.IdxStato, 0);
|
|
// resetta il microstato in modo da ricevere successive info HW
|
|
await TabDServ.resetMicrostatoMacchina(idxMacc);
|
|
}
|
|
|
|
forceResetSel = true;
|
|
var ListMSE = await MDService.MseGetAll(true);
|
|
CurrMachSel = new();
|
|
await Task.Delay(250);
|
|
await ReloadData();
|
|
forceResetSel = false;
|
|
CheckSelection(new());
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione selezione evento da registrare x le macchine selezionate
|
|
/// </summary>
|
|
/// <param name="selEv"></param>
|
|
/// <returns></returns>
|
|
private async Task EventRecord(SelEventDTO selEv)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Hai {CurrMachSel.Count} impianti selezionati.{Environment.NewLine}Confermi di voler registrare l'evento {selEv.Descript}?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// recupero evento
|
|
var rigaEvento = SMServ.GetEventRow(selEv.IdxEv);
|
|
if (rigaEvento != null)
|
|
{
|
|
// se conferma ciclo x ogni macchina e registro
|
|
foreach (var idxMacc in CurrMachSel)
|
|
{
|
|
var rigaStato = MDService.StatoMacchina(idxMacc);
|
|
|
|
// preparo info utente x Value...
|
|
string valData = $"SPEC | FRep.Inizio | {MService.DomainName}\\{MService.UserName}";
|
|
// processo evento...
|
|
DateTime adesso = DateTime.Now.Floor(TimeSpan.FromSeconds(1));
|
|
EventListModel newRec = new EventListModel()
|
|
{
|
|
IdxMacchina = idxMacc,
|
|
InizioStato = adesso,
|
|
IdxTipo = selEv.IdxEv,
|
|
CodArticolo = rigaStato.CodArticolo,
|
|
Value = valData,
|
|
MatrOpr = 0,
|
|
pallet = rigaStato.pallet
|
|
};
|
|
// FORZO con metodo TAB
|
|
await TabDServ.EvListInsert(newRec, tipoInputEvento.barcode);
|
|
// resetta il microstato in modo da ricevere successive info HW
|
|
await TabDServ.resetMicrostatoMacchina(idxMacc);
|
|
}
|
|
forceResetSel = true;
|
|
var ListMSE = await MDService.MseGetAll(true);
|
|
CurrMachSel = new();
|
|
await Task.Delay(250);
|
|
await ReloadData();
|
|
forceResetSel = false;
|
|
CheckSelection(new());
|
|
isLoading = false;
|
|
}
|
|
}
|
|
|
|
private bool forceResetSel = false;
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
CurrMSE = await MDService.MseGetAll(false);
|
|
SearchFermate = MDService.AnagEventiGeneral();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |