FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour xBrowse + SetTree() + TDolphin
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM
xBrowse + SetTree() + TDolphin
Posted: Thu Nov 08, 2012 02:28 PM

Gente;
alguien que me pueda brindar un ejemplo sencillo.
gracias

Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM
Re: xBrowse + SetTree() + TDolphin
Posted: Thu Nov 08, 2012 03:20 PM
Esto es lo que hago, aunque me da error (seguramente porque no entiendo el concepto)
Code (fw): Select all Collapse
   // Browse Obras
   oQryOb:= oConx:SelectObras()
   oTree := ::MakeTree( oQryOb )

   @ 0, 0 XBROWSE oBrwOb COLUMNS "desc_tipo","desc_obra" OBJECT oQryOb OF ::aoMn[_OL2003]:aDialogs[1] SIZE ::aoMn[_OL2003]:aDialogs[ 1 ]:nWidth-2, 250 PIXEL

   oBrwOb:SetTree( oTree,                      ; // Tree object
                   { "OPEN","CLOSE","GREEN" }  ) // [Optional] Bitmap Resources Open, Close and NoChildren

   ADD TO oBrwOb DATA oBrwOb:oTreeItem:Cargo[ 1 ]
   ADD TO oBrwOb DATA oBrwOb:oTreeItem:Cargo[ 2 ]

   WITH OBJECT oBrwOb
      :lHScroll:= FALSE

      :CreateFromCode()
   END

...
//
METHOD MakeTree( oQryOb ) CLASS Menues
   local oTree
   local cState

   oQryOb:GoTop()
   TREE oTree
   while !oQryOb:Eof()
      if oQryOb:desc_tipo == cState
         _TreeItem( oQryOb:desc_tipo ):Cargo := { oQryOb:desc_obra }
      else
         if cState != nil
            ENDTREE
         endif
         _TreeItem( oQryOb:desc_tipo ):Cargo := { oQryOb:desc_obra }
         cState   := oQryOb:desc_tipo
         TREE
      endif
      oQryOb:Skip( 1 )
   enddo
   ENDTREE
   ENDTREE
   oQryOb:GoTop()

   return( oTree )
// Fin

el error:
    Descripción de Error generado:
    ___________________________________________________

    Error BASE/1005 Class: 'NIL' has no property: OPREV
    Args:
    [ 1] = U
    [ 2] = O TTREEITEM


    Llamadas al Stack:
    ___________________________________________________

    Llamado desde: _OPREV(0)
    Llamado desde: .\source\classes\TREES.PRG TREEEND(72)
    Llamado desde: D:\Fuen32\SiGIC\CI2\Source\Menues.prg MENUES:MAKETREE(138)
    Llamado desde: D:\Fuen32\SiGIC\CI2\Source\Menues.prg MENUES:CREATEMENUPPL(63)
    Llamado desde: D:\Fuen32\SiGIC\CI2\Source\CtrlPpl.prg CONTROLADORPPL:CONCEPTOMENUES(56)
    Llamado desde: D:\Fuen32\SiGIC\CI2\Source\CI2_Main.prg (b)MGMAIN(36)
    Llamado desde: .\source\classes\WINDOW.PRG TWINDOW:ACTIVATE(973)
    Llamado desde: D:\Fuen32\SiGIC\CI2\Source\CI2_Main.prg MGMAIN(36)
    [/list:u]
Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: xBrowse + SetTree() + TDolphin
Posted: Tue Nov 13, 2012 01:00 PM

Hola Mario

podrias colocarnos un ejemplo autocontenido que podamos construir para probar lo que estas haciendo...

gracias

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: xBrowse + SetTree() + TDolphin
Posted: Tue Nov 13, 2012 01:59 PM
Mario

aqui tienes un ejemplo funcional tomado de los samples de fivewin, donde cambio el uso de ADO por Dolphin

Code (fw): Select all Collapse
#INCLUDE "fivewin.ch"

FUNCTION Main()

   LOCAL oTest := TestTree():New()

   oTest:Run()
   
  
RETURN NIL


CLASS TestTree

   DATA oWnd
   DATA oCon
   DATA oRs

   METHOD New()
   
   METHOD MainMenu()
   
   METHOD Run()
   
   METHOD TreeBrowse(n)   
   METHOD MakeTree(n)
   METHOD TDolphinGetTotals()
   
   METHOD TDolphinGetsummary()
   METHOD ConnectToDolphin()

ENDCLASS


METHOD TestTree:New()


   DEFINE WINDOW ::oWnd MDI ;
      TITLE "Test Xbrowse" ;
      MENU ::MainMenu()
      
   SET MESSAGE OF ::oWnd TO "Testing XBrowse" 2010   

RETURN Self


METHOD TestTree:Run()
 
   ACTIVATE WINDOW ::oWnd

RETURN NIL

METHOD TestTree:MainMenu()

   LOCAL oMenu, oSelf := Self

   MENU oMenu 2010
         MENUITEM "Tree Browse"
         MENU
            MENUITEM "Method,1"      ACTION oSelf:TreeBrowse( 1 )
            MENUITEM "Method.2"      ACTION oSelf:TreeBrowse( 2 )
         ENDMENU

      oMenu:AddMdi()

   ENDMENU

RETURN oMenu

METHOD TestTree:TreeBrowse( nMethod )

   LOCAL oTree, oItem, oBold, oBrw, oRs, oRsTot, oWnd

   oRs = ::TDolphinGetsummary()
      
   oTree = ::MakeTree( oRs, nMethod )
   oItem = oTree:oFirst
   
   // Setup Browse

   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
   DEFINE WINDOW oWnd MDICHILD OF ::oWnd() ;
      TITLE If( nMethod == 1, ;
                "Tree Browse with data", ;
                "Tree Browse with data from Linked Recordset" )

   @ 0,0 XBROWSE oBrw OF oWnd LINES CELL

   if nMethod == 1
      oBrw:SetTree( oTree,           ; // Tree object
         { "OPEN","CLOSE","GREEN" }  ) // [Optional] Bitmap Resources Open, Close and NoChildren

      ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] PICTURE "9999" HEADER "Employees"
      ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] PICTURE "999,999,999.99" HEADER "TotSalary"
      ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] / oBrw:oTreeItem:Cargo[ 1 ] ;
            PICTURE "999,999,999.99" HEADER "AvgSalary"

   else
      oBrw:SetTree( oTree,           ; // Tree object
         { "OPEN","CLOSE","GREEN" }, ; // [Optional] Bitmap Resources Open, Close and NoChildren
         { | OItem | oRs:nRecNo := oItem:Cargo } ) // To Sync DataSource with oItem

     ADD TO oBrw DATA oRs:employees PICTURE "9999" HEADER "Employees"
     ADD TO oBrw DATA oRs:totSalary PICTURE "999,999,999.99" HEADER "TotSalary"
     ADD TO oBrw DATA oRs:totSalary / oRs:employees ;
            PICTURE "999,999,999.99" HEADER "AvgSalary"

   endif

   oBrw:aCols[ 1 ]:cHeader         := "State / City"
   // If different fonts are required on the basis of oItem:nLevel
   AEval( oBrw:aCols, { |oCol| oCol:oDataFont := { || If( oBrw:oTreeItem:nLevel == 1, oBold, oBrw:oFont ) } } )

   // Get Totals for footers
   oRsTot            := ::TDolphinGetTotals()

   // Set Totals in Footers
   oBrw:lFooter      := .t.
   oBrw:aCols[ 1 ]:cFooter := "Total"
   oBrw:aCols[ 2 ]:cFooter := oRsTot:FieldGet( 1 )
   oBrw:aCols[ 3 ]:cFooter := oRsTot:FieldGet( 2 )
   oBrw:aCols[ 4 ]:cFooter := oRsTot:FieldGet( 2 ) / oRsTot:FieldGet( 1 )
   oRsTot:End()
   // note: cFooter can be of any data type. If cFooter is not Character,
   // the value will be formatted using column's picture
   // cFooter can be a codeblock also
   AEval( oBrw:aCols, { |oCol| oCol:oFooterFont := oBold } )

   oBrw:MakeTotals()
   oBrw:createFromCode()
   oWnd:oClient := obrw

   // Create ButtonBar
   //BtnBar( oBrw )    // Commn ButtonBar for all sample Browses

//   DEFINE BUTTON OF oWnd:oBar ;
//      RESOURCE "EXPAND" TOP PROMPT "Expand ALL" ;
//      ACTION ( oBrw:Expand(), oBrw:Refresh(), oBrw:SetFocus() )
//
//   DEFINE BUTTON OF oWnd:oBar ;
//      RESOURCE "COLLAPS" TOP PROMPT "Collapse ALL" ;
//      ACTION ( oBrw:Collapse(), oBrw:Refresh(), oBrw:SetFocus() )

   SET MESSAGE OF oWnd TO oWnd:cCaption 2007
   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus() VALID (oRs:End(), .T.)

RETURN NIL

METHOD TestTree:TDolphinGetsummary

   LOCAL oRs, csql

   cSql := ;
   "SELECT state,city, COUNT(*) AS EMPLOYEES, SUM(salary) AS totsalary " + ;
   "FROM customer " + ;
   "GROUP BY state, city " + ;
   "UNION ALL " + ;
   "SELECT state, '' AS city, employees, totsalary FROM " + ;
   "(SELECT state, COUNT(*) AS employees, SUM(salary) AS totsalary " + ;
   "FROM customer " + ;
   "GROUP BY state ) t_b2 " + ;
   "ORDER BY state, city "
   
   IF ::oCon == NIL
      ::oCon = ::ConnectToDolphin()
   ENDIF

   IF ! ::oCon:lError
      oRs = ::oCon:Query( cSql )
      IF ::oCon:lError 
         MsgInfo('Access Table Open Failure')
         RETURN NIL
      ENDIF
   ELSE
      MsgInfo( "Access Connect Fail" )
   ENDIF

RETURN oRs

METHOD TestTree:ConnectToDolphin()

   LOCAL oCon
   LOCAL cHost := "dolphintest.sitasoft.net"
   LOCAL cUser := "test_dolphin"
   LOCAL cPass := "123456"
   LOCAL cDB   := "dolphin_man"
   
   oCon = TDolphinSrv():New( cHost, cUser, cPass, , , cDB )

RETURN oCon



METHOD TestTree:MakeTree( oRs, nMethod )

   local oTree
   local cState

   oRs:GoTop()
   TREE oTree
   do while !oRs:Eof()
      if oRs:state == cState
         if nMethod == 1
            _TreeItem( oRs:city ):Cargo := ;
               { oRs:employees, ;
                 oRs:totSalary  ;
               }
         else
            _TreeItem( Trim( oRs:city ) ):Cargo := oRs:RecNo()
         endif
      else
         if cState != nil
            ENDTREE
         endif
         if nMethod == 1
            _TreeItem( oRs:state ):Cargo := ;
               { oRs:employees, ;
                 oRs:totSalary  ;
               }
         else
            _TreeItem( oRs:state ):Cargo := oRs:RecNo()
         endif
         cState   := oRs:state
         TREE
      endif
      oRs:Skip()
   enddo
   ENDTREE
   ENDTREE
   oRs:GoTop()

return oTree

METHOD TestTree:TDolphinGetTotals()

   local oRs, csql

   cSql := ;
   "SELECT COUNT(*) AS employees, SUM(salary) AS totsalary FROM customer"

   IF ! ::oCon:lError
      oRs = ::oCon:Query( cSql )
      IF ::oCon:lError 
         MsgInfo('Access Table Open Failure')
         RETURN NIL
      ENDIF
   ELSE
      MsgInfo( "Access Connect Fail" )
   ENDIF

return oRs
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM
Re: xBrowse + SetTree() + TDolphin
Posted: Tue Nov 13, 2012 03:13 PM

Daniel;
muchas gracias! (justo estaba rehaciendo un sample con la DATABASE Tdolphin)
Lo pruebo... (bue... no tengo dudas que que ahora si funcionará)
Saludos

Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina

Continue the discussion