Você está na página 1de 6

CLEAR

SET CENT ON

SET DATE TO ITALIAN && OBLIGATORIU

WCNP = ' '

@ 6, 17 say 'CNP : ' GET WCNP PICTURE '@! xxxxxxxxxxxxx' VALID VERCNP(WCNP)

READ

FUNCTION VERCNP

PARAMETER LCCNP

PRIVATE LAC, LAPO

IF WCNP==' '

RETURN .T.

ENDIF

DIMENSION LAC( 13), LAPO( 12)

PRIVATE LNCC, I, DA1, DA2, DA3

WF = .T.

LAC( 1) = SUBSTR(LCCNP, 1, 1)

LAPO( 1) = 2

LAC( 2) = SUBSTR(LCCNP, 2, 1)

LAPO( 2) = 7

LAC( 3) = SUBSTR(LCCNP, 3, 1)

LAPO( 3) = 9

LAC( 4) = SUBSTR(LCCNP, 4, 1)

LAPO( 4) = 1

LAC( 5) = SUBSTR(LCCNP, 5, 1)

LAPO( 5) = 4

LAC( 6) = SUBSTR(LCCNP, 6, 1)

LAPO( 6) = 6

LAC( 7) = SUBSTR(LCCNP, 7, 1)
LAPO( 7) = 3

LAC( 8) = SUBSTR(LCCNP, 8, 1)

LAPO( 8) = 5

LAC( 9) = SUBSTR(LCCNP, 9, 1)

LAPO( 9) = 8

LAC( 10) = SUBSTR(LCCNP, 10, 1)

LAPO( 10) = 2

LAC( 11) = SUBSTR(LCCNP, 11, 1)

LAPO( 11) = 7

LAC( 12) = SUBSTR(LCCNP, 12, 1)

LAPO( 12) = 9

LAC( 13) = SUBSTR(LCCNP, 13, 1)

FOR I = 1 TO 13

IF .NOT. ISDIGIT(LAC(I))

DO WARN WITH 'Eroare validare CNP', 'Codul numeric personal nu este un numar.'

RETURN .F.

ENDIF

ENDFOR

*****

LU3 = LAC(4)+LAC(5) &&LUNA

IF .NOT. (BETWEEN(VAL(LU3), 1, 12))

DO WARN WITH 'Eroare validare CNP', 'LUNA nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

DA3 = LAC(6)+LAC(7) && ZIUA

LU3 = LAC(4)+LAC(5)

if INLIST(VAL(LU3), 2)
IF .NOT. (BETWEEN(VAL(DA3), 1, 29))

DO WARN WITH 'Eroare validare CNP', 'ZIUA nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

endif

DA3 = LAC(6)+LAC(7) && ZIUA

LU3 = LAC(4)+LAC(5)

IF INLIST(VAL(LU3), 4, 6, 9, 11)

IF .NOT. (BETWEEN(VAL(DA3), 1, 30))

DO WARN WITH 'Eroare validare CNP', 'ZIUA nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

endif

DA3 = LAC(6)+LAC(7) && ZIUA

LU3 = LAC(4)+LAC(5)

if INLIST(VAL(LU3), 1, 3, 5, 7, 8, 10, 12)

IF .NOT. (BETWEEN(VAL(DA3), 1, 31))

DO WARN WITH 'Eroare validare CNP', 'ZIUA nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

endif

******

DO CASE

CASE INLIST(LAC(1), '1', '2')

DA1 = LAC(6)+LAC(7)+'-'+LAC(4)+LAC(5)+'-'+'19'+LAC(2)+LAC(3)

DA2 = DTOC(CTOD(DA1))

IF .NOT. (DA1==DA2)
DO WARN WITH 'Eroare validare CNP', 'Anul nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

CASE INLIST(LAC(1), '3', '4')

DA1 = LAC(6)+LAC(7)+'-'+LAC(4)+LAC(5)+'-'+'18'+LAC(2)+LAC(3)

DA2 = DTOC(CTOD(DA1))

IF .NOT. (DA1==DA2)

DO WARN WITH 'Eroare validare CNP', 'Anul nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

CASE INLIST(LAC(1), '5', '6')

DA1 = LAC(6)+LAC(7)+'-'+LAC(4)+LAC(5)+'-'+'20'+LAC(2)+LAC(3)

DA2 = DTOC(CTOD(DA1))

IF .NOT. (DA1==DA2)

DO WARN WITH 'Eroare validare CNP', 'Anul nasterii din CNP nu este una valida.'

RETURN .F.

ENDIF

CASE INLIST(LAC(1), '7', '8')

OTHERWISE

DO WARN WITH 'Eroare validare CNP', 'CNP-ul are prima cifra incorecta.'

RETURN .F.

ENDCASE

DA3 = LAC(8)+LAC(9)

IF .NOT. (BETWEEN(VAL(DA3), 1, 47) .OR. INLIST(VAL(DA3), 51, 52, 99))

DO WARN WITH 'Eroare validare CNP', 'CNP-ul are codul judetului incorect.'

RETURN .F.

ENDIF

LNCC = 0
FOR I = 1 TO 12

LNCC = LNCC+VAL(LAC(I))*LAPO(I)

ENDFOR

LNCC = MOD(LNCC, 11)

IF LNCC==10

LNCC = 1

ENDIF

IF LNCC<>VAL(LAC(13))

DO WARN WITH 'Eroare validare CNP', 'Eroare la controlul codului numeric personal'

RETURN .F.

ENDIF

RETURN WF

FUNCTION WARN

PARAMETER CWINDOW, CMSGTEXT

PRIVATE CTITLE

M.CTITLE = ' '+ALLTRIM(CWINDOW)+' '

= READ1()

RETURN .F.

FUNCTION READ1

PRIVATE M.CURRAREA, M.TALKSTAT, M.COMPSTAT

IF SET('TALK')='ON'

SET TALK OFF

M.TALKSTAT = 'ON'

ELSE

M.TALKSTAT = 'OFF'

ENDIF
M.COMPSTAT = SET('COMPATIBLE')

SET COMPATIBLE TO FOXPLUS

IF .NOT. WEXIST('warn') .OR. UPPER(WTITLE('WARN'))=='WARN.PJX' .OR.


UPPER(WTITLE('WARN'))=='WARN.SCX' .OR. UPPER(WTITLE('WARN'))=='WARN.MNX' .OR.
UPPER(WTITLE('WARN'))=='WARN.PRG'

DEFINE WINDOW WARN FROM INT((SROWS()-10)/2), INT((SCOLS()-55)/2) TO INT((SROWS()-


10)/2)+9, INT((SCOLS()-55)/2)+54 FLOAT NOCLOSE SHADOW TITLE M.CTITLE NOMINIMIZE
DOUBLE COLOR SCHEME 7

ENDIF

IF WVISIBLE('warn')

ACTIVATE WINDOW SAME WARN

ELSE

ACTIVATE WINDOW NOSHOW WARN

ENDIF

@ 3, 5 SAY CMSGTEXT SIZE 2, 46

@ 1, 1 TO 3, 3

@ 2, 2 SAY '!' SIZE 1, 1, 0

@ 6, 22 GET CREPLY DEFAULT 1 SIZE 1, 6, 1 PICTURE '@*HT !?


@ 1, 22 SAY 'AVERTISMENT' SIZE 1, 11, 0

IF .NOT. WVISIBLE('warn')

ACTIVATE WINDOW WARN

ENDIF

READ CYCLE

RELEASE WINDOW WARN

IF M.TALKSTAT='ON'

SET TALK ON

ENDIF

RETURN .F.