#include 'fivewin.ch'
#include 'xbrowse.ch'
#include "report.ch"
REQUEST DBFCDX
static lType1 := .f.
Function Main()
local cDir:=".\data\"
RDDSETDEFAULT( "DBFCDX" )
SET DATE ITALIAN
SET CENTURY ON
FwNumFormat( 'E', .t. )
SetGetColorFocus()
USE &(cdir+"Customer") NEW EXCLUSIVE ALIAS DB
INDEX ON Upper(First) TAG FIRST FOR !Deleted()
INDEX ON Upper(Last) TAG LAST FOR !Deleted()
INDEX ON Upper(City) TAG CITY FOR !Deleted()
INDEX ON Upper(State) TAG STATE FOR !Deleted()
INDEX ON Upper(State)+Upper(First) TAG STATEFIRST FOR !Deleted()
CLOSE DB
Customer()
return nil
function Customer()
local oDlg, oBrw, oFont,oBold
local cSeek:=Space(100)
local oSay:=array(2)
local oGet
local nWd := GetSysMetrics(0) * .58
local nHt := (GetSysMetrics(1) / 2 ) -20
local aCols := { ;
{ "FIRST", "First" ,, 120, },;
{ "LAST", "Last" ,, 120, },;
{ "STREET", "Address" ,, 150, },;
{ "CITY", "City" ,, 100, },;
{ "STATE", "State" ,, 80, } }
oDbf:=TCustomer():New()
oDbf:SetOrder(1)
oDbf:Gotop()
DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -14
DEFINE FONT oBold NAME 'Tahoma' SIZE 0, -14 BOLD
DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL ;
TITLE "Demo Customer xbrowsetree" COLOR CLR_BLACK, nRGB( 245,245,235)
@ 12,15 say oSay[1] Prompt "Search " SIZE 46,24 PIXEL OF oDlg FONT oBold TRANSPARENT
@ 10, 75 GET oGet VAR cSeek SIZE 200,21 PIXEL OF oDlg PICTURE "@!"
@ 12,290 say oSay[2] Prompt "in" SIZE 20,24 PIXEL OF oDlg FONT oBold TRANSPARENT
@ 60,20 XBROWSE oBrw OF oDlg SIZE -10,-40 PIXEL ;
DATASOURCE oDbf COLUMNS aCols ;
AUTOSORT FONT oFont;
NOBORDER CELL LINES
WITH OBJECT oBrw
:SetMultiSelectCol()
:nRowHeight := 25
:l2007 := .F.
:l2015 := .T.
:lRecordSelector := .F.
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nStretchCol := STRETCHCOL_WIDEST
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:lDrawBorder := .t.
:nClrBorder := Rgb(195,195,185)
:bClrStd := { || { CLR_BLACK, If( oBrw:KeyNo % 2 == 0, CLR_WHITE,CLR_HGRAY ) } }
:lIncrFilter := .t.
:bOnSort := { |b,oCol| oBrw:Seek( "" ), ;
oBrw:cFilterFld := oCol:cExpr, ;
oBrw:SetFocus() }
:oSeek := oGet
:CreateFromCode()
END
* xbrowser oBrw:oSortCbx:aItems
* aadd(oBrw:oSortCbx:aItems ,{ "Starting With", "Containing" } )
@ 10, 330 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder;
SIZE 150,400 PIXEL OF oDlg HEIGHTGET 18 STYLE CBS_DROPDOWN
//----------------------------------//
@ 10, 500 BTNBMP oGroup Prompt "Group on" ;
FLAT SIZE 80, 24 OF oDlg PIXEL ;
RIGHT NOROUND;
ACTION ::ShowPopUp( { |oBtn| BtnPop( oBrw,oDbf,oGet) } )
//----------------------------------//
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont, oBold
RETURN NIL
//------------------------------------------------------------------------------//
Function BtnPop(oBrw,oDbf,oGet)
local oItem1,oItem2
MENU oMenu POPUP
MENUITEM oItem1 PROMPT "On State" ;
ACTION (lType1 := !lType1,;
( Iif( lType1,Maketree(oBrw,oDbf,oGet),;
MakeBrowse(oBrw,oDbf,oGet) )))
oItem1:SetCheck(lType1)
ENDMENU
RETURN oMenu
//---------------------------------------------------------------//
Function Maketree(oBrw,oDbf,oGet)
local cSeek:=Space(100)
local aCols := { ;
{ "STATE", "State" ,, 80, },;
{ "FIRST", "First" ,, 120, },;
{ "LAST", "Last" ,, 120, },;
{ "STREET", "Address" ,, 150, },;
{ "CITY", "City" ,, 100, } }
/* local aCols := { ;
{ "FIRST", "First" ,, 120, },;
{ "LAST", "Last" ,, 120, },;
{ "STREET", "Address" ,, 150, },;
{ "CITY", "City" ,, 100, },;
{ "STATE", "State" ,, 80, } }
*/
oDbf:SetOrder("State") //state
oDbf:Gotop()
oBrw:ResetData( oDbf,aCols )
WITH OBJECT oBrw
:nStretchCol := 1
:SetTree()
:oTree:OpenAll()
:lDisplayZeros := .f.
:lIncrFilter := .t.
:bOnSort := { |b,oCol| oBrw:Seek( "" ), ;
oBrw:cFilterFld := oCol:cExpr, ;
oBrw:SetFocus() }
:oSeek := oGet
:bSeek := { |c| uSeekTree( oBrw, Upper(c),oDbf ) }
:bClrStd := { || { CLR_BLACK, If( oBrw:oTreeItem:oTree == nil, CLR_WHITE, CLR_YELLOW ) } }
:CreateFromCode()
END
return nil
//----------------------------------------------------------------------//
Function MakeBrowse(oBrw,oDbf,oGet)
local aCols := { ;
{ "FIRST", "First" ,, 120, },;
{ "LAST", "Last" ,, 120, },;
{ "STREET", "Address" ,, 150, },;
{ "CITY", "City" ,, 100, },;
{ "STATE", "State" ,, 80, } }
oDbf:Setorder(1)
oDbf:Gotop()
oBrw:ResetData( oDbf,aCols )
WITH OBJECT oBrw
:SetMultiSelectCol()
:nRowHeight := 25
:l2007 := .F.
:l2015 := .T.
:lRecordSelector := .F.
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nStretchCol := STRETCHCOL_WIDEST
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:lDrawBorder := .t.
:nClrBorder := Rgb(195,195,185)
:bClrStd := { || { CLR_BLACK, If( oBrw:KeyNo % 2 == 0, CLR_WHITE,CLR_HGRAY ) } }
:lIncrFilter := .t.
:bOnSort := { |b,oCol| oBrw:Seek( "" ), ;
oBrw:cFilterFld := oCol:cExpr, ;
oBrw:SetFocus() }
:oSeek := oGet
:CreateFromCode()
END
RETURN NIL
//-------------------------------------------------------------------------//
CLASS TXData from TDatabase
DATA cPath init ".\Data\"
ENDCLASS
CLASS TCustomer from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TCustomer
Default lShared := .t.
::super:New(,::cPath+"Customer" ,"DBFCDX", lShared)
if ::use()
::setOrder(1)
::gotop()
endif
RETURN Self
//-------------------------------------------------------------------------//
STATIC FUNCTION uSeekTree( oBrw, cSeek,oDbf )
LOCAL oTree := oBrw:oTree
LOCAL oFound, oItem := oTree:oFirst
LOCAL lFound := .F.
local nOrder :=oDbf:SetOrder()
oDbf:SetOrder(5) //state +First
oDbf:Gotop()
oBrw:cSeek := cSeek
DO WHILE oItem <> NIL
IF oBrw:cSeek $ Upper(SubStr(oItem:cPrompt,1,Len(oBrw:cSeek)))
oFound := oItem
EXIT
ENDIF
oItem := oItem:GetNext()
ENDDO
IF oFound <> nil
oBrw:oTreeItem := oFound
oBrw:Refresh()
lFound := .t.
ENDIF
RETURN lFoun