diff --git a/EgwProxy.SqlDb/Controllers/DbController.cs b/EgwProxy.SqlDb/Controllers/DbController.cs
index e5bc40b7..72c265d3 100644
--- a/EgwProxy.SqlDb/Controllers/DbController.cs
+++ b/EgwProxy.SqlDb/Controllers/DbController.cs
@@ -58,9 +58,9 @@ namespace EgwProxy.SqlDb.Controllers
///
///
///
- public List EvListGetNew(int lastIdx)
+ public List EvListGetNew(int lastIdx)
{
- List dbResult = new List();
+ List dbResult = new List();
using (var dbSyncStateCtx = new SyncStateDbContext(connString))
{
dbResult = dbSyncStateCtx
diff --git a/EgwProxy.SqlDb/DbModels/MachEventListModel.cs b/EgwProxy.SqlDb/DbModels/MachSigLogModel.cs
similarity index 54%
rename from EgwProxy.SqlDb/DbModels/MachEventListModel.cs
rename to EgwProxy.SqlDb/DbModels/MachSigLogModel.cs
index f2f0049a..9bdc7c5b 100644
--- a/EgwProxy.SqlDb/DbModels/MachEventListModel.cs
+++ b/EgwProxy.SqlDb/DbModels/MachSigLogModel.cs
@@ -11,29 +11,20 @@ namespace EgwProxy.SqlDb.DbModels
//
// This is here so CodeMaid doesn't reorganize this document
//
- [Table("MachineEventList")]
- public partial class MachEventListModel
+ [Table("MachineSignalLog")]
+ public partial class MachSigLogModel
{
[Key, Column("IdxEv"), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; } = 0;
- public DateTime InizioStato { get; set; } = DateTime.Now;
+ public DateTime DtEve { get; set; } = DateTime.Now;
[StringLength(50)]
public string IdxMacchina { get; set; } = "";
- public int IdxTipo { get; set; } = 0;
+ public int ValInt { get; set; } = 0;
- [StringLength(50)]
- public string CodArticolo { get; set; } = "";
-
- [StringLength(250)]
- public string Value { get; set; } = "";
-
- public int MatrOpr { get; set; } = 0;
-
- [StringLength(20)]
- public string Pallet { get; set; } = "";
+ public string Valore { get; set; } = "";
}
}
diff --git a/EgwProxy.SqlDb/EgwProxy.SqlDb.csproj b/EgwProxy.SqlDb/EgwProxy.SqlDb.csproj
index 248e0ea5..d9e9c0f0 100644
--- a/EgwProxy.SqlDb/EgwProxy.SqlDb.csproj
+++ b/EgwProxy.SqlDb/EgwProxy.SqlDb.csproj
@@ -66,7 +66,7 @@
-
+
@@ -92,6 +92,10 @@
+
+ Always
+
+
Always
@@ -107,7 +111,7 @@
Always
-
+
Always
@@ -122,6 +126,7 @@
202303131054149_AddStoredProc.cs
+
diff --git a/EgwProxy.SqlDb/Migrations/202303131054149_AddStoredProc.cs b/EgwProxy.SqlDb/Migrations/202303131054149_AddStoredProc.cs
index 7395c057..b0b718d6 100644
--- a/EgwProxy.SqlDb/Migrations/202303131054149_AddStoredProc.cs
+++ b/EgwProxy.SqlDb/Migrations/202303131054149_AddStoredProc.cs
@@ -13,6 +13,7 @@
// aggiunta stored
addStoredProc("SyncPodlToMachine");
addStoredProc("GetMachineEvList");
+ addStoredProc("GetMachineSigLog");
addStoredProc("GetMachineFluxLog");
addStoredProc("BackupDb");
addStoredProc("ExportAll");
@@ -27,6 +28,7 @@
// drop delle stored
DropStoredProcedure("dbo.SyncPodlToMachine");
DropStoredProcedure("dbo.GetMachineEvList");
+ DropStoredProcedure("dbo.GetMachineSigLog");
DropStoredProcedure("dbo.GetMachineFluxLog");
DropStoredProcedure("dbo.BackupDb");
DropStoredProcedure("dbo.ExportAll");
diff --git a/EgwProxy.SqlDb/SqlScript/AddFunc.sql b/EgwProxy.SqlDb/SqlScript/AddFunc.sql
new file mode 100644
index 00000000..c4e98d26
--- /dev/null
+++ b/EgwProxy.SqlDb/SqlScript/AddFunc.sql
@@ -0,0 +1,24 @@
+
+/***************************************
+* FUNCTION f_padLeft
+*
+* fornisce una stringa della lunghezza desiderata aggiungendo a sx il carattere richiesto alla @string originale
+*
+* Steamware, S.E.L.
+* mod: 2010.03.19
+*
+****************************************/
+CREATE FUNCTION [dbo].[f_padLeft] (@string VARCHAR(255), @desired_length INTEGER, @pad_character CHAR(1))
+RETURNS VARCHAR(255) AS
+BEGIN
+
+ -- Prefix the required number of spaces to bulk up the string and then replace the spaces with the desired character
+ RETURN CASE
+ WHEN LEN(@string) < @desired_length
+ THEN REPLACE(SPACE(@desired_length - LEN(@string)), ' ', @pad_character) + @string
+ ELSE @string
+ END
+
+END
+
+GO;
\ No newline at end of file
diff --git a/EgwProxy.SqlDb/StoredProc/GetMachineSigLog.sql b/EgwProxy.SqlDb/StoredProc/GetMachineSigLog.sql
new file mode 100644
index 00000000..41930eb4
--- /dev/null
+++ b/EgwProxy.SqlDb/StoredProc/GetMachineSigLog.sql
@@ -0,0 +1,76 @@
+
+-- SET NOCOUNT ON added to prevent extra result sets from
+-- interfering with SELECT statements.
+SET NOCOUNT ON;
+
+BEGIN tran
+
+ -- dichiarazioni variabili x recupero dati
+ DECLARE @LastIdx INT = 0
+ DECLARE @NewIdx INT = 0
+
+ -- recupero valore ultima riga stato processata...
+ SELECT @LastIdx = ISNULL(LastIdx,0)
+ FROM SyncState
+ WHERE TableName = 'syn_M2ERP_MACHINE_STATE'
+
+ -- recupero nuovo MAX idx
+ SELECT @NewIdx = ISNULL(MAX(ID),0)
+ FROM syn_M2ERP_MACHINE_STATE
+
+ /* --------------------------------------------------
+ * DECODIFICA STANDARD
+ * STATE MACHINE 60
+ * bitmap MAPO
+ * B0: POWER_ON
+ * B1: RUN
+ * B2: pzCount
+ * B3: allarme
+ * B4: manuale
+ * B5: slowTC
+ * B6: WarmUpCoolDown
+ * B7: emergenza
+ * -------------------------------------------------- */
+
+ -- decodifica colonne PAMA:
+ -- M_ON --> PowerON (B0)
+ -- Auto --> Lavora (B1)
+ -- AlarmMode --> Allarme (B3)
+ -- ManualMode/Mda/Jog --> Manuale (B4)
+ -- Mda/Jog --> Manuale (B4)
+ -- ManualMode --> Manuale (B4)
+
+ -- recupero i nuovi record da processare...
+ ;WITH cteSigLog AS
+ (
+ SELECT [DateTime] AS DtEve
+ ,Targa AS IdxMacchina
+ , 128 -- B7: emergenza armata (B7 --> 128)
+ + CASE WHEN M_ON = 1 THEN 1 ELSE 0 END -- B0: spenta
+ + CASE WHEN [Auto] = 1 THEN 2 ELSE 0 END -- B1: lavora
+ + CASE WHEN AlarmMode = 1 THEN 8 ELSE 0 END -- B3: allarme
+ + CASE WHEN (ManualMode = 1 OR Mda = 1 OR Jog = 1) THEN 16 ELSE 0 END -- B4: manuale
+ AS ValInt
+ FROM syn_M2ERP_MACHINE_STATE
+ WHERE ID > @LastIdx AND ID <= @NewIdx
+ )
+
+ --vero insert valori
+ INSERT INTO MachineSignalLog(DtEve, IdxMacchina, ValInt, Valore)
+ SELECT *
+ ,CAST(CONVERT(VARBINARY(2), ValInt) AS NVARCHAR(50)) AS Valore
+ FROM cteSigLog
+
+ -- aggiorno valore indice processato
+ MERGE SyncState AS tgt
+ USING (SELECT @NewIdx as LastIdx, 'syn_M2ERP_MACHINE_STATE' AS TableName) as src (LastIdx, TableName)
+ ON (tgt.TableName = src.TableName)
+ WHEN MATCHED THEN
+ UPDATE SET LastIdx = src.LastIdx
+ ,Note = 'UPDATED from ' + CAST(@LastIdx AS NVARCHAR(50))
+ ,LastUpdate = GETDATE()
+ WHEN NOT MATCHED THEN
+ INSERT (LastIdx, TableName, Note, LastUpdate)
+ VALUES (src.LastIdx, src.TableName, 'CREATED', GETDATE());
+
+COMMIT tran
\ No newline at end of file
diff --git a/EgwProxy.SqlDb/SyncStateDbContext.cs b/EgwProxy.SqlDb/SyncStateDbContext.cs
index 3dc3836d..acffcbf0 100644
--- a/EgwProxy.SqlDb/SyncStateDbContext.cs
+++ b/EgwProxy.SqlDb/SyncStateDbContext.cs
@@ -98,7 +98,7 @@ namespace EgwProxy.SqlDb
///
/// DbSet Flux Log già decodificato
///
- public virtual DbSet DbSetMachEvList { get; set; }
+ public virtual DbSet DbSetMachEvList { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{