Good afternoon Silvio. I'm learning to use xBrowse, could you tell me if I made a mistake, please?
Buenas tardes Silvio. Estoy aprendiendo a usar xBrowse, ¿podría decirme si cometí un error, por favor?
Code: Select all | Expand
// C:\SILVXBRW\TESTXBR5.PRG - Simples teste de xBrowse com indices.
// MODIFICADO EM: 03/05/2024 - INDEX ou ORDSCOPE()? - kapiabafwh@gmail.com
#Include 'Fivewin.ch'
#Include 'xBrowse.ch'
ANNOUNCE RDDSYS
REQUEST OrdKeyNo, OrdKeyCount, OrdCreate, OrdKeyGoto
REQUEST DBFCDX, DBFFPT
STATIC nOpcRad := 3, oMarried, lMarried := .F., oAge, lAge := .F.
FUNCTION Main()
FIELD FIRST, LAST, STREET, CITY, STATE, ZIP, HIREDATE, MARRIED, AGE, ;
SALARY, NOTES
LOCAL oDlg, oBrw, oFont, oFnt, ovFont, oSaida, cTitle, aGrad, cAlias
hb_gcAll( .F. )
RDDSETDEFAULT("DBFCDX")
RDDREGISTER( "DBFCDX", 1 )
SET CENTURY ON
SET DATE BRITISH
SET TIME FORMAT TO "HH:MM:SS"
SET EPOCH TO YEAR( DATE() ) - 30
SET SOFTSEEK OFF
SET WRAP ON
SETCANCEL( .F. )
SET CONFIRM OFF
SET DELETED ON
SET _3DLOOK ON
SET UNIQUE OFF
SET ESCAPE OFF
SET EXACT ON
SET EXCLUSIVE OFF
SET MULTIPLE OFF
SET OPTIMIZE ON
SetBalloon( .T. )
SkinButtons()
IF FILE( "CUSTOMER.CDX" )
FErase( "CUSTOMER.CDX" )
ENDIF
USE CUSTOMER NEW EXCLUSIVE ALIAS CUSTOMER
INDEX ON STREET TAG 01 TO CUSTOMER FOR .NOT. DELETED()
INDEX ON MARRIED TAG 02 TO CUSTOMER FOR .NOT. DELETED()
INDEX ON AGE TAG 03 TO CUSTOMER FOR .NOT. DELETED()
CLOSE DATABASES
USE CUSTOMER INDEX CUSTOMER NEW SHARED
SET ORDER TO 01 // STREET
GO TOP
cAlias := ALIAS()
cTitle := "xBrowse Filter Advanced 3.0 Model by Silvio Falconi"
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0, - 14 BOLD
DEFINE FONT oFnt NAME 'TAHOMA' SIZE 0, - 12 BOLD
DEFINE FONT oVfont NAME 'TAHOMA' SIZE 0, - 12 NESCAPEMENT 900 BOLD
aGrad := { { 0.30, nRGB( 221, 245, 255 ), nRGB( 192, 221, 255 ) }, ;
{ 0.50, nRGB( 192, 221, 255 ), nRGB( 221, 245, 255 ) } }
// 460
DEFINE DIALOG oDlg SIZE 560, 500 PIXEL TRUEPIXEL FONT oFont ;
TITLE cTitle GRADIENT aGrad
oDlg:lHelpIcon := .F.
@ 20, 10 XBROWSE oBrw SIZE 540, 380 PIXEL OF oDlg FONT oFnt ;
COLUMNS "First", "Last", "Street", "Married", "Age" ;
ALIAS 'CUSTOMER' LINES CELL
xBrwColors( oBrw, .T. )
oBrw:nColSel := 3
oBrw:aCols[ 1 ]:nWidth := 80 // First
oBrw:aCols[ 1 ]:nDataStrAlign := AL_CENTER
oBrw:aCols[ 2 ]:nWidth := 80 // Last
oBrw:aCols[ 2 ]:nDataStrAlign := AL_CENTER
oBrw:aCols[ 3 ]:nWidth := 190 // Street
oBrw:aCols[ 3 ]:bClrStd := { || { CLR_BLACK, RGB( 255, 255, 200 ) } }
oBrw:aCols[ 4 ]:nWidth := 60 // Married
oBrw:aCols[ 4 ]:nDataStrAlign := AL_CENTER
oBrw:aCols[ 5 ]:nWidth := 40 // Age
oBrw:aCols[ 5 ]:nDataStrAlign := AL_CENTER
oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:nStretchCol := STRETCHCOL_WIDEST // Ajusta as colunas do xBrowse.
oBrw:lDrawBorder := .T.
oBrw:nClrBorder := Rgb( 195, 195, 185 )
WITH OBJECT oBrw:oCol( "First" )
:oHeaderFont := oVFont
:cHeader := "Primero"
END
WITH OBJECT oBrw:oCol( "Last" )
:oHeaderFont := oVFont
:cHeader := "Último"
END
WITH OBJECT oBrw:oCol( "Street" )
:oHeaderFont := oVFont
:cHeader := "Calle"
END
WITH OBJECT oBrw:oCol( "Married" )
:oHeaderFont := oVFont
:cHeader := "Cadado"
END
WITH OBJECT oBrw:oCol( "Age" )
:oHeaderFont := oVFont
:cHeader := "Edad"
END
oBrw:CreateFromCode()
oDlg:oClient := oBrw
@ 415, 075 SAY "Filtrar por: " SIZE 150, 20 OF oDlg PIXEL UPDATE ;
COLORS METRO_ORANGE, CLR_WHITE FONT oFnt TRANSPARENT
@ 415, 150 CHECKBOX oMarried VAR lMarried PROMPT "&Casados" OF oDlg ;
SIZE 100, 15 PIXEL UPDATE ;
ON CHANGE( MENU_SILVIO_FILTRO_MARRIED( cAlias, oBrw, oMarried ) )
oMarried:cToolTip := OemToAnsi( "Búsqueda de casados(Married)" )
@ 415, 250 CHECKBOX oAge VAR lAge PROMPT "&Edad" OF oDlg ;
SIZE 100, 15 PIXEL UPDATE ;
ON CHANGE( MENU_SILVIO_FILTRO_EDAD( cAlias, oBrw, oAge ) )
oAge:cToolTip := OemToAnsi( "Búsqueda por Edad(Age)" )
@ 470, 005 SAY "kapiabafwh@gmail.com" SIZE 200, 20 OF oDlg PIXEL UPDATE ;
COLORS METRO_COBALT, CLR_WHITE FONT oFnt TRANSPARENT
@ 440, 400 BUTTONBMP oSaida PROMPT " &Salida" OF oDlg TEXTRIGHT PIXEL ;
BITMAP ".\EXIT.BMP" SIZE 100, 40 ACTION( oDlg:End(), LIBERA_TUDO() ) ;
FONT oFont CANCEL
oSaida:cToolTip := "Saida - Exit - Cancelar"
ACTIVATE DIALOG oDlg CENTERED ON INIT( CTRLS_COLORS( oDlg ) )
oFont:End()
ovFont:End()
dbCloseAll() // CLOSE DATABASES
// seguridad
lMarried := .F.
lAge := .F.
RETURN NIL
FUNCTION MENU_SILVIO_FILTRO_MARRIED( cAlias, oBrw, oMarried )
LOCAL oDlg, oFont, oFnt, ovFont, oSaida, cTitle, aGrad, oSay, oRadmenu
nOpcRad := 3
oMarried:Disable()
oMarried:Refresh()
cTitle := "xBrowse: Filtrar: Elija una opción:"
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0, - 14 BOLD
DEFINE FONT oFnt NAME 'TAHOMA' SIZE 0, - 12 BOLD
DEFINE FONT oVfont NAME 'TAHOMA' SIZE 0, - 12 NESCAPEMENT 900 BOLD
aGrad := { { 0.30, nRGB( 221, 245, 255 ), nRGB( 192, 221, 255 ) }, ;
{ 0.50, nRGB( 192, 221, 255 ), nRGB( 221, 245, 255 ) } }
DEFINE DIALOG oDlg SIZE 250, 200 PIXEL TRUEPIXEL FONT oFont ;
TITLE cTitle GRADIENT aGrad
oDlg:lHelpIcon := .F.
@ 12, 090 SAY oSay PROMPT "Filtrar Por: " SIZE 100, 24 PIXEL OF oDlg ;
FONT oFont COLORS METRO_COBALT, CLR_WHITE TRANSPARENT
@ 50.5, 070 RADIO oRadMenu VAR nOpcRad ITEMS "Casados" OF oDlg ;
SIZE 100, 16 PIXEL UPDATE ;
ON CHANGE( CHANGE_INDICES_CASADO( nOpcRad, cAlias, oBrw ), ;
oBrw:Refresh(), oBrw:SetFocus() )
@ 80.5, 070 RADIOITEM "No Casados" RADIOMENU oRadMenu OF oDlg ;
SIZE 100, 16 PIXEL UPDATE
@ 140, 072 BUTTONBMP oSaida PROMPT " &Salida" OF oDlg TEXTRIGHT PIXEL ;
BITMAP ".\EXIT.BMP" SIZE 100, 40 ACTION( oDlg:End() ) FONT oFont CANCEL
oSaida:cToolTip := "Saida - Exit - Cancelar"
ACTIVATE DIALOG oDlg CENTERED ON INIT( CTRLS_COLORS( oDlg ) )
lMarried := .F.
oMarried:Enable()
oMarried:Refresh()
oBrw:SetFocus()
RETURN NIL
FUNCTION MENU_SILVIO_FILTRO_EDAD( cAlias, oBrw, oAge )
LOCAL oDlg, oFont, oFnt, ovFont, oSaida, cTitle, aGrad, oSay, oRadmenu
nOpcRad := 3
oAge:Disable()
oAge:Refresh()
cTitle := "xBrowse: Filtrar: Elija una opción:"
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0, - 14 BOLD
DEFINE FONT oFnt NAME 'TAHOMA' SIZE 0, - 12 BOLD
DEFINE FONT oVfont NAME 'TAHOMA' SIZE 0, - 12 NESCAPEMENT 900 BOLD
aGrad := { { 0.30, nRGB( 221, 245, 255 ), nRGB( 192, 221, 255 ) }, ;
{ 0.50, nRGB( 192, 221, 255 ), nRGB( 221, 245, 255 ) } }
DEFINE DIALOG oDlg SIZE 250, 200 PIXEL TRUEPIXEL FONT oFont ;
TITLE cTitle GRADIENT aGrad
oDlg:lHelpIcon := .F.
@ 12, 090 SAY oSay PROMPT "Filtrar Por: " SIZE 100, 24 PIXEL OF oDlg ;
FONT oFont COLORS METRO_COBALT, CLR_WHITE TRANSPARENT
@ 50.5, 070 RADIO oRadMenu VAR nOpcRad ITEMS "Hasta 20 años" OF oDlg ;
SIZE 130, 16 PIXEL UPDATE ;
ON CHANGE( CHANGE_INDICES_EDAD( nOpcRad, cAlias, oBrw ), ;
oBrw:Refresh(), oBrw:SetFocus() )
@ 80.5, 070 RADIOITEM "Más de 50 años" RADIOMENU oRadMenu OF oDlg ;
SIZE 130, 16 PIXEL UPDATE
@ 140, 072 BUTTONBMP oSaida PROMPT " &Salida" OF oDlg TEXTRIGHT PIXEL ;
BITMAP ".\EXIT.BMP" SIZE 100, 40 ACTION( oDlg:End() ) FONT oFont CANCEL
oSaida:cToolTip := "Saida - Exit - Cancelar"
ACTIVATE DIALOG oDlg CENTERED ON INIT( CTRLS_COLORS( oDlg ) )
lAge := .F.
oAge:Enable()
oAge:Refresh()
oBrw:SetFocus()
RETURN NIL
FUNCTION CHANGE_INDICES_CASADO( nOpcRad, cAlias, oBrw )
LOCAL lCasado := .T., lNoCasado := .F.
IF nOpcRad == 2 // No Casados
SET ORDER TO 02 // MARRIED
ORDSCOPE( 0, lNoCasado )
ORDSCOPE( 1, lNoCasado )
GO TOP
IF EOF()
ORDSCOPE( 0, Nil )
ORDSCOPE( 1, Nil )
GO TOP
SELECT( cAlias )
SET ORDER TO 01
GO TOP
ENDIF
ELSEIF nOpcRad == 1 //-> CASADOS
SET ORDER TO 02 // MARRIED
ORDSCOPE( 0, lCasado )
ORDSCOPE( 1, lCasado )
GO TOP
IF EOF()
ORDSCOPE( 0, Nil )
ORDSCOPE( 1, Nil )
GO TOP
SELECT( cAlias )
SET ORDER TO 01
GO TOP
ENDIF
ENDIF
GO TOP
oBrw:GoBottom()
oBrw:Refresh()
oBrw:Gotop()
RETURN NIL
FUNCTION CHANGE_INDICES_EDAD( nOpcRad, cAlias, oBrw )
LOCAL cEdad20I := 20, cEdad20F := 29, cEdadIni := 50, cEdadFin := 100 //->anos
IF nOpcRad == 2 // mas de 50 anos
SET ORDER TO 03 // EDAD/AGE
ORDSCOPE( 0, cEdadIni )
ORDSCOPE( 1, cEdadFin )
GO TOP
IF EOF()
ORDSCOPE( 0, Nil )
ORDSCOPE( 1, Nil )
GO TOP
SELECT( cAlias )
SET ORDER TO 01
GO TOP
ENDIF
ELSEIF nOpcRad == 1 //-> EDAD/AGE // 20/29 anos.
SET ORDER TO 03 // EDAD/AGE
ORDSCOPE( 0, cEdad20I )
ORDSCOPE( 1, cEdad20F )
GO TOP
IF EOF()
ORDSCOPE( 0, Nil )
ORDSCOPE( 1, Nil )
GO TOP
SELECT( cAlias )
SET ORDER TO 01
GO TOP
ENDIF
ENDIF
GO TOP
oBrw:GoBottom()
oBrw:Refresh()
oBrw:Gotop()
RETURN NIL
// ESTA EM: INV1.PRG
STATIC FUNCTION xBrwColors( oBrw, lFoot )
LOCAL cClrBack
DEFAULT lFoot := .F.
oBrw:l2007 := .T.
// oBrw:nRowHeight := 24
// oBrw:nHeaderHeight := 24
oBrw:lFooter := lFoot
// oBrw:lRecordSelector := .F.
// oBrw:lColDividerComplete := .F.
// oBrw:lRowDividerComplete := .F.
oBrw:lFlatStyle := .F.
oBrw:bClrHeader := { || { CLR_BLACK, CLR_WHITE, CLR_WHITE } }
oBrw:lFullGrid := .F.
// tira as linhas, nao gostei.
// oBrw:nRowDividerStyle := LINESTYLE_NOLINES
// oBrw:nColDividerStyle := LINESTYLE_NOLINES
// oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW // Marca toda as celula, nao gostei.
oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
{ If( ( oBrw:cAlias )->( DELETED() ), CLR_HRED, CLR_BLUE ),;
RGB( 198, 255, 198 ) }, ;
{ If( ( oBrw:cAlias )->( DELETED() ), CLR_HRED, CLR_BLUE ),;
RGB( 232, 255, 232 ) } ) }
oBrw:bClrSel = { || { If( ( oBrw:cAlias )->( DELETED() ), CLR_HRED, CLR_WHITE ),;
RGB( 34, 177, 76 ) } }
cClrBack = Eval( oBrw:bClrSelFocus )[ 2 ]
oBrw:bClrSelFocus := { || { If( ( oBrw:cAlias )->( DELETED() ), CLR_HRED, CLR_WHITE ),;
cClrBack } }
oBrw:SetColor( CLR_CYAN, RGB( 232, 255, 232 ) )
RETURN NIL
// By Giovanny Vecchi - TESTRAD.PRG
FUNCTION CTRLS_COLORS( f_oDlgContainer )
LOCAL lc_aCtrls := {}, lc_iFor := 0
LOCAL lc_aItemsRadio := {}
lc_aCtrls := f_oDlgContainer:aControls
FOR lc_iFor := 1 TO Len( lc_aCtrls )
IF ValType( lc_aCtrls[lc_iFor] ) == "O"
IF lc_aCtrls[lc_iFor]:ClassName() == "TRADIO"
aEval( lc_aCtrls[lc_iFor]:oRadMenu:aItems, ;
{|_oRadId|{ SetWindowTheme( _oRadId:hWnd, "", "" ), ;
_oRadId:SetColor( METRO_ORANGE, METRO_AMBER ) } } )
ELSEIF lc_aCtrls[lc_iFor]:ClassName() == "TCHECKBOX"
SetWindowTheme( lc_aCtrls[lc_iFor]:hWnd, "", "" )
// C:\FWH\INCLUDE\COLORS.CH
lc_aCtrls[lc_iFor]:SetColor( METRO_RED, METRO_AMBER )
ENDIF
ENDIF
NEXT
RETURN NIL
FUNCTION LIBERA_TUDO()
IF File( "testxbr5.log" )
DELETEFILE( "testxbr5.log" )
ENDIF
dbCommitAll()
dbUnlockAll()
dbCloseAll()
FreeResources()
RELEASE ALL
SysRefresh()
hb_gcAll( .T. )
CLEAR MEMORY
PostQuitMessage( 0 )
QUIT
RETURN NIL
// FIM / END kapiabafwh@gmail.com
Tks, gracias.
Regards, saludos.