From 48915ab10d83b4abfc1fad50707252b9e5c9d23c Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 3 Sep 2019 10:43:34 -0500 Subject: [PATCH] Checkpoint del registro de conexion --- App_Code/ClsAF.vb | 41 ++++++++++++++++++++++++++++++++++++- App_Code/ClsAIMMGM.vb | 40 +++++++++++++++++++++++++++++++++++- App_Code/ClsAcumuladores.vb | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/App_Code/ClsAF.vb b/App_Code/ClsAF.vb index 42eb253bb..d312871aa 100644 --- a/App_Code/ClsAF.vb +++ b/App_Code/ClsAF.vb @@ -19,6 +19,8 @@ Public Class ClsAF Private Data As DataTable Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 #End Region #Region "Propiedades" @@ -96,7 +98,7 @@ Public Class ClsAF End If SqlAdapter = New SqlDataAdapter("", SqlConexion) - + ConexionAdd() End Sub Private Sub DataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -107,6 +109,42 @@ Public Class ClsAF If Not SqlTransacc Is Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc Data = New DataTable End Sub +#Region "Conexiones" + + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + DataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + End Sub + + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Public Function IniciaTransacSQL() As SqlTransaction If SqlTransacc Is Nothing Then SqlTransacc = SqlConexion.BeginTransaction() Return SqlTransacc @@ -3225,6 +3263,7 @@ Public Class ClsAF ' Visual Basic agregó este código para implementar correctamente el modelo descartable. Public Sub Dispose() Implements IDisposable.Dispose ' No cambie este código. Coloque el código de limpieza en Dispose (ByVal que se dispone como Boolean). + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsAIMMGM.vb b/App_Code/ClsAIMMGM.vb index 085124e37..3509f4b9d 100644 --- a/App_Code/ClsAIMMGM.vb +++ b/App_Code/ClsAIMMGM.vb @@ -16,6 +16,8 @@ Public Class ClsAIMMGM Private SqlTransacc As SqlTransaction Private Data As DataTable Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 #End Region #Region "Propiedades" @@ -61,7 +63,7 @@ Public Class ClsAIMMGM SqlAdapter = New SqlDataAdapter("", SqlConexion) SqlCommand = New SqlCommand("", SqlConexion) - + ConexionAdd() End Sub Private Sub DataAdapter(pStrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) @@ -73,7 +75,42 @@ Public Class ClsAIMMGM If Not SqlTransacc Is Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc Data = New DataTable End Sub +#Region "Conexiones" + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + DataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + End Sub + + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Private Sub DataCommand(pStrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlCommand @@ -726,6 +763,7 @@ Public Class ClsAIMMGM ' Visual Basic agregó este código para implementar correctamente el modelo descartable. Public Sub Dispose() Implements IDisposable.Dispose ' No cambie este código. Coloque el código de limpieza en Dispose (ByVal que se dispone como Boolean). + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsAcumuladores.vb b/App_Code/ClsAcumuladores.vb index 14c4d0c58..38d227c6e 100644 --- a/App_Code/ClsAcumuladores.vb +++ b/App_Code/ClsAcumuladores.vb @@ -17,6 +17,8 @@ Public Class ClsAcumuladores Private Data As DataTable Private DSet As New DataSet Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 Private Sub SqlDataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -63,9 +65,44 @@ Public Class ClsAcumuladores End If SqlAdapter = New SqlDataAdapter("", SqlConexion) + ConexionAdd() + End Sub +#Region "Conexiones" + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + SqlDataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If End Sub + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + SqlDataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Public ReadOnly Property DtResultados() As DataTable Get DtResultados = Data @@ -810,6 +847,7 @@ Public Class ClsAcumuladores ' Visual Basic agregó este código para implementar correctamente el modelo descartable. Public Sub Dispose() Implements IDisposable.Dispose ' No cambie este código. Coloque el código de limpieza en Dispose (ByVal que se dispone como Boolean). + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub