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

  1. DATABASE leads
  2. GLOBALS "globals.4gl"
  3.  
  4. FUNCTION decide(uflag)
  5. {
  6. The decide function displays the f_decide form and
  7. matches the user's input to rows in the prospect table.
  8. If an exact match isn't found, the choose function displays 
  9. a list of possible matches for the user to choose from.
  10.  
  11. uflag = 1 for query for old or new prospect,
  12. uflag = 2 for no query (assume old).
  13. }
  14. DEFINE   buf1              CHAR(40),
  15.          new               CHAR(1),
  16.          uflag, numrows    SMALLINT
  17. INITIALIZE pr_prospect.* TO NULL
  18.  
  19. DECLARE   c_prospect CURSOR FOR
  20.    SELECT      *
  21.       INTO     pr_prospect.*
  22.       FROM     prospect
  23.       WHERE    prospect.company = pr_prospect.company
  24.                AND prospect.lname = pr_prospect.lname
  25.  
  26. DECLARE   c_try1 CURSOR FOR
  27.    SELECT      fname,
  28.                lname,
  29.                company,
  30.                ref
  31.       FROM     prospect
  32.       WHERE    prospect.company = pr_prospect.company
  33.                AND prospect.lname = pr_prospect.lname
  34.       ORDER BY lname,
  35.                fname,
  36.                company
  37.  
  38. DECLARE c_try2 CURSOR FOR
  39.    SELECT      fname,
  40.                lname,
  41.                company,
  42.                ref
  43.       FROM     prospect
  44.       WHERE    prospect.company LIKE buf1
  45.                OR prospect.lname = pr_prospect.lname
  46.       ORDER BY lname,
  47.                fname,
  48.                company
  49.  
  50. IF (uflag = 1) THEN
  51.    OPEN FORM f_decide FROM "f_decid1"
  52.    DISPLAY FORM f_decide
  53.    INPUT BY NAME  pr_prospect.lname,
  54.                   pr_prospect.company,
  55.                   new
  56. ELSE
  57.    OPEN FORM f_decide FROM "f_decid2"
  58.    DISPLAY FORM f_decide
  59.    INPUT BY NAME  pr_prospect.lname,
  60.                   pr_prospect.company
  61.    LET new = "O"
  62. END IF
  63.  
  64. CLEAR SCREEN
  65. SELECT      COUNT(*)
  66.    INTO     numrows
  67.    FROM     prospect
  68.    WHERE    prospect.company = pr_prospect.company
  69.             AND prospect.lname = pr_prospect.lname
  70.  
  71. OPEN c_prospect
  72. CASE
  73.       {One row found, not a new prospect.  Use the row.}
  74.       WHEN  (numrows = 1 AND new = "O") 
  75.             FETCH c_prospect
  76.  
  77.       {More than one row found, not a new prospect. Review rows.}
  78.       WHEN  (numrows >  1 AND new = "O")
  79.             CALL choose(uflag, 1, 1)
  80.  
  81.       {No rows found, not a new prospect. Review possible rows.}
  82.       WHEN  (numrows = 0 AND new = "O" )
  83.             LET buf1 = pr_prospect.company[1,5], "%"
  84.             CALL choose(uflag, 2, 2)
  85.  
  86.       {All is well, take no action.}
  87.       WHEN  (numrows = 0 AND new = "N")
  88.  
  89.       {>= 1 row found, it was supposed to be a new prospect. Verify.}
  90.       WHEN  (numrows >= 1 AND new = "N")
  91.             CALL choose(uflag, 1, 3)
  92. END CASE
  93. CLEAR SCREEN
  94. END FUNCTION
  95.  
  96. FUNCTION choose(uuflag, uflag, msg)
  97. {
  98. uuflag    is the uflag from the calling routine
  99. uflag     specifies the type of select
  100. msg       specifies the proper message for display
  101. }
  102. DEFINE   pa_ref         ARRAY[25] OF LIKE prospect.ref,
  103.          pa_prosp       ARRAY[25] OF RECORD
  104.             flname      CHAR(31),
  105.             company     LIKE prospect.company
  106.          END RECORD,
  107.          msg1, msg2, msg3, msg4, msg5, msg6, msg7     CHAR(75),
  108.          buf1, buf2                                 CHAR(15),
  109.          cnt, uuflag, uflag, msg          SMALLINT
  110.  
  111.  
  112. LET msg1 = " There is more than one possible prospect."
  113. LET msg2 =
  114. " The prospect does not exist in the database exactly as you specified it."
  115. LET msg3 = " The prospect may already exist in the database."
  116. LET msg4 =
  117. " Use the ARROW keys to move the cursor, press ESCAPE to make a selection."
  118. LET msg5 = " Select the first entry if the name you want is not on the list."
  119. LET msg6 = " This is a new prospect."
  120. LET msg7 = " Prospect does not exist in the database."
  121. LET pa_prosp[1].flname = ">>> NOT ON THE LIST <<<"
  122. LET pa_prosp[1].company = NULL
  123. LET cnt = 2
  124.  
  125. IF (uflag = 1) THEN
  126.    FOREACH c_try1
  127.       INTO  buf1,
  128.             buf2,
  129.             pa_prosp[cnt].company,
  130.             pa_ref[cnt]
  131.       LET pa_prosp[cnt].flname = buf1 CLIPPED, 1 SPACE, buf2
  132.       LET cnt = cnt + 1
  133.    END FOREACH
  134. ELSE
  135.    FOREACH c_try2
  136.       INTO  buf1,
  137.             buf2,
  138.             pa_prosp[cnt].company,
  139.             pa_ref[cnt]
  140.       LET pa_prosp[cnt].flname = buf1 CLIPPED, 1 SPACE, buf2
  141.       LET cnt = cnt + 1
  142.    END FOREACH
  143. END IF
  144. CALL SET_COUNT(cnt - 1)
  145. IF (cnt = 2) THEN
  146.    IF (uuflag = 1) THEN
  147.       DISPLAY msg6 AT 3,1 ATTRIBUTE(REVERSE)
  148.       SLEEP 3
  149.       INITIALIZE pr_prospect.* TO NULL
  150.    ELSE
  151.       DISPLAY msg7 AT 3,1 ATTRIBUTE(REVERSE)
  152.       SLEEP 3
  153.    END IF
  154. ELSE
  155.    OPEN FORM f_decide FROM "f_decid3"
  156.    DISPLAY FORM f_decide
  157.    IF (msg = 1) THEN DISPLAY msg1 AT 3,1 ATTRIBUTE(REVERSE) END IF
  158.    IF (msg = 2) THEN DISPLAY msg2 AT 3,1 ATTRIBUTE(REVERSE) END IF
  159.    IF (msg = 3) THEN DISPLAY msg3 AT 3,1 ATTRIBUTE(REVERSE) END IF
  160.    DISPLAY msg4 AT 5,1 ATTRIBUTE(REVERSE)
  161.    DISPLAY msg5 AT 6,1 ATTRIBUTE(REVERSE)
  162.    DISPLAY ARRAY pa_prosp to sr_decide.*
  163.    LET cnt = ARR_CURR()
  164.    IF (cnt = 1) THEN
  165.       INITIALIZE pr_prospect.* TO NULL
  166.    ELSE
  167.       SELECT      *
  168.          INTO     pr_prospect.*
  169.          FROM     prospect
  170.          WHERE    prospect.ref = pa_ref[cnt]
  171.    END IF
  172. END IF
  173. END FUNCTION
  174.