Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class ABD
    'ABD = Acceso a Base de Datos
    Public Conect As String
    Dim cnn As New SqlConnection

    Public Function Abrir() As SqlConnection
        If cnn.State = ConnectionState.Closed Then
            cnn.ConnectionString = Conect

            cnn.Open()
        End If

        Return cnn
    End Function

    Public Sub Abrir(ByRef sqlc As SqlConnection)
        If sqlc.State = ConnectionState.Closed Then
            sqlc.ConnectionString = Conect

            sqlc.Open()
        End If
    End Sub

    Public Sub Cerrar(ByRef sqlc As SqlConnection)
        sqlc.Close()
    End Sub

    Public Sub Leer()
        ' Use reflection to find the location of the config file. 
        Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        Dim strConfigLoc As String = Asm.Location

        Dim strTemp As String
        strTemp = strConfigLoc
        strTemp = System.IO.Path.GetDirectoryName(strConfigLoc)

        Dim FileInfo As System.IO.FileInfo = New System.IO.FileInfo(strTemp & "\Total.xml")

        Dim XmlDocument As New System.Xml.XmlDocument
        XmlDocument.Load(FileInfo.FullName)

        Dim Node As System.Xml.XmlNode
        For Each Node In XmlDocument.Item("configuration").Item("Usuario")
            ' Skip any comments.
            If Node.Name = "add" Then
                If Node.Attributes.GetNamedItem("key").Value = "Conect" Then
                    Conect = Node.Attributes.GetNamedItem("value").Value
                End If
            End If
        Next Node
    End Sub

    Public Sub New()
        Leer()
    End Sub
End Class