Crear Menus desde archivo texto

Crear Menus desde archivo texto

Postby jponce » Thu Oct 15, 2009 6:21 pm

Hola a Todos,

Como crear un menu desde archivo texto?


Atentamente
Julio Ponce
jponce
 
Posts: 194
Joined: Fri Apr 18, 2008 4:21 pm
Location: Guatemala

Re: Crear Menus desde archivo texto

Postby jrestojeda » Thu Oct 15, 2009 8:10 pm

Hola amigo...
Usa un MEMOREAD y carga el archivo de texto en un Array, de ahi te olvidas del archivo de texto y trabaja con el Array.

Code: Select all  Expand view
// FUNCION PARA LEER UN ARCHIVO DE TEXTO //
Function LeoTxt()
Local Archivo,mVar,CanLineas,Q,Li,aMenu[0]

mVar:=Curdir()+"MENU.txt"

Archivo   :=MEMOREAD(mVar)
CantLineas:=MLCOUNT(Archivo)

FOR Q=1 TO CantLineas
   Li:=MEMOLINE(Archivo,80,Q)
   AADD(aMenu,Li)
NEXT
Return nil
//

Espero te sirva la idea.
Ojeda Esteban Eduardo.
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
User avatar
jrestojeda
 
Posts: 583
Joined: Wed Jul 04, 2007 3:51 pm
Location: Buenos Aires - Argentina

Re: Crear Menus desde archivo texto

Postby jponce » Thu Oct 15, 2009 8:30 pm

jrestojeda wrote:Hola amigo...
Usa un MEMOREAD y carga el archivo de texto en un Array, de ahi te olvidas del archivo de texto y trabaja con el Array.

Code: Select all  Expand view
// FUNCION PARA LEER UN ARCHIVO DE TEXTO //
Function LeoTxt()
Local Archivo,mVar,CanLineas,Q,Li,aMenu[0]

mVar:=Curdir()+"MENU.txt"

Archivo   :=MEMOREAD(mVar)
CantLineas:=MLCOUNT(Archivo)

FOR Q=1 TO CantLineas
   Li:=MEMOLINE(Archivo,80,Q)
   AADD(aMenu,Li)
NEXT
Return nil
//

Espero te sirva la idea.


Gracias pero como lleno el menu?

Atentamente
Julio Ponce
jponce
 
Posts: 194
Joined: Fri Apr 18, 2008 4:21 pm
Location: Guatemala

Re: Crear Menus desde archivo texto

Postby acuellar » Thu Oct 15, 2009 9:27 pm

Julio, asi como te indica Esteban
Tenés que leer la tabla aMenu

y harias así

MENU oMenu 2007
MENU
MENUITEM aMenu[1] MESSAGE "mensage" ACTION tufuncion()
ENDMENU
ENDMENU

Saludos

Adhemar
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Crear Menus desde archivo texto

Postby jponce » Thu Oct 15, 2009 9:51 pm

Ya lo logre hacer así, pero como poner los Action tambien en la matriz, si no de que sirve tener el archivo texto,

Esto lo quiero para que el usuario pueda crear su propio menu desde el archivo texto sin tener que compilar el programa.

Atentamente
Julio Ponce
acuellar wrote:Julio, asi como te indica Esteban
Tenés que leer la tabla aMenu

y harias así

MENU oMenu 2007
MENU
MENUITEM aMenu[1] MESSAGE "mensage" ACTION tufuncion()
ENDMENU
ENDMENU

Saludos

Adhemar
jponce
 
Posts: 194
Joined: Fri Apr 18, 2008 4:21 pm
Location: Guatemala

Re: Crear Menus desde archivo texto

Postby joseluisysturiz » Fri Oct 16, 2009 4:28 am

??? es buena la idea, pero creo que puedes separar por comas (,) el item del menu y luego la funcion y se la pasas a un macro, lo puedes hacer en forma vertical asi lo lees por numero de linea o en un campo MEMO, nose, digo, es una idea que se me vino derepente, saludos, seguire esto que se ve bueno, aunque por alli habia algo parecido para personaliozar los menues a traves del nivel del usuario para restringirlo.
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Crear Menus desde archivo texto

Postby acuellar » Fri Oct 16, 2009 12:26 pm

Julio trata de esta manera

Contenido del archivo de texto: MENU.TXT

Opcion Menu1,Realiza lo siguiente,FUNCION1()
Opcion Menu2,Realiza esto,FUNCION2()

Code: Select all  Expand view

Function CreaMenu()
   Local oMenu
  If !File('MENU.DBF')
     DbCreate( "MENU", { { "ITEM",   "C", 15,0 },{ "MSG",   "C",25,0 },{ "FUNCION", "C", 12,0 } }, "DBFCDX" )
   ENDIF
   USE MENU  NEW EXCLUSIVE
   DBZAP()
   APPEND FROM "MENU.TXT" DELIMITED
   DBGOTOP()
   MENU oMenu 2007
      MENUITEM "&Datos" MESSAGE "Datos generales"
        MENU
         Do While !Eof()
          MENUITEM ITEM MESSAGE MSG ACTION &FUNCION
          DbSkip()
         Enddo
        ENDMENU
ENDMENU

 


También podés hacerlo con una tabla de 3 columnas

Espero te sirva

Saludos

Adhemar
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Crear Menus desde archivo texto

Postby ADBLANCO » Fri Oct 16, 2009 1:04 pm

Aqui Tienes Esto, Espero te ayude
Aunque está hecho para mysql y Dbase

Code: Select all  Expand view

//------------------------------------------------
// Carga Menu Principal desde una Tabla (DBASE Y MYSQL)
// VERSION polivalente
// por: Angel Blanco
//      Valencia, Venezuela
//      Agosto-2.005
// se apoya en este Comando para agregar seleccion en menu (CLASE TMENU)
//    MenuAddItem( <cPrompt>, <cMsg>,;
//             <.checked.>, [ Upper(<(enable)>) == "ENABLED" ],;
//             [\{|oMnuItem|<uAction>\}],;
//             <cBmpFile>, <cResName>, <oMnu>, <bAction>, <nState>, <nVirtKey>,;
//             <.help.>, <nHelpId>, [<{uWhen}>], <.break.> )

FUNCTION MaiMenu( oWnd,oNamUsr,cTabla )
LOCAL oMnu,c_Accion,n_mnu,n_CountReg:=0
LOCAL a_Op:={},n_regist
LOCAL cComand,oQuery
LOCAL lMySql:=.t.  // para que sea por sql
  CURSORWAIT()
  IF lMySql
    cComand:='SELECT SysAccTot.IntMenu,'+;
                     'SysAccTot.IntOpcion,'+;
                     'SysAccTot.VchSeleccion,'+;
                     'SysAccTot.VchMsg,'+;
                     'SysAccTot.VchAccion,'+;
                     'SysAccTot.IntMenuSal,'+;
                     'SysAccTot.VchCondPres,'+;
                     'SysAccTot.VchCondAcc '+;
              'FROM '+cDtComun+'.SysAccTot '+;
          'WHERE SysAccTot.VchModulo ="HCM" AND '+;
                'SysAccTot.VchTipo = "M" '+;
          'ORDER BY SysAccTot.IntMenu,'+;
                   'SysAccTot.IntOpcion'
    oQuery    :=TMSQuery():New( oDtBase )
    oQuery:Open( cComand )

    // Traemos el resultado a nuestro cliente
    IF ( oQuery:nRowCount>0 )
      // necesario para garantizar la organizacion de la informacion
      DO WHILE !oQuery:lEof
        AADD(a_Op,{oQuery:xFieldGet( 1 ),;       // MENU
                  oQuery:xFieldGet( 2 ),;       // OPCION
                  oQuery:xFieldGet( 3 ),;       // SELECCION
                  oQuery:xFieldGet( 4 ),;       // MSG
                  oQuery:xFieldGet( 5 ),;       // ACCION
                  oQuery:xFieldGet( 6 ),;       // MENU SALIDA
                  IIF(LEN(ALLTRIM(oQuery:xFieldGet( 7 )))=0,".T.",ALLTRIM(oQuery:xFieldGet( 7 ))),;
                  IIF(LEN(ALLTRIM(oQuery:xFieldGet( 8 )))=0,".T.",ALLTRIM(oQuery:xFieldGet( 8 )))})
        n_CountReg +=1
        oQuery:Fetch()
      ENDDO
    ENDIF
    oQuery:Close()
  ELSE
    IF FILE("MENU.NTX")
      DELETE FILE MENU.NTX
    ENDIF
    *USE C:\FUENTES\HCM\MENU.MNU SHARED alias MNU
    USE &cTabla SHARED alias MNU
    INDEX ON str(_field->menu,2,0)+str(_field->opcion,2,0) to MENU.NTX
    //
    // COPIANDO TABLA A ARREGLO
    DO WHILE !MNU->(EOF())
      AADD(a_Op,{MNU->MENU,;
                MNU->OPCION,;
                MNU->SELECCION,;
                MNU->MSG,;
                MNU->ACCION,;
                MNU->MENUSAL,;
                IIF(LEN(ALLTRIM(MNU->COND_PRES))=0,".T.",ALLTRIM(MNU->COND_PRES)),;
                IIF(LEN(ALLTRIM(MNU->COND_ACC))=0,".T.",ALLTRIM(MNU->COND_ACC))})
      n_CountReg +=1
      MNU->(DBSKIP())
    ENDDO
    use
  ENDIF
  IF n_CountReg>0
    n_regist := 1
    oMnu   := MenuBegin()                              // inicia menu
    AgregaNivel(a_Op,1,@oMnu,n_CountReg)               // GENERA MENU
  ENDIF

RETURN oMnu

//------------------------------------------------
// AGREGA NIVEL DE MENU (CONCURRENTE)
// VERSION polivalente
//
static PROCEDURE AgregaNivel(a_Op,n_nummenu,oMnu,n_CountReg)
LOCAL n_mnu,c_Accion,n_regist:=1,cPres,cWhen
  DO WHILE a_Op[n_regist,1]<>n_nummenu
    n_regist +=1
    IF n_regist>n_CountReg
      EXIT
    ENDIF
  ENDDO
  IF n_regist<=n_CountReg
    IF n_nummenu>1
      MenuBegin()                                               // comienza menu
    ENDIF
    DO WHILE a_Op[n_regist,1]=n_nummenu                         // solo para ESE MENU
      cPres:=a_Op[n_regist,7]
      cWhen:=a_Op[n_regist,8]
      if &cPres
        DO CASE
          CASE LEN(alltrim(a_Op[n_regist,5])) =0                  // No tiene accion!!!
            IF a_Op[n_regist,6] >0                                // Llama a otro menu
              MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen ,,,,oMnu,,,,.F., )
              n_mnu:=n_regist                                     // guarda el registro para restaurar
              AgregaNivel(a_Op,a_Op[n_regist,6],@oMnu,n_CountReg) // Agrega otro nivel de menu
              n_regist:=n_mnu                                     // restaura al registro
            ELSE                                                  // agrega Espacio
              IF LEN(alltrim(a_Op[n_regist,3]))=0                 // si no tiene etiqueta
                MenuAddItem(,,.F.,,,,,oMnu,,,,.F., )              // Agrega Espacio
              ELSE                                                // si tiene etiqueta
                c_Accion:="{ || msgAlert('Por Implementar') }"    // la presenta
                MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen,&c_Accion,,,oMnu,,,,.F., )
              ENDIF
            ENDIF
          CASE LEN(alltrim(a_Op[n_regist,5])) >0                  // Es un Renglon de menu
            c_Accion:="{ || "+alltrim(a_Op[n_regist,5])+" }"
            MenuAddItem(alltrim(a_Op[n_regist,3]),alltrim(a_Op[n_regist,4]),.F.,&cWhen,&c_Accion,,,oMnu,,,,.F., )
        ENDCASE
      ENDIF
      n_regist +=1                                               // nuevo registro
      IF n_regist>n_CountReg
        EXIT
      ENDIF
    ENDDO
    MenuEnd()                                                    // fin de menu
  ENDIF
  RETURN

 


Saludos...
Saludos

Angel, Valencia, Venezuela

xH .997 - FW 7.9 - BCC55 - WorkShop - MySql
User avatar
ADBLANCO
 
Posts: 299
Joined: Mon Oct 22, 2007 3:03 pm
Location: Valencia - Venezuela

Re: Crear Menus desde archivo texto

Postby Antonio Linares » Fri Oct 16, 2009 2:41 pm

Julio,

Tienes un ejemplo en FWH\samples\TestMnu.prg que construye el menú desde una DBF :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Crear Menus desde archivo texto

Postby Compuin » Sat Nov 18, 2017 8:01 pm

Si utilizo esta funcion siempre me agrega la nueva opcion al final de DBF

Existe alguna forma de organizarlo controlado ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests