REDEFINE GET oGet VAR cCodSag PICTURE "99999" ID 60 FONT oFont OF oDlg
...
...
REDEFINE SBUTTON ID 47 FILENAME "Search.bmp" OF oDlg ACTION Seek_Productor(oGet,400,150 ) TOOLTIP {"Buscar productor...","Busqueda"}
...
...
//-------------------------------------------------------------------------
STATIC FUNCTION Seek_Productor( oGet, nWidth, nHeight )
LOCAL oWnd, vLbx, aPoint, cBus, xVal , bRestore, lNormal
SELECT PA18 ; __dbZap() ; DBAPPEND()
PA18->NOMB := "Busqueda por Rut...." ; DBGOTOP()
bRestore := {|| IF( !lNormal, ( oGet:VarPut( xVal ), oGet:SetFocus() ), ), oWnd:End() }
xVal := oGet:VarGet()
cBus := ""
lNormal := .F.
aPoint := AdjustWnd( oGet, nWidth, nHeight )
DEFINE WINDOW oWnd FROM aPoint[1] + 1, aPoint[2] TO aPoint[1] + nHeight, aPoint[2] + nWidth pixel STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_BORDER )
@ 0, 0 LISTBOX vLbx FIELDS PA18->RUTT,PA18->CODI, PA18->NOMB ;
HEADER "Rut","Código","Nombre" ALIAS "PA18" FIELDSIZES 70,40,300 SIZE nWidth,nHeight OF oWnd ;
COLOR CLR_BUSCAR ;
FONT oApp:aWFont[23] PIXEL ON CHANGE ( oGet:VarPut( PA18->CODI ), oGet:refresh()) ;
ON DBLCLICK ( oGet:VarPut( PA18->CODI ), oGet:refresh(), oGet:SetFocus(), oWnd:End() )
vLbx:bKeyChar := { |nkey, nFlags| IF(nKey >= 32,(cBus += CHR(nKey) , BuscarProductor( vLbx, cBus )),),IF(nKey = 8, (cBus := LEFT(cBus,LEN(cBus)-1), BuscarProductor( vLbx, cBus )),) }
vLbx:bLostFocus := {|| ( oGet:VarPut( PA18->CODI ), oGet:refresh() , oGet:SetFocus() ) }
vLbx:bKeyDown := {|nKey| IF( nKey = 13, (lNormal := .T., eval( bRestore ) ), IF( nKey = 27, (lNormal := .T., eval( bRestore) ), ) ) }
ACTIVATE WINDOW oWnd ON INIT ( SetTransparent( oWnd, 231 ), oWnd:bLostFocus := {|| oWnd:bLostFocus := nil, eval( bRestore ) } , vLbx:Refresh() ) VALID ( lNormal := .T. )
RETURN Nil
//-------------------------------------------------------------------------
*
* yo utilizo tOdbcDirect para extraer datos de la DB SQLServer y el Metodo oDbf:Query_All() es propio
* pero básicamente extrae el codigo,rut y el nombre del productor.
*
STATIC FUNCTION BuscarProductor( vLbx, cBus )
LOCAL oDbf, n
SELECT PA18 ; __dbZap()
oDbf:= oApp:oConnect:Query("SELECT TOP 100 PR_Codigo_PK, PR_Rut_PK, PR_Nombre FROM CGE_Productores WHERE PR_Rut_PK LIKE '"+cBus+"%' ORDER BY PR_Rut_PK")
oDbf:Query_All()
For n := 1 TO oDbf:nRecord
SELECT PA18 ; dbAppend()
PA18->CODI := oDbf:aDataAll[n][ 1]
PA18->RUTT := oDbf:aDataAll[n][ 2]
PA18->NOMB := oDbf:aDataAll[n][ 3]
Next ; oDbf:End()
SELECT PA18 ; DBGOTOP()
vLbx:UpStable()
vLbx:Refresh()
RETURN .T.
//-------------------------------------------------------------------------