I modify your sample https://forums.fivetechsupport.com/viewtopic.php?f=3&t=44500&sid=ca68d176cc14f86e1359d15301a5e80f to use with tdatabase and the possiblity to select the state but I have problem to run the cfilter
1) when I go to ResetFilter( aFilters,oDbf, nIndex ) nIndex is allways 3
2) to create a filter I select the state and create the new filter ( ru nok I put as 3)
local cState:= space(25)
If nIndex=3
Selection_State( @cstate )
cFilter:= 'STATE='+ "'"+cState+"'"
endif
see the code pls
- Code: Select all Expand view
#include "fivewin.ch"
REQUEST DBFCDX
function Main()
local oDlg, oBrw
local cFilter := ""
local aFilters := { { .f., "AGE>40" }, { .f., "STATE='NY'" }, { .f., "MARRIED" } }
local aCheck[ 3 ], n
local nRow := 40
local nCol := 40
* USE CUSTOMER NEW SHARED VIA "DBFCDX"
oDbf:=TCustomer():New()
oDbf:setorder(1)
oDbf:Gotop()
DEFINE DIALOG oDlg SIZE 600,400 PIXEL TRUEPIXEL
for n := 1 to Len( aFilters )
aCheck[ n ] := CreateChk( nRow, nCol, oDlg, aFilters, n )
aCheck[ n ]:bChange := { || cFilter := ResetFilter( aFilters,oDbf,n ), oDlg:Update() }
aCheck[ n ]:lTransparent := .t.
nCol += 150
if n == 3
EXIT
endif
next
@ 80, 40 SAY { || "FILTER : " + cFilter } SIZE 400, 25 PIXEL OF oDlg CENTER UPDATE
@ 115, 40 XBROWSE oBrw SIZE -40,-40 PIXEL OF oDlg ;
DATASOURCE oDbf ;
COLUMNS "ID", "CITY", "STATE", "MARRIED", "AGE" ;
CELL LINES NOBORDER UPDATE
oBrw:SetChecks()
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
return nil
static function CreateChk( nRow, nCol, oDlg, aFilters, nIndex )
local oChk
@ nRow, nCol CHECKBOX oChk VAR aFilters[ nIndex, 1 ] ;
PROMPT aFilters[ nIndex, 2 ] SIZE 150,15 PIXEL OF oDlg
return oChk
static function ResetFilter( aFilters,oDbf, nIndex )
local cState:= space(25)
local cFilter := ""
local af := {}
AEval( aFilters, { |a| If( a[ 1 ], AAdd( af, a[ 2 ] ), nil ) } )
cFilter := FW_ArrayAsList( af, " .AND. " )
?nIndex
If nIndex=3
Selection_State( @cstate )
cFilter:= 'STATE='+ "'"+cState+"'"
endif
if Empty( cFilter )
// SET FILTER TO
oDbf:ClearFilter()
else
// SET FILTER TO &cFilter
oDbf:SetFilter(cFilter)
endif
*GO TOP
oDbf:gotop()
return cFilter
//----------------------------------------------//
Function Selection_State( cstate )
local oList
local oDlg,oBrw
local lOk := .f.
local nArea := Select()
olist:=TState():New()
olist:setorder(1)
olist:Gotop()
DEFINE DIALOG oDlg SIZE 600,400 PIXEL TRUEPIXEL
@ 115, 40 XBROWSE oBrw SIZE -40,-40 PIXEL OF oDlg ;
DATASOURCE oList ;
COLUMNS "CODE", "NAME" ;
CELL LINES NOBORDER UPDATE
oBrw:CreateFromCode()
aEval( oBrw:aCols, { |oCol| oCol:bLDClickData := { || lOk := .T., oDlg:End() } } )
ACTIVATE DIALOG oDlg CENTERED
if lOK
cstate :=oList:code
Endif
Select (nArea)
oList:close()
return nil
//------------------------------------------------------------------------//
CLASS TXData from TDatabase
DATA cDbfPath init ".\"
ENDCLASS
CLASS TCustomer from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TCustomer
Default lShared := .t.
::super:New(,::cDbfPath + "Customer" ,"DBFCDX", lShared)
if ::use()
::setOrder(1)
::gotop()
endif
RETURN Self
CLASS TState from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TState
Default lShared := .t.
::super:New(,::cDbfPath + "States" ,"DBFCDX", lShared)
if ::use()
::setOrder(0)
::gotop()
endif
RETURN Self