Xbrowse class technical question

Xbrowse class technical question

Postby George » Sun Dec 21, 2014 7:10 pm

Hi,
Would be possible, maybe using arrays, create sub-groups summary and totaling some columns in a xbrowse table?
Please see below a graph example of what I am expecting to do:
[url][url=http://postimage.org/]Image[/url]

Regards,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Xbrowse class technical question

Postby Antonio Linares » Mon Dec 22, 2014 8:04 am

George,

Please review FWH\samples\xbgrpsum.prg

It is not exactly what you are looking for but it may help you. Anyhow Rao is our xbrowse master and surely he will help you to fine tune exactly what you need :-)
regards, saludos

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

Re: Xbrowse class technical question

Postby horacio » Mon Dec 22, 2014 2:01 pm

He hecho algo parecido en xbrowse con un array

Image

http://i62.tinypic.com/2gtvjx4.jpg

Mira si te sirve, te posteo el código ...

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Xbrowse class technical question

Postby George » Mon Dec 22, 2014 3:26 pm

Antonio,
Thanks for your suggestion.
Already I had previously seen the code you mention as well the "testmerg.prg" code, but what I need is something like Horacio did.
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Xbrowse class technical question

Postby George » Mon Dec 22, 2014 3:30 pm

Horacio,
Gracias por responder mi email.
Exactamente algo como lo que tu hiciste es lo que necesito.
Por favor postea el codigo como lo sugieres en tu email.

Saludos y gracias,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Xbrowse class technical question

Postby horacio » Mon Dec 22, 2014 3:52 pm

Aquí el código, los datos los obtengo de una BBDD MySql.

Code: Select all  Expand view

//----------------------------------------------------------------------------//
Function TablaEmpleadosSubEmpresa()

    Local i
    Local oGr2_1
    Local oGr3_1
    Local oGr4_1
    Local oFont1
    Local oFont2
    Local oFont3
    Local oFont4
    Local oMenu
   Local oRBar
    Local oBtn1_2_1
    Local oBtn2_2_1
    Local oBtn1_3_1
    Local oBtn1_4_1
    Local aRowGrad  := { { .5, nRGB( 255, 255, 255 ), nRGB( 240, 240, 240 ) }, ;
                      { .5, nRGB( 240, 240, 240 ), nRGB( 232, 232, 232 ) } }
   Local aSelGrad    := { { .5, nRGB( 255, 255, 180 ), nRGB( 255, 237, 178 ) }, ;
                           { .5, nRGB( 255, 218, 103 ), nRGB( 255, 233, 162 ) } }
    Memvar oVarGlobales
   
    Define Font oFont1 Name 'Arial'  Size 0, -10 //Italic
    Define Font oFont2 Name 'Tahoma' Size 0, -09 Bold
    Define Font oFont3 Name 'Arial'  Size 0, -11 Bold //Italic
    Define Font oFont4 Name 'Timesw New Roman' Size 0, -10 Bold //Italic
   
    MsgRun( 'Leyendo datos, espere por favor ...',, { || BuscaLosDatos() } )
    oVarGlobales : oWndMain : SetMenu( MenuTablaLegajos() )
   
   Menu oMenu PopUp _2007
      MenuItem '&Todos...  ' Action( .t. )
      MenuItem '&Activos'    Action( .t. )
      MenuItem '&Licencia'   Action( .t. )
      MenuItem '&Baja'       Action( .t. )
   EndMenu

    Define Window oWndTree MdiChild Of oVarGlobales : oWndMain Color 0, CLR_WHITE NoSysMenu
   
        Define RibbonBar oRBar Window oWndTree Height 55 TopMargin 0 2010 Color RGB( 220, 235, 252 ) //ColorBox RGB( 218, 229, 243 ), RGB( 218, 229, 243 ) //CLR_HRED, CLR_HBLUE
        oRBar : nClrBoxOut := Rgb( 240, 240, 240 )
        oRBar : nClrBoxIn  := Rgb( 240, 240, 240 )
       
       Add Group oGr2_1 Ribbon oRBar TO Option 1 Prompt "volcado" Width 108 Gradiant { { 0.05, CLR_WHITE, CLR_WHITE }, { 0.9, 16777215, 12961221 } }
       @ 003, 003 Add Button  oBtn1_2_1 Prompt "" Bitmap "imagen02"  Group oGr2_1 Action  oBrw : Report( 'Listado de empleados por sub-empresas' ) Size 50, 25 Top Tooltip "Imprimir"
       @ 003, 054 Add Button  oBtn2_2_1 Prompt "" Bitmap "imagen130" Group oGr2_1 Action MsgRun( "Generando listado, espere por favor ... ",, { || oBrw : ToExcel() } ) Size 50, 25 Top Tooltip "Exportar a planilla de cálculo"

        Add Group oGr3_1 Ribbon oRBar TO Option 1 Prompt "filtros" Width 57 Gradiant { { 0.05, CLR_WHITE, CLR_WHITE }, { 0.9, 16777215, 12961221 } }
       @ 003, 003 Add Button  oBtn1_3_1 Prompt "" Bitmap "imagen08"   Group oGr3_1 Action  FiltrosPorCategorias() Size 50, 30 Popup Top Menu oMenu Tooltip 'Filtros'      
        //@ 003, 003 Add Button  oBtn1_3_1 Prompt "" Bitmap "imagen08" Group oGr3_1 Popup Menu _MenuFiltros() Action oVarCon : oWndCon : End() Size 50, 25 Top

       Add Group oGr4_1 Ribbon oRBar TO Option 1 Prompt "salir" Width 57 Gradiant { { 0.05, CLR_WHITE, CLR_WHITE }, { 0.9, 16777215, 12961221 } }
    @ 003, 003 Add Button oBtn1_4_1 Prompt "" Bitmap "imagen98" Group oGr4_1 Action oWndTree : End()  Size 50, 25 Top Tooltip 'Cerrar'
       
        @ 0, 0 xBrowse oBrw Of oWndTree
    oBrw : SetTree( oTree, { "#8083", "folder", "go" }, { || PonMensaje() } )
       Add To oBrw Data oBrw : oTreeItem : Cargo[ 01 ] Header "ESTADO"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 02 ] Header "CARGO"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 03 ] Header "Nº LEGAJO"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 04 ] Header "C. DESCRIP"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 05 ] Header "ANTIG."
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 06 ] Header "ALTA"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 07 ] Header "BAJA"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 08 ] Header "CARACT."
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 09 ] Header "CATEG."
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 10 ] Header "BRUTO"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 11 ] Header "NETO"
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 12 ] Header "NO REM."
    Add To oBrw Data oBrw : oTreeItem : Cargo[ 13 ] Header "DESC."
       With Object oBrw
            For i := 1 To Len( :aCols )
                Switch i
                    Case 1
                        :aCols[ i ] : oDataFont   := { || If( oBrw : oTreeItem : nLevel == 1, oFont3, If( oBrw : oTreeItem : nLevel == 2 .and. oBrw : oTreeItem : cPrompt == "TOTAL", oFont2, oFont1 ) ) }
                        :aCols[ i ] : oHeaderFont := oFont2
                        :aCols[ i ] : nWidth      := 250
                        Exit
                    Case 2
                   :aCols[ i ] : AddResource( 'd_ver' )
                        :aCols[ i ] : AddResource( 'd_roj' )
                     :aCols[ i ] : AddResource( 'd_ama' )  
                     :aCols[ i ] : AddResource( 'amas' )  
                        :aCols[ i ] : bBmpData      := { || BmpData( oBrw ) }
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ] : nWidth        := 80
                        Exit
                    Case 3
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ] : nWidth        := 50
                        Exit
                    Case 4
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        Exit
                    Case 5
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ] : nWidth        := 220
                        Exit
                    Case 6
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        :aCols[ i ] : nWidth        := 50
                        Exit
                    Case 7
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        :aCols[ i ] : nWidth        := 75
                        Exit
                    Case 8
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        :aCols[ i ] : nWidth        := 75
                        Exit
                    Case 9
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        :aCols[ i ] : nWidth        := 55
                        Exit
                    Case 10
                        :aCols[ i ] : oDataFont     := oFont1
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_CENTER
                        :aCols[ i ] : nWidth        := 45
                        Exit
                    Case 11
                        :aCols[ i ] : oDataFont     := oFont4
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_RIGHT
                        :aCols[ i ] : nWidth        := 65
                        Exit
                    Case 12
                        :aCols[ i ] : oDataFont     := oFont4
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_RIGHT
                        :aCols[ i ] : nWidth        := 65
                        Exit
                    Case 13
                        :aCols[ i ] : oDataFont     := oFont4
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_RIGHT
                        :aCols[ i ] : nWidth        := 65
                        Exit
                    Case 14
                        :aCols[ i ] : oDataFont     := oFont4
                        :aCols[ i ] : oHeaderFont   := oFont2
                        :aCols[ i ]  :nDataStrAlign := AL_RIGHT
                        :aCols[ i ] : nWidth        := 65
                        Exit
                EndSwitch                      
            Next
        :nRowHeight        := 23
          :nHeaderHeight     := 25
          :nFooterHeight     := 25
       :nColDividerStyle  := 5
       //:nRowDividerStyle  := 5
            :nMarqueeStyle     := MARQSTYLE_HIGHLROW
            :nColorPen         := Rgb( 225, 225, 255 )
            :nRecSelColor      := nRGB( 240, 240, 240 )
            :bClrSel           := { || { CLR_BLACK, RGB( 255, 255, 255 ) } }
            :bClrSelFocus      := { || { CLR_BLACK, aSelGrad } }
          :bClrRowFocus      := { || { CLR_BLACK, aRowGrad } }
            :bClrGrad          := { | lInvert | If( !lInvert,  { { 0.5, nRGB( 255, 255, 255 ), nRGB( 240, 240, 240 ) }, ;
                                                            { 0.5, nRGB( 240, 240, 240 ), nRGB( 232, 232, 232 ) } },;
                                                            { { 0.50, 12961221, 16777215 }, { 0.50, 16777215, 12961221 } } ) }
            :bClrHeader        := {|| { CLR_BLUE, nRGB( 245, 245, 245 ) } }
            :bClrFooter        := {|| { 0,16777215 } }
            :bRClicked         := { || oBrw : ToExcel() }
            :bKeyDown          := { | nKey | KeyArbol( nKey ) }
            :lFooter           := .t.
        :lRecordSelector   := .f.
        :lHScroll          := .f.
            :lColDividerComplete := .t.
       :nStretchCol       := STRETCHCOL_WIDEST
            :CreateFromCode()
        :aCols[ 1 ] : cHeader := "SUB-EMPRESA / EMPLEADO"
        :oWnd : bKeyDown := { | nKey | If( nKey == VK_ESCAPE, oWndTree : End(), ) }
    EndWith 
        oWndTree : oClient := oBrw

    Activate Window oWndTree Maximized On Init( oBrw : SetFocus() ) ;
                                     Valid ( oVarGlobales : oWndMain : SetMenu( MainMenu() ), oFont1 : End(), oFont2 : End(), oFont3 : End(), oFont4 : End(), .t. )
    /*
    Activate Window oWndTree Maximized On Paint( oWndTree :     SetFont( oFont3 ), DrawText( oWndTree : hDc, 'c:\la concha de la vaca\la puta que te pario', { 100, 100, 300, 285 }, DT_PATH_ELLIPSIS ) )
    */

    Return Nil 
   
//----------------------------------------------------------------------------//
Static Function MenuTablaLegajos()

    Local oMenu
   
    Menu oMenu _2007
    MenuItem "&Opciones"
    Menu
        EndMenu
    EndMenu
    Return oMenu   
   
   
//----------------------------------------------------------------------------//
Function PonMensaje()

    If( oBrw : oTreeItem : nLevel == 1 )
        //oSay : SetText( oBrw : oTreeItem : cPrompt )
        oBrw : aCols[ 1 ] : cFooter := oBrw : oTreeItem : cPrompt
        //oBrw : Refresh( .f. )
    End
    Return Nil
   
//----------------------------------------------------------------------------//
Function KeyArbol( nKey )

    Local oItem := oBrw : oTreeItem
   
    Switch nKey
        Case VK_RETURN
            //? oItem : Cargo[ 2 ], Valtype( oItem : Cargo[ 5 ] )
            Exit
    EndSwitch
    Return 0                               

//----------------------------------------------------------------------------//
Static Function BuscaLosDatos()

    Local i
    Local oRs
    Local cQuery
    Local nNetos
    Local nNoRem
    Local nBrutos
    Local nDescuen
    Memvar oVarGlobales
   
    Tree oTree
        For i := 1 To Len( oVarGlobales : aSubEmpresa )
            cQuery := 'select b.nombre, a.id_legajo, a.cargo, a.estado, a.alta, a.baja, a.anti_anios, a.anti_meses, a.c_cargo, a.caracter, a.categoria, ' +;
                         'bruto( a.id_legajo ), neto( a.id_legajo ), noremunerativo( a.id_legajo ), descuento( a.id_legajo ) ' +;
                         'from legajo a, padron b ' +;
                      'where a.id_empleado = b.id_empleado and a.id_empresa = ' + Alltrim( Str( oVarGlobales : nCodCol ) ) +;
                         ' and a.id_empresa1 = ' + Alltrim( Str( oVarGlobales : aSubEmpresa[ i ][ 2 ] ) ) + ' and a.estado = "NORMAL" order by b.nombre, a.id_legajo'
            Query( @oRs, cQuery )
            nBrutos  := 0
            nNetos   := 0
            nNoRem   := 0
            nDescuen := 0
            If( oRs : RecordCount # 0 )
                _TreeItem( oVarGlobales : aSubEmpresa[ i ][ 4 ] ) : Cargo := { Space( 15 ), Space( 10 ), Space( 10 ), Space( 50 ), Space( 10 ), Space( 20 ), Space( 20 ), Space( 20 ), Space( 10 ), Space( 10 ), Space( 10 ), Space( 10 ), Space( 10 ) }
                Tree
                    While( !oRs : Eof() )
                        If( oRs : Fields( 'estado' ) : Value # 'BAJA' )
                            _TreeItem( Space( 10 ) + oRs : Fields( 'nombre' ) : Value ) : Cargo := { oRs : Fields( 'estado' ) : Value,;
                                                                                                                            oRs : Fields( 'cargo' ) : Value,;
                                                                                                                             StrZero( oRs : Fields( 'id_legajo' ) : Value, 6 ),;
                                                                                                                             oRs : Fields( 'c_cargo' ) : Value,;
                                                                                                                             StrZero( oRs : Fields( 'anti_anios' ) : Value, 2 ) + '/' + StrZero( oRs : Fields( 'anti_meses' ) : Value, 2 ),;
                                                                                                                             If( Valtype( oRs : Fields( 'alta' ) : Value ) == 'D', oRs : Fields( 'alta' ) : Value, CToD( '' ) ),;
                                                                                                                             If( Valtype( oRs : Fields( 'baja' ) : Value ) == 'D', oRs : Fields( 'baja' ) : Value, CToD( '' ) ),;
                                                                                                                             oRs : Fields( 'caracter' ) : Value,;
                                                                                                                             oRs : Fields( 'categoria' ) : Value,;
                                                                                                                             Transform( oRs : Fields( 'bruto( a.id_legajo )' ) : Value, '@E 999,999,999.99' ),;
                                                                                                                             Transform( oRs : Fields( 'neto( a.id_legajo )' ) : Value, '@E 999,999,999.99' ),;
                                                                                                                             Transform( oRs : Fields( 'noremunerativo( a.id_legajo )' ) : Value, '@E 999,999,999.99' ),;
                                                                                                                             Transform( oRs : Fields( 'descuento( a.id_legajo )' ) : Value, '@E 999,999,999.99' ) }        
                        Else
                            _TreeItem( Space( 10 ) + oRs : Fields( 'nombre' ) : Value ) : Cargo := { oRs : Fields( 'estado' ) : Value, oRs : Fields( 'cargo' ) : Value, StrZero( oRs : Fields( 'id_legajo' ) : Value, 6 ), oRs : Fields( 'c_cargo' ) : Value, StrZero( oRs : Fields( 'anti_anios' ) : Value, 2 ) + '/' + StrZero( oRs : Fields( 'anti_meses' ) : Value, 2 ), If( Valtype( oRs : Fields( 'alta' ) : Value ) == 'D', oRs : Fields( 'alta' ) : Value, CToD( '' ) ), If( Valtype( oRs : Fields( 'baja' ) : Value ) == 'D', oRs : Fields( 'baja' ) : Value, CToD( '' ) ), oRs : Fields( 'caracter' ) : Value, oRs : Fields( 'categoria' ) : Value, Transform( 0.00, '@E 999,999,999.99' ), Transform( 0.00, '@E 999,999,999.99' ), Transform( 0.00, '@E 999,999,999.99' ), Transform( 0.00, '@E 999,999,999.99' ) }         
                        End
                        nBrutos  += oRs : Fields( 'bruto( a.id_legajo )' ) : Value
                        nNetos   += oRs : Fields( 'neto( a.id_legajo )'  ) : Value
                        nNoRem   += oRs : Fields( 'noremunerativo( a.id_legajo )' ) : Value
                        nDescuen += oRs : Fields( 'descuento( a.id_legajo )' ) : Value
                        oRs : MoveNext()
                    Enddo
                    _TreeItem( Space( 10 ) + 'TOTAL' ) : Cargo := { Space( 15 ), Space( 10 ), Space( 10 ), Space( 50 ), Space( 10 ), Space( 20 ), Space( 20 ), Space( 20 ), Space( 10 ), Transform( nBrutos, '@E 999,999,999.99' ), Transform( nNetos, '@E 999,999,999.99' ), Transform( nNoRem, '@E 999,999,999.99' ), Transform( nDescuen, '@E 999,999,999.99' ) }
                EndTree 
            End
            oRs : Close()
        Next i
    EndTree
    Return oTree
   
//----------------------------------------------------------------------------//
Static Function BmpData()

    Local nBmp  := 1

    /*If( Empty( oBrw : oTreeItem : cargo[ 1 ] ) )
        Return  */

    If( oBrw : oTreeItem : nLevel == 1 )
        nBmp := 4
    ElseIf( Alltrim( oBrw : oTreeItem : cargo[ 1 ] ) == 'NORMAL' )
        nBmp := 1
    ElseIf( Alltrim( oBrw : oTreeItem : cargo[ 1 ] ) == 'LICENCIA' )
        nBmp := 3
    ElseIf( Alltrim( oBrw : oTreeItem : cargo[ 1 ] ) == 'BAJA' )
        nBmp := 2
    Else
        nBmp := 4
    End                                
    Return nBmp
   
//-------------------------------------------------------------------------//
Function BuscaElCargo( oRs )
   
    Local oRec
    Local cDescrip := ''
    Local cQuery := "select descrip from cargos where nomencla = '" + Alltrim( oRs : Fields( 'cargo'  ) : Value ) + "'"
       
    Return cDescrip
    Query( @oRec, cQuery )
    If( oRec : RecordCount # 0 )
        cDescrip := oRec : Fields( 'descrip' ) : Value
    End
    oRec : Close()
    Return( cDescrip )
   
//----------------------------------------------------------------------------//
Function FiltrosPorCategorias() 

    Return 0
 


Cualquier duda preguntame.

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Xbrowse class technical question

Postby George » Mon Dec 22, 2014 3:57 pm

Gracias Horacio!
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Xbrowse class technical question

Postby nageswaragunupudi » Sat Dec 27, 2014 4:13 pm

The screen-shot posted first can be achieved either through Tree or simple array. Tree allows the user greater flexibility of viewing the summary and/or details. (Drill-down view)

Here is a sample program using Tree. This sample uses CUSTOMER.DBF and STATES.DBF in the fwh\samples folder. Creates a Tree with States as groups and Cities as detail items. This sample assumes fwh is installed in c:\fwh\ folder. If your fwh is installed in a different folder you need to change the static variable cFwhPath to your installation path.

This sample shows:
1) Creation of tree with group totals and grand totals.
2) Browse the tree:
(a) When a group item ( State ) is collapsed, group totals are displyed in the same row.
(b) When the group item is expanded, the totals are shown at the bottom of the list.
(c) The values in columns 3 and 4 can be edited in line with fastedit
(d) When the values are edited,
(i) the group subtotals and grand totals are automatically updated
(ii) Corresponding fields in the customer.dbf are also modified.

Code: Select all  Expand view

#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

//----------------------------------------------------------------------------//

REQUEST DBFCDX

static cFwhPath   := "c:\\fwh\\"

//----------------------------------------------------------------------------//

function Main()

   BrowseTree( MakeTree() )

return (0)

//----------------------------------------------------------------------------//

init procedure PrgInit

   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO "HH:MM:SS"
   SET EPOCH TO YEAR(DATE())-50

   SET DELETED ON
   SET EXCLUSIVE OFF

   RDDSETDEFAULT( "DBFCDX" )

   XbrNumFormat( 'E', .t. )
   SetKinetic( .f. )
   SetGetColorFocus()
   SetBalloon( .t. )

return

//----------------------------------------------------------------------------//

static function MakeTree()

   field STATE,CODE,CITY

   local cPath    := cFwhPath + "samples\\"
   local oTree, oState, oCity

   USE ( cPath + "STATES" ) NEW SHARED
   INDEX ON CODE TAG CODE TO STMP MEMORY
   USE ( cPath + "CUSTOMER" ) NEW ALIAS CUST SHARED
   INDEX ON STATE+CITY TAG STATE TO CTMP MEMORY
   SET RELATION TO STATE INTO STATES
   GO TOP

   TREE oTree
   oTree:Cargo    := { "", 0, 0.00, 0 }
   do while ! CUST->( eof() )
      TREEITEM oState PROMPT STATES->NAME CARGO { CTOD( "" ), 0, 0.00, 0 }
      TREE
         do while STATES->NAME == oState:cPrompt .and. ! CUST->( eof() )
            TREEITEM oCity PROMPT CUST->CITY ;
               CARGO { CUST->HIREDATE, CUST->AGE, CUST->SALARY, CUST->( RECNO() ) }
            oState:Cargo[ 2 ]    += oCity:Cargo[ 2 ]
            oState:Cargo[ 3 ]    += oCity:Cargo[ 3 ]
            CUST->( DbSkip( 1 ) )
         enddo
         TREEITEM "Sub-Total" CARGO oState:Cargo
         oTree:Cargo[ 2 ]  += oState:Cargo[ 2 ]
         oTree:Cargo[ 3 ]  += oState:Cargo[ 3 ]
      ENDTREE

   enddo
   ENDTREE

return oTree

//----------------------------------------------------------------------------//

static function BrowseTree( oTree )

   local oDlg, oBrw, oFont
   local nGrpClr     := RGB(255,250,220)
   local nTotClr     := RGB(200,255,200)

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 620,700 PIXEL FONT oFont ;
      TITLE "EDITABLE TREE BROWSE WITH SUBTOTALS"

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE oTree ;
      COLUMNS 1, 2, 3 ;
      HEADERS "State/City", "HireDate", "Number", "Salary" ;
      PICTURES nil, nil, nil, NumPict ( 12, 2 ) ;
      CELL LINES FOOTERS FASTEDIT NOBORDER

   WITH OBJECT oBrw
      :nStretchCol         := 1
      :lDisplayZeros       := .f.
      :bChange             := { || CUST->( DBGOTO( oBrw:oTreeItem:Cargo[ 4 ] ) ) }
      :bLock               := { || CUST->( RLOCK() ) }
      :bUnLock             := { || CUST->( DBUNLOCK() ) }

      :bClrStd             := { || { CLR_BLACK, If( oBrw:oTreeItem:nLevel == 1, nGrpClr, ;
                                                If( oBrw:oTreeItem:cPrompt == "Sub-Total", nTotClr, ;
                                                CLR_WHITE ) ) } }
      // Bitmaps
      WITH OBJECT :aCols[ 1 ]
         :AddBitmap( {  FWRArrow(), FWDArrow(), cFwhPath + "bitmaps\16x16\reset.bmp" } )
         :cFooter          := "GRAND TOTAL"
      END
      // When Group is closed show totals. When open show totals at bottom
      // Allow edit of columns and save data to DBF, update group and grand totals
      WITH OBJECT :aCols[ 3 ]
         :bEditValue       := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
                                    If( x == nil, oBrw:oTreeItem:Cargo[ 2 ], ;
                                    CUST->AGE := oBrw:oTreeItem:Cargo[ 2 ] := x ) ) }
         :nTotal           := oTree:Cargo[ 2 ]
         //
         :nEditType        := EDIT_GET
         :bEditWhen        := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
         :bOnChange        := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 2 ] += ( o:Value - nOld ), oBrw:Refresh() }
      END
      WITH OBJECT :aCols[ 4 ]
         :bEditValue       := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
                                    If( x == nil, oBrw:oTreeItem:Cargo[ 3 ], ;
                                    CUST->SALARY := oBrw:oTreeItem:Cargo[ 3 ] := x ) ) }
         :nTotal           := oTree:Cargo[ 3 ]
         //
         :nEditType        := EDIT_GET
         :bEditWhen        := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
         :bOnChange        := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 3 ] += ( o:Value - nOld ), oBrw:Refresh() }
      END
      //
      :CreateFromCode()
   END

   Eval( oBrw:bChange )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Xbrowse class technical question

Postby George » Sat Dec 27, 2014 6:19 pm

Thanks Mr. Rao for your sample code.

Regards,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Xbrowse class technical question

Postby Silvio.Falconi » Sun Dec 28, 2014 10:46 pm

Mr Nages,

I tried to modify your test with my databases

In Italy we have regions, Provinces and Cities

In this Picture you can see the customer for Regions

Image


I'll like show the customer also for Provinces or for another field with a combobox I insert on top of the dialog and refresh the xbrowse on select .... how I can male it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowse class technical question

Postby nageswaragunupudi » Mon Dec 29, 2014 3:42 am

Do you want to show a 4 level tree like this?

Region
-- Province
-- -- City
-- -- -- Customer

?

What variable/field do you want to use combobox?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Xbrowse class technical question

Postby Silvio.Falconi » Wed Dec 31, 2014 6:36 pm

I sent you my dbfs :

customers (clienti.dbf)
---------------------------------------------
States ( stati.dbf)
Regions ( regioni.dbf)
City ( comuni.dbf) on this there are symbols of provinces and Code postal - the first code of dbf is to calc a Italy code fiscal
Provinces ( province.dbf) on this there are symbols of provinces

I wish a combo or a menu with :
"Nazione " -> state
"Regione" -> Region
"Provincia" -> Provinces
"Cap" -> Postal code
"Listino" -> field cllistino
"Pagamento" -> field clcodpag

thanks
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7033
Joined: Thu Oct 18, 2012 7:17 pm

Re: Xbrowse class technical question

Postby Marc Venken » Wed May 08, 2019 6:26 pm

nageswaragunupudi wrote:The screen-shot posted first can be achieved either through Tree or simple array. Tree allows the user greater flexibility of viewing the summary and/or details. (Drill-down view)

Here is a sample program using Tree. This sample uses CUSTOMER.DBF and STATES.DBF in the fwh\samples folder. Creates a Tree with States as groups and Cities as detail items. This sample assumes fwh is installed in c:\fwh\ folder. If your fwh is installed in a different folder you need to change the static variable cFwhPath to your installation path.

This sample shows:
1) Creation of tree with group totals and grand totals.
2) Browse the tree:
(a) When a group item ( State ) is collapsed, group totals are displyed in the same row.
(b) When the group item is expanded, the totals are shown at the bottom of the list.
(c) The values in columns 3 and 4 can be edited in line with fastedit
(d) When the values are edited,
(i) the group subtotals and grand totals are automatically updated
(ii) Corresponding fields in the customer.dbf are also modified.

Code: Select all  Expand view

#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

//----------------------------------------------------------------------------//

REQUEST DBFCDX

static cFwhPath   := "c:\\fwh\\"

//----------------------------------------------------------------------------//

function Main()

   BrowseTree( MakeTree() )

return (0)

//----------------------------------------------------------------------------//

init procedure PrgInit

   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO "HH:MM:SS"
   SET EPOCH TO YEAR(DATE())-50

   SET DELETED ON
   SET EXCLUSIVE OFF

   RDDSETDEFAULT( "DBFCDX" )

   XbrNumFormat( 'E', .t. )
   SetKinetic( .f. )
   SetGetColorFocus()
   SetBalloon( .t. )

return

//----------------------------------------------------------------------------//

static function MakeTree()

   field STATE,CODE,CITY

   local cPath    := cFwhPath + "samples\\"
   local oTree, oState, oCity

   USE ( cPath + "STATES" ) NEW SHARED
   INDEX ON CODE TAG CODE TO STMP MEMORY
   USE ( cPath + "CUSTOMER" ) NEW ALIAS CUST SHARED
   INDEX ON STATE+CITY TAG STATE TO CTMP MEMORY
   SET RELATION TO STATE INTO STATES
   GO TOP

   TREE oTree
   oTree:Cargo    := { "", 0, 0.00, 0 }
   do while ! CUST->( eof() )
      TREEITEM oState PROMPT STATES->NAME CARGO { CTOD( "" ), 0, 0.00, 0 }
      TREE
         do while STATES->NAME == oState:cPrompt .and. ! CUST->( eof() )
            TREEITEM oCity PROMPT CUST->CITY ;
               CARGO { CUST->HIREDATE, CUST->AGE, CUST->SALARY, CUST->( RECNO() ) }
            oState:Cargo[ 2 ]    += oCity:Cargo[ 2 ]
            oState:Cargo[ 3 ]    += oCity:Cargo[ 3 ]
            CUST->( DbSkip( 1 ) )
         enddo
         TREEITEM "Sub-Total" CARGO oState:Cargo
         oTree:Cargo[ 2 ]  += oState:Cargo[ 2 ]
         oTree:Cargo[ 3 ]  += oState:Cargo[ 3 ]
      ENDTREE

   enddo
   ENDTREE

return oTree

//----------------------------------------------------------------------------//

static function BrowseTree( oTree )

   local oDlg, oBrw, oFont
   local nGrpClr     := RGB(255,250,220)
   local nTotClr     := RGB(200,255,200)

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 620,700 PIXEL FONT oFont ;
      TITLE "EDITABLE TREE BROWSE WITH SUBTOTALS"

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE oTree ;
      COLUMNS 1, 2, 3 ;
      HEADERS "State/City", "HireDate", "Number", "Salary" ;
      PICTURES nil, nil, nil, NumPict ( 12, 2 ) ;
      CELL LINES FOOTERS FASTEDIT NOBORDER

   WITH OBJECT oBrw
      :nStretchCol         := 1
      :lDisplayZeros       := .f.
      :bChange             := { || CUST->( DBGOTO( oBrw:oTreeItem:Cargo[ 4 ] ) ) }
      :bLock               := { || CUST->( RLOCK() ) }
      :bUnLock             := { || CUST->( DBUNLOCK() ) }

      :bClrStd             := { || { CLR_BLACK, If( oBrw:oTreeItem:nLevel == 1, nGrpClr, ;
                                                If( oBrw:oTreeItem:cPrompt == "Sub-Total", nTotClr, ;
                                                CLR_WHITE ) ) } }
      // Bitmaps
      WITH OBJECT :aCols[ 1 ]
         :AddBitmap( {  FWRArrow(), FWDArrow(), cFwhPath + "bitmaps\16x16\reset.bmp" } )
         :cFooter          := "GRAND TOTAL"
      END
      // When Group is closed show totals. When open show totals at bottom
      // Allow edit of columns and save data to DBF, update group and grand totals
      WITH OBJECT :aCols[ 3 ]
         :bEditValue       := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
                                    If( x == nil, oBrw:oTreeItem:Cargo[ 2 ], ;
                                    CUST->AGE := oBrw:oTreeItem:Cargo[ 2 ] := x ) ) }
         :nTotal           := oTree:Cargo[ 2 ]
         //
         :nEditType        := EDIT_GET
         :bEditWhen        := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
         :bOnChange        := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 2 ] += ( o:Value - nOld ), oBrw:Refresh() }
      END
      WITH OBJECT :aCols[ 4 ]
         :bEditValue       := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
                                    If( x == nil, oBrw:oTreeItem:Cargo[ 3 ], ;
                                    CUST->SALARY := oBrw:oTreeItem:Cargo[ 3 ] := x ) ) }
         :nTotal           := oTree:Cargo[ 3 ]
         //
         :nEditType        := EDIT_GET
         :bEditWhen        := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
         :bOnChange        := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 3 ] += ( o:Value - nOld ), oBrw:Refresh() }
      END
      //
      :CreateFromCode()
   END

   Eval( oBrw:bChange )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//
 


Image


Can this example also be expanded with the options that the GETBAR of xbrowse can be used?

I would like to adapt this program with the getbar option, so that from a huge database, a selection of record's is done (wildseek) and the this program will make a nice summary like above.

In this example above, i would be nice if it was possible with all record/state that has the words "PARK" insite the state/city. and than the view
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Xbrowse class technical question

Postby nageswaragunupudi » Thu May 09, 2019 12:07 pm

Mr. Marc

I guess you want to do this with MySql databases.
That is a lot simpler than DBFs.
I posted some sample using GROUP BY and ROLLUP. Please search and look into those samples
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Xbrowse class technical question

Postby Marc Venken » Thu May 09, 2019 12:49 pm

nageswaragunupudi wrote:Mr. Marc

I guess you want to do this with MySql databases.
That is a lot simpler than DBFs.
I posted some sample using GROUP BY and ROLLUP. Please search and look into those samples


In fact... It's just dbf that I want to use ))

I think of a workaround that I use Xbrowse for the selection and from xbrowse save/create a tmp dbf with the result and use that dbf for the sample from you.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 45 guests