#include 'fivewin.ch'
#include 'xbrowse.ch'
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
function Main()
local oDlg, oBrw, oFont
local aData
local oFilter, oClear
local lSearch:= .f.
local cDbf :="customer"
local cAlias:="CL"
rddSetDefault( "DBFCDX" )
setHandleCount( 100 )
USE CUSTOMER ALIAS CL
INDEX ON upper(CL->FIRST) TAG CU1 TO CUSTOMER
INDEX ON upper(CL->LAST) TAG CU2 TO CUSTOMER
DbCloseAll()
USE ( cDbf + ".dbf" ) ;
INDEX ( cDbf + ".cdx" ) ;
ALIAS ( cAlias ) ;
NEW
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 640,440 PIXEL
@ 30, 10 XBROWSE oBrw OF oDlg SIZE 300, 200 PIXEL ;
AUTOCOLS ALIAS 'CUST' NOBORDER
oBrw:nMarqueeStyle = MARQSTYLE_HIGHLWIN7
oBrw:CreateFromCode()
@ 10, 20 BTNBMP PROMPT "add" SIZE 40,20 PIXEL OF oDlg FLAT ;
ACTION edita( .t.)
@ 10,100 BTNBMP PROMPT "Mod" SIZE 40,20 PIXEL OF oDlg FLAT ;
ACTION edita( .f.)
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//------------------------------------------------------------------------------------------------------------------//
FUNCTION edita( lAdd )
LOCAL oDlg
LOCAL lSave := .F.
LOCAL oFont
LOCAL oBtn
LOCAL oGrp
LOCAL cFirst
LOCAL cLast
LOCAL cStreet
LOCAL cCity
LOCAL cState
LOCAL cZip
LOCAL dHiredate
LOCAL lMarried
LOCAL nAge
LOCAL nSalary
LOCAL cNotes
local aGet[11]
local nMode
local aTitle := { "Add a customer",;
"Modify a customer"}
IF lAdd
CL->(dbGoBottom())
CL->(dbSkip())
ENDIF
cFirst := CL->FIRST
cLast := CL->LAST
cStreet := CL->STREET
cCity := CL->CITY
cState := CL->STATE
cZip := CL->ZIP
dHiredate := CL->HIREDATE
lMarried := CL->MARRIED
nAge := CL->AGE
nSalary := CL->SALARY
cNotes := CL->NOTES
If ladd
nMode:=1
else
nMode:=2
endif
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 8
DEFINE DIALOG oDlg FROM 100, 100 TO 482,916;
TITLE aTitle[nMode] PIXEL FONT oFont
@ 0, 4 GROUP oGrp TO 168, 404 OF oDlg PIXEL
@ 12, 10 SAY "First:" OF oDlg SIZE 14, 8 PIXEL FONT oFont
@ 10, 43 GET aGet[1] var cFirst OF oDlg SIZE 105, 12 PIXEL FONT oFont ;
VALID Custvalid( cFirst, aGet[1], nMode, 1)
@ 26, 10 SAY "Last:" OF oDlg SIZE 14, 8 PIXEL FONT oFont
@ 24, 43 GET aGet[2] var cLast OF oDlg SIZE 105, 12 PIXEL FONT oFont ;
VALID Custvalid( cLast , aGet[2], nMode,2)
@ 40, 10 SAY "Street:" OF oDlg SIZE 19, 8 PIXEL FONT oFont
@ 38, 43 GET aGet[3] var cStreet OF oDlg SIZE 155, 12 PIXEL FONT oFont
@ 54, 10 SAY "City:" OF oDlg SIZE 13, 8 PIXEL FONT oFont
@ 52, 43 GET aGet[4] var cCity OF oDlg SIZE 155, 12 PIXEL FONT oFont
@ 68, 10 SAY "State:" OF oDlg SIZE 17, 8 PIXEL FONT oFont
@ 66, 43 GET aGet[5] var cState OF oDlg SIZE 15, 12 PIXEL FONT oFont
@ 82, 10 SAY "Zip:" OF oDlg SIZE 11, 8 PIXEL FONT oFont
@ 80, 43 GET aGet[6] var cZip OF oDlg SIZE 55, 12 PIXEL FONT oFont
@ 96, 10 SAY "Hiredate:" OF oDlg SIZE 28, 8 PIXEL FONT oFont
@ 94, 43 GET aGet[7] var dHiredate OF oDlg SIZE 44, 12 PIXEL FONT oFont
@ 108, 43 CHECKBOX aGet[8] var lMarried PROMPT "&Married:" OF oDlg SIZE 42, 12 PIXEL FONT oFont
@ 124, 10 SAY "Age:" OF oDlg SIZE 14, 8 PIXEL FONT oFont
@ 122, 43 GET aGet[9] var nAge OF oDlg SIZE 12, 12 PIXEL PICTURE "99" FONT oFont
@ 138, 10 SAY "Salary:" OF oDlg SIZE 21, 8 PIXEL FONT oFont
@ 136, 43 GET aGet[10] var nSalary OF oDlg SIZE 40, 12 PIXEL PICTURE "999999.99" FONT oFont
@ 152, 10 SAY "Notes:" OF oDlg SIZE 20, 8 PIXEL FONT oFont
@ 150, 43 GET aGet[11] var cNotes OF oDlg SIZE 355, 12 PIXEL FONT oFont
// @ 172, 4 BUTTON oBtn PROMPT "&Help" OF oDlg SIZE 42, 14 PIXEL FONT oFont // ACTION ()
@ 172, 318 BUTTON oBtn PROMPT "Conferma" OF oDlg SIZE 42, 14 PIXEL FONT oFont DEFAULT ACTION (oDlg:End(), lSave := .T.)
@ 172, 362 BUTTON oBtn PROMPT "Annulla" OF oDlg SIZE 42, 14 PIXEL FONT oFont CANCEL ACTION (oDlg:End())
ACTIVATE DIALOG oDlg CENTERED
IF lSave
IF lAdd
CL->(dbAppend())
ELSE
CL->(RLock())
ENDIF
CL->FIRST := cFirst
CL->LAST := cLast
CL->STREET := cStreet
CL->CITY := cCity
CL->STATE := cState
CL->ZIP := cZip
CL->HIREDATE := dHiredate
CL->MARRIED := lMarried
CL->AGE := nAge
CL->SALARY := nSalary
CL->NOTES := cNotes
CL->(dbUnlock())
ENDIF
RETURN NIL
//-----------------------------------------------------------------------------------------//
function Custvalid( cCliente, oGet, nMode,ntag)
local lReturn := .f.
local nRecno := CL->( RecNo() )
local nOrder := CL->( OrdNumber() )
local nArea := Select()
if Empty( cCliente )
if nMode == 4 .OR. nTag == 2
RETURN .t.
else
MsgStop("This field cannot be empty..")
RETURN .f.
endif
endif
SELECT CL
CL->( DbSetOrder( nTag ) )
CL->( DbGoTop() )
if CL->( DbSeek( UPPER( cCliente ) ) )
DO CASE
Case nMode == 1 .OR. nMode == 3
lReturn := .f.
MsgStop("Existing customer")
Case nMode == 2
if CL->( Recno() ) == nRecno
lReturn := .t.
else
lReturn := .f.
MsgStop("Existing customer")
endif
Case nMode == 4
lReturn := .t.
END CASE
else
if nMode < 4
lReturn := .t.
else
if MsgYesNo("The customer not exit. ¿ Do you wish add now ? ")
// lReturn := edita( , 1, , , @cCliente )
else
lReturn := .f.
endif
endif
endif
if lReturn == .f.
iif(nTag==1,oGet:cText(space(15)),oGet:cText(space(15)))
else
oGet:cText( cCliente )
endif
CL->( DbSetOrder( nOrder ) )
CL->( DbGoTo( nRecno ) )
Select (nArea)
return lReturn
//---------------------------------------------------------------------------------------------//