diff --git a/App_Code/ClsBancos.vb b/App_Code/ClsBancos.vb index dfdc4803e..93b53fd36 100644 --- a/App_Code/ClsBancos.vb +++ b/App_Code/ClsBancos.vb @@ -9,6 +9,7 @@ Imports System.Configuration Imports Microsoft.Reporting.WebForms Imports System.Xml Imports System.IO +Imports System.Web Public Class ClsBancos Implements IDisposable @@ -47,10 +48,12 @@ Public Class ClsBancos Public Property CveUsuarioCancelacion As Integer Public Property UsuarioCancelacion As String Public Property FechaIngCancelacion As Date - Public Property FechaCancelacion As Date - + Public Property FechaCancelacion As Date + + 'CONTROL DE LA CONEXION + Private CveConexion As Integer = 0 #End Region - + #Region " P R O P I E D A D E S - B A N C O S - I E" Public Property CveIE As Integer Public Property CveCuenta As Integer @@ -175,19 +178,28 @@ Public Class ClsBancos If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString + SqlCommand = New SqlCommand("", SqlConexion) + SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() + ConexionAdd(HttpContext.Current.Request.Url.AbsolutePath.ToString) Catch ex As Exception - OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) + OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try Else SqlConexion = TransaccionCompartida.Connection SqlTransacc = TransaccionCompartida + SqlCommand = New SqlCommand("", SqlConexion) + SqlAdapter = New SqlDataAdapter("", SqlConexion) End If - SqlCommand = New SqlCommand("", SqlConexion) - SqlAdapter = New SqlDataAdapter("", SqlConexion) - + 'SqlCommand = New SqlCommand("", SqlConexion) + 'SqlAdapter = New SqlDataAdapter("", SqlConexion) + 'Try + ' ConexionAdd(HttpContext.Current.Request.Url.AbsolutePath.ToString) + 'Catch ex As Exception + + 'End Try End Sub Private Sub DataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -197,7 +209,49 @@ Public Class ClsBancos End With If Not SqlTransacc Is Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc Data = New DataTable + End Sub + +#Region "Conexiones" + + Private Sub ConexionAdd(Url As String) + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo + 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("@Modulo", SqlDbType.VarChar).Value = Url + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + + Try + 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 .Parameters.Clear() @@ -4066,8 +4120,9 @@ Public Class ClsBancos 'End Sub ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. + Public Sub Dispose() Implements IDisposable.Dispose + ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsCompras.vb b/App_Code/ClsCompras.vb index a7f69b063..bdc3ec926 100644 --- a/App_Code/ClsCompras.vb +++ b/App_Code/ClsCompras.vb @@ -19,10 +19,12 @@ Public Class ClsCompras Private StrSQL As StringBuilder 'Atributos de la clase - Private disposedValue As Boolean = False ' Para detectar llamadas redundantes - + Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIONES ABIERTAS + Private CveConexion As Integer = 0 + #End Region - + #Region "Propiedades" Public ReadOnly Property DtResultados() As DataTable Get @@ -53,17 +55,20 @@ Public Class ClsCompras If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString + SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() + ConexionAdd() Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try Else SqlConexion = TransaccionCompartida.Connection SqlTransacc = TransaccionCompartida + SqlAdapter = New SqlDataAdapter("", SqlConexion) End If - SqlAdapter = New SqlDataAdapter("", SqlConexion) + 'SqlAdapter = New SqlDataAdapter("", SqlConexion) End Sub @@ -75,10 +80,48 @@ Public Class ClsCompras End With Data = New DataTable If SqlTransacc IsNot Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc + End Sub + +#Region "Conexiones" + + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo + 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 + + Try + 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 GetCompras(CveCompra As Integer, Serie As String, Folio As String, CveProveedor As Integer, IdPoliza As Integer, CveEmpresa As Integer, Optional ProveedorRFC As String = "-1") As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Comp_ComprasGet") @@ -1838,6 +1881,7 @@ Public Class ClsCompras ' This code added by Visual Basic to correctly implement the disposable pattern. Public Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsRH.vb b/App_Code/ClsRH.vb index 228bd9b3f..44e3ba416 100644 --- a/App_Code/ClsRH.vb +++ b/App_Code/ClsRH.vb @@ -83,7 +83,7 @@ Public Class ClsRH 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo DataAdapter("PA_Sis_RegistrarConexion") With SqlAdapter.SelectCommand.Parameters - .Add("@Clase", SqlDbType.VarChar).Value = "ClsRH" + .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 @@ -99,7 +99,7 @@ Public Class ClsRH End Sub Private Sub ConexionClose() - If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + 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) diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index 8d5a5a673..03bf1c482 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -81,6 +81,7 @@ Public Class ClsVentas If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString + SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() ConexionAdd() @@ -90,9 +91,10 @@ Public Class ClsVentas Else SqlConexion = TransaccionCompartida.Connection SqlTransacc = TransaccionCompartida + SqlAdapter = New SqlDataAdapter("", SqlConexion) End If - SqlAdapter = New SqlDataAdapter("", SqlConexion) + 'SqlAdapter = New SqlDataAdapter("", SqlConexion) End Sub Private Sub DataAdapter(ByVal pStrSQL As String, Optional ByVal TipoComando As CommandType = CommandType.StoredProcedure) @@ -105,41 +107,43 @@ Public Class ClsVentas Data = New DataTable End Sub -#Region "Conexiones" - - Private Sub ConexionAdd() - If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then - - DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsVentas',{0})", HttpContext.Current.Request.Url.Authority), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo - With SqlAdapter.SelectCommand.Parameters - - .Add("@CveConexion", SqlDbType.Int).Direction = ParameterDirection.Output - End With - - Try - SqlAdapter.Fill(Data) - CveConexion = SqlAdapter.SelectCommand.Parameters("@Opcion").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 ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then - - DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE WHERE CveConexion = ", 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 +#Region "Conexiones" + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo + 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 + + Try + 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 @@ -3963,6 +3967,7 @@ Public Class ClsVentas ' This code added by Visual Basic to correctly implement the disposable pattern. Public Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub