QBasic Project 3-Record Management

PW: PASSWORD

DECLARE FUNCTION age! (a!)
DECLARE SUB DeleteRec ()
DECLARE SUB SearchRec ()
DECLARE SUB AddRec ()
DECLARE SUB EditRec ()
DECLARE SUB DelRec ()
DECLARE SUB MENU ()
DECLARE SUB DisplayRec ()
DECLARE SUB Search ()
DECLARE SUB Finish ()
DECLARE SUB drawbox ()
CLS
LOCATE 2, 20: PRINT "WELCOME TO XYZ PVT. LTD. EMPLOYEE DATABASE"
LOCATE 8, 24: INPUT "ENTER PASSWORD TO PROCEED"; w$
IF w$ = "PASSWORD" THEN
CALL drawbox
LOCATE 12, 32: PRINT "CORRECT PASSWORD"
LOCATE 24, 25: PRINT "PRESS ANY KEY TO ENTER"
SLEEP 2
GOTO LAST
ELSE
CALL drawbox
LOCATE 12, 32: PRINT "PASSWORD MISMATCH"
LOCATE 13, 32: PRINT "INTRUDERS ALERT"
LOCATE 24, 25: PRINT "PRESS ANY KEY TO EXIT"
END IF
END
LAST:
DO
CALL MENU
LOCATE 10, 55: INPUT CH
SELECT CASE CH
CASE 1
CALL AddRec
CASE 2
CALL DisplayRec
CASE 3
CALL SearchRec
CASE 4
CALL DeleteRec
CASE 5
CALL EditRec
END SELECT
LOOP WHILE CH <> 6
CLS
CALL drawbox
LOCATE 12, 36: PRINT "Good Bye!!"
LOCATE 14, 34: PRINT "See U Again!!!"
END




REM SUB-PROGRAM TO ADD RECORDS TO THE DATA FILE "employee.dat"

SUB AddRec
OPEN "c:\employee.dat" FOR APPEND AS #1
top:
DO
CLS
PRINT TAB(30); "Add Record"
PP:
INPUT "Enter Your Employee NO."; s
INPUT "Enter Your F-Name"; f$
f$ = UCASE$(f$)
INPUT "Enter Your L-Name"; l$
l$ = UCASE$(l$)
INPUT "Enter Your Age"; a
V = age(a)
IF V = 1 THEN
CLS
CALL drawbox
LOCATE 12, 34: PRINT "Age Not Valid"
LOCATE 24, 25: PRINT "PRESS ANY KEY TO ENTER AGAIN"
X$ = INPUT$(1)
CLS
GOTO PP
ELSE
INPUT "Enter Your Post In Office"; p$
p$ = UCASE$(p$)
INPUT "Enter Your Department"; d$
d$ = UCASE$(d$)
INPUT "Enter Your Monthly Salary"; m
END IF
WRITE #1, s, f$, l$, a, p$, d$, m
LOCATE 18, 25: INPUT "Want To Input More Data (Y/N)"; CH$
LOOP WHILE UCASE$(CH$) = "Y"
CLOSE #1
END SUB

REM USER-DEFINED FUNCTION TO CHECK VALIDATION OF AGE

FUNCTION age (a)
IF a <= 18 OR a >= 60 THEN
age = 1
ELSE
age = 0
END IF
END FUNCTION

REM SUB-PROGRAM TO DELETE THE RECORD FROM THE DATA FILE "employee.dat"

SUB DeleteRec
OPEN "c:\employee.dat" FOR INPUT AS #1
OPEN "c:\temp.dat" FOR OUTPUT AS #2
CLS
LOCATE 12, 30
PRINT "Delete-Mode"
LOCATE 14, 30
INPUT "Enter Name to Delete:"; i$
s$ = UCASE$(i$)
FLAG = 0
DO
CLS
LOCATE 12, 30
PRINT "Delete-Mode"
INPUT #1, s, f$, l$, a, p$, d$, m
IF s$ <> f$ THEN
WRITE #2, s, f$, l$, a, p$, d$, m
ELSE
CLS
LOCATE 2, 30: PRINT "Delete-Mode"
PRINT TAB(3); "SN."; TAB(10); "F-Name"; TAB(20); "L-Name"; TAB(29); "Age"; TAB(37); "Post"; TAB(47);

PRINT TAB(3); s; TAB(10); f$; TAB(20); l$; TAB(29); a; TAB(37); p$; TAB(47); d$; TAB(62); m
PRINT: PRINT
LOCATE 8, 10
FLAG = 1
INPUT "Are You Sure To Delete This Record (Y/N):"; CH$
IF UCASE$(CH$) <> "Y" THEN
WRITE #2, s, f$, l$, a, p$, d$, m
ELSE
PRINT
CLS
CALL drawbox
LOCATE 12, 34: PRINT "Record Deleted"
SLEEP 2
END IF
END IF
LOOP WHILE NOT EOF(1)
CLS
IF FLAG = 0 THEN
CALL drawbox
LOCATE 12, 33: PRINT "Data Not Found"
SLEEP 2
END IF
CLOSE #1, #2
KILL "c:\employee.dat"
NAME "c:\temp.dat" AS "c:\employee.dat"
END SUB




REM SUB-PROGRAM TO DISPLAY RECORDS FROM THE DATA FILE "employee.dat"

SUB DisplayRec
OPEN "c:\employee.dat" FOR INPUT AS #1
CLS
PRINT TAB(20); "List Of Employee"
PRINT
PRINT TAB(3); "SN."; TAB(10); "F-Name"; TAB(20); "L-Name"; TAB(29); "Age"; TAB(37); "Post"; TAB(47); "Department"; TAB(62); "Salary"
PRINT
DO
INPUT #1, s, f$, l$, a, p$, d$, m
IF s <> 0 THEN
PRINT TAB(3); s; TAB(10); f$; TAB(20); l$; TAB(29); a; TAB(37); p$; TAB(47); d$; TAB(62); m
END IF
LOOP WHILE NOT EOF(1)
PRINT
PRINT TAB(15); "PRESS ANY KEY TO GOTO THE MAINMENU"
X$ = INPUT$(1)
CLOSE #1
END SUB

REM SUB-PROGRAM TO DRAW A BOX

SUB drawbox
LOCATE 10, 30
PRINT STRING$(20, "*")
FOR i = 11 TO 15
LOCATE i, 30: PRINT "*"
LOCATE i, 49: PRINT "*"
NEXT i
LOCATE 15, 30
PRINT STRING$(20, "*")
END SUB
REM SUB-PROGRAM TO EDIT RECORDS OF THE DATA FILE "employee.dat"
SUB EditRec
OPEN "c:\employee.dat" FOR INPUT AS #1
OPEN "c:\temp.dat" FOR OUTPUT AS #2
CLS
LOCATE 12, 30
PRINT "EDIT MODE"
LOCATE 14, 30
INPUT "Enter NAME to EDIT"; s$
FLAG = 0
CLS
DO
CLS
INPUT #1, s, f$, l$, a, p$, d$, m
IF s$ <> f$ THEN
WRITE #2, s, f$, l$, a, p$, d$, m
ELSE
LOCATE 2, 30: PRINT "EDIT MODE"
PRINT: PRINT
PRINT TAB(3); "SN."; TAB(10); "F-Name"; TAB(20); "L-Name"; TAB(29); "Age"; TAB(37); "Post"; TAB(47); "Department"; TAB(62); "Salary"
PRINT TAB(3); s; TAB(10); f$; TAB(20); l$; TAB(29); a; TAB(37); p$; TAB(47); d$; TAB(62); m
PRINT: PRINT
LOCATE 8, 10
FLAG = 1
INPUT "WANT TO EDIT THIS Y/N"; CH$
IF UCASE$(CH$) = "Y" THEN
PRINT TAB(3); "SN."; TAB(10); "F-Name"; TAB(20); "L-Name"; TAB(29); "Age"; TAB(37); "Post"; TAB(47); "Department"; TAB(62); "Salary"
INPUT "Enter Your Employee NO."; Ns
INPUT "Enter Your F-Name"; Nf$
INPUT "Enter Your L-Name"; Nl$
INPUT "Enter Your Age"; Na
INPUT "Enter Your Post In Office"; Np$
INPUT "Enter Your Department"; Nd$
INPUT "Enter Your Monthly Salary"; Nm
WRITE #2, Ns, Nf$, Nl$, Na, Np$, Nd$, Nm
CLS
CALL drawbox
LOCATE 12, 34: PRINT "DATA EDITED"
SLEEP 2
ELSE
WRITE #2, s, f$, l$, a, p$, d$, m
END IF
END IF
LOOP WHILE NOT EOF(1)
LOCATE 11, 25
IF FLAG = 0 THEN
CALL drawbox
LOCATE 12, 33: PRINT "DATA NOT FOUND"
SLEEP 2
END IF
CLOSE #1, #2
KILL "c:\employee.dat"
NAME "c:\temp.dat" AS "c:\employee.dat"
END SUB




REM SUB-PROGRAM FOR MENU

SUB MENU
CLS
LOCATE 1, 15
PRINT STRING$(50, "*")
FOR i = 2 TO 12
LOCATE i, 15: PRINT "*"
LOCATE i, 65: PRINT "*"
NEXT i
LOCATE 12, 15
PRINT STRING$(50, "*")
LOCATE 2, 30
PRINT "MAIN MENU"
LOCATE 4, 20
PRINT "1.Add Records"
LOCATE 5, 20
PRINT "2.Display Records"
LOCATE 6, 20
PRINT "3.Search Records"
LOCATE 7, 20
PRINT "4.Delete Record"
LOCATE 8, 20
PRINT "5.Edit Record"
LOCATE 9, 20
PRINT "6.Exit"
LOCATE 10, 20
PRINT "ENTER YOUR CHOICE:: 1/2/3/4/5/6/…"
END SUB

REM SUB-PROGRAM TO SEARCH RECORDS FROM THE DATA FILE "employee.dat"

SUB SearchRec
OPEN "c:\employee.dat" FOR INPUT AS #1
CLS
LOCATE 12, 25
INPUT "Enter Name To Search Data By Name?::"; s$
FLAG = 0
CLS
LOCATE 2, 25: PRINT "SEARCH RESULT"
PRINT: PRINT
PRINT TAB(3); "SN"; TAB(10); "F-Name"; TAB(20); "L-Name"; TAB(29); "Age"; TAB(37); "Post"; TAB(47); "Department"; TAB(62); "Salary"
DO
INPUT #1, s, f$, l$, a, p$, d$, m
IF s$ = f$ THEN
PRINT TAB(3); s; TAB(10); f$; TAB(20); l$; TAB(29); a; TAB(37); p$; TAB(47); d$; TAB(62); m
FLAG = 1
END IF
LOOP WHILE NOT EOF(1)
PRINT
IF FLAG = 0 THEN PRINT "DATA NOT FOUND"
PRINT
PRINT "PRESS ANY KEY TO GOTO MAIN MENU"
X$ = INPUT$(1)
CLOSE #1
END SUB

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image