increment search in DBF BROWSE

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

increment search in DBF BROWSE

Post by AUGE_OHR »

i know the HMG Sample but it is based on Array GRID

i do have Problem with it when try with DBF so i wrote a new Version.
it include these Listview Function
Procedure ItemMark()
Procedure UnMarkAll()
Function ListView_GETSELECTIONMARK()
Function ListView_GETNEXTITEM()
Function ListView_GETSELECTEDCOUNT()
Sample work with "Outlook" DBF Structure here https://www.hmgforum.com/viewtopic.php?f=5&t=6686
DBFinc.jpg
DBFinc.jpg (62.24 KiB) Viewed 2006 times
Attachments
DBFINC.ZIP
(3.93 KiB) Downloaded 99 times
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: increment search in DBF BROWSE

Post by AUGE_OHR »

hi,

i miss 1 line in last Version ... sorry
DBFINC2.ZIP
(4 KiB) Downloaded 139 times

Code: Select all

PROCEDURE DoSearchSubject()
LOCAL cSeek  := TRIM( SearchForm.SearchText.Value )
LOCAL nRecno := RECNO()
LOCAL hGrid
   SEEK( UPPER( cSeek ) )
   IF FOUND()
      nRecno := RECNO()
      Domethod( "SearchForm", "SearchGrid", "REFRESH" )
      hGrid := GetControlHandle( "SearchGrid", "SearchForm" )
      UnMarkAll( hGrid, .T. )
      // this line need before mark
      Setproperty( "SearchForm", "SearchGrid", "VALUE", nRecno  )
      ItemMark( hGrid, nRecno )
   ELSE
      GOTO( nRecno )
   ENDIF
RETURN
have fun
Jimmy
User avatar
mustafa
Posts: 1172
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: increment search in DBF BROWSE

Post by mustafa »

Hi jimmy
Look at this code?
Search for any Letter

Code: Select all


STATIC PROCEDURE DoSearchSubject()

PRIVATE Filtro

 USE OUTLOOK INDEX OUTLOOK

 IF LEN( SearchForm.SearchText.Value) != 0
       Filtro :=  LOWER(SearchForm.SearchText.Value)   
       SET FILTER TO AT(Filtro,OUTLOOK->SUBJECT) <>0
       SET FILTER TO FILTRO $  OUTLOOK->SUBJECT

       SET SOFTSEEK ON
       GO TOP
       SearchForm.SearchGrid.value := OUTLOOK->(RecNo())
       SearchForm.SearchGrid.Refresh
               
   ELSE
     SET FILTER TO
    SearchForm.SearchGrid.value := OUTLOOK->(RecNo())
    SearchForm.SearchGrid.Refresh 

  ENDIF

 SET SOFTSEEK OFF 

RETURN

Regards
Mustafa
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: increment search in DBF BROWSE

Post by AUGE_OHR »

hi,
mustafa wrote: Wed Nov 25, 2020 10:56 am Look at this code?
Search for any Letter
it is not the Way to "search" ... it is to display in BROWSE "while type" into Keyboard.

SET FILTER can be very slow with big Database and not need for "Quick Search" to navigate in BROWSE.
i guess your Code is when have "full String" to search while i want "increment search" after every Keystoke.
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: increment search in DBF BROWSE

Post by SALINETAS24 »

Hola Jimmy.

Te paso la función que yo utilizo, de una manera algo distinta a lo que tu quieres pero puede ser que te muestre el camino.
En mi caso yo cargo un grid con los campos que cumple la condición y utilizo (OrdWildSeek( "*" + cCod + "*",.T. ) ), que con los asteriscos "*" me permite buscar en cualquier posición del campo.

Recibe un saludo.

Code: Select all

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// --> Busca_Aprox
// ----------------------------------------------------------------------
// --> Busca registros por aproximación. 
// --> Solo cuando son indices Alfabeticos
// ----------------------------------------------------------------------
// --> LLAMADA --> Busca_Aprox(cCod,cArea,nOrden)
// ----------------------------------------------------------------------
// --> DEVUELVE--> Numero del Registro seleccionado - 0 no hay selección.
// ----------------------------------------------------------------------
// --> Parametros
// cCod		--> Cadena de Caracteres a buscar
// cArea	--> Alias del fichero 
// nOrden   --> Numero de Indice que se activará para realizar la busqueda.
// ----------------------------------------------------------------------
FUNC Busca_Aprox(cCod,cArea,nOrden)
LOCAL cIndiceActivo , nArea
LOCAL aItem := {}
LOCAL nRec:=0	
*	msgbox(cCod+" -- "+cArea+" -- "+ str(nOrden) )
	nArea   := (cArea)->( INDEXORD() )
	(cArea)-> (DbSetOrder(nOrden))
	cIndiceActivo := (cArea)->( INDEXORD() )
	
	IF TYPE((cArea)->(INDEXKEY(cIndiceActivo)))="C"
		(cArea)->(DbGoTop())
		// --> No funciona con claves numericas
*		DO WHILE IF(TYPE((cArea)->(INDEXKEY(cIndiceActivo)))="N",OrdWildSeek(cCod,.T. ) ,	OrdWildSeek( "*" + cCod + "*",.T. ) )
		DO WHILE (cArea)->(OrdWildSeek( "*" + cCod + "*",.T. ) )
			AAdd( aItem, {(cArea)->(FIELDGET(1)),(cArea)->(FIELDGET(2)),(cArea)->(Recno())} )
		ENDDO

		IF LEN(aItem)>0
			DEFINE WINDOW Form_1 AT 0,0 WIDTH 350 HEIGHT 550 ;
				TITLE 'Busqueda de Registros' ; 
				MODAL ;				
				BACKCOLOR  { 209,220,231 } ;
				FONT "Arial" SIZE 10  ;
				NOSIZE 
							
				@ 15,5 GRID Grid_1 ;
					WIDTH 335 ;
					HEIGHT 500 ;
					HEADERS {(cArea)->(FIELDNAME(1)),(cArea)->(FIELDNAME(2)),"Np"} ;
					WIDTHS {100,270,3};
					ITEMS aItem ;
					VALUE 1 ;
					ON DBLCLICK (nRec:=VAL(ValorCelda("Form_1", "Grid_1",3)),ThisWindow.Release() )
					
			END WINDOW
			CENTER WINDOW Form_1
			ACTIVATE WINDOW Form_1
		ELSE
			lMsgExclamation("No hay Registros","ATENCION")
		ENDIF
	ELSE
		//--> Es númerica, la busco
		IF (cArea)->(DbSeek(VAL(cCod)))
			nRec:= (cArea)->(Recno())
		ENDIF
		
	ENDIF
	(cArea)->(DbSetOrder(nArea))
RETURN nRec



Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: increment search in DBF BROWSE

Post by AUGE_OHR »

hi,

thx for Code but my Problem is NOT to Seek() / OrdwildSeek().

when use

Code: Select all

   ON CHANGE DoSearchSubject()

PROCEDURE DoSearchSubject()
LOCAL cSeek  := TRIM( SearchForm.SearchText.Value )
   SEEK( UPPER( cSeek ) )
   IF FOUND()
      nRecno := RECNO()
      Domethod( "SearchForm", "SearchGrid", "REFRESH" )
it does move Pointer ...
but it is not "hight-light" in BROWSE / GRID while Focus is on TEXTBOX where i type

so i add some Listview API Function

Code: Select all

      // now geht Handle of BROWSE
      hGrid := GetControlHandle( "SearchGrid", "SearchForm" )
      // unmark 1st
      UnMarkAll( hGrid, .T. )
      // now set Value to GRID
      Setproperty( "SearchForm", "SearchGrid", "VALUE", nRecno  )
      // mark it and make it visible in BROWSE / GRID Area
      ItemMark( hGrid, nRecno )
   ELSE
      GOTO( nRecno )
   ENDIF
Increment_Search.gif
Increment_Search.gif (229.25 KiB) Viewed 1849 times
IMHO those Listview Function are missing so i posted them in Demo.


hm ... it does not work with Demo Sample ... but it is same Code ... :o
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: increment search in DBF BROWSE

Post by SALINETAS24 »

Hola Jimi, entiendo que quieres pintar una fila determinada de tu BROWSE. La que esta activa en la búsqueda.

Para el control GRID existe la opción ColumnDYNAMICBACKCOLOR, que te permitiría marcar la fila seleccionada, pero NO existe para BROWSE. Con esta función te evitas el refresh continuo.

Mirate esto, te puede resultar interesante y diviertete!! ;)

viewtopic.php?f=5&t=5742&p=55838&hilit= ... LOR#p55838

Un saludo virtual con una cervecita bien fresquita!!
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: increment search in DBF BROWSE

Post by franco »

Jimmy, try this it can be elaborated on.

Code: Select all

#include <hmg.ch>
PROC Main()
tbls()

use inv new shared
index on num1 to num1

DEFINE WINDOW frmQSMain ;
AT 0,0 ;
WIDTH GetDesktopWidth() * 0.75 ;
HEIGHT GetDesktopHeight() * 0.75 ;
TITLE "Quick Search Implementation on HMG Reference Guide" ;
MAIN

ON KEY ESCAPE ACTION frmQSMain.Release
ON KEY ESCAPE ACTION ''


DEFINE COMBOBOX button_1 // FOR BUTTON TO CLICK
ROW 10
COL 211
WIDTH 20
HEIGHT 20 // 20
ON GOTFOCUS { || frmQSMain.textSEARCH.VISIBLE := .T. , frmQSMain.brwItems.VISIBLE := .T. , frmQSMain.textSEARCH.setfocus }
END COMBOBOX

DEFINE BROWSE brwItems
ROW 33 //33
COL 211
WIDTH 330
HEIGHT 290 //290
BACKCOLOR {220,220,228}
HEADERS { "Item","Description"}
WIDTHS { 100,200 }
WORKAREA inv
FIELDS { 'inv->num1', 'inv->desc' }
ONDBLCLICK { || frmQSMain.text_1.refresh , frmQSMain.textSEARCH.VISIBLE := .F. , frmQSMain.brwItems.VISIBLE := .F. }
ONLOSTFOCUS { || frmQSMain.text_1.refresh , frmQSMain.textSEARCH.VALUE := '' , ;
frmQSMain.brwItems.VISIBLE := .F. , frmQSMain.textSEARCH.VISIBLE := .F. , ;
frmQSMain.textSEARCH.VALUE := ' ' }
ONCHANGE { || dbgoto(this.value) }
NOLINES .T.
END BROWSE // brwItems

DEFINE TEXTBOX textSearch
ROW 10
COL 232
WIDTH 200 // 200 can make 0 so you cannot see
HEIGHT 24
ONCHANGE { || DBSEEK( UPPER( this.Value ), .T. ), frmQSMain.brwItems.value := inv->(RECNO() ) }
ONENTER { || frmQSMain.brwItems.SETFOCUS }
ONLOSTFOCUS { || frmQSMain.brwItems.SETFOCUS}
END TEXTBOX // tbxSearch

DEFINE TEXTBOX text_1
ROW 10
COL 10
WIDTH 200
HEIGHT 24
FIELD INV->NUM1
END TEXTBOX

END WINDOW // frmQSMain
frmQSMain.text_1.SETFOCUS
frmQSMain.textSEARCH.VISIBLE := .F.
frmQSMain.brwItems.VISIBLE := .F.
frmQSMain.Center
frmQSMain.Activate
return
// HMG_HELP Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.


FUNCTION TBLS

LOCAL CF := {}
if ! file('inv.dbf')
CF := {}
aADD(CF,{'NUM1' ,'C' , 15,0})
aADD(CF,{'DESC' ,'C' , 15,0})
DBCREATE( 'INV.DBF',CF )
USE
use inv new
index on num1 to num1
set index to num1
do while recno() < 1000000
append blank
replace num1 with alltrim(str(100+recno()))
replace desc with 'DESC' +alltrim(str(100+recno()))
loop
enddo
close inv
endif

return
The first time in it takes a bit to create file, but index is quick.
All The Best,
Franco
Canada
Post Reply