se agrego el registro de la conexión en la base de datos

This commit is contained in:
Antonio Gonzalez
2019-09-03 09:46:29 -05:00
parent 5958c2baf0
commit 995c101689
4 changed files with 154 additions and 50 deletions

View File

@@ -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
@@ -49,6 +50,8 @@ Public Class ClsBancos
Public Property FechaIngCancelacion 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"
@@ -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)
End Try
Else
SqlConexion = TransaccionCompartida.Connection
SqlTransacc = TransaccionCompartida
End If
SqlCommand = New SqlCommand("", SqlConexion)
SqlAdapter = New SqlDataAdapter("", SqlConexion)
End If
'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
@@ -198,6 +210,48 @@ Public Class ClsBancos
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()
@@ -4068,6 +4122,7 @@ Public Class ClsBancos
' 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

View File

@@ -20,6 +20,8 @@ Public Class ClsCompras
'Atributos de la clase
Private disposedValue As Boolean = False ' Para detectar llamadas redundantes
'REGISTRAR CONEXIONES ABIERTAS
Private CveConexion As Integer = 0
#End Region
@@ -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
@@ -77,7 +82,45 @@ Public Class ClsCompras
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
@@ -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

View File

@@ -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)

View File

@@ -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)
@@ -110,15 +112,17 @@ Public Class ClsVentas
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
'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("@CveConexion", SqlDbType.Int).Direction = ParameterDirection.Output
.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("@Opcion").Value.ToString.ToEntero
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
@@ -127,9 +131,9 @@ Public Class ClsVentas
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 = ", CveConexion), CommandType.Text)
DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text)
Try
SqlAdapter.Fill(Data)
@@ -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