home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 6 / 06.iso / a / a610 / 6.ddi / DEMO / FGL / SPERSON.4GL < prev    next >
Encoding:
Text File  |  1989-12-08  |  2.7 KB  |  89 lines

  1. DATABASE leads
  2. GLOBALS "globals.4gl"
  3.  
  4. FUNCTION sperson(uflag)
  5. {
  6. The sperson function either adds, updates, or deletes a
  7. salesperson from the sperson table depending on the value of
  8. the calling argument.  In each case it uses the f_sperson form.
  9.  
  10. uflag =  1 to add a new salesperson
  11.          2 to update information on an existing salesperson
  12.          3 to delete an existing salesperson
  13. }
  14. DEFINE   uflag, cnt     SMALLINT,
  15.          empno          CHAR (10),
  16.          answer         CHAR(1)
  17.  
  18. OPEN FORM f_sperson FROM "f_sperson"
  19. CLEAR SCREEN
  20.  
  21. CASE (uflag)
  22.    WHEN 1
  23.       DISPLAY FORM f_sperson
  24.       INPUT BY NAME pr_sperson.*
  25.          AFTER FIELD empnum
  26.             SELECT      COUNT(*)
  27.                INTO     cnt
  28.                FROM     sperson
  29.                WHERE    empnum = pr_sperson.empnum
  30.             IF (cnt != 0) THEN
  31.                ERROR "Number in use."
  32.                NEXT FIELD empnum
  33.             END IF
  34.             IF (pr_sperson.empnum = 0
  35.                OR pr_sperson.empnum IS NULL) THEN
  36.                ERROR "Enter another employee number "
  37.                NEXT FIELD empnum
  38.             END IF
  39.       END INPUT
  40.       INSERT INTO sperson VALUES (pr_sperson.*)
  41.  
  42.    WHEN 2
  43.       PROMPT "Enter an employee number (or just RETURN): " FOR empno
  44.       IF (empno IS NULL) THEN
  45.          CALL rd_sperson()
  46.          PROMPT "\nEnter an employee number: " FOR empno
  47.       END IF
  48.       SELECT      *
  49.          INTO     pr_sperson.*
  50.          FROM     sperson
  51.          WHERE    empnum = empno
  52.       IF (status = NOTFOUND) THEN
  53.          ERROR "There is no employee number ", empno USING "###"
  54.          SLEEP 3
  55.          EXIT CASE
  56.       END IF
  57.       DISPLAY FORM f_sperson
  58.       DISPLAY BY NAME pr_sperson.empnum
  59.       INPUT BY NAME pr_sperson.position THRU pr_sperson.phone WITHOUT DEFAULTS
  60.       UPDATE sperson
  61.          SET sperson.* = pr_sperson.*
  62.          WHERE empnum = pr_sperson.empnum
  63.  
  64.    WHEN 3
  65.       PROMPT "Enter an employee number (or just press RETURN ",
  66.          "for a list of employees): " FOR empno
  67.       IF (empno IS NULL) THEN
  68.          CALL rd_sperson()
  69.          PROMPT "\nEnter an employee number: " FOR empno
  70.       END IF
  71.       SELECT      *
  72.          INTO     pr_sperson.*
  73.          FROM     sperson
  74.          WHERE    empnum = empno
  75.       IF (status = NOTFOUND) THEN
  76.          ERROR "There is no employee number ", empno USING "###"
  77.          SLEEP 3
  78.          EXIT CASE
  79.       END IF
  80.       DISPLAY FORM f_sperson
  81.       DISPLAY BY NAME pr_sperson.*
  82.       PROMPT "Delete this sales person? (y/n) " FOR CHAR answer
  83.       IF (answer = "y" OR answer = "Y") THEN
  84.          DELETE FROM sperson WHERE empnum = empno
  85.       END IF
  86. END CASE
  87. CLEAR SCREEN
  88. END FUNCTION
  89.