279 lines
10 KiB
C#
279 lines
10 KiB
C#
using global::Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
using MP.Data;
|
|
using MP.Data.DbModels;
|
|
using MP.Data.Services;
|
|
using MP_TAB3.Components;
|
|
using NLog;
|
|
|
|
namespace MP_TAB3.Pages
|
|
{
|
|
public partial class ProdStop
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected int dltMinRealtime = 1;
|
|
|
|
protected bool isProcessing = false;
|
|
|
|
protected string lblOut = "";
|
|
protected int minAnticipoRicalcolo = 1;
|
|
|
|
protected bool rdm_ChkOnly = false;
|
|
|
|
protected int rdm_nEvCheck = 1;
|
|
|
|
protected int rdm_nEvStep = 1;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string alertCss { get; set; } = "alert-danger";
|
|
|
|
protected DateTime DtRif { get; set; } = DateTime.Now;
|
|
|
|
protected List<vSelEventiBCodeModel> events2show { get; set; } = new List<vSelEventiBCodeModel>();
|
|
|
|
/// <summary>
|
|
/// Determina se insert sia Realtime o batch con DataOra (in base a diff tra DataOra
|
|
/// selezionata e realtime, se superiore ad X minuti NON � realtime)
|
|
/// </summary>
|
|
protected bool insRealtime
|
|
{
|
|
get
|
|
{
|
|
bool answ = true;
|
|
if (Math.Abs(DtRif.Subtract(DateTime.Now).TotalMinutes) > dltMinRealtime)
|
|
{
|
|
answ = false;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected StatusData MDataService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
protected NotesEditor? noteEdit { get; set; }
|
|
|
|
[Inject]
|
|
protected SharedMemService SMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataService TabDServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Processo registrazione eventi
|
|
/// </summary>
|
|
/// <param name="IdxEv"></param>
|
|
/// <returns></returns>
|
|
protected async Task EventRecord(int IdxEv)
|
|
{
|
|
isProcessing = true;
|
|
bool needReload = false;
|
|
await Task.Delay(1);
|
|
// salvo evento e processo...
|
|
if (IdxEv > 0)
|
|
{
|
|
var rigaEvento = SMServ.GetEventRow(IdxEv);
|
|
if (rigaEvento != null)
|
|
{
|
|
var rigaStato = TabDServ.StatoMacchina(IdxMacc);
|
|
// processo evento...
|
|
if (insRealtime)
|
|
{
|
|
DateTime adesso = DateTime.Now.Floor(TimeSpan.FromSeconds(1));
|
|
EventListModel newRec = new EventListModel()
|
|
{
|
|
IdxMacchina = IdxMacc,
|
|
InizioStato = adesso,
|
|
IdxTipo = IdxEv,
|
|
CodArticolo = rigaStato.CodArticolo,
|
|
Value = "DRT",
|
|
MatrOpr = MatrOpr,
|
|
pallet = rigaStato.pallet
|
|
};
|
|
// se realtime
|
|
await TabDServ.EvListInsert(newRec, MP.Core.Objects.Enums.tipoInputEvento.barcode);
|
|
// resetta il microstato in modo da ricevere successive info HW
|
|
await TabDServ.resetMicrostatoMacchina(IdxMacc);
|
|
}
|
|
else
|
|
{
|
|
needReload = true;
|
|
// in primis disabilito insert...
|
|
TabDServ.MacchinaSetInsEnab(IdxMacc, false);
|
|
|
|
// calcolo evento
|
|
string evento = $"{IdxEv}";
|
|
string commento = "";
|
|
try
|
|
{
|
|
evento = rigaEvento.Nome.Replace("Barcode - ", "");
|
|
}
|
|
catch
|
|
{ }
|
|
// genero stringa pseudo-univoca
|
|
string codRich = $"{DateTime.Now:yyMMddHHmmss}-{IdxEv}";
|
|
// x prima cosa scrivo un evento tipo "1" x chiudere la durata appena prima
|
|
// dell'evento successivo
|
|
try
|
|
{
|
|
// cerco da 1 sec DOPO evento...
|
|
var tabNext = TabDServ.DDB_getNext(IdxMacc, DtRif.AddSeconds(1));
|
|
|
|
DateTime nextEvDT = tabNext != null ? tabNext.InizioStato : DateTime.Now.AddMinutes(-1);
|
|
|
|
// fix salvo la dichiarazione di chiusura
|
|
commento = $"999 - M.Lav EndEvt: {evento} [{codRich}]";
|
|
// 1 hard-coded x resettare
|
|
EventListModel newRec = new EventListModel()
|
|
{
|
|
IdxMacchina = IdxMacc,
|
|
InizioStato = nextEvDT.AddSeconds(-1),
|
|
IdxTipo = 1,
|
|
CodArticolo = rigaStato.CodArticolo,
|
|
Value = commento,
|
|
MatrOpr = MatrOpr,
|
|
pallet = rigaStato.pallet
|
|
};
|
|
await TabDServ.EvListInsert(newRec, MP.Core.Objects.Enums.tipoInputEvento.barcode);
|
|
|
|
// update commento apertura!
|
|
commento = $"999 - Dich StartEvt: {evento} [{codRich}]";
|
|
newRec = new EventListModel()
|
|
{
|
|
IdxMacchina = IdxMacc,
|
|
InizioStato = DtRif.AddSeconds(1),
|
|
IdxTipo = IdxEv,
|
|
CodArticolo = rigaStato.CodArticolo,
|
|
Value = commento,
|
|
MatrOpr = MatrOpr,
|
|
pallet = rigaStato.pallet
|
|
};
|
|
await TabDServ.EvListInsert(newRec, MP.Core.Objects.Enums.tipoInputEvento.barcode);
|
|
// eseguo ricalcolo!
|
|
DateTime startRicalcolo = DtRif.AddMinutes(minAnticipoRicalcolo);
|
|
// eseguo ricalcolo periodo..
|
|
await TabDServ.DDB_DoRecalc(IdxMacc, startRicalcolo, 1, rdm_nEvStep, rdm_nEvCheck, rdm_ChkOnly);
|
|
// chiamo registrazione commento...
|
|
if (noteEdit != null)
|
|
{
|
|
await noteEdit.ForceSave(DtRif.AddSeconds(5));
|
|
DtRif = DateTime.Now;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in fase di riqualifica fermi{Environment.NewLine}{exc}");
|
|
}
|
|
|
|
// riabilito insert... anche se non dovrebbe servire x stored ricalcolo precedente...
|
|
TabDServ.MacchinaSetInsEnab(IdxMacc, true);
|
|
}
|
|
// mostro esito
|
|
alertCss = "alert-primary";
|
|
titleOut = rigaEvento.Nome;
|
|
lblOut = $"Registrata dichiarazione fermata alle {DateTime.Now:HH:mm:ss}";
|
|
}
|
|
else
|
|
{
|
|
alertCss = "alert-warning";
|
|
lblOut = $"Codice evento non valido! {IdxEv}";
|
|
}
|
|
}
|
|
// faccio refresh x singola macchina 2019.03.26
|
|
await TabDServ.RicalcMse(IdxMacc, 0);
|
|
// rileggo e salvo..
|
|
var ListMSE = await MDataService.MseGetAll(true);
|
|
if (ListMSE != null)
|
|
{
|
|
// salvo in LocalStorage...
|
|
await MsgServ.SaveMse(ListMSE);
|
|
// aggiorno MSE attuale
|
|
CurrMSE = ListMSE.Find(x => x.IdxMacchina == IdxMacc);
|
|
}
|
|
isProcessing = false;
|
|
// se non era realtime --> rimando a commenti
|
|
if (needReload)
|
|
{
|
|
await MsgServ.LastOpenedPageSet("notes");
|
|
NavMan.NavigateTo("notes");
|
|
}
|
|
}
|
|
|
|
protected void ForceReloadPage()
|
|
{
|
|
NavMan.NavigateTo(NavMan.Uri, true);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await base.OnInitializedAsync();
|
|
dltMinRealtime = SMServ.GetConfInt("dltMinRealtime");
|
|
minAnticipoRicalcolo = SMServ.GetConfInt("minAnticipoRicalcolo");
|
|
rdm_nEvStep = SMServ.GetConfInt("rdm_nEvStep");
|
|
rdm_nEvCheck = SMServ.GetConfInt("rdm_nEvCheck");
|
|
rdm_ChkOnly = SMServ.GetConfBool("rdm_ChkOnly");
|
|
}
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
// leggo gli altri dati
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task ReloadData()
|
|
{
|
|
if (string.IsNullOrEmpty(IdxMacc))
|
|
{
|
|
try
|
|
{
|
|
await base.ReloadData();
|
|
// recupero eventi
|
|
var eventsAll = TabDServ.AnagEventiGetByMacch(IdxMacc);
|
|
if (eventsAll != null)
|
|
{
|
|
events2show = eventsAll.Where(x => x.EventoTablet).ToList();
|
|
//events2show = eventsAll.Where(x => x.EventoTablet).OrderBy(x => x.label).ToList();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"ProdStop: Eccezione in reloadData {Environment.NewLine}{exc}");
|
|
await MsgServ.LastOpenedPageSet("/");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void SetDate(DateTime newDate)
|
|
{
|
|
DtRif = newDate;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private string titleOut = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int MatrOpr
|
|
{
|
|
get => MsgServ.MatrOpr;
|
|
}
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |