Attribute VB_Name = "modGesCol"

'Para Centrado de Formulario
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
    ByVal uAction As Long, _
    ByVal uParam As Long, ByRef lpvParam As Any, _
    ByVal fuWinIni As Long) As Long

Private Type RECT
    Izq As Long
    Sup As Long
    Der As Long
    Inf As Long
End Type
Public Const SPI_GETWORKAREA = 48


'*************************************************
' SECCION DE SUBS
'*************************************************
''Public Sub LlenaCombo(Control As ComboBox, tabla, campo, criteriobus As String, Conexion As ADODB.Connection)
''    'esta funcion llena un combo con un campo X sin array
''    Dim rs As ADODB.Recordset
''    Dim a As String
''    Dim t As Integer
''    Set rs = New ADODB.Recordset
''    rs.CursorLocation = adUseClient
''    a = "SELECT " & campo & " FROM " & tabla & " " & criteriobus
''    rs.Open a, Conexion
''    If rs.RecordCount > 0 Then
''        For t = 0 To rs.RecordCount - 1
''            Control.AddItem rs(0)
''            rs.MoveNext
''        Next t
''    End If
''    rs.Close
''End Sub

Public Sub CentrarForma(frm As Form)
    Dim R As RECT
    Dim lRes As Long
    Dim lAncho As Long
    Dim lLargo As Long
    With frm
        If .WindowState = vbMinimized Or .WindowState = vbMaximized Then Exit Sub
    End With
    lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, R, 0)
    If lRes Then
        With R
            .Izq = Screen.TwipsPerPixelX * .Izq
            .Sup = Screen.TwipsPerPixelY * .Sup
            .Der = Screen.TwipsPerPixelX * .Der
            .Inf = Screen.TwipsPerPixelY * .Inf
            lAncho = .Der - .Izq
            lLargo = .Inf - .Sup

            frm.Move (.Izq + (lAncho - frm.Width) \ 2) - 35, (.Sup + (lLargo - frm.Height) \ 2) - 510
        End With
    End If
End Sub



'**********************************************************
' SECCION DE FUNCIONES
'**********************************************************
Function Conecta(Conexion As ADODB.Connection, DireccionIP As String, BaseDatos As String, Password As String) As Boolean
    'connect to MySQL server using MySQL ODBC 3.51 Driver
On Error GoTo FallaConeccion
    Set Conexion = New ADODB.Connection
    Conexion.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
        "SERVER=" & DireccionIP & "; " & _
        "DATABASE=" & BaseDatos & "; " & _
        "UID=groot;" & _
        "PWD=kripplefight;" & _
        "OPTION=" & "35"
    Conexion.Open
    Conecta = True
    Exit Function

FallaConeccion:
    Conecta = False
    If MsgBox("No fue posible establecer conexión con el Servidor" & Chr(13) & "Dirección IP      : " & DireccionIP & Chr(13) & "Base de Datos  : " & BaseDatos, vbRetryCancel + vbInformation, "Problemas de conexión.....") = vbRetry Then
        Resume
    End If
End Function



'Public Function DevuelveCampo(tabla As String, entracampo As String, salecampo As String, criteriobus As String, Conexion As ADODB.Connection) As String
'    ' esta funcion devuelve un campo por otro acompañado de un criterio de busqueda
'    Dim rsFuncion As ADODB.Recordset
'    Dim a As String
'    Set rsFuncion = New ADODB.Recordset
'    rsFuncion.CursorLocation = adUseClient
'    'rs.Open "select " & salecampo & "," & "from " & tabla & " where " & criteriobus, Conexion
'    a = "select " & salecampo & " from " & tabla & " where " & criteriobus
'    rsFuncion.Open a, Conexion
'    If rsFuncion.RecordCount > 0 Then
'        rsFuncion.MoveFirst
'        DevuelveCampo = IIf(Not IsNull(rsFuncion(0)), rsFuncion(0), "")
'    Else
'        DevuelveCampo = ""
'    End If
'    rsFuncion.Close
'    Set rsFuncion = Nothing
'End Function

Public Function InvierteFecha(fecha As Date, DerechoReves As String) As String
    If UCase(DerechoReves) = "D" Then InvierteFecha = Format(fecha, "dd/mm/yyyy")
    If UCase(DerechoReves) = "R" Then InvierteFecha = Format(fecha, "yyyy/mm/dd")
End Function

'Public Function ExistReg(NameTabla As String, criteriobus As String, Conexion As ADODB.Connection) As Boolean
'    On Error GoTo controler
'    Dim abrio As Boolean
'    Set rsER = New ADODB.Recordset
'    rsER.CursorLocation = adUseClient
'    abrio = False
'    rsER.CursorLocation = adUseClient
'    'revisa Si el registro existe
'    rsER.Open "SELECT * FROM " & NameTabla & " where " & criteriobus, Conexion, adOpenKeyset
'    abrio = True
'    If rsER.RecordCount > 0 Then
'        ExistReg = True
'    Else
'        ExistReg = False
'    End If
'    rsER.Close
'Exit Function
'controler:     'Controla el error E_Fail
'    If Err.Number = -2147467259 Then
'        ExistReg = True
'        If abrio Then
'            rsER.Close ' tener cuidado cuando intente cerrar la conexión al recordset si haberla abierto.
'        End If
'    End If
'End Function

