Page 1 of 1

Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Fri Mar 04, 2022 11:12 pm
by leandro
Hola buenas tardes para todos

Estoy intentando cambiar por completo el oTree que tengo montado sobre el xbrowse, intento usar la función oBrw:settree() pero lo que hace es sobre poner las columnas que se están mostrando.

Si se hace varias veces clic sobre el botón de cambio, se aumentan mas y mas columnas.

Image

Code: Select all  Expand view

#include "fivewin.ch"

function Main()

local oTree, oFont2, oBtCmb
local oDlg, oFont, oBrw

Local cbCambioEstado := <|x|
    oBrw:oTreeItem:Cargo[2] := x
    oBrw:refresh()
>

Local cbCambioTree := <||
    oTree := buildtree2()
    oBrw:SetTree(oTree)
    oBrw:refresh() 
    oTree:OpenAll() 
>

oTree := buildtree1()

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
DEFINE FONT oFont2 NAME "TAHOMA" SIZE 0,-9

DEFINE DIALOG oDlg SIZE 700,500 PIXEL TRUEPIXEL FONT oFont

    @ 0, 20 BUTTONBMP oBtCmb OF oDlg PIXEL size 80, 21 PROMPT "Cambiar oTree" FONT oFont2 ACTION EVAL(cbCambioTree) 

    @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
    DATASOURCE oTree ;
    COLUMNS 2 ;
    HEADERS "ITEM", "AUTO";
    CELL LINES NOBORDER

    WITH OBJECT oBrw
    :lDisplayZeros := .f.
    :aCols[ 1 ]:AddBitmap( { FWDArrow(), FWRArrow(), GetTreeBmps()[ 2 ] } )

    :aCols[2]:bEditValue := {|| oBrw:oTreeItem:Cargo[2] }
    :aCols[2]:cDataType  := "L"
    :aCols[2]:nEditType := EDIT_GET
    :aCols[2]:SetCheck()
    :aCols[2]:bOnPostEdit    := { | o, x, n | EVAL(cbCambioEstado,x) }     

    :bClrStd := { || { CLR_BLACK, If( oBrw:oTreeItem:nLevel == 1, CLR_YELLOW, CLR_WHITE ) } }

    :CreateFromCode()
    END
    oTree:OpenAll()

ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont

return nil

//CONSTRUIMOS EL PRIMER TREE
function buildtree1()
Local oTree
Local aData := {}
Local aData2 := {}
Local t,r

aData    := ;
{  { "Facturas", 00,.T.  } ;
,  { "Pedidos", 00,.F. } ;
,  { "Remsiones", 00,.F. } ;
,  { "Notas", 00,.F. } ;
}

aData2    := ;
{  { "Agregar ", 01,.T. } ;
,  { "Modificar ", 02,.T. } ;
}

TREE oTree
FOR r:=1 TO len(aData)
    TREEITEM aData[r][1] CARGO {  aData[r][2] , aData[r][3]  }     
    TREE
    FOR t:=1 TO len(aData2)
        TREEITEM aData2[t][1] CARGO { aData2[t][2] , aData2[t][3]  }
    NEXT  
    ENDTREE
NEXT   
ENDTREE

Return oTree

//CONSTRUIMOS EL SEGUNDO TREE
function buildtree2()
Local oTree
Local aData := {}
Local aData2 := {}
Local t,r

aData    := ;
{  { "Cuentas", 00,.T.  } ;
,  { "Comprobantes", 00,.F. } ;
,  { "Centros", 00,.F. } ;
,  { "Conceptos", 00,.F. } ;
,  { "Consultas", 00,.F. } ;
}

aData2    := ;
{  { "Eliminar", 00,.T. } ;
,  { "Enviar ", 00,.T. } ;
,  { "Procesar ", 00,.T. } ;
,  { "Anular ", 00,.T. } ;
}

TREE oTree
FOR r:=1 TO len(aData)
    TREEITEM aData[r][1] CARGO {  aData[r][2] , aData[r][3]  }     
    TREE
    FOR t:=1 TO len(aData2)
        TREEITEM aData2[t][1] CARGO { aData2[t][2] , aData2[t][3]  }
    NEXT  
    ENDTREE
NEXT   
ENDTREE

Return oTree
 

Re: Cambiar Tree Completo Sobre xBrowse

PostPosted: Sat Mar 05, 2022 8:33 am
by Antonio Linares
Estimado Leandro,

Esto tiene que revisarlo Rao. Se lo comento, gracias :-)

Re: Cambiar Tree Completo Sobre xBrowse

PostPosted: Sat Mar 05, 2022 12:30 pm
by nageswaragunupudi
Use this code
Code: Select all  Expand view
Local cbCambioTree := <||
    oTree := buildtree2()
    oBrw:oTree := oTree
    oBrw:GoTop()
    oBrw:refresh()
    oTree:OpenAll()
    oBrw:SetFocus()
    return nil
>
 

Re: Cambiar Tree Completo Sobre xBrowse

PostPosted: Sat Mar 05, 2022 1:06 pm
by nageswaragunupudi
Remove this code:
Code: Select all  Expand view

    :aCols[2]:bEditValue := {|| oBrw:oTreeItem:Cargo[2] }
    :aCols[2]:cDataType  := "L"
    :aCols[2]:nEditType := EDIT_GET
    :aCols[2]:SetCheck()
    :aCols[2]:bOnPostEdit    := { | o, x, n | EVAL(cbCambioEstado,x) }
 

This one line of code is recommended.
Code: Select all  Expand view

    :aCols[ 2 ]:SetCheck( nil, .t. )
 


XBrowse automatically creates codeblocks bEditValue and bOnPostEdit. Better not to override them.

Re: Cambiar Tree Completo Sobre xBrowse

PostPosted: Sat Mar 05, 2022 2:33 pm
by leandro
Excelente Mr Rao, muchas gracias. :D :D :D

Lo único es que deje bOnPostEdit, por que necesito ejecutar una acción sobre la base de datos, diferente a cambiar el setcheck.

El código quedo de la siguiente manera:

Code: Select all  Expand view

#include "fivewin.ch"

function Main()

local oTree, oFont2, oBtCmb
local oDlg, oFont, oBrw

Local cbCambioEstado := <|x|
    //Aqui ejecuto mi acción personalizada, sobre la base de datos
    oBrw:oTreeItem:Cargo[2] := x
    oBrw:refresh()
>

Local cbCambioTree := <||
    oTree := buildtree2()
    oBrw:oTree := oTree
    oBrw:GoTop()
    oBrw:refresh()
    oTree:OpenAll()
    oBrw:SetFocus()
    return nil 
>

oTree := buildtree1()

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
DEFINE FONT oFont2 NAME "TAHOMA" SIZE 0,-9

DEFINE DIALOG oDlg SIZE 700,500 PIXEL TRUEPIXEL FONT oFont

    @ 0, 20 BUTTONBMP oBtCmb OF oDlg PIXEL size 80, 21 PROMPT "Cambiar oTree" FONT oFont2 ACTION EVAL(cbCambioTree) 

    @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
    DATASOURCE oTree ;
    COLUMNS 2 ;
    HEADERS "ITEM", "AUTO";
    CELL LINES NOBORDER

    WITH OBJECT oBrw
    :lDisplayZeros := .f.
    :aCols[ 1 ]:AddBitmap( { FWDArrow(), FWRArrow(), GetTreeBmps()[ 2 ] } )

    :aCols[ 2 ]:SetCheck( nil, .t. )
    :aCols[ 2 ]:bOnPostEdit    := { | o, x, n | EVAL(cbCambioEstado,x) }

    :bClrStd := { || { CLR_BLACK, If( oBrw:oTreeItem:nLevel == 1, CLR_YELLOW, CLR_WHITE ) } }

    :CreateFromCode()
    END
    oTree:OpenAll()

ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont

return nil

//CONSTRUIMOS EL PRIMER TREE
function buildtree1()
Local oTree
Local aData := {}
Local aData2 := {}
Local t,r

aData    := ;
{  { "Facturas", 00,.T.  } ;
,  { "Pedidos", 00,.F. } ;
,  { "Remsiones", 00,.F. } ;
,  { "Notas", 00,.F. } ;
}

aData2    := ;
{  { "Agregar ", 01,.T. } ;
,  { "Modificar ", 02,.T. } ;
}

TREE oTree
FOR r:=1 TO len(aData)
    TREEITEM aData[r][1] CARGO {  aData[r][2] , aData[r][3]  }     
    TREE
    FOR t:=1 TO len(aData2)
        TREEITEM aData2[t][1] CARGO { aData2[t][2] , aData2[t][3]  }
    NEXT  
    ENDTREE
NEXT   
ENDTREE

Return oTree

//CONSTRUIMOS EL SEGUNDO TREE
function buildtree2()
Local oTree
Local aData := {}
Local aData2 := {}
Local t,r

aData    := ;
{  { "Cuentas", 00,.T.  } ;
,  { "Comprobantes", 00,.F. } ;
,  { "Centros", 00,.F. } ;
,  { "Conceptos", 00,.F. } ;
,  { "Consultas", 00,.F. } ;
}

aData2    := ;
{  { "Eliminar", 00,.T. } ;
,  { "Enviar ", 00,.T. } ;
,  { "Procesar ", 00,.T. } ;
,  { "Anular ", 00,.T. } ;
}

TREE oTree
FOR r:=1 TO len(aData)
    TREEITEM aData[r][1] CARGO {  aData[r][2] , aData[r][3]  }     
    TREE
    FOR t:=1 TO len(aData2)
        TREEITEM aData2[t][1] CARGO { aData2[t][2] , aData2[t][3]  }
    NEXT  
    ENDTREE
NEXT   
ENDTREE

Return oTree
 

Re: Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Thu Mar 10, 2022 9:25 am
by nageswaragunupudi
Lo único es que deje bOnPostEdit, por que necesito ejecutar una acción sobre la base de datos, diferente a cambiar el setcheck.

Instead we recommend using
Code: Select all  Expand view

oCol:bOnChange := { |oCol,uOldVal| <OtherChanges>( oCol,uOldVal ) }
 

To the extent possible, please avoid coding bOnPostEdit. It is deprecated.

Re: Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Sat Jan 20, 2024 2:59 pm
by goosfancito
Estimado,
El campo que tengo en mysql es del tipo
"N" de 1.

este campo lo quiero mostrar en el browser con la capacidad del checkbox, pero al momento no logro hacerlo.
la unica forma que, al menos me mostró la tilde, fue esta:

Code: Select all  Expand view
 WITH OBJECT :acols[ 7 ]
         :bEditValue    := { | x | IIf( ::oQry:FieldGet( "c13" ) > 0, .T., .F. ) }
         :SetCheck(, .T. )
      ENDWITH


pero sola me la muestra con o sin tilde, lo. que necesito es que cambie el estado de la tilde, por lo que necesito ir y actualizar la tabla, pero cuando quiero usar la tabla pero no se con que metodo. podes ayudarme?

Re: Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Sat Jan 20, 2024 6:05 pm
by nageswaragunupudi
Code: Select all  Expand view

WITH OBJECT :acols[ 7 ]
   :bEditValue := { | x | If( x == nil, ::oQry:FieldGet( "c13" ) > 0, ::oQry:FieldPut( "c13", If( x, 1, 0 ) ) }
   :SetCheck(, .T. )
ENDWITH
 


OR
Code: Select all  Expand view

WITH OBJECT :acols[ 7 ]
   :bEditValue := { | x | If( x == nil, ::oQry:c13 != 0, ::oQry:c13 := If( x, 1, 0 ) ) }
   :SetCheck(, .T. )
ENDWITH
 



If field "c13" type is TinyInt,
Set
Code: Select all  Expand view

MYSQL_TINYINTASLOGICAL( .T. )
 


and then
Code: Select all  Expand view

WITH OBJECT :acols[ 7 ]
   :bEditValue := { | x | If( x == nil, ::oQry:c13, ::oQry:c13 := x ) }
   :SetCheck(, .T. )
ENDWITH
 

Re: Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Sun Jan 21, 2024 6:27 am
by goosfancito
Rao,
Buen dia, la unica manera de que funcione en mi caso es hacerlo asi

Code: Select all  Expand view
     WITH OBJECT :c13
         :setcheck(, .T. )
         :bLDClickData := { || ::actualizarTag()  }
      ENDWITH


PERO ni este ni ningun browser. me esta actualizando los datos, tengo que salir del dialogo y volver a entrar. y ya probe con :oqry:requery
las consultas las hago por procedimientos almacenados


Code: Select all  Expand view
METHOD actualizarTag( x )  CLASS TCliente

   DO CASE
   CASE  ::oBrw:nColSel = 7

      ::oCnx:update( "tbinfissi", ;
                     { ;
                       { "inf_p", !::oQry:FieldGet( "c13" ) } ;
                     }, NIL, ;
                     { { "id", ::oQry:FieldGet( "id" ) } } ;
                   )


   END CASE
   ::oqry:refresh()       <-------------- no funciona
   ::obrw:refresh()
   RETURN ( NIL )
 

Re: Cambiar Tree Completo Sobre xBrowse (solucionado)

PostPosted: Mon Jan 22, 2024 9:08 am
by Silvio.Falconi
Dear Rao,
a question
if I have an xbrowse with customer.dbf (with a combobox to select the indexes and a get to search for customers - see the example diagram below)

Code: Select all  Expand view
USE CUSTOMER....

 DEFINE DIALOG oDlg


@ 10, 165 GET oGet VAR cSeek SIZE 200,19 PIXEL OF oDlg PICTURE "@!"


   @ 103,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg

 WITH OBJECT oBrw
          :oSeek := oGet
            :CreateFromCode()
         END

  @ 10, 550 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder



How can I switch to a tree view in the same xbrowse and viceversa?

And when I'm in the tree view how can I use a combobox to select the tree indexes and use the customer search get?