diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index a6953b4c..e785e576 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -1690,23 +1690,17 @@ namespace MP_IO.Controllers return answ; } - //[HttpPost] - //public string takeFlogSnapshot(string id, int maxSec) - //{ - // string answ = ""; - // string caller = "takeFlogSnapshot(id)"; - - // answ = doSaveFLSnapshot(id, maxSec, caller); - // return answ; - //} - - [HttpPost] + // GET: IOB/takeFlogSnapshot/SIMUL_03 public string takeFlogSnapshot(string id) { string answ = ""; - string caller = "takeFlogSnapshot(id)"; + string caller = $"takeFlogSnapshot({id})"; - answ = doSaveFLSnapshot(id, 10, caller); + DateTime adesso = DateTime.Now; + DateTime dtEnd = adesso; + DateTime dtStart = adesso.AddDays(-1); + //effettuo chiamata! + answ = doSaveFLSnapshot(id, dtStart, dtEnd, caller); return answ; } @@ -1914,18 +1908,18 @@ namespace MP_IO.Controllers /// /// /// - private static string doSaveFLSnapshot(string id, int maxSec, string caller) + private static string doSaveFLSnapshot(string id, DateTime dtStart, DateTime dtEnd, string caller) { string answ; DateTime dataOraEvento = DateTime.Now; if (memLayer.ML.CRI("_logLevel") > 6) { - logger.lg.scriviLog($"{caller} | Richiesta snapshot dati FluxLog macchina: idxMacchina: {id} ", tipoLog.INFO); + logger.lg.scriviLog($"{caller} | Richiesta snapshot dati FluxLog macchina: idxMacchina: {id} | periodo: {dtStart} - {dtEnd}", tipoLog.INFO); } try { DataLayer DataLayerObj = new DataLayer(); - answ = DataLayerObj.takeFlogSnapshot(id, maxSec); + answ = DataLayerObj.takeFlogSnapshotLast(id, dtStart, dtEnd); } catch (Exception exc) { diff --git a/MapoDb/DS_applicazione.Designer.cs b/MapoDb/DS_applicazione.Designer.cs index f62bc355..aa72e55f 100644 --- a/MapoDb/DS_applicazione.Designer.cs +++ b/MapoDb/DS_applicazione.Designer.cs @@ -28802,7 +28802,7 @@ SELECT IdxMacchina, dtEvento, CodFlux, Valore, Cnt FROM FluxLog WHERE (CodFlux = [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "17.0.0.0")] private void InitCommandCollection() { - this._commandCollection = new global::System.Data.SqlClient.SqlCommand[7]; + this._commandCollection = new global::System.Data.SqlClient.SqlCommand[8]; this._commandCollection[0] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[0].Connection = this.Connection; this._commandCollection[0].CommandText = "SELECT * FROM dbo.FluxLog"; @@ -28865,6 +28865,14 @@ SELECT IdxMacchina, dtEvento, CodFlux, Valore, Cnt FROM FluxLog WHERE (CodFlux = this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IdxMacchina", global::System.Data.SqlDbType.NVarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@MaxSec", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7] = new global::System.Data.SqlClient.SqlCommand(); + this._commandCollection[7].Connection = this.Connection; + this._commandCollection[7].CommandText = "dbo.stp_FL_TakeSnapshotLast"; + this._commandCollection[7].CommandType = global::System.Data.CommandType.StoredProcedure; + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IdxMacchina", global::System.Data.SqlDbType.NVarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@DtMin", global::System.Data.SqlDbType.DateTime, 8, global::System.Data.ParameterDirection.Input, 23, 3, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@DtMax", global::System.Data.SqlDbType.DateTime, 8, global::System.Data.ParameterDirection.Input, 23, 3, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -29343,6 +29351,46 @@ SELECT IdxMacchina, dtEvento, CodFlux, Valore, Cnt FROM FluxLog WHERE (CodFlux = } return returnValue; } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "17.0.0.0")] + [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] + public virtual int TakeSnapshotLast(string IdxMacchina, global::System.Nullable DtMin, global::System.Nullable DtMax) { + global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[7]; + if ((IdxMacchina == null)) { + command.Parameters[1].Value = global::System.DBNull.Value; + } + else { + command.Parameters[1].Value = ((string)(IdxMacchina)); + } + if ((DtMin.HasValue == true)) { + command.Parameters[2].Value = ((System.DateTime)(DtMin.Value)); + } + else { + command.Parameters[2].Value = global::System.DBNull.Value; + } + if ((DtMax.HasValue == true)) { + command.Parameters[3].Value = ((System.DateTime)(DtMax.Value)); + } + else { + command.Parameters[3].Value = global::System.DBNull.Value; + } + global::System.Data.ConnectionState previousConnectionState = command.Connection.State; + if (((command.Connection.State & global::System.Data.ConnectionState.Open) + != global::System.Data.ConnectionState.Open)) { + command.Connection.Open(); + } + int returnValue; + try { + returnValue = command.ExecuteNonQuery(); + } + finally { + if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) { + command.Connection.Close(); + } + } + return returnValue; + } } /// diff --git a/MapoDb/DS_applicazione.xsd b/MapoDb/DS_applicazione.xsd index 1d3d9084..cda05192 100644 --- a/MapoDb/DS_applicazione.xsd +++ b/MapoDb/DS_applicazione.xsd @@ -2623,6 +2623,19 @@ SELECT IdxMacchina, dtEvento, CodFlux, Valore, Cnt FROM FluxLog WHERE (CodFlux = + + + + dbo.stp_FL_TakeSnapshotLast + + + + + + + + + @@ -3844,46 +3857,46 @@ FROM v_AlarmLog - + - - - - + + + + - + - - - + + + - - + + - - - + + + @@ -4020,33 +4033,33 @@ FROM v_AlarmLog - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index 17816e5b..aec3cad2 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -3403,7 +3403,7 @@ namespace MapoDb } /// - /// Effettua chaimata DB x snapshot del FluxLog della macchina richiesta (insieme set ultimi dati) + /// Effettua chiamata DB x snapshot del FluxLog della macchina richiesta (insieme set ultimi dati) /// /// IdxMacchina /// @@ -3432,6 +3432,35 @@ namespace MapoDb return answ; } + /// + /// Effettua chiamata DB x snapshot del FluxLog della macchina richiesta (insieme set ultimi dati) + /// + /// IdxMacchina + /// DT start x effettuare snapshot + /// DT end x effettuare snapshot + /// + public string takeFlogSnapshotLast(string id, DateTime dtMin, DateTime dtMax) + { + string answ = "ND"; + // instanzio un nuovo oggetto MapoDb + MapoDb connDb = new MapoDb(); + // scrivo keep alive!!! (se necessario, altrimenti รจ in cache...) + connDb.scriviKeepAlive(id, DateTime.Now); + + try + { + // ora chiamo la stored di duplicazione + DataLayer DLMan = new DataLayer(); + DLMan.taFL.TakeSnapshotLast(id, dtMin, dtMax); + answ = "OK"; + } + catch (Exception exc) + { + logger.lg.scriviLog($"TakeSnapshotLast:{Environment.NewLine}{exc}", tipoLog.EXCEPTION); + } + return answ; + } + /// /// Aggiornamento parametro per macchina ///