// Incremental Search
// adorick.prg
#include "FiveWin.ch"
#Include "Xbrowse.ch"
#include "dtpicker.ch"
STATIC oWnd,oBar,lOK,lOk1,oWndChild,oLbx
STATIC cLname,oLname,oFname,cFname,oFontB
Static dDatePur,oDatePur
//-------------
Func Main()
Local catNewDB,cFile,aDir,dExe,cDefa,mStart
Local oCn,cSql,oErr,oRsCust,cLOGIN,Saying,xLogin,cRights
Local cTitle,oButt1,oButt2,nYear,nScr1,nScr2,xMessage,cRdd
PUBLIC xCONNECT,xSource,xProvider
lOK := .F.
//-- get timestamp on .exe //
cFILE := GetModuleFileName( GetInstance() )
aDIR := DIRECTORY( cFILE )
dEXE := aDIR[1] [3]
// where .exe started from is default directory //
mSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,mSTART-1)
aDIR := NIL
SET DEFA to ( cDEFA )
SET DELETED on
SET CENTURY on
SET 3DLOOK on
nYEAR := ( year( DATE() )-30 )
SET EPOCH to ( nYEAR )
REQUEST DBFCDX
rddsetdefault ( "DBFCDX" )
nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)
xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE := cDEFA+"\Rick.mdb"
cRDD := xPROVIDER+" -- "+xSOURCE
// global connection string
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE
If .not. File( cDefa+"\Rick.mdb" )
Ferase( cDefa+"\Rick.mdb" )
// create the adox object
Try
catNewDB := CreateObject("ADOX.Catalog")
Catch
MsgInfo( "Could not Create ADOX object")
Return(.f.)
End try
// create the table Rick.mdb
Try
catNewDB:Create('Provider='+xProvider+';Data Source='+xSource+';Jet OLEDB:Engine Type=5' )
Catch
MsgInfo( "Could not create the table "+xSource )
Return(.f.)
End Try
Try
oCn := CREATEOBJECT( "ADODB.Connection" )
Catch
MsgInfo( "Could not create the ADO object for connection")
End Try
TRY
oCn:Open( xCONNECT )
CATCH oErr
MsgInfo( "Could not open a Connection to Database "+xSource )
RETURN(.F.)
END TRY
cSQL := "CREATE TABLE CUSTOMER"
cSQL += "( "
cSQL += "[CUSTOMEREID] char(18) NOT NULL, "
cSQL += "[LAST NAME] char(30) NULL, "
cSQL += "[FIRST NAME] char(30) NULL, "
cSQL += "[MID INIT] char(30) NULL, "
cSQL += "[ADDRESS1] char(30) NULL, "
cSQL += "[CITY] char(30) NULL, "
cSQL += "[STATE] char(30) NULL, "
cSql += "[MEMO] LONGBINARY NULL,"
cSql += "[DATEPUR] DateTime NULL, "
cSQL += "CONSTRAINT PK_USERINFO PRIMARY KEY ( CUSTOMEREID )"
cSQL += " )"
Try
oCn:Execute( cSQL )
Catch
MsgInfo( "Table CUSTOMER Failed" )
Return(.f.)
End try
oCn:Close()
oCn := nil
Endif
xLOGIN := UPPER( WNetGetuser() )+space(8) // fivewin
xLOGIN := SUBSTR(xLOGIN,1,8)
oRsCust := TOleAuto():New( "ADODB.Recordset" )
oRsCust:CursorType := 1 // opendkeyset
oRsCust:CursorLocation := 3 // local cache
oRsCust:LockType := 3 // lockoportunistic
// check for very first user
cSQL := "SELECT * FROM CUSTOMER"
TRY
oRsCust:Open( cSQL, xCONNECT )
CATCH oErr
MsgInfo( "Error in Opening CUSTOMER table here" )
RETURN(.F.)
END TRY
If oRsCust:eof
oRsCust:AddNew()
oRsCust:Fields("CustomerEid"):Value := "011111111111111111"
oRsCust:Fields("Last Name"):Value := "Lipkin"
oRsCust:Fields("First Name"):Value := "Richard"
oRsCust:Fields("Mid Init"):Value := "M"
oRsCust:Fields("Address1"):Value := "123 Anywhere"
oRsCust:Fields("City"):Value := "Columbia"
oRsCust:Fields("State"):Value := "SC"
oRsCust:Fields("DatePur"):Value := Date()
oRsCust:Update()
oRsCust:AddNew()
oRsCust:Fields("CustomerEid"):Value := "011111111111111112"
oRsCust:Fields("Last Name"):Value := "Lipinsky"
oRsCust:Fields("First Name"):Value := "Jason"
oRsCust:Fields("Mid Init"):Value := "S"
oRsCust:Fields("Address1"):Value := "123 Arborgate"
oRsCust:Fields("City"):Value := "Columbia"
oRsCust:Fields("State"):Value := "SC"
oRsCust:Fields("DatePur"):Value := Date()
oRsCust:Update()
oRsCust:AddNew()
oRsCust:Fields("CustomerEid"):Value := "011111111111111113"
oRsCust:Fields("Last Name"):Value := "Lipkin"
oRsCust:Fields("First Name"):Value := "Beth"
oRsCust:Fields("Mid Init"):Value := " "
oRsCust:Fields("Address1"):Value := "123 Lake Murray Blvd"
oRsCust:Fields("City"):Value := "Lexington"
oRsCust:Fields("State"):Value := "SC"
oRsCust:Fields("DatePur"):Value := Date()
oRsCust:Update()
oRsCust:AddNew()
oRsCust:Fields("CustomerEid"):Value := "011111111111111114"
oRsCust:Fields("Last Name"):Value := "Lizzarous"
oRsCust:Fields("First Name"):Value := "Tim"
oRsCust:Fields("Mid Init"):Value := "J"
oRsCust:Fields("Address1"):Value := "456 Broad River"
oRsCust:Fields("City"):Value := "Irmo"
oRsCust:Fields("State"):Value := "SC"
oRsCust:Fields("DatePur"):Value := Date()
oRsCust:Update()
Endif
oFontB := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )
cRIGHTS := "(RWS)"
xMESSAGE := "User "+xLOGIN+" Rights "+cRIGHTS+ ;
" Default= "+cDEFA+" Rdd= "+cRDD+ ;
" Revision "+DTOC(dEXE)+;
" -r"+str(nSCR1,4)+" x "+STR(nSCR2,4)
cTitle := "Test Incremental Search with ON CHANGE"
DEFINE WINDOW oWnd ;
TITLE cTITLE ;
MENU _BuildMenu();
MDI
DEFINE BUTTONBAR oBar OF oWnd SIZE 65,70 3DLOOK 2007
oBar:SetColor(0)
DEFINE BUTTON oButt1 OF oBar ;
MESSAGE "Customer Information" ;
ACTION _Custview( "A",oWnd,oButt1,oButt2 ) ;
PROMPT "Customer Info"
DEFINE BUTTON oButt2 OF oBar ;
MESSAGE "Close Application" ;
ACTION ( oWnd:End() ) ;
PROMPT "Quit"
SET MESSAGE OF oWnd ;
to xMESSAGE CLOCK 2007
ACTIVATE WINDOW oWnd MAXIMIZED ;
VALID ( IIF( !lOK, _ExitPgm(.T.), .F. ))
RETURN( NIL )
//---------------------------
Static FUNCTION _BuildMenu()
LOCAL oMENU, cDEFA
cDEFA := SET(7)
MENU oMenu 2007
menuitem "Login..." ;
MENUITEM "&About..."
MENUITEM "&Quit" ;
MESSAGE "Close this program";
ACTION oWND:END()
ENDMENU
RETURN( oMenu )
//-----------------------
Static FUNCTION _ExitPgm( lCLEAN )
LOCAL lOK3
lOK3 := .F.
IF lCLEAN = .T.
lOK3 := .T.
lOK := .T.
SET RESOURCES to
ENDIF
RETURN( lOK3 )
//-------------------------------
Static FUNC _Custview( cMODE,oWnd,oBtn1,oBtn2 )
LOCAL SAYING,cDEFA
LOCAL cTITLE
LOCAL oIco,oFld,oCust
LOCAL oRsCust,cSql
lOK1 := .F.
cSQL := "SELECT * from CUSTOMER order by [Last Name]"
oRsCust := TOleAuto():New( "ADODB.Recordset" )
oRsCust:CursorType := 1 // opendkeyset
oRsCust:CursorLocation := 3 // local cache
oRsCust:LockType := 3 // lockoportunistic
TRY
oRsCust:Open( cSQL,xCONNECT )
CATCH oErr
MsgInfo( "Error in Opening CUSTOMER table" )
RETURN(.F.)
END TRY
SysReFresh()
cTITLE := "Customer Maintenance"
DO CASE
CASE cMODE = "E"
cTITLE := "Customer Maintenance EDIT"
CASE cMODE = "A"
cTITLE := "Customer Maintenance ADD"
CASE cMODE = "V"
cTITLE := "Customer Maintenance VIEW"
ENDCASE
oBtn1:Disable()
oBtn2:Disable()
DEFINE WINDOW oWndChild ;
MDICHILD ;
FROM 0,0 to 32,100 ;
OF oWnd ;
TITLE cTITLE
DEFINE DIALOG oCust RESOURCE "CUSTOMER" of oWndChild
REDEFINE FOLDEREX oFld ID 109 of oCust PROMPT "Billing Information", "Service Address";
DIALOGS "CUSTVIEW", "SERVVIEW"
_Folder_1( cMode, oWnd, oRsCust, oFld ) // Custview folder
ACTIVATE DIALOG oCust NOWAIT ;
ON INIT ( oCust:Move( 0, 0 ));
VALID(!GETKEYSTATE( 27 ))
ACTIVATE WINDOW oWndChild ;
ON INIT oWndChild:SetSize( oCust:nWidth, oCust:nHeight, .T. );
VALID ( IIF( !lOK1, _ExitPgm1(.T.,oWndChild,oRsCust,oBtn1,oBtn2), .F. ))
RETURN( NIL )
// ---------- FOLDER-PAGE 1
Static FUNC _Folder_1( cMode, oWnd, oRsCust, oFld )
Local oSay1,oSay2,oSay3,oSay4,oSay5
cLname := space(50)
cFname := space(50)
dDatePur := if(empty(oRsCust:Fields("datePur"):Value), Date(),;
_TtoDate(oRsCust:Fields("datePur"):Value ))
REDEFINE SAY oSay1 PROMPT "Customer Type" ID 110 OF oFld:aDialogs[1] UPDATE
oSay1:SetFont( oFontB )
REDEFINE SAY oSay2 PROMPT "Customer Id" ID 111 OF oFld:aDialogs[1] UPDATE
oSay2:SetFont( oFontB )
REDEFINE SAY oSay3 PROMPT "Company or Last Name" ID 112 OF oFld:aDialogs[1] UPDATE
oSay3:SetFont( oFontB )
REDEFINE SAY oSay4 PROMPT "First Name" ID 113 OF oFld:aDialogs[1] UPDATE
oSay4:SetFont( oFontB )
REDEFINE SAY oSay5 PROMPT "Date Purchased" ID 163 OF oFld:aDialogs[1] UPDATE
oSay4:SetFont( oFontB )
REDEFINE GET oLname var cLname ID 153 of oFld:aDialogs[1] ;
ON CHANGE ( _Isearch( oLname, cLname, oLbx, oRsCust )) UPDATE
REDEFINE GET oFname var cFname ID 154 of oFld:aDialogs[1] UPDATE
REDEFINE DTPICKER oDatePur VAR dDatePur ID 164 OF oFld:aDialogs[1] PICTURE '@D' UPDATE // ;
* When cMode <> "V" UPDATE
REDEFINE xBROWSE oLBX ;
RECORDSET oRsCust ;
COLUMNS "CUSTOMEREID" ;
COLSIZES 50 ;
HEADERS "Cust Id" ;
ID 172 of oFld:aDialogs[1] ;
AUTOCOLS LINES
ADD oCol TO oLbx AT 1 DATA {|x| x := _ChkName(oRsCust:Fields("Last Name"):Value,;
oRsCust:Fields("First Name"):Value,;
oRsCust:Fields("Mid Init"):Value) };
HEADER "Last Name or Company" size 190
ADD oCol TO oLbx AT 2 DATA {|x| x := _ChkAdd(oRsCust:Fields("Address1"):Value,;
oRsCust:Fields("City"):Value,;
oRsCust:Fields("State"):Value) };
HEADER "Address" size 200
RETURN( nil )
//--------------------------
Static Function _TtoDate( tDate )
If empty( tDate)
Return( ctod("00/00/00"))
Endif
If ValType( tDate ) = "D"
Return(tDate )
Endif
Return( stod( substr( ttos( tDate ), 1, 8 ) ))
//----------------------------
Static Func _ChkName( cLast,cFirst,cMiddle )
Local cName
cName := substr("Unk"+space(45),1,45)
If cMiddle = " "
If cFirst = " " .or. empty( cFirst )
cName = substr( alltrim( cLast)+space(45),1,45)
Else
cName := substr(alltrim(cLast)+", "+alltrim(cFirst)+space(45),1,45)
Endif
Else
If cFirst = " " .or. empty( cFirst )
cName = substr( alltrim( cLast)+space(45),1,45)
Else
cName := substr(alltrim(cLast)+", "+alltrim(cFirst)+" "+;
alltrim(cMiddle)+space(45),1,45)
Endif
Endif
Return( cName )
//-------------------------------
Static Func _ChkAdd( cAddress, cCity, cState )
LOCAL cName
cName := if( cAddress = " " .or. empty( cAddress ), " ", alltrim( cAddress ))+" "+;
if( cCity = " " .or. empty( cCity), " ", alltrim(cCity))+" "+;
if( cState = " " .or. empty( cState), " ", alltrim(cState))
cName := substr( alltrim( cName ) +space(45),1,45)
Return( cName )
//-------------
Static Func _Isearch( oLname1, cLname1, oBrw, oRsCust )
cLname1 = Alltrim( oLName1:GetText() )
if Empty( cLname1 )
return .T.
endif
oRsCust:Filter := "[Last Name] like '"+cLname1+"%'"
oBrw:ReFresh()
Return .T.
//-------------------------------
Static FUNCTION _ExitPgm1( lCLEAN,oWndchild,oRsCust,oBtn1,oBtn2 )
LOCAL cDEFA, lOK3
cDEFA := SET(7)
IF lCLEAN = .T.
lOK1 := .T.
oRsCust:CLose()
oWndChild:End()
oBtn1:Enable()
oBtn2:Enable()
ENDIF
RETURN( lOK1 )
// -- end