|
9
21st April 23:32
External User
|
problem with quotes and "&" operator
The problem is that I don't know at compiletime if user wil want to search
for either a name, a birthdate or both.
Yes, I think this is the correct solution.
Here's the code, sorry for the long post. Comments are in dutch and Pan
wrapped some lines. The idea is to present a screen to the user
(that's a seperate part of code) allowing him to enter one or more
values to search for in several tables (about 800).
/***
*
* naam : li_zm
* doel : zoek een medewerker op verschillende criteria
* parameters : met defaultwaarden:
* 1 "klantcode"
* 2 space(4)
* 3 "beeindigde klanten meenemen"
* 4 "N"
* 5 "medewerkercode"
* 6 space(LEN_MWCODE)
* 7 "sofinummer"
* 8 " . . "
* 9 "achternaam"
* 10 space(30)
* 11 "exact op achternaam zoeken"
* 12 "J"
* 13 "geboortedatum"
* 14 ctod("")
* 15 "alleen eerste treffer tonen"
* 16 "N"
* retour : naam van bestand waarin de uitvoer staat
* maker : Jules Alberts 2000
*
*/
#include "ara_io.ch"
#include "ara_dbf.ch"
#include "ara_loc.ch"
function li_zm(aParams)
local cUitvoer := '', ;
aSet := setall(), ;
cOldpath := ''
// de parameters
local cKlant := aParams[2], ;
lBeeindigd := if(aParams[4] == "J", .t., .f.), ;
cMwCode := aParams[6], ;
cSofi := aParams[8], ;
cNaam := aParams[10], ;
lExact := if(aParams[12] == "J", .t., .f.), ;
dGeboren := aParams[14], ;
lAlleenEerste := if(aParams[16] == "J", .t., .f.), ;
aKl := {}, ;
i := 0
local cConditie := ""
memvar cDataPad
private cNewpath := "", ;
lEerste := .t.
waarschuw('de lijst wordt voorbereid...')
// stel de conditie samen if !empty(cMwCode)
cConditie := "upper(medewerk->code) == '" + cMwCode + "'"
endif
if !empty(charrem("0", charrem(".", cSofi)))
cConditie := if(empty(cConditie), cConditie, cConditie + " .and. ")
cConditie += "crypt(medewerk->sofinummer, memvar->cPw) == '" + cSofi + "'"
endif
if !empty(cNaam)
cConditie := if(empty(cConditie), cConditie, cConditie + " .and. ") if lExact
cConditie += "alltrim(upper(medewerk->naam)) == ["
cConditie += alltrim(upper(cNaam)) + "]" else
cConditie += "soundex(alltrim(upper(medewerk->naam))) == ["
cConditie += soundex(alltrim(upper(cNaam))) + "]"
endif
endif
if !empty(dGeboren)
cConditie := if(empty(cConditie), cConditie, cConditie + " .and. ")
cConditie += "dtos(medewerk->geboren) == '" + dtos(dGeboren) + "'"
endif
if empty(cConditie)
melding("Er is geen conditie ingevuld")
return (NIL)
endif
dbcloseall()
cUitvoer := tempfile(delslash(TEMPDIR), 'tmp')
set alternat to (cUitvoer)
begin sequence
do case
case empty(cKlant)
if dbfopen(,,"klant") == DBF_ERROR
melding()
break
else
if !lBeeindigd
// zet index op alleen actuele klanten
klant->(dbsetfilter({||!beeindigd()}, '!beeindigd()')) endif endif
klant->(dbgotop())
do while !klant->(eof())
waarschuw("klant " + klant->code + " wordt verwerkt")
set path to (sl(cDataPad) + klant->code)
if verwerk(klant->code, cConditie, lAlleenEerste)
break
endif
set path to dbfclose("medewerk")
klant->(toonskip())
enddo
case alltrim(upper(cKlant)) == "BA"
aKl := asort(BA_KLANTEN)
for i := 1 to len(aKl)
waarschuw(aKl[i] + " wordt verwerkt")
set path to (sl(cDataPad) + aKl[i])
if verwerk(aKl[i], cConditie, lAlleenEerste)
break
endif
set path to
dbfclose("medewerk")
next
case alltrim(upper(cKlant)) == "ZVBM"
aKl := asort(ZVBM_KLANTEN)
for i := 1 to len(aKl)
waarschuw(aKl[i] + " wordt verwerkt")
set path to (sl(cDataPad) + aKl[i])
if verwerk(aKl[i], cConditie, lAlleenEerste)
break
endif
set path to
dbfclose("medewerk")
next
otherwise // cKlant is ingevuld
set path to (sl(cDataPad) + cKlant)
if verwerk(cKlant, cConditie, lAlleenEerste)
break
endif
dbfclose("medewerk")
set path to
endcase
end sequence
set alternat to
dbcloseall()
setall(aSet)
waarschuw()
return (cUitvoer)
static function verwerk(cKlant, cConditie, lAlleenEerste)
if dbfopen(,,"medewerk") == DBF_ERROR
LOG_AAN
? "fout bij openen medewerkertabel van klant " + cKlant
LOG_UIT
return (.f.) endif
medewerk->(dbgotop())
do while !medewerk->(eof())
if &cConditie
schrijf(cKlant)
if lAlleenEerste
return (.t.) endif endif
medewerk->(dbskip())
enddo
return (.f.)
static function schrijf(cKlant)
memvar lEerste
LOG_AAN
if lEerste
lEerste := .f.
?? "klant medewerker" + space(30) + "geboren sofinummer"
? ""
endif
? cKlant + " "
?? medewerk->code + " "
?? padr(substr(alltrim(medewerk->naam) + ", " +
alltrim(medewerk->initialen), 1, 25), 25, ".") + "..."
?? dtoc(medewerk->geboren)
?? " " + crypt(medewerk->sofinummer, memvar->cPw)
LOG_UIT
return (NIL)
|