Cambio tipo de datos xbrowse

Cambio tipo de datos xbrowse

Postby leandro » Wed Mar 08, 2023 2:48 pm

Hola buenos días para todos

Como dice el encabezado, requiero cambiar el tipo de datos que se muestra en un xbrowse, inicialmente cargamos un tree, pero quiero poder cambiarlo por un array. Tambien cambiar la cantidad de columnas que se muestran.

Dejo este código para ver si pueden ayudarme, espero haberme hecho entender, de antemano gracias

Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()  

    local oWnd, oBrw
    local oTree , oBtn
    local aOther := {}
    local hLine := {=>}
    local aCols := {"Code","Name","Cant","Value"}
    local aCol2 := {"cod","name","cant","value"}
    local cbChange := <||
        oBrw:nDataType := DATATYPE_ARRAY
        oBrw:SetArray( aOther, nil, nil, aCol2 )
        oBrw:refresh()
        msginfo("finish")
    >
   
    hLine["cod"] := "001"
    hLine["name"] := "First"
    hLine["cant"] := 1
    hLine["value"] := 15
    AADD(aOther,hLine)
    hLine := {=>}
   
    hLine["cod"] := "002"
    hLine["name"] := "Second"
    hLine["cant"] := 2
    hLine["value"] := 54
    AADD(aOther,hLine)
    hLine := {=>}

    hLine["cod"] := "001"
    hLine["name"] := "Third"
    hLine["cant"] := 9
    hLine["value"] := 77
    AADD(aOther,hLine)
    hLine := {=>}
   
    USE Customer
    INDEX ON Field->State TO State
    SET ORDER TO "State"
    GO TOP
   
    DEFINE WINDOW oWnd TITLE "Cambiando el tipo de datos xbrowse"
   
        oTree := BuildTree()
       
        @ 10,10 BUTTONBMP oBtn OF oWnd PIXEL size 60, 30 PROMPT "Cambiar" ACTION EVAL(cbChange) 
       
        @ 50,0 XBROWSE oBrw OF oWnd ;
        LINES STYLE FLAT NOBORDER ;
        DATASOURCE oTree COLUMNS 1,2,3 ;
        HEADERS "State & City", "Last", "First" PIXEL

        oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
        oBrw:CreateFromCode()

   
    ACTIVATE WINDOW oWnd
   
return nil  

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
               TREE
            endif  
         endif  
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := { Customer->Last, Customer->First }
         endif  
         SKIP
      enddo
      ENDTREE
   ENDTREE
   oTree:OpenAll()
   
   GO TOP

return oTree
 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Cambio tipo de datos xbrowse

Postby cmsoft » Fri Mar 10, 2023 3:31 am

Algo asi Leandro?
Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()  

    local oWnd, oBrw
    local oTree , oBtn
    local aOther := {}
    local hLine := {=>}
    Local aCols := {"Code","Name","Cant","Value"}
    Local aCol2 := {"cod","name","cant","value"}

   
    hLine["cod"] := "001"
    hLine["name"] := "First"
    hLine["cant"] := 1
    hLine["value"] := 15
    AADD(aOther,hLine)
    hLine := {=>}
   
    hLine["cod"] := "002"
    hLine["name"] := "Second"
    hLine["cant"] := 2
    hLine["value"] := 54
    AADD(aOther,hLine)
    hLine := {=>}

    hLine["cod"] := "001"
    hLine["name"] := "Third"
    hLine["cant"] := 9
    hLine["value"] := 77
    AADD(aOther,hLine)
    hLine := {=>}
   
    USE Customer
    INDEX ON Field->State TO State
    SET ORDER TO "State"
    GO TOP
    lTree := .t.
    DEFINE WINDOW oWnd TITLE "Cambiando el tipo de datos xbrowse"
   
        oTree := BuildTree()

        @ 10,200 BTNBMP PROMPT "HASH" SIZE 150,30 PIXEL OF oWnd FLAT ;
        ACTION  Mutar(aOther,oBrw, aCol2)
       
        @ 50,0 XBROWSE oBrw OF oWnd ;
        LINES STYLE FLAT NOBORDER ;
        DATASOURCE oTree COLUMNS 1,2,3 ;
        HEADERS "State & City", "Last", "First" PIXEL SIZE 1300,600

        oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
        oBrw:CreateFromCode()

   
    ACTIVATE WINDOW oWnd MAXIMIZED
   
return nil  

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
               TREE
            endif  
         endif  
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := { Customer->Last, Customer->First }
         endif  
         SKIP
      enddo
      ENDTREE
   ENDTREE
   oTree:OpenAll()
   
   GO TOP

return oTree


******************************************
** Mutar a Hash
STATIC FUNCTION Mutar(aOther,oBrw,aCol2)
   oBrw:SetArray( aOther, .f., 0, aCol2 )  
   oBrw:GoTop()
RETURN nil  
 


Lo que no encuentro es como volver de nuevo a la vista arbol.
Si lo solucionas avisa.
Saludos
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Cambio tipo de datos xbrowse

Postby leandro » Sat Mar 11, 2023 12:05 pm

Hola Cesar buenos días, muchas gracias por responder

Si funciona, perfecto para array, tambien estuve intentando devolverlo a tree, pero no funciona. Esta tarde continuo intentando, si obtengo algún resultado positivo, de cuento.

Gracias por la ayuda.
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Cambio tipo de datos xbrowse

Postby leandro » Thu Mar 23, 2023 9:14 pm

+1

Mr. Nages buenas tardes

Sera que tu, nos puedes ayudar a cambiar el tipo de datos de array a tree. :oops:
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Cambio tipo de datos xbrowse

Postby cmsoft » Thu Mar 23, 2023 9:55 pm

Hola Leandro:
Fijate aqui https://forums.fivetechsupport.com/viewtopic.php?f=6&t=42922&sid=0396673029a2a41b3f374dd4ec04a26f&sid=0396673029a2a41b3f374dd4ec04a26f#p258122
Aqui cambias pero con la misma estructura de datos (es en dbf, pero podría adaptarse a Mysql o Array)
También otra respuesta que había visto en el foro, es mostrar y ocultar los xbrowse superpuestos, cuando los datos nada tienen que ver unos con otros, y no me parecio mala idea.
Code: Select all  Expand view


#include "FiveWin.ch"
#include "xbrowse.ch"
STATIC lTree
function Main()  

    local oWnd, oBrw, oBrw1
    local oTree , oBtn
    local aOther := {}
    local hLine := {=>}
    Local aCols := {"Code","Name","Cant","Value"}
    Local aCol2 := {"cod","name","cant","value"}

   
    hLine["cod"] := "001"
    hLine["name"] := "First"
    hLine["cant"] := 1
    hLine["value"] := 15
    AADD(aOther,hLine)
    hLine := {=>}
   
    hLine["cod"] := "002"
    hLine["name"] := "Second"
    hLine["cant"] := 2
    hLine["value"] := 54
    AADD(aOther,hLine)
    hLine := {=>}

    hLine["cod"] := "001"
    hLine["name"] := "Third"
    hLine["cant"] := 9
    hLine["value"] := 77
    AADD(aOther,hLine)
    hLine := {=>}
   
    USE Customer
    INDEX ON Field->State TO State
    SET ORDER TO "State"
    GO TOP
    lTree := .t.
    DEFINE WINDOW oWnd TITLE "Cambiando el tipo de datos xbrowse"
   
        oTree := BuildTree()

        @ 10,200 BTNBMP oBtn PROMPT "HASH" SIZE 150,30 PIXEL OF oWnd FLAT ;
        ACTION  (Mutar(oBrw, oBrw1), oBtn:cTitle := IF(lTree,"HASH","TREE"))
       
        @ 50,0 XBROWSE oBrw OF oWnd ;
        LINES STYLE FLAT NOBORDER ;
        DATASOURCE oTree COLUMNS 1,2,3 ;
        HEADERS "State & City", "Last", "First" PIXEL SIZE 1300,600

        @ 50,0 XBROWSE oBrw1 OF oWnd ;
        LINES STYLE FLAT NOBORDER ;
        DATASOURCE aOther COLUMNS "Cod","Name","Cant","Value" ;
        HEADERS "Code","Name","Cant","Value" PIXEL SIZE 1300,600

        oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
        oBrw:CreateFromCode()
        oBrw1:nMarqueeStyle = MARQSTYLE_HIGHLROW
        oBrw1:CreateFromCode()
        oBrw1:Hide()

   
    ACTIVATE WINDOW oWnd MAXIMIZED
   
return nil  

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
               TREE
            endif  
         endif  
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := { Customer->Last, Customer->First }
         endif  
         SKIP
      enddo
      ENDTREE
   ENDTREE
   oTree:OpenAll()
   
   GO TOP

return oTree


******************************************
** Mutar a Hash
STATIC FUNCTION Mutar(oBrw,oBrw1)
   IF lTree
      oBrw:Hide()
      oBrw1:Show()
      ELSE
      oBrw1:Hide()
      oBrw:Show()
   ENDIF
lTree := !lTree      
RETURN nil  
 
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Cambio tipo de datos xbrowse

Postby leandro » Fri Mar 24, 2023 3:01 pm

Cesar, como siempre gracias por responder.

Si buena idea lo de los dos xbrowse, voy a irme por ese lado.

Por que intente con el ejemplo de dbf que mencionaste, pero no funciona, aunque cambia los datos, no cambia las columnas.

De nuevo gracias
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests