diff --git a/MP-TAB-SERV/MP-TAB-SERV.csproj b/MP-TAB-SERV/MP-TAB-SERV.csproj
index b7b22d09..aa2be04f 100644
--- a/MP-TAB-SERV/MP-TAB-SERV.csproj
+++ b/MP-TAB-SERV/MP-TAB-SERV.csproj
@@ -3,7 +3,7 @@
net6.0
enable
- 6.16.2310.615
+ 6.16.2310.617
enable
MP_TAB_SERV
diff --git a/MP-TAB-SERV/Pages/ProdStop.razor.cs b/MP-TAB-SERV/Pages/ProdStop.razor.cs
index fec92a39..395ef8b9 100644
--- a/MP-TAB-SERV/Pages/ProdStop.razor.cs
+++ b/MP-TAB-SERV/Pages/ProdStop.razor.cs
@@ -58,7 +58,7 @@ namespace MP_TAB_SERV.Pages
if (insRealtime)
{
// se realtime
- TabServ.scriviRigaEventoBarcode(IdxMacc, IdxEv, rigaStato.CodArticolo, "DRT", MatrOpr, rigaStato.pallet);
+ await TabServ.scriviRigaEventoBarcode(IdxMacc, IdxEv, rigaStato.CodArticolo, "DRT", MatrOpr, rigaStato.pallet);
// resetta il microstato in modo da ricevere successive info HW
TabServ.resetMicrostatoMacchina(IdxMacc);
}
diff --git a/MP-TAB-SERV/Resources/ChangeLog.html b/MP-TAB-SERV/Resources/ChangeLog.html
index 3d18e7ef..82600be5 100644
--- a/MP-TAB-SERV/Resources/ChangeLog.html
+++ b/MP-TAB-SERV/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
Modulo MAPOSPEC
- Versione: 6.16.2310.615
+ Versione: 6.16.2310.617
Note di rilascio:
-
diff --git a/MP-TAB-SERV/Resources/VersNum.txt b/MP-TAB-SERV/Resources/VersNum.txt
index b1409f9e..82ae98ad 100644
--- a/MP-TAB-SERV/Resources/VersNum.txt
+++ b/MP-TAB-SERV/Resources/VersNum.txt
@@ -1 +1 @@
-6.16.2310.615
+6.16.2310.617
diff --git a/MP-TAB-SERV/Resources/manifest.xml b/MP-TAB-SERV/Resources/manifest.xml
index 0ef7c5c3..f7f365d1 100644
--- a/MP-TAB-SERV/Resources/manifest.xml
+++ b/MP-TAB-SERV/Resources/manifest.xml
@@ -1,6 +1,6 @@
-
- 6.16.2310.615
+ 6.16.2310.617
https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/MP-TAB-SERV.zip
https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/ChangeLog.html
false
diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs
index 73bf2c1c..5b289575 100644
--- a/MP.Data/Controllers/MpIocController.cs
+++ b/MP.Data/Controllers/MpIocController.cs
@@ -300,7 +300,7 @@ namespace MP.Data.Controllers
}
///
- /// Intera tabella relazione master/slave in machine (gestione setup master --> slave)
+ /// Intera tabella state machine ingressi 2 eventi
///
///
public List StateMachineIngressi(int idxFam)
diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs
index 8daa35f3..c1c50278 100644
--- a/MP.Data/Controllers/MpTabController.cs
+++ b/MP.Data/Controllers/MpTabController.cs
@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using static MP.Data.Objects.Enums;
namespace MP.Data.Controllers
{
@@ -24,6 +25,23 @@ namespace MP.Data.Controllers
#region Public Methods
+ ///
+ /// Restituisce l'anagrafica EVENTI per intero
+ ///
+ ///
+ public List AnagEventiGetAll()
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetAnagEventi
+ .AsNoTracking()
+ .ToList();
+ }
+ return dbResult;
+ }
+
///
/// Restituisce l'anagrafica EVENTI per intero
///
@@ -44,22 +62,7 @@ namespace MP.Data.Controllers
}
return dbResult;
}
- ///
- /// Restituisce l'anagrafica EVENTI per intero
- ///
- ///
- public List AnagEventiGetAll()
- {
- List dbResult = new List();
- using (var dbCtx = new MoonProContext(_configuration))
- {
- dbResult = dbCtx
- .DbSetAnagEventi
- .AsNoTracking()
- .ToList();
- }
- return dbResult;
- }
+
///
/// Restituisce l'anagrafica STATI per intero
///
@@ -77,6 +80,98 @@ namespace MP.Data.Controllers
return dbResult;
}
+ ///
+ /// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma
+ /// --> dtEvent)
+ ///
+ /// idx macchina da confermare
+ /// 0=periodo, 1 = giorno, 2 = turno
+ /// qta pezzi BUONI da confermare
+ /// qta pezzi SCARTO da confermare
+ /// DataOra in cui registrare approvazione
+ /// Matricola operatore
+ ///
+ public bool ConfermaProdMacchina(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
+ {
+ bool answ = false;
+ try
+ {
+ var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
+ var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
+ var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
+ var DataTo = new SqlParameter("@dataTo", DataOraApp);
+ var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
+ var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
+ var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
+ var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
+ var TestConferma = new SqlParameter("@TestConferma", true);
+
+ var result = dbCtx
+ .Database
+ .ExecuteSqlRaw("EXEC stp_ConfermaProduzCompleta @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziScar, @TipoConf, @DataOraApp, @TestConferma ", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziScar, TipoConf, DtOraApp, TestConferma);
+
+ // indico eseguito!
+ answ = result > 0;
+ }
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione in ConfermaProdMacchina:{Environment.NewLine}{exc}");
+ }
+ return answ;
+ }
+
+ ///
+ /// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma
+ /// --> dtEvent)
+ ///
+ /// idx macchina da confermare
+ /// 0=periodo, 1 = giorno, 2 = turno
+ /// qta pezzi BUONI da confermare
+ ///
+ /// qta pezzi LASCIATI alla macchina da confermare (2 eventi 121 rettifica neg/pos)
+ ///
+ /// qta pezzi SCARTO da confermare
+ /// DataOra in cui registrare approvazione
+ /// Matricola operatore
+ ///
+ public bool ConfermaProdMacchinaFull(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
+ {
+ bool answ = false;
+ try
+ {
+ var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
+ var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
+ var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
+ var DataTo = new SqlParameter("@dataTo", DataOraApp);
+ var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
+ var PezziLasc = new SqlParameter("@pezziLasciati", numPzLasciati);
+ var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
+ var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
+ var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
+ var TestConferma = new SqlParameter("@TestConferma", true);
+
+ var result = dbCtx
+ .Database
+ .ExecuteSqlRaw("EXEC stp_ConfermaProduzCompletaFull @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziLasciati, @pezziScar, @TipoConf, @DataOraApp, @TestConferma ", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziLasc, PezziScar, TipoConf, DtOraApp, TestConferma);
+
+ // indico eseguito!
+ answ = result > 0;
+ }
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione in ConfermaProdMacchinaFull con rett ev121:{Environment.NewLine}{exc}");
+ }
+ return answ;
+ }
+
///
/// Elenco da tabella Config
///
@@ -100,6 +195,215 @@ namespace MP.Data.Controllers
_configuration = null;
}
+ ///
+ /// Aggiunta record EventList
+ ///
+ ///
+ ///
+ public async Task EvListInsert(EventListModel newRec)
+ {
+ bool fatto = false;
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ try
+ {
+ var currRec = dbCtx
+ .DbSetEvList
+ .Add(newRec);
+ await dbCtx.SaveChangesAsync();
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione durante EvListInsert{Environment.NewLine}{exc}");
+ }
+ }
+ await Task.Delay(1);
+ return fatto;
+ }
+
+ ///
+ /// MicroStato macchina (da key)
+ ///
+ ///
+ ///
+ public MicroStatoMacchinaModel MicroStatoMacchina(string idxMacchina)
+ {
+ MicroStatoMacchinaModel dbResult = new MicroStatoMacchinaModel();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetMicroStatoMacc
+ .Where(x => x.IdxMacchina == idxMacchina)
+ .AsNoTracking()
+ .FirstOrDefault();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Stato macchina - tutte
+ ///
+ ///
+ ///
+ public List MicroStatoMacchinaGetAll()
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetMicroStatoMacc
+ .AsNoTracking()
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Aggiornamento record Microstato macchina
+ ///
+ ///
+ ///
+ public bool MicroStatoMacchinaUpsert(MicroStatoMacchinaModel newRec)
+ {
+ bool fatto = false;
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var actRec = dbCtx
+ .DbSetMicroStatoMacc
+ .Where(x => x.IdxMacchina == newRec.IdxMacchina)
+ .AsNoTracking()
+ .FirstOrDefault();
+ if (actRec == null)
+ {
+ dbCtx
+ .DbSetMicroStatoMacc
+ .Add(newRec);
+ }
+ else
+ {
+ actRec.IdxMicroStato = newRec.IdxMicroStato;
+ actRec.InizioStato = newRec.InizioStato;
+ actRec.Value = newRec.Value;
+
+ dbCtx.Entry(actRec).State = EntityState.Modified;
+ }
+ dbCtx.SaveChanges();
+ fatto = true;
+ }
+ return fatto;
+ }
+
+ ///
+ /// Effettua ricalcolo MSE x macchina indicata
+ ///
+ /// idx macchina da confermare
+ /// Num massimo secondi di "vecchiaia" del dato
+ ///
+ public bool RicalcMse(string idxMacchina, int maxAgeSec)
+ {
+ bool answ = false;
+ try
+ {
+ var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
+ var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
+
+ var result = dbCtx
+ .Database
+ .ExecuteSqlRaw("EXEC stp_MSE_recalc @maxAgeSec, @idxMacchina ", MaxAgeSec, IdxMacchina);
+
+ // indico eseguito!
+ answ = result > 0;
+ }
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione in RicalcMse:{Environment.NewLine}{exc}");
+ }
+ return answ;
+ }
+
+ ///
+ /// Intera tabella state machine eventi 2 stati
+ ///
+ ///
+ public List SMES_GetAll()
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetSMES
+ .AsNoTracking()
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Tabella state machine eventi 2 stati data famiglia
+ ///
+ ///
+ public List SMES_GetByFam(int idxFam)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetSMES
+ .Where(x => x.IdxFamiglia == idxFam)
+ .AsNoTracking()
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Tabella state machine eventi 2 stati data macchina e tipo evento
+ ///
+ ///
+ ///
+ public List SMES_getUserForced(string idxMacchina, int idxTipo)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
+ var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
+ dbResult = dbCtx
+ .DbSetSMES
+ .FromSqlRaw("exec dbo.stp_TS_getUserForcedTrans @IdxMacchina, @IdxTipo", IdxMacchina, IdxTipo)
+ .AsNoTracking()
+ .AsEnumerable()
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Tabella state machine eventi 2 stati data macchina e tipo evento
+ ///
+ ///
+ ///
+ public List SMES_getHwTransitions(string idxMacchina, int idxTipo)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
+ var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
+ dbResult = dbCtx
+ .DbSetSMES
+ .FromSqlRaw("exec dbo.stp_TS_getByIdxMacchIdxTipoEv @IdxMacchina, @IdxTipo", IdxMacchina, IdxTipo)
+ .AsNoTracking()
+ .AsEnumerable()
+ .ToList();
+ }
+ return dbResult;
+ }
+
///
/// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL
///
@@ -150,6 +454,46 @@ namespace MP.Data.Controllers
return dbResult;
}
+ ///
+ /// Intera tabella state machine ingressi 2 eventi data famiglia
+ ///
+ ///
+ ///
+ public List StateMachineIngressi(int idxFam)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
+ dbResult = dbCtx
+ .DbSetSMI
+ .FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
+ .AsNoTracking()
+ .AsEnumerable()
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Stato macchina (da key)
+ ///
+ ///
+ ///
+ public StatoMacchineModel StatoMacchina(string idxMacchina)
+ {
+ StatoMacchineModel dbResult = new StatoMacchineModel();
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbSetStatoMacc
+ .Where(x => x.IdxMacchina == idxMacchina)
+ .AsNoTracking()
+ .FirstOrDefault();
+ }
+ return dbResult;
+ }
+
///
/// Stato prod macchina (completo)
///
@@ -175,220 +519,115 @@ namespace MP.Data.Controllers
return dbResult;
}
- ///
- /// Stato macchina (da key)
- ///
- ///
- ///
- public StatoMacchineModel StatoMacchina(string idxMacchina)
- {
- StatoMacchineModel dbResult = new StatoMacchineModel();
- using (var dbCtx = new MoonProContext(_configuration))
- {
- dbResult = dbCtx
- .DbSetStatoMacc
- .Where(x => x.IdxMacchina == idxMacchina)
- .AsNoTracking()
- .FirstOrDefault();
- }
- return dbResult;
- }
- ///
- /// MicroStato macchina (da key)
- ///
- ///
- ///
- public MicroStatoMacchinaModel MicroStatoMacchina(string idxMacchina)
- {
- MicroStatoMacchinaModel dbResult = new MicroStatoMacchinaModel();
- using (var dbCtx = new MoonProContext(_configuration))
- {
- dbResult = dbCtx
- .DbSetMicroStatoMacc
- .Where(x => x.IdxMacchina == idxMacchina)
- .AsNoTracking()
- .FirstOrDefault();
- }
- return dbResult;
- }
- ///
- /// Stato macchina - tutte
- ///
- ///
- ///
- public List MicroStatoMacchinaGetAll()
- {
- List dbResult = new List();
- using (var dbCtx = new MoonProContext(_configuration))
- {
- dbResult = dbCtx
- .DbSetMicroStatoMacc
- .AsNoTracking()
- .ToList();
- }
- return dbResult;
- }
- ///
- /// Aggiornamento record Microstato macchina
- ///
- ///
- ///
- public bool MicroStatoMacchinaUpsert(MicroStatoMacchinaModel newRec)
+ #endregion Public Methods
+
+ public bool DDB_InsStatoBatch(string idxMacchina, DateTime inizioStato, int idxStato, string codArt, string value, int matrOpr, string pallet)
{
bool fatto = false;
using (var dbCtx = new MoonProContext(_configuration))
{
- var actRec = dbCtx
- .DbSetMicroStatoMacc
- .Where(x => x.IdxMacchina == newRec.IdxMacchina)
- .AsNoTracking()
- .FirstOrDefault();
- if(actRec==null)
- {
- dbCtx
- .DbSetMicroStatoMacc
- .Add(newRec);
- }
- else
- {
- actRec.IdxMicroStato = newRec.IdxMicroStato;
- actRec.InizioStato = newRec.InizioStato;
- actRec.Value = newRec.Value;
+ var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
+ var InizioStato = new SqlParameter("@InizioStato", inizioStato);
+ var IdxStato = new SqlParameter("@IdxStato", idxStato);
+ var CodArticolo = new SqlParameter("@CodArticolo", codArt);
+ var Value = new SqlParameter("@Value", value);
+ var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
+ var Pallet = new SqlParameter("@pallet", pallet);
- dbCtx.Entry(actRec).State = EntityState.Modified;
- }
- dbCtx.SaveChanges();
- fatto = true;
+ var result = dbCtx
+ .Database
+ .ExecuteSqlRaw("exec dbo.stp_DDB_InsStatoBatch @IdxMacchina, @InizioStato, @IdxStato, @CodArticolo, @Value, @MatrOpr, @pallet", IdxMacchina, InizioStato, IdxStato, CodArticolo, Value, MatrOpr, Pallet);
+
+ // indico eseguito!
+ fatto = result > 0;
}
return fatto;
}
///
- /// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma
- /// --> dtEvent)
+ /// Verifica se sia necessario inserire un cambio di stato impianto in modalità batch
///
- /// idx macchina da confermare
- /// 0=periodo, 1 = giorno, 2 = turno
- /// qta pezzi BUONI da confermare
- ///
- /// qta pezzi LASCIATI alla macchina da confermare (2 eventi 121 rettifica neg/pos)
- ///
- /// qta pezzi SCARTO da confermare
- /// DataOra in cui registrare approvazione
- /// Matricola operatore
- ///
- public bool ConfermaProdMacchinaFull(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void CheckCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
{
- bool answ = false;
- try
+ List tabTransStati = new List();
+ TransizioneStatiModel rigaTransStati = new TransizioneStatiModel();
+ switch (tipoInput)
{
- var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
- using (var dbCtx = new MoonProContext(_configuration))
- {
- var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
- var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
- var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
- var DataTo = new SqlParameter("@dataTo", DataOraApp);
- var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
- var PezziLasc = new SqlParameter("@pezziLasciati", numPzLasciati);
- var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
- var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
- var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
- var TestConferma = new SqlParameter("@TestConferma", true);
+ case tipoInputEvento.barcode:
+ // effettuo cambio stato INDIPENDENTEMENTE da stato precedente
+ try
+ {
+ tabTransStati = SMES_getUserForced(IdxMacchina, IdxTipo);
+ if (tabTransStati != null)
+ {
+ if (tabTransStati.Count > 0)
+ {
+ rigaTransStati = tabTransStati.FirstOrDefault();
+ // solo se cambia stato...
+ if (rigaTransStati.IdxStato != rigaTransStati.next_IdxStato)
+ {
+ DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTransStati.next_IdxStato, CodArt, Value, MatrOpr, pallet);
+ // aggiorno MSE
+ RicalcMse(IdxMacchina, 0);
+ }
+ }
+ else
+ {
+ Log.Debug($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
+ }
+ }
+ }
+ catch (Exception exc)
+ {
+ // non dovrebbe succedere... input utente da barcode dovrebbero TUTTI essere
+ // inseriti in tab transizione con famiglia 1...
+ Log.Error($"Eccezione controllo transizione stato x evento barcode: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}{Environment.NewLine}{exc}");
+ }
+ break;
- var result = dbCtx
- .Database
- .ExecuteSqlRaw("EXEC stp_ConfermaProduzCompletaFull @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziLasciati, @pezziScar, @TipoConf, @DataOraApp, @TestConferma ", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziLasc, PezziScar, TipoConf, DtOraApp, TestConferma);
-
- // indico eseguito!
- answ = result > 0;
- }
+ case tipoInputEvento.hw:
+ // verifico se ci sia necessità di cambio stato
+ try
+ {
+ tabTransStati = SMES_getHwTransitions(IdxMacchina, IdxTipo);
+ if (tabTransStati != null)
+ {
+ if (tabTransStati.Count > 0)
+ {
+ //rigaTransStati = tabTransStati[0];
+ rigaTransStati = tabTransStati.FirstOrDefault();
+ if (rigaTransStati != null)
+ {
+ // solo se cambia stato...
+ if (rigaTransStati.IdxStato != rigaTransStati.next_IdxStato)
+ {
+ DDB_InsStatoBatch(IdxMacchina, InizioStato, rigaTransStati.next_IdxStato, CodArt, Value, MatrOpr, pallet);
+ }
+ }
+ }
+ else
+ {
+ Log.Debug($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}");
+ }
+ }
+ }
+ catch (Exception exc)
+ {
+ // non trovo riga [0]... NON scrivo!
+ Log.Error($"Errore controllo transizione stato x evento barcode: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}{Environment.NewLine}{exc}");
+ }
+ break;
}
- catch (Exception exc)
- {
- Log.Error($"Eccezione in ConfermaProdMacchinaFull con rett ev121:{Environment.NewLine}{exc}");
- }
- return answ;
}
- ///
- /// Effettua conferma prod macchina dell'intero periodo da confermare (ultima conferma
- /// --> dtEvent)
- ///
- /// idx macchina da confermare
- /// 0=periodo, 1 = giorno, 2 = turno
- /// qta pezzi BUONI da confermare
- /// qta pezzi SCARTO da confermare
- /// DataOra in cui registrare approvazione
- /// Matricola operatore
- ///
- public bool ConfermaProdMacchina(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr)
- {
- bool answ = false;
- try
- {
- var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
- using (var dbCtx = new MoonProContext(_configuration))
- {
- var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
- var MatrApp = new SqlParameter("@MatrApp ", MatrOpr);
- var DataFrom = new SqlParameter("@dataFrom ", rigaProd.DataFrom);
- var DataTo = new SqlParameter("@dataTo", DataOraApp);
- var PezziConf = new SqlParameter("@pezziConf", numPzConfermati);
- var PezziScar = new SqlParameter("@pezziScar", numPzScarto);
- var TipoConf = new SqlParameter("@TipoConf", modoConfProd);
- var DtOraApp = new SqlParameter("@DataOraApp", DataOraApp);
- var TestConferma = new SqlParameter("@TestConferma", true);
-
- var result = dbCtx
- .Database
- .ExecuteSqlRaw("EXEC stp_ConfermaProduzCompleta @idxMacchina, @MatrApp, @dataFrom, @dataTo, @pezziConf, @pezziScar, @TipoConf, @DataOraApp, @TestConferma ", IdxMacchina, MatrApp, DataFrom, DataTo, PezziConf, PezziScar, TipoConf, DtOraApp, TestConferma);
-
- // indico eseguito!
- answ = result > 0;
- }
- }
- catch (Exception exc)
- {
- Log.Error($"Eccezione in ConfermaProdMacchina:{Environment.NewLine}{exc}");
- }
- return answ;
- }
-
- ///
- /// Effettua ricalcolo MSE x macchina indicata
- ///
- /// idx macchina da confermare
- /// Num massimo secondi di "vecchiaia" del dato
- ///
- public bool RicalcMse(string idxMacchina, int maxAgeSec)
- {
- bool answ = false;
- try
- {
- var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
- using (var dbCtx = new MoonProContext(_configuration))
- {
- var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
- var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
-
- var result = dbCtx
- .Database
- .ExecuteSqlRaw("EXEC stp_MSE_recalc @maxAgeSec, @idxMacchina ", MaxAgeSec, IdxMacchina);
-
- // indico eseguito!
- answ = result > 0;
- }
- }
- catch (Exception exc)
- {
- Log.Error($"Eccezione in RicalcMse:{Environment.NewLine}{exc}");
- }
- return answ;
- }
-
- #endregion Public Methods
-
#region Private Fields
private static IConfiguration _configuration;
diff --git a/MP.Data/DatabaseModels/DiarioDiBordoModel.cs b/MP.Data/DatabaseModels/DiarioDiBordoModel.cs
new file mode 100644
index 00000000..9b03d1cd
--- /dev/null
+++ b/MP.Data/DatabaseModels/DiarioDiBordoModel.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+
+#nullable disable
+//
+// This is here so CodeMaid doesn't reorganize this document
+//
+namespace MP.Data.DatabaseModels
+{
+ [Table("DiarioDiBordo")]
+ public partial class DiarioDiBordoModel
+ {
+ #region Public Properties
+
+ [MaxLength(50)]
+ public string IdxMacchina { get; set; } = "NA";
+ public DateTime InizioStato { get; set; } = DateTime.Now;
+ public DateTime? FineStato { get; set; } = DateTime.Now;
+ public int IdxStato { get; set; } = 0;
+ public float DurataMinuti { get; set; } = 0;
+ [MaxLength(50)]
+ public string Value { get; set; } = "";
+ [MaxLength(50)]
+ public string CodArticolo { get; set; } = "";
+ public float TempoCicloBase { get; set; } = 0;
+ public int PzPalletProd { get; set; } = 0;
+ public int MatrOpr { get; set; } = 0;
+ [MaxLength(20)]
+ public string pallet { get; set; } = "";
+
+ ///
+ /// Navigazione oggetto Machine
+ ///
+ [ForeignKey("IdxMacchina")]
+ public virtual Macchine MachineNav { get; set; } = null!;
+ ///
+ /// Navigazione oggetto Articolo
+ ///
+ [ForeignKey("CodArticolo")]
+ public virtual AnagArticoli ArticoloNav { get; set; } = null!;
+
+ #endregion Public Properties
+ }
+}
\ No newline at end of file
diff --git a/MP.Data/DatabaseModels/TransizioneIngressiModel.cs b/MP.Data/DatabaseModels/TransizioneIngressiModel.cs
index 72e3ad15..c9a3f9e1 100644
--- a/MP.Data/DatabaseModels/TransizioneIngressiModel.cs
+++ b/MP.Data/DatabaseModels/TransizioneIngressiModel.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
namespace MP.Data.DatabaseModels
{
+ [Table("TransizioneIngressi")]
public partial class TransizioneIngressiModel
{
public int IdxFamigliaIngresso { get; set; }
diff --git a/MP.Data/DatabaseModels/TransizioneStatiModel.cs b/MP.Data/DatabaseModels/TransizioneStatiModel.cs
new file mode 100644
index 00000000..378c2c99
--- /dev/null
+++ b/MP.Data/DatabaseModels/TransizioneStatiModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace MP.Data.DatabaseModels
+{
+ [Table("TransizioneStati")]
+ public partial class TransizioneStatiModel
+ {
+ public int IdxFamiglia { get; set; } = 0;
+ public int IdxStato { get; set; } = 0;
+ public int IdxTipo { get; set; } = 0;
+ public int next_IdxStato { get; set; } = 0;
+ }
+}
diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs
index 4355ea4e..e75729c7 100644
--- a/MP.Data/MoonProContext.cs
+++ b/MP.Data/MoonProContext.cs
@@ -55,6 +55,7 @@ namespace MP.Data
public virtual DbSet DbSetStatOdl { get; set; }
public virtual DbSet DbSetPzProd { get; set; }
public virtual DbSet DbSetEvList { get; set; }
+ public virtual DbSet DbSetDDB { get; set; }
public virtual DbSet DbSetVocabolario { get; set; }
public virtual DbSet DbOperatori { get; set; }
public virtual DbSet DbSetGrp2Oper { get; set; }
@@ -63,6 +64,7 @@ namespace MP.Data
public virtual DbSet DbSetMSFD { get; set; }
public virtual DbSet DbSetM2S { get; set; }
public virtual DbSet DbSetSMI { get; set; }
+ public virtual DbSet DbSetSMES { get; set; }
public virtual DbSet DbSetKeepAlive { get; set; }
public virtual DbSet DbSetMicroStatoMacc { get; set; }
public virtual DbSet DbSetStatoMacc { get; set; }
@@ -331,6 +333,11 @@ namespace MP.Data
{
entity.HasKey(e => new { e.IdxMacchina, e.InizioStato, e.IdxTipo });
+ });
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => new { e.IdxMacchina, e.InizioStato });
+
});
modelBuilder.Entity(entity =>
{
@@ -505,6 +512,12 @@ namespace MP.Data
});
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => new { e.IdxFamiglia, e.IdxStato, e.IdxTipo });
+
+ });
+
OnModelCreatingPartial(modelBuilder);
}
diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs
index 2301728e..468e5ac2 100644
--- a/MP.Data/Services/TabDataService.cs
+++ b/MP.Data/Services/TabDataService.cs
@@ -1,6 +1,6 @@
-using Microsoft.Extensions.Configuration;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
using MP.Data.DatabaseModels;
-using MP.Data.DTO;
using MP.Data.Objects;
using Newtonsoft.Json;
using NLog;
@@ -18,6 +18,10 @@ namespace MP.Data.Services
{
#region Public Constructors
+ ///
+ /// Init servizio TAB
+ ///
+ ///
public TabDataService(IConfiguration configuration)
{
_configuration = configuration;
@@ -54,42 +58,14 @@ namespace MP.Data.Services
}
}
}
- // sistemo
+ // sistemo
DataSource = connStrParams["Server"];
DataBase = connStrParams["Database"];
}
}
- private Dictionary connStrParams = new Dictionary();
- private string ConnStr = "";
- private string CodModulo = "";
- private string DataSource = "";
- private string DataBase = "";
-
- private string redHash(string keyName)
- {
- string result = keyName;
- try
- {
- result = $"{CodModulo}:{DataSource}:{DataBase}:{keyName}".Replace("\\", "_");
- }
- catch (Exception exc)
- {
- Log.Error($"Errore in redHash{Environment.NewLine}{exc}");
- }
-
- return result;
- }
-
#endregion Public Constructors
- #region Public Properties
-
- private static Controllers.MpIocController dbIocController { get; set; } = null!;
- private static Controllers.MpTabController dbTabController { get; set; } = null!;
-
- #endregion Public Properties
-
#region Public Methods
///
@@ -128,6 +104,7 @@ namespace MP.Data.Services
Log.Debug($"AnagEventiGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
+
///
/// Elenco EVENTI validi x macchina
///
@@ -275,8 +252,17 @@ namespace MP.Data.Services
return result;
}
-
-
+ public void Dispose()
+ {
+ // Clear database controller
+ dbTabController.Dispose();
+ dbIocController.Dispose();
+ }
+ ///
+ /// Recupero info IOB x TAB (da info registrate IOB-WIN--> MP-IO)
+ ///
+ ///
+ ///
public async Task IobInfo(string IdxMacchina)
{
string source = "DB";
@@ -300,487 +286,6 @@ namespace MP.Data.Services
return result;
}
- public void Dispose()
- {
- // Clear database controller
- dbTabController.Dispose();
- }
-
- ///
- /// Effettua ricalcolo MSE x macchina indicata
- ///
- /// idx macchina da confermare
- /// Num massimo secondi di "vecchiaia" del dato
- ///
- public bool RicalcMse(string idxMacchina, int maxAgeSec)
- {
- bool answ = false;
- answ = dbTabController.RicalcMse(idxMacchina, maxAgeSec);
- return answ;
- }
-
- ///
- /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL
- ///
- ///
- ///
- ///
- public async Task
> STAR_byGrpOdl(string codGruppo, int idxODL)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- List? result = new List();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:START:{codGruppo}:{idxODL}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject>($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbTabController.STAR_byGrpOdl(codGruppo, idxODL);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, LongCache);
- }
- if (result == null)
- {
- result = new List();
- }
- sw.Stop();
- Log.Debug($"STAR_byGrpOdl | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
-
- ///
- /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL
- ///
- ///
- ///
- ///
- ///
- public async Task> STAR_byGrpOdlLbl(string codGruppo, string label, int idxODL)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- List? result = new List();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:START:{codGruppo}:{label}:{idxODL}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject>($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbTabController.STAR_byGrpOdlLbl(codGruppo, label, idxODL);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, LongCache);
- }
- if (result == null)
- {
- result = new List();
- }
- sw.Stop();
- Log.Debug($"STAR_byGrpOdlLbl | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
-
- ///
- /// Stato prod macchina (completo)
- ///
- ///
- ///
- ///
- public async Task StatoProdMacchina(string idxMacchina, DateTime dtReq)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- StatoProdModel? result = new StatoProdModel();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:StatoProd:{idxMacchina}:{dtReq:HHmmss}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbTabController.StatoProdMacchina(idxMacchina, dtReq);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
- }
- if (result == null)
- {
- result = new StatoProdModel();
- }
- sw.Stop();
- Log.Debug($"StatoProdMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
- ///
- /// Stato macchina
- ///
- ///
- ///
- public async Task StatoMacchina(string idxMacchina)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- StatoMacchineModel? result = new StatoMacchineModel();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:StatoMacc:{idxMacchina}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbTabController.StatoMacchina(idxMacchina);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(2));
- }
- if (result == null)
- {
- result = new StatoMacchineModel();
- }
- sw.Stop();
- Log.Debug($"StatoMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
-
- ///
- /// Intera vista v_MSFD
- ///
- ///
- public async Task> VMSFDGetAll()
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- List result = new List();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:MSFD:ALL";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject>($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbIocController.VMSFDGetAll();
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
- }
- if (result == null)
- {
- result = new List();
- }
- sw.Stop();
- Log.Debug($"VMSFDGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
-
- ///
- /// Vista v_MSFD x singola macchina (da stored) - singolo record
- ///
- ///
- ///
- public async Task> VMSFDGetByMacc(string idxMacc)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- List? result = new List();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:MSFD:MACCH:{idxMacc}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject>($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbIocController.VMSFDGetByMacc(idxMacc);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
- }
- if (result == null)
- {
- result = new List();
- }
- sw.Stop();
- Log.Debug($"VMSFDGetByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
- ///
- /// Vista v_MSFD delle machine MULTI filtrato x macchina (da stored)
- ///
- ///
- ///
- public async Task> VMSFDGetMultiByMacc(string idxMacc)
- {
- // setup parametri costanti
- string source = "DB";
- Stopwatch sw = new Stopwatch();
- sw.Start();
- List? result = new List();
- // cerco in redis...
- string currKey = $"{redisBaseKey}:MSFD:MULTI:{idxMacc}";
- RedisValue rawData = await redisDb.StringGetAsync(currKey);
- if (!string.IsNullOrEmpty($"{rawData}"))
- {
- result = JsonConvert.DeserializeObject>($"{rawData}");
- source = "REDIS";
- }
- else
- {
- result = dbIocController.VMSFDGetByMacc(idxMacc);
- // serializzp e salvo...
- rawData = JsonConvert.SerializeObject(result);
- await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
- }
- if (result == null)
- {
- result = new List();
- }
- sw.Stop();
- Log.Debug($"VMSFDGetMultiByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms");
- return result;
- }
-
- #endregion Public Methods
-
- #region Protected Fields
-
- ///
- /// Oggetto per connessione a REDIS
- ///
- protected ConnectionMultiplexer redisConn = null!;
-
- ///
- /// Oggetto DB redis da impiegare x chiamate R/W
- ///
- protected IDatabase redisDb = null!;
-
- #endregion Protected Fields
-
- #region Private Fields
-
- private static Logger Log = LogManager.GetCurrentClassLogger();
- private string redisBaseKey = "MP:TAB:Cache";
- private string moonProRedisBaseKey = "MoonPro:SQL2016DEV:MoonPro:hM2IOB";
-
- #endregion Private Fields
- ///
- /// Aggiunta record EventList
- ///
- ///
- ///
- public async Task EvListInsert(EventListModel newRec)
- {
- bool fatto = false;
- using (var dbCtx = new MoonProContext(_configuration))
- {
- try
- {
- var currRec = dbCtx
- .DbSetEvList
- .Add(newRec);
- await dbCtx.SaveChangesAsync();
- }
- catch (Exception exc)
- {
- Log.Error($"Eccezione durante EvListInsert{Environment.NewLine}{exc}");
- }
- }
- await Task.Delay(1);
- return fatto;
- }
-
- ///
- /// scrive una riga di evento inviato da Barcode nel db
- ///
- /// codice macchina
- /// idx evento
- /// Codice Articolo
- /// valore
- /// matricola operatore
- /// pallet (vuoto se nd)
- ///
- public async Task scriviRigaEventoBarcode(string idxMacchina, int idxTipo, string codArticolo, string value, int matrOpr, string pallet)
- {
- bool inserito = false;
- DateTime adesso = DateTime.Now;
- EventListModel newRec = new EventListModel()
- {
- IdxMacchina = idxMacchina,
- InizioStato = adesso,
- IdxTipo = idxTipo,
- CodArticolo = codArticolo,
- Value = value,
- MatrOpr = matrOpr,
- pallet = pallet
- };
- try
- {
- // inserisco evento
- inserito = await EvListInsert(newRec);
- }
- catch (Exception exc)
- {
- string logMsg = $"Eccezione in fase di scrittura evento con i seguenti dati | macchina: {idxMacchina} | IdxTipo: {idxTipo} | CodArticolo: {codArticolo} | Value {value} | MatrOpr {matrOpr} | Pallet {pallet}{Environment.NewLine}{exc}";
- Log.Error(logMsg);
- }
- try
- {
- // faccio controllo per eventuale cambio stato da tab transizioni...
- checkCambiaStatoBatch(tipoInputEvento.barcode, idxMacchina, adesso, idxTipo, codArticolo, value, matrOpr, pallet);
- }
- catch (Exception exc)
- {
- string logMsg = $"Eccezione in checkCambiaStatoBatch(6) | tipoInputEvento: {tipoInputEvento.barcode} | macchina: {idxMacchina} | dataOra: {adesso} | IdxTipo: {idxTipo} | CodArticolo: {codArticolo} | Value {value} | MatrOpr {matrOpr} | Pallet {pallet}{Environment.NewLine}{exc}";
- Log.Error(logMsg);
- }
- // formatto output
- inputComandoMapo answ = new inputComandoMapo();
- answ.outValue = inserito.ToString();
- answ.needStatusRefresh = true;
- return answ;
- }
- ///
- /// Verifica se sia necessario inserire un cambio di stato impianto in modalità batch
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private void checkCambiaStatoBatch(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet)
- {
-#if false
- DS_applicazione.TransizioneStatiDataTable tabTransStati;
- DS_applicazione.TransizioneStatiRow rigaTransStati;
- switch (tipoInput)
- {
- case tipoInputEvento.barcode:
- // effettuo cambio stato INDIPENDENTEMENTE da stato precedente
- try
- {
- tabTransStati = MapoDbObj.taTranSt.GetUserForcedTransitions(IdxMacchina, IdxTipo);
- if (tabTransStati != null)
- {
- if (tabTransStati.Count > 0)
- {
- rigaTransStati = tabTransStati[0];
- // solo se cambia stato...
- if (rigaTransStati.IdxStato != rigaTransStati.next_IdxStato)
- {
- MapoDbObj.taDiario.InsStatoBatch(IdxMacchina, InizioStato, rigaTransStati.next_IdxStato, CodArt, Value, MatrOpr, pallet);
- // aggiorno MSE
- taMSE.forceRecalc(0, IdxMacchina);
- }
- }
- else
- {
- if (_logLevel > 6)
- {
- Log.Info($"Non trovata riga per: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}", tipoLog.INFO);
- }
- }
- }
- }
- catch (Exception exc)
- {
- // non dovrebbe succedere... input utente da barcode dovrebbero TUTTI essere
- // inseriti in tab transizione con famiglia 1...
- Log.Info($"Errore controllo transizione stato x evento barcode: BARCODE | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
- }
- break;
-
- case tipoInputEvento.hw:
- // verifico se ci sia necessità di cambio stato
- try
- {
- tabTransStati = MapoDbObj.taTranSt.GetHwTransitions(IdxMacchina, IdxTipo);
- if (tabTransStati != null)
- {
- if (tabTransStati.Count > 0)
- {
- rigaTransStati = tabTransStati[0];
- if (rigaTransStati != null)
- {
- // solo se cambia stato...
- if (rigaTransStati.IdxStato != rigaTransStati.next_IdxStato)
- {
- MapoDbObj.taDiario.InsStatoBatch(IdxMacchina, InizioStato, rigaTransStati.next_IdxStato, CodArt, Value, MatrOpr, pallet);
- }
- }
- }
- else
- {
- if (_logLevel > 6)
- {
- Log.Info($"Non trovata riga per: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}", tipoLog.INFO);
- }
- }
- }
- }
- catch (Exception exc)
- {
- // non trovo riga [0]... NON scrivo!
- Log.Info($"Errore controllo transizione stato x evento barcode: HW | IdxMacchina: {IdxMacchina} | IdxTipo: {IdxTipo} | CodArt: {CodArt} | Value: {Value} | MatrOpr: {MatrOpr} | pallet: {pallet}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
- }
- break;
- }
-#endif
- }
-
- ///
- /// Effettua reset microstato macchina
- ///
- ///
- public void resetMicrostatoMacchina(string idxMacchina)
- {
- // salvo microstato 0...
- MicroStatoMacchinaModel newRecMS = new MicroStatoMacchinaModel()
- {
- IdxMacchina = idxMacchina,
- InizioStato = DateTime.Now,
- IdxMicroStato = 0,
- Value = "FER"
- };
- var result = dbTabController.MicroStatoMacchinaUpsert(newRecMS);
- // reset in redis
- resetDatiMacchina(idxMacchina);
- }
-
///
/// Resetta (rileggendo) i dati della macchina
///
@@ -878,9 +383,403 @@ namespace MP.Data.Services
else
{
Log.Info("Errore in chiamata stp_MSFD_getMacc (connDb.taMSFD.getByIdxMacc(idxMacchina))");
- }
+ }
#endif
return answ;
}
+
+ ///
+ /// Effettua reset microstato macchina
+ ///
+ ///
+ public void resetMicrostatoMacchina(string idxMacchina)
+ {
+ // salvo microstato 0...
+ MicroStatoMacchinaModel newRecMS = new MicroStatoMacchinaModel()
+ {
+ IdxMacchina = idxMacchina,
+ InizioStato = DateTime.Now,
+ IdxMicroStato = 0,
+ Value = "FER"
+ };
+ var result = dbTabController.MicroStatoMacchinaUpsert(newRecMS);
+ // reset in redis
+ resetDatiMacchina(idxMacchina);
+ }
+
+ ///
+ /// Effettua ricalcolo MSE x macchina indicata
+ ///
+ /// idx macchina da confermare
+ /// Num massimo secondi di "vecchiaia" del dato
+ ///
+ public bool RicalcMse(string idxMacchina, int maxAgeSec)
+ {
+ bool answ = false;
+ answ = dbTabController.RicalcMse(idxMacchina, maxAgeSec);
+ return answ;
+ }
+
+ ///
+ /// scrive una riga di evento inviato da Barcode nel db
+ ///
+ /// codice macchina
+ /// idx evento
+ /// Codice Articolo
+ /// valore
+ /// matricola operatore
+ /// pallet (vuoto se nd)
+ ///
+ public async Task scriviRigaEventoBarcode(string idxMacchina, int idxTipo, string codArticolo, string value, int matrOpr, string pallet)
+ {
+ bool inserito = false;
+ DateTime adesso = DateTime.Now;
+ EventListModel newRec = new EventListModel()
+ {
+ IdxMacchina = idxMacchina,
+ InizioStato = adesso,
+ IdxTipo = idxTipo,
+ CodArticolo = codArticolo,
+ Value = value,
+ MatrOpr = matrOpr,
+ pallet = pallet
+ };
+ try
+ {
+ // inserisco evento
+ inserito = await dbTabController.EvListInsert(newRec);
+ }
+ catch (Exception exc)
+ {
+ string logMsg = $"Eccezione in fase di scrittura evento con i seguenti dati | macchina: {idxMacchina} | IdxTipo: {idxTipo} | CodArticolo: {codArticolo} | Value {value} | MatrOpr {matrOpr} | Pallet {pallet}{Environment.NewLine}{exc}";
+ Log.Error(logMsg);
+ }
+ try
+ {
+ // faccio controllo per eventuale cambio stato da tab transizioni...
+ dbTabController.CheckCambiaStatoBatch(tipoInputEvento.barcode, idxMacchina, adesso, idxTipo, codArticolo, value, matrOpr, pallet);
+ }
+ catch (Exception exc)
+ {
+ string logMsg = $"Eccezione in checkCambiaStatoBatch(6) | tipoInputEvento: {tipoInputEvento.barcode} | macchina: {idxMacchina} | dataOra: {adesso} | IdxTipo: {idxTipo} | CodArticolo: {codArticolo} | Value {value} | MatrOpr {matrOpr} | Pallet {pallet}{Environment.NewLine}{exc}";
+ Log.Error(logMsg);
+ }
+ // formatto output
+ inputComandoMapo answ = new inputComandoMapo();
+ answ.outValue = inserito.ToString();
+ answ.needStatusRefresh = true;
+ return answ;
+ }
+
+ ///
+ /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL
+ ///
+ ///
+ ///
+ ///
+ public async Task> STAR_byGrpOdl(string codGruppo, int idxODL)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:START:{codGruppo}:{idxODL}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbTabController.STAR_byGrpOdl(codGruppo, idxODL);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, LongCache);
+ }
+ if (result == null)
+ {
+ result = new List();
+ }
+ sw.Stop();
+ Log.Debug($"STAR_byGrpOdl | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task> STAR_byGrpOdlLbl(string codGruppo, string label, int idxODL)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:START:{codGruppo}:{label}:{idxODL}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbTabController.STAR_byGrpOdlLbl(codGruppo, label, idxODL);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, LongCache);
+ }
+ if (result == null)
+ {
+ result = new List();
+ }
+ sw.Stop();
+ Log.Debug($"STAR_byGrpOdlLbl | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Stato macchina
+ ///
+ ///
+ ///
+ public async Task StatoMacchina(string idxMacchina)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ StatoMacchineModel? result = new StatoMacchineModel();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:StatoMacc:{idxMacchina}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbTabController.StatoMacchina(idxMacchina);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(2));
+ }
+ if (result == null)
+ {
+ result = new StatoMacchineModel();
+ }
+ sw.Stop();
+ Log.Debug($"StatoMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Stato prod macchina (completo)
+ ///
+ ///
+ ///
+ ///
+ public async Task StatoProdMacchina(string idxMacchina, DateTime dtReq)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ StatoProdModel? result = new StatoProdModel();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:StatoProd:{idxMacchina}:{dtReq:HHmmss}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbTabController.StatoProdMacchina(idxMacchina, dtReq);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
+ }
+ if (result == null)
+ {
+ result = new StatoProdModel();
+ }
+ sw.Stop();
+ Log.Debug($"StatoProdMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Intera vista v_MSFD
+ ///
+ ///
+ public async Task> VMSFDGetAll()
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List result = new List();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:MSFD:ALL";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbIocController.VMSFDGetAll();
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ }
+ if (result == null)
+ {
+ result = new List();
+ }
+ sw.Stop();
+ Log.Debug($"VMSFDGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Vista v_MSFD x singola macchina (da stored) - singolo record
+ ///
+ ///
+ ///
+ public async Task> VMSFDGetByMacc(string idxMacc)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:MSFD:MACCH:{idxMacc}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbIocController.VMSFDGetByMacc(idxMacc);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
+ }
+ if (result == null)
+ {
+ result = new List();
+ }
+ sw.Stop();
+ Log.Debug($"VMSFDGetByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ ///
+ /// Vista v_MSFD delle machine MULTI filtrato x macchina (da stored)
+ ///
+ ///
+ ///
+ public async Task> VMSFDGetMultiByMacc(string idxMacc)
+ {
+ // setup parametri costanti
+ string source = "DB";
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ List? result = new List();
+ // cerco in redis...
+ string currKey = $"{redisBaseKey}:MSFD:MULTI:{idxMacc}";
+ RedisValue rawData = await redisDb.StringGetAsync(currKey);
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+ source = "REDIS";
+ }
+ else
+ {
+ result = dbIocController.VMSFDGetByMacc(idxMacc);
+ // serializzp e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
+ }
+ if (result == null)
+ {
+ result = new List();
+ }
+ sw.Stop();
+ Log.Debug($"VMSFDGetMultiByMacc | {source} | {sw.Elapsed.TotalMilliseconds}ms");
+ return result;
+ }
+
+ #endregion Public Methods
+
+ #region Protected Fields
+
+ ///
+ /// Oggetto per connessione a REDIS
+ ///
+ protected ConnectionMultiplexer redisConn = null!;
+
+ ///
+ /// Oggetto DB redis da impiegare x chiamate R/W
+ ///
+ protected IDatabase redisDb = null!;
+
+ #endregion Protected Fields
+
+ #region Private Fields
+
+ private static Logger Log = LogManager.GetCurrentClassLogger();
+ private string CodModulo = "";
+ private string ConnStr = "";
+ private Dictionary connStrParams = new Dictionary();
+ private string DataBase = "";
+ private string DataSource = "";
+
+ private string redisBaseKey = "MP:TAB:Cache";
+
+ #endregion Private Fields
+
+ #region Private Properties
+
+ private static Controllers.MpIocController dbIocController { get; set; } = null!;
+
+ private static Controllers.MpTabController dbTabController { get; set; } = null!;
+
+ #endregion Private Properties
+
+ #region Private Methods
+
+ private string redHash(string keyName)
+ {
+ string result = keyName;
+ try
+ {
+ result = $"{CodModulo}:{DataSource}:{DataBase}:{keyName}".Replace("\\", "_");
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Errore in redHash{Environment.NewLine}{exc}");
+ }
+
+ return result;
+ }
+
+ #endregion Private Methods
}
}
\ No newline at end of file