en GUI, Harbour

Herramienta para MySQL – Código Liberado I

2015-05-17_180102
MySQLInfo.prg – Parte I

#include "oohg.ch"
#include "tdolphin.ch"

#define _GEN_PROGRAMA           "MySQLInfo Enhanced by MigSoft"
#define _GEN_AUTOR              "(c) 2004-2015 Cristobal Molla"

#define FNT_BUTTON_NAME         "MS Sans Serif"
#define FNT_BUTTON_SIZE         8
#define FNT_FRAME_NAME          "MS Sans Serif"
#define FNT_FRAME_SIZE          8
#define FNT_LABEL_NAME          "MS Sans Serif"
#define FNT_LABEL_SIZE          8
#define FNT_STATUS_NAME         "MS Sans Serif"
#define FNT_STATUS_SIZE         8
#define FNT_TAB_NAME            "MS Sans Serif"
#define FNT_TAB_SIZE            8
#define FNT_TEXT_NAME           "Arial"
#define FNT_TEXT_SIZE           9


*------------------------------------------------------------*
PROCEDURE Main()
*------------------------------------------------------------*
    // Declaración de variables publicas.----------------------------------
    PUBLIC _cServidor   := "localhost"
    PUBLIC _cUsuario    := "root"
    PUBLIC _cClave      := ""
    PUBLIC _cBase       := ""
    PUBLIC _nPuerto     := 3306
    PUBLIC _nFlags      := 0

    PUBLIC _lConectado  := .F.
    PUBLIC oServidor    := NIL
    PUBLIC oQry_Actual  := Nil
    PUBLIC aServer := {}, aUser := {}, aPass := {}, aPort := {}, aDbase := {}, aFlags := {}
    PUBLIC aSesion := {}, nTotLog := 0, cSesion := "", nPort := 0, nFlags := 0
    PUBLIC cServer := "", cUser := "", cPass := "", cDbase := "", lNueva := .F.

    // Modificadores de Harbour.-------------------------------------------
    SET date british
    SET century ON
    REQUEST HB_LANG_ES
    hb_LangSelect( "ES" )
    D_SetCaseSensitive( .T. )

    // Modificadores de HMG.-----------------------------------------------
    //SET interactiveclose off

    // Define la ventana principal.----------------------------------------
    DEFINE window wndPrincipal OBJ oWin1  ;
        at          0, 0                ;
        width       700                 ;           // 600
        height      540                 ;           // 440
        title       _GEN_PROGRAMA       ;
            icon        "A_ICO_32_MAIN"     ;
            main                            ;
            ON INIT     {|| UpdateMain() }

        oWin1:Anchor := "TOPLEFTBOTTOMRIGHT"

        // Define el menu principal de la ventana principal............
        DEFINE main menu
            DEFINE popup " &Archivo "
                menuitem "  &Conectar  "                ;
                    action { || CtrlConecta() }            ;
                    name mnuConectar
                menuitem "  &Desconectar  "             ;
                    action { || Desconectar() }         ;
                    name mnuDesconectar
                SEPARATOR
                menuitem "  &Consulta SQL  "            ;
                    action {|| Sql()  } ;
                    name mnuSql
                SEPARATOR
                menuitem "  &Acerca de...  "            ;
                    action {|| MainCreditos() }         ;
                    name mnuCreditos
                SEPARATOR
                menuitem "  Co&ntrol Conexión  "        ;
                    action { || CtrlConecta() }         ;
                    name mnuConecta
                menuitem "  &Salir  "                   ;
                    action {|| MainFin() }              ;
                    name mnuSalir
            END popup
        END menu

        // Define la barra de botones de la ventana principal..........
        DEFINE splitbox
            DEFINE toolbar tbPrincipal1     ;
                buttonsize 40, 32       ;
                flat                    ;
                righttext

            button tbbSalir                             ;
                tooltip "Salir"                         ;
                picture "BMP_32_SALIR"                  ;
                action {|| MainFin() }                  ;
                autosize                                ;
                Separator
            button tbbConectar                          ;
                tooltip "Conectar"                      ;
                picture "BMP_32_CONECTAR"               ;
                action {|| CtrlConecta() }                 ;
                autosize
            button tbbDesconectar                       ;
                tooltip "Desconectar"                   ;
                picture "BMP_32_DESCONECTAR"            ;
                action {|| Desconectar( .T. ) }         ;
                autosize
            button tbbConsulta                          ;
                tooltip "Consulta SQL"                  ;
                picture "BMP_32_CONSULTA"               ;
                action {|| SQL() }                      ;
                autosize                                ;
                Separator

            button tbbEditar                            ;
                tooltip "Editar Tabla MySQL"            ;
                picture "BMP_32_EDITAR"                 ;
                action     EditaTabla()                 ;
                autosize                                ;
                Separator

            button tbbExportar                            ;
                tooltip "Exportar Tabla MySQL"            ;
                picture "BMP_32_GUARDARXLS"               ;
                action     ExportaTabla()   DROPDOWN      ;
                autosize

            button tbbImportar                            ;
                tooltip "Importar Tabla DBF"              ;
                picture "BMP_32_TABLA"                    ;
                action     ImportaTabla()                 ;
                autosize

            button tbbEliminar                            ;
                tooltip "Eliminar Tabla MySQL"            ;
                picture "BMP_32_ELIMINAR"                 ;
                action     EliminaTabla()                 ;
                autosize

            END toolbar

            DEFINE DROPDOWN MENU BUTTON tbbExportar
                ITEM 'Dbf'             ACTION  ExportaTabla( EXP_DBF )
                ITEM 'Txt'             ACTION  ExportaTabla( EXP_TEXT )
                ITEM 'Sql'             ACTION  ExportaTabla( EXP_SQL )
                ITEM 'Html'            ACTION  ExportaTabla( EXP_HTML )
                ITEM 'Xlsx'            ACTION  ExportaTabla( EXP_EXCEL )
                ITEM 'Docx'            ACTION  ExportaTabla( EXP_WORD )
            END MENU

        END splitbox

        // Define la barra de estado de la ventana principal...........
        DEFINE statusbar font FNT_STATUS_NAME size FNT_STATUS_SIZE
        statusitem ""                               // 1
        statusitem ""                                   width 085  // 2
        statusitem "Conectado"  icon "ICO_32_LEDOFF"    width 090  // 3
        date                                            width 085  // 4
        clock                                           width 070  // 5
        END statusbar

        // Definicion de controles.....................................
        // Arbol de tablas.............................................

        DEFINE tree treArbol OBJ oTree                         ;
            at           60,10                                 ;
            width        250                                   ;  // 200
        height       400                                   ;  // 300
        font         FNT_TEXT_NAME                         ;
            size         FNT_TEXT_SIZE                         ;
            ON change    ( ArbolChange(), UpDateMain() )       ;
            nodeimages   { "BMP_16_SERVIDOR" }                 ;
            itemimages   { "BMP_16_ITEMOFF", "BMP_16_ITEMON" } ;
            itemids

        END tree

        oTree:Anchor := "TOPLEFTBOTTOM"

        // Paginas de informacion......................................
        DEFINE tab tabInfo OBJ oTab ;
            at        60, 270       ;               // 60 , 220
        width     365           ;                   // 365
        height    400           ;                   // 300
        value     1             ;
            font      FNT_TAB_NAME  ;
            size      FNT_TAB_SIZE  ;
            ON change {|| NIL }     ;
            buttons                 ;
            flat

        oTab:Anchor := "TOPLEFTBOTTOMRIGHT"

        // Pagina de variables.................................
        page "&Variables"
        @ 30, 15 frame frmVariables OBJ oFrame1 ;
            caption "show variables"        ;
            width   385                     ;       // 335
        height  355                     ;           // 255
        font    FNT_FRAME_NAME          ;
            size    FNT_FRAME_SIZE          ;
            bold

        oFrame1:Anchor := "TOPLEFTBOTTOMRIGHT"

        @ 50, 30 grid grdVariables OBJ oGrid1       ;
            width        355                        ;  // 305
        height       320                        ;   // 220
        headers      { "Variable", "Valor" }    ;
            widths       { 250,250 }                ;
            font         FNT_TEXT_NAME              ;
            size         FNT_TEXT_SIZE              ;
            ON gotfocus  {|| setControl( .T. ) }    ;
            ON lostfocus {|| setControl( .F. ) }
        END page

        oGrid1:Anchor := "TOPLEFTBOTTOMRIGHT"

        // Pagina de estados...................................
        page "&Estado"
        @ 30, 15 frame frmEstado OBJ oFrame2 ;
            caption "show status"           ;
            width   385                     ;       // 335
        height  355                     ;           // 255
        font    FNT_FRAME_NAME          ;
            size    FNT_FRAME_SIZE          ;
            bold

        oFrame2:Anchor := "TOPLEFTBOTTOMRIGHT"

        @ 50, 30 grid grdEstado OBJ oGrid2          ;
            width        355                        ;  // 305
        height       320                        ;   // 220
        headers      { "Estado", "Valor" }      ;
            widths       { 250,250 }                ;
            font         FNT_TEXT_NAME              ;
            size         FNT_TEXT_SIZE              ;
            ON gotfocus  {|| setControl( .T. ) }    ;
            ON lostfocus {|| setControl( .F. ) }
        END page

        oGrid2:Anchor := "TOPLEFTBOTTOMRIGHT"

        // Pagina de estructura de tabla.......................
        page "&Tabla"
        @ 30, 15 frame frmTabla OBJ oFrame3 ;
            caption "Estructura"            ;
            width   385                     ;       // 335
        height  355                     ;           // 255
        font    FNT_FRAME_NAME          ;
            size    FNT_FRAME_SIZE          ;
            bold

        oFrame3:Anchor := "TOPLEFTBOTTOMRIGHT"

        @ 50, 30 grid grdTabla OBJ oGrid3           ;
            width        355                        ;  // 305
        height       320                        ;   // 220
        headers      { "Campo", "Tipo",         ;
            "Nulo", "Clave",         ;
            "Valor por defecto",     ;
            "Extra" }                ;
            widths       { 250, 125, 50, 50,        ;
            125, 150 }               ;
            font         FNT_TEXT_NAME              ;
            size         FNT_TEXT_SIZE              ;
            ON gotfocus  {|| setControl( .T. ) }    ;
            ON lostfocus {|| setControl( .F. ) }

        oGrid3:Anchor := "TOPLEFTBOTTOMRIGHT"

        END page

        // Pagina de datos de tabla.............................
        page "&Datos"
        @ 30, 15 frame frmDatos OBJ oFrame4 ;
            caption "show datos"            ;
            width   385                     ;       // 335
        height  355                     ;           // 255
        font    FNT_FRAME_NAME          ;
            size    FNT_FRAME_SIZE          ;
            bold

        oFrame4:Anchor := "TOPLEFTBOTTOMRIGHT"

        @ 50, 30 grid grdDatos OBJ oGrid4           ;
            width        355                        ;  // 305
        height       320                        ;   // 220
        headers      { "" }                     ;
            widths       { 100 }                    ;
            items        { { "" } }                 ;
            value        1                          ;
            font         FNT_TEXT_NAME              ;
            size         FNT_TEXT_SIZE              ;
            DOUBLEBUFFER                            ;
            ON gotfocus  {|| setControl( .T. ) }    ;
            ON CHANGE    {|| setmessage("Record: "+AllTrim(Str(wndPrincipal.grdDatos.value),5), 2 ) } ;
            ON lostfocus {|| setControl( .F. ) }

        oGrid4:Anchor := "TOPLEFTBOTTOMRIGHT"

        END page
        END tab
    END window


    // Activa la ventana principal.----------------------------------------
    center window wndPrincipal
    activate window wndPrincipal

RETURN