home *** CD-ROM | disk | FTP | other *** search
- DATABASE leads
- GLOBALS "globals.4gl"
-
- FUNCTION sperson(uflag)
- {
- The sperson function either adds, updates, or deletes a
- salesperson from the sperson table depending on the value of
- the calling argument. In each case it uses the f_sperson form.
-
- uflag = 1 to add a new salesperson
- 2 to update information on an existing salesperson
- 3 to delete an existing salesperson
- }
- DEFINE uflag, cnt SMALLINT,
- empno CHAR (10),
- answer CHAR(1)
-
- OPEN FORM f_sperson FROM "f_sperson"
- CLEAR SCREEN
-
- CASE (uflag)
- WHEN 1
- DISPLAY FORM f_sperson
- INPUT BY NAME pr_sperson.*
- AFTER FIELD empnum
- SELECT COUNT(*)
- INTO cnt
- FROM sperson
- WHERE empnum = pr_sperson.empnum
- IF (cnt != 0) THEN
- ERROR "Number in use."
- NEXT FIELD empnum
- END IF
- IF (pr_sperson.empnum = 0
- OR pr_sperson.empnum IS NULL) THEN
- ERROR "Enter another employee number "
- NEXT FIELD empnum
- END IF
- END INPUT
- INSERT INTO sperson VALUES (pr_sperson.*)
-
- WHEN 2
- PROMPT "Enter an employee number (or just RETURN): " FOR empno
- IF (empno IS NULL) THEN
- CALL rd_sperson()
- PROMPT "\nEnter an employee number: " FOR empno
- END IF
- SELECT *
- INTO pr_sperson.*
- FROM sperson
- WHERE empnum = empno
- IF (status = NOTFOUND) THEN
- ERROR "There is no employee number ", empno USING "###"
- SLEEP 3
- EXIT CASE
- END IF
- DISPLAY FORM f_sperson
- DISPLAY BY NAME pr_sperson.empnum
- INPUT BY NAME pr_sperson.position THRU pr_sperson.phone WITHOUT DEFAULTS
- UPDATE sperson
- SET sperson.* = pr_sperson.*
- WHERE empnum = pr_sperson.empnum
-
- WHEN 3
- PROMPT "Enter an employee number (or just press RETURN ",
- "for a list of employees): " FOR empno
- IF (empno IS NULL) THEN
- CALL rd_sperson()
- PROMPT "\nEnter an employee number: " FOR empno
- END IF
- SELECT *
- INTO pr_sperson.*
- FROM sperson
- WHERE empnum = empno
- IF (status = NOTFOUND) THEN
- ERROR "There is no employee number ", empno USING "###"
- SLEEP 3
- EXIT CASE
- END IF
- DISPLAY FORM f_sperson
- DISPLAY BY NAME pr_sperson.*
- PROMPT "Delete this sales person? (y/n) " FOR CHAR answer
- IF (answer = "y" OR answer = "Y") THEN
- DELETE FROM sperson WHERE empnum = empno
- END IF
- END CASE
- CLEAR SCREEN
- END FUNCTION
-