en GUI, Harbour

Herramienta para MySQL – Código Liberado V

MySQLInfo.prg – Parte V

*------------------------------------------------------------*
Procedure RellenaArray()
*------------------------------------------------------------*
   If lNueva
      Aadd( aServer, CtrlVentana.text_1.value    )
      Aadd( aUser,   CtrlVentana.text_2.value    )
      Aadd( aPass,   CtrlVentana.text_3.value    )
      Aadd( aDbase,  CtrlVentana.text_4.value    )
      Aadd( aFlags,  CtrlVentana.text_5.value    )
      Aadd( aPort,   CtrlVentana.Spinner_1.Value )
   Endif
Return

*------------------------------------------------------------*
Procedure LimpiaArray()
*------------------------------------------------------------*
    aServer := {}
    aUser   := {}
    aPass   := {}
    aDbase  := {}
    aPort   := {}
    aFlags  := {}
Return

*------------------------------------------------------------*
Procedure CambiaArray()
*------------------------------------------------------------*
    i := CtrlVentana.Grid_1.Value
        Afill( aServer, CtrlVentana.text_1.value ,   i )
        Afill( aUser,   CtrlVentana.text_2.value ,   i )
        Afill( aPass,   CtrlVentana.text_3.value ,   i )
        Afill( aDbase,  CtrlVentana.text_4.value ,   i )
        Afill( aFlags,  CtrlVentana.text_5.value ,   i )
        Afill( aPort,   CtrlVentana.Spinner_1.Value ,i )
Return

*------------------------------------------------------------*
Procedure CambiaText( i )
*------------------------------------------------------------*
    n := CtrlVentana.Grid_1.Value
    If n > 0
       If      i == 1
               Afill( aServer, CtrlVentana.text_1.value ,   n )
        ElseIf i == 2
               Afill( aUser,   CtrlVentana.text_2.value ,   n )
        ElseIf i == 3
               Afill( aPass,   CtrlVentana.text_3.value ,   n )
        ElseIf i == 4
               Afill( aDbase,  CtrlVentana.text_4.value ,   n )
        ElseIf i == 5
               Afill( aPort,   CtrlVentana.Spinner_1.Value ,n )
        ElseIf i == 6
               Afill( aFlags,  CtrlVentana.text_5.value,    n )
       Endif
    Endif
    CtrlVentana.Grid_1.Enabled := .T.
Return

*------------------------------------------------------------*
Procedure BorrarSesion()
*------------------------------------------------------------*
    n := CtrlVentana.Grid_1.Value
    If !Empty( CtrlVentana.Grid_1.Item( n ) )
        CtrlVentana.Grid_1.DeleteItem( n )
    Endif
    BorraArray( n )
    NuevaLong()
    if CtrlVentana.Grid_1.ItemCount > 0
       CtrlVentana.Grid_1.Value := 1
       CambiaDatos( CtrlVentana.Grid_1.Value )
    Else
       LimpiarTextos()
    Endif
Return

*------------------------------------------------------------*
Procedure BorraArray( x )
*------------------------------------------------------------*
    ADel( aServer, x )
    ADel( aUser,   x )
    ADel( aPass,   x )
    ADel( aDbase,  x )
    ADel( aPort,   x )
    ADel( aFlags,  x )
Return

*------------------------------------------------------------*
Procedure NuevaLong()
*------------------------------------------------------------*
    s := CtrlVentana.Grid_1.ItemCount
    ASize( aServer, s )
    ASize( aUser,   s )
    ASize( aPass,   s )
    ASize( aDbase,  s )
    ASize( aPort,   s )
    ASize( aFlags,  s )
Return

*------------------------------------------------------------*
Procedure CambiaDatos( i )
*------------------------------------------------------------*
   If !lNueva .AND. CtrlVentana.Grid_1.ItemCount > 0
       i := Iif( i > 0, i, 1)
       CtrlVentana.text_1.value    := aServer[i]
       CtrlVentana.text_2.value    := aUser[i]
       CtrlVentana.text_3.value    := aPass[i]
       CtrlVentana.text_4.value    := aDbase[i]
       CtrlVentana.text_5.value    := aFlags[i]
       CtrlVentana.Spinner_1.Value := aPort[i]
   Endif
Return

*------------------------------------------------------------*
Procedure VerArrays()
*------------------------------------------------------------*
    AutoMsgInfo(aServer,"aServer")
    AutoMsgInfo(aUser,"aUser")
    AutoMsgInfo(aPass,"aPass")
    AutoMsgInfo(aDbase,"aDbase")
    AutoMsgInfo(aPort,"aPort")
    AutoMsgInfo(aFlags,"aFlags")
Return

*------------------------------------------------------------*
Procedure AbrirIni()
*------------------------------------------------------------*

    CtrlVentana.Grid_1.DeleteAllItems

    BEGIN INI FILE "MyCli2.ini"

        GET nTotLog  SECTION 'Sesion' ENTRY 'Totses'   DEFAULT 0

        If nTotLog > 0
            For i := 1 To nTotLog
                GET cSesion  SECTION 'Sesion' ENTRY 'Conecta'+AllTrim(Str(i)) DEFAULT ""
                CtrlVentana.Grid_1.AddItem( cSesion )
                Aadd( aSesion, cSesion )
                GET cServer        SECTION 'Login'+AllTrim(Str(i))  ENTRY "Server"+AllTrim(Str(i)) DEFAULT 'localhost'
                Aadd( aServer, cServer )
                GET cUser          SECTION 'Login'+AllTrim(Str(i))  ENTRY "User"+AllTrim(Str(i))   DEFAULT 'root'
                Aadd( aUser, cUser )
                GET cPass          SECTION 'Login'+AllTrim(Str(i))  ENTRY "Pass"+AllTrim(Str(i))   DEFAULT ''
                Aadd( aPass, EncDec( cPass, 2 ) )
                GET cDbase         SECTION 'Login'+AllTrim(Str(i))  ENTRY "Dbase"+AllTrim(Str(i))  DEFAULT ''
                Aadd( aDbase, cDbase )
                GET nPort          SECTION 'Login'+AllTrim(Str(i))  ENTRY "Port"+AllTrim(Str(i))   DEFAULT 3306
                Aadd( aPort, nPort )
                GET nFlags         SECTION 'Login'+AllTrim(Str(i))  ENTRY "Flags"+AllTrim(Str(i))  DEFAULT 0
                Aadd( aFlags, nFlags )
                cSesion := ""; cServer := "" ; cUser := ""; cPass := ""; cDbase := ""; nPort := 0; nFlags := 0
            Next i
        Else
            LimpiaArray()
        Endif

    END INI

    CtrlVentana.Grid_1.Value := 1
    CambiaDatos( CtrlVentana.Grid_1.Value )

Return

*------------------------------------------------------------*
Procedure GuardaIni()      // Guarda variables en Ini
*------------------------------------------------------------*
    If lNueva
       RellenaArray()
       lNueva := .F.
    Endif

    Erase("MyCli2.ini")

    n := CtrlVentana.Grid_1.ItemCount

    BEGIN INI FILE "MyCli2.ini"

        SET SECTION 'Sesion' ENTRY "Totses" TO n

        If n > 0
            For i := 1 To n
                cSesion := AllTrim(CtrlVentana.Grid_1.Item(i) )
                SET SECTION 'Sesion'                ENTRY "Conecta"+AllTrim(Str(i))  TO cSesion
                cServer := aServer[i]
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'Server'+AllTrim(Str(i))   TO cServer
                cUser := aUser[i]
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'User'+AllTrim(Str(i))     TO cUser
                cPass := EncDec( aPass[i], 1 )
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'Pass'+AllTrim(Str(i))     TO cPass
                cDbase := aDbase[i]
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'Dbase'+AllTrim(Str(i))    TO cDbase
                nPort := aPort[i]
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'Port'+AllTrim(Str(i))     TO nPort
                nFlags := aFlags[i]
                SET SECTION 'Login'+AllTrim(Str(i)) ENTRY 'Flags'+AllTrim(Str(i))    TO nFlags
                cSesion := ""; cServer := "" ; cUser := ""; cPass := ""; cDbase := ""; nPort := 0; nFlags := 0
            Next
        Endif

    END INI

Return

*--------------------------------------------------------------------------*
Procedure MakeObjCon( _cServidor,_cUsuario,_cClave,_cBase,_nPuerto,_nFlags )
*--------------------------------------------------------------------------*
    // Crea el objeto de conexion a MySql.---------------------------------
    IF !Empty( _cServidor ) .AND. !Empty( _cUsuario )
        // Si el servidor esta disponible intenta conectarse.----------
        setMessage( "Conectando al servidor MySql..." , 1 )

        oServidor := TDolphinSrv():New( _cServidor,_cUsuario,_cClave,_nPuerto,_nFlags,_cBase,  ;
                     {| oServer, nError, lInternal | GetError( oServer, nError, lInternal  ) } )

        If !( oServidor:lError )
            _lConectado := .T.
            wndPrincipal.Title := _GEN_PROGRAMA+" - [ "+oServidor:cHost+" ]"
            UpdateTree()
            UpdateVars()
            UpdateStatus()
            SalirConecta()
        ENDIF
        // Actualiza la ventana principal.-------------------------------------
        setMessage()
        UpdateMain()
    ENDIF

Return