by Rick Lipkin » Fri Dec 14, 2007 11:21 pm
Armondo
Here is a simple listbox look up program I use ..
xPROVIDER := "SQLOLEDB"
xSOURCE := "YOURSERVER"
xCATALOG := "DATABASENAME"
xUSERID := "SQLUSER"
xPASSWORD := "PASSWORD"
//-- grpslct.prg
//
//
STATIC oDLG,oLBX
#INCLUDE "FIVEWIN.CH"
//----------------------
Func GRPGET( cNAME, cMODE, oOBJ, oRs, cTABLE )
LOCAL oBTN1, oBTN2, oRs2,oErr, cSQL, cTITLE
IF cNAME = "ALL"
RETURN(.T.)
ENDIF
IF EMPTY( oOBJ )
oOBJ = " "
ENDIF
IF EMPTY( cTABLE )
cTABLE := "BOGUS"
ENDIF
IF cMODE = "E"
DO CASE
CASE cTABLE = "EMPLOYEE"
IF SUBSTR(cNAME,1,2 ) = SUBSTR(oRs:Fields("GROUP1"):Value,1,2) .and.;
oRs:Fields("GROUP1"):Value <> SPACE(2)
RETURN(.T.)
ENDIF
ENDCASE
ENDIF
IF EMPTY( cNAME )
cNAME := "BOGUS"
ENDIF
cNAME := UPPER(ALLTRIM(cNAME))
oRs2 := TOleAuto():New( "ADODB.Recordset" )
oRs2:CursorType := 1 // opendkeyset
oRs2:CursorLocation := 3 // local cache
oRs2:LockType := 3 // lockoportunistic
IF xADMIN = 'Y'
cSQL := "SELECT * FROM GROUPS order by progid,code"
cTITLE := "GROUP Select for ALL"
ELSE
cSQL := "SELECT * from GROUPS where progid = '"+xPROGID+"' order by code"
cTITLE := "GROUP Select for Progid "+xPROGID
ENDIF
TRY
oRS2:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
MsgInfo( "Error in Opening GROUPS table" )
RETURN(.F.)
END TRY
IF EMPTY( cNAME ) .or. cNAME = " "
cNAME := "BOGUS"
ENDIF
cNAME := UPPER(ALLTRIM(cNAME))
oRs2:Find( "code like '"+cNAME+"%'" )
IF oRs2:eof
oRs2:MoveFirst()
ENDIF
DEFINE DIALOG oDlg RESOURCE "GRPSLCT" ;
COLOR "N/W" ;
TITLE cTITLE
REDEFINE LISTBOX oLBX FIELDS ;
oRs2:Fields("CODE"):Value, ;
oRs2:Fields("DESC"):Value, ;
oRs2:Fields("PROGID"):Value ;
HEADERS "Code", ;
"Desc", ;
"ProgID" ;
SIZES 50,170, 50 ;
ID 111 of oDlg
oLbx:bLogicLen := { || oRs2:RecordCount }
oLbx:bGoTop := { || oRs2:MoveFirst() }
oLbx:bGoBottom := { || oRs2:MoveLast() }
oLbx:bSkip := { | nSkip | Skipper( oRs2, nSkip ) }
oLbx:cAlias := "ARRAY"
REDEFINE BUTTON oBTN1 ID 112 of oDLG ;
ACTION ( zGROUP1 := oRs2:Fields("CODE"):Value, ;
oOBJ:Refresh(), ;
oDlg:END()) ;
DEFAULT
REDEFINE BUTTON oBTN2 ID 118 of oDLG ;
ACTION ( oDlg:End() )
ACTIVATE DIALOG oDlg
oDLG := NIL
oLBX := NIL
oRs2:Close()
SysReFresh()
RETURN( .T. )
//-------------------------------
STATIC FUNCTION SKIPPER( oRsx, nSkip )
LOCAL nRec := oRsx:AbsolutePosition
oRsx:Move( nSkip )
IF oRsx:EOF; oRsx:MoveLast(); ENDIF
IF oRsx:BOF; oRsx:MoveFirst(); ENDIF
RETURN( oRsx:AbsolutePosition - nRec )
// end grpslct.prg