diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index 6d76c64c..bba5c444 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -746,11 +746,11 @@ namespace MP.Data.Controllers using (var dbCtx = new MoonProContext(_configuration)) { var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); - var DataElab = new SqlParameter("@DataElab", dtCurr); + var DataElab = new SqlParameter("@pDataOra", dtCurr); var dbResult = await dbCtx .Database - .ExecuteSqlRawAsync("EXEC stp_IM_ElaboraInsManuali @IdxMacchina, @DataElab", IdxMacc, DataElab); + .ExecuteSqlRawAsync("EXEC stp_IM_ElaboraInsManuali @IdxMacchina, @pDataOra", IdxMacc, DataElab); fatto = dbResult > 0; } @@ -2056,6 +2056,35 @@ namespace MP.Data.Controllers return answ; } + /// + /// Esegue il ripristino stato precedente x una macchina che abbia una dichiarazione manuale (es Pausa pranzo) da cui "uscire" + /// + /// + /// + /// + /// + /// + /// + public async Task RipristinaStatoPrec(string idxMacchina, DateTime dtCurr, string valore, int idxStato = 0, int matrOpr = 0) + { + bool fatto = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + var pIdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); + var pDataOra = new SqlParameter("@DataOra", dtCurr); + var pIdxStato = new SqlParameter("@IdxStato", idxStato); + var pMatrOpr = new SqlParameter("@MatrOpr", matrOpr); + var pValueEv = new SqlParameter("@ValueEv", valore); + + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC stp_DDB_RipristinaStato @IdxMacchina, @DataOra, @IdxStato, @MatrOpr, @ValueEv", pIdxMacc, pDataOra, pIdxStato, pMatrOpr, pValueEv); + fatto = dbResult > 0; + } + + return fatto; + } + public bool SetDerogaSt(StCheckOverride deroga) { bool fatto = false; diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 8ff2ce72..82dbab87 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -9,7 +9,6 @@ using NLog; using StackExchange.Redis; using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Data; using System.Diagnostics; using System.Globalization; @@ -3034,6 +3033,35 @@ namespace MP.Data.Services return answ; } + /// + /// Esegue il ripristino stato precedente x una macchina che abbia una dichiarazione manuale (es Pausa pranzo) da cui "uscire" + /// + /// + /// + /// + /// + /// + /// + public async Task RipristinaStatoPrec(string idxMacchina, DateTime dtCurr, string valore, int idxStato = 0, int matrOpr = 0) + { + bool inserito = false; + try + { + // inserisco evento + inserito = await dbTabController.RipristinaStatoPrec(idxMacchina, dtCurr, valore, idxStato, matrOpr); + // reset cache eventi/commenti + await FlushCache("EvList"); + await FlushCache("Commenti"); + } + catch (Exception exc) + { + string logMsg = $"Eccezione in fase di RipristinaStatoPrec | macchina: {idxMacchina} | dtCurr: {dtCurr} | valore: {valore} | idxStato {idxStato} | matrOpr {matrOpr}{Environment.NewLine}{exc}"; + Log.Error(logMsg); + } + + return inserito; + } + /// /// Processa registrazione di un counter x una data macchina IOB /// @@ -3989,7 +4017,7 @@ namespace MP.Data.Services } answ = true; } - } + } #endif // notifico update ai client in ascolto x reset cache NotifyReloadRequest($"FlushRedisCache | {pat2Flush}"); diff --git a/MP.SPEC/Pages/RepStop.razor b/MP.SPEC/Pages/RepStop.razor index 4b12028d..30f02427 100644 --- a/MP.SPEC/Pages/RepStop.razor +++ b/MP.SPEC/Pages/RepStop.razor @@ -29,6 +29,8 @@
@if (showFermate) { + +
} else diff --git a/MP.SPEC/Pages/RepStop.razor.cs b/MP.SPEC/Pages/RepStop.razor.cs index 89bfc906..00864769 100644 --- a/MP.SPEC/Pages/RepStop.razor.cs +++ b/MP.SPEC/Pages/RepStop.razor.cs @@ -4,17 +4,24 @@ using MP.Core.DTO; using MP.Data; using MP.Data.DbModels; using MP.Data.Services; -using MP.SPEC.Components.Reparti; using MP.SPEC.Data; using Newtonsoft.Json; -using NLog.LayoutRenderers; using static MP.Core.Objects.Enums; -using static MP.Data.Services.ExecStatsCollector; namespace MP.SPEC.Pages { - public partial class RepStop: IDisposable + 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] @@ -23,12 +30,18 @@ namespace MP.SPEC.Pages [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 @@ -40,43 +53,6 @@ namespace MP.SPEC.Pages TDFeeder.resumeTimers(); } - [Inject] - protected TabDataFeeder TDFeeder { get; set; } = null!; - - public void Dispose() - { - TDFeeder.pauseTimers(); - TDFeeder.dataPipe.EA_NewMessage -= DataPipe_EA_NewMessage; - } - - /// - /// Ricevuto nuovi dati da mostrare! - /// - /// - /// - private void DataPipe_EA_NewMessage(object? sender, EventArgs e) - { - PubSubEventArgs currArgs = (PubSubEventArgs)e; - // conversione on-the-fly List --> allarmi - if (!string.IsNullOrEmpty(currArgs.newMessage)) - { - try - { - List? dataList = JsonConvert.DeserializeObject>(currArgs.newMessage); - if (dataList != null) - { - InvokeAsync(() => SaveData(dataList)); - } - } - catch - { } - } - InvokeAsync(() => - { - StateHasChanged(); - }); - } - protected async Task SaveData(List newList) { // salvo valori ricevuti @@ -108,6 +84,34 @@ namespace MP.SPEC.Pages showFermate = listSelezione.Count > 0; } + /// + /// Ricevuto nuovi dati da mostrare! + /// + /// + /// + private void DataPipe_EA_NewMessage(object? sender, EventArgs e) + { + PubSubEventArgs currArgs = (PubSubEventArgs)e; + // conversione on-the-fly List --> allarmi + if (!string.IsNullOrEmpty(currArgs.newMessage)) + { + try + { + List? dataList = JsonConvert.DeserializeObject>(currArgs.newMessage); + if (dataList != null) + { + InvokeAsync(() => SaveData(dataList)); + } + } + catch + { } + } + InvokeAsync(() => + { + StateHasChanged(); + }); + } + private async Task DoReload(bool forceReload) { isLoading = true; @@ -116,9 +120,36 @@ namespace MP.SPEC.Pages isLoading = false; } + /// + /// Gestione ritorno a stato precedente, tramite stored + /// + /// + private async Task DoRestorePrevious() + { + if (!await JSRuntime.InvokeAsync("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; - [Inject] - protected MsgServiceSpec MService { get; set; } = null!; + 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 | {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); + } + + var ListMSE = await MDService.MseGetAll(true); + await Task.Delay(250); + await ReloadData(); + isLoading = false; + } /// /// Gestione selezione evento da registrare x le macchine selezionate @@ -142,7 +173,7 @@ namespace MP.SPEC.Pages { var rigaStato = MDService.StatoMacchina(idxMacc); - // mpreparo info utente x Value... + // preparo info utente x Value... string valData = $"SPEC | {MService.DomainName}\\{MService.UserName}"; // processo evento... DateTime adesso = DateTime.Now.Floor(TimeSpan.FromSeconds(1)); @@ -153,7 +184,7 @@ namespace MP.SPEC.Pages IdxTipo = selEv.IdxEv, CodArticolo = rigaStato.CodArticolo, Value = valData, - MatrOpr = 0, + MatrOpr = 0, pallet = rigaStato.pallet }; // FORZO con metodo TAB