home *** CD-ROM | disk | FTP | other *** search
- DATABASE leads
- GLOBALS "globals.4gl"
-
- FUNCTION decide(uflag)
- {
- The decide function displays the f_decide form and
- matches the user's input to rows in the prospect table.
- If an exact match isn't found, the choose function displays
- a list of possible matches for the user to choose from.
-
- uflag = 1 for query for old or new prospect,
- uflag = 2 for no query (assume old).
- }
- DEFINE buf1 CHAR(40),
- new CHAR(1),
- uflag, numrows SMALLINT
- INITIALIZE pr_prospect.* TO NULL
-
- DECLARE c_prospect CURSOR FOR
- SELECT *
- INTO pr_prospect.*
- FROM prospect
- WHERE prospect.company = pr_prospect.company
- AND prospect.lname = pr_prospect.lname
-
- DECLARE c_try1 CURSOR FOR
- SELECT fname,
- lname,
- company,
- ref
- FROM prospect
- WHERE prospect.company = pr_prospect.company
- AND prospect.lname = pr_prospect.lname
- ORDER BY lname,
- fname,
- company
-
- DECLARE c_try2 CURSOR FOR
- SELECT fname,
- lname,
- company,
- ref
- FROM prospect
- WHERE prospect.company LIKE buf1
- OR prospect.lname = pr_prospect.lname
- ORDER BY lname,
- fname,
- company
-
- IF (uflag = 1) THEN
- OPEN FORM f_decide FROM "f_decid1"
- DISPLAY FORM f_decide
- INPUT BY NAME pr_prospect.lname,
- pr_prospect.company,
- new
- ELSE
- OPEN FORM f_decide FROM "f_decid2"
- DISPLAY FORM f_decide
- INPUT BY NAME pr_prospect.lname,
- pr_prospect.company
- LET new = "O"
- END IF
-
- CLEAR SCREEN
- SELECT COUNT(*)
- INTO numrows
- FROM prospect
- WHERE prospect.company = pr_prospect.company
- AND prospect.lname = pr_prospect.lname
-
- OPEN c_prospect
- CASE
- {One row found, not a new prospect. Use the row.}
- WHEN (numrows = 1 AND new = "O")
- FETCH c_prospect
-
- {More than one row found, not a new prospect. Review rows.}
- WHEN (numrows > 1 AND new = "O")
- CALL choose(uflag, 1, 1)
-
- {No rows found, not a new prospect. Review possible rows.}
- WHEN (numrows = 0 AND new = "O" )
- LET buf1 = pr_prospect.company[1,5], "%"
- CALL choose(uflag, 2, 2)
-
- {All is well, take no action.}
- WHEN (numrows = 0 AND new = "N")
-
- {>= 1 row found, it was supposed to be a new prospect. Verify.}
- WHEN (numrows >= 1 AND new = "N")
- CALL choose(uflag, 1, 3)
- END CASE
- CLEAR SCREEN
- END FUNCTION
-
- FUNCTION choose(uuflag, uflag, msg)
- {
- uuflag is the uflag from the calling routine
- uflag specifies the type of select
- msg specifies the proper message for display
- }
- DEFINE pa_ref ARRAY[25] OF LIKE prospect.ref,
- pa_prosp ARRAY[25] OF RECORD
- flname CHAR(31),
- company LIKE prospect.company
- END RECORD,
- msg1, msg2, msg3, msg4, msg5, msg6, msg7 CHAR(75),
- buf1, buf2 CHAR(15),
- cnt, uuflag, uflag, msg SMALLINT
-
-
- LET msg1 = " There is more than one possible prospect."
- LET msg2 =
- " The prospect does not exist in the database exactly as you specified it."
- LET msg3 = " The prospect may already exist in the database."
- LET msg4 =
- " Use the ARROW keys to move the cursor, press ESCAPE to make a selection."
- LET msg5 = " Select the first entry if the name you want is not on the list."
- LET msg6 = " This is a new prospect."
- LET msg7 = " Prospect does not exist in the database."
- LET pa_prosp[1].flname = ">>> NOT ON THE LIST <<<"
- LET pa_prosp[1].company = NULL
- LET cnt = 2
-
- IF (uflag = 1) THEN
- FOREACH c_try1
- INTO buf1,
- buf2,
- pa_prosp[cnt].company,
- pa_ref[cnt]
- LET pa_prosp[cnt].flname = buf1 CLIPPED, 1 SPACE, buf2
- LET cnt = cnt + 1
- END FOREACH
- ELSE
- FOREACH c_try2
- INTO buf1,
- buf2,
- pa_prosp[cnt].company,
- pa_ref[cnt]
- LET pa_prosp[cnt].flname = buf1 CLIPPED, 1 SPACE, buf2
- LET cnt = cnt + 1
- END FOREACH
- END IF
- CALL SET_COUNT(cnt - 1)
- IF (cnt = 2) THEN
- IF (uuflag = 1) THEN
- DISPLAY msg6 AT 3,1 ATTRIBUTE(REVERSE)
- SLEEP 3
- INITIALIZE pr_prospect.* TO NULL
- ELSE
- DISPLAY msg7 AT 3,1 ATTRIBUTE(REVERSE)
- SLEEP 3
- END IF
- ELSE
- OPEN FORM f_decide FROM "f_decid3"
- DISPLAY FORM f_decide
- IF (msg = 1) THEN DISPLAY msg1 AT 3,1 ATTRIBUTE(REVERSE) END IF
- IF (msg = 2) THEN DISPLAY msg2 AT 3,1 ATTRIBUTE(REVERSE) END IF
- IF (msg = 3) THEN DISPLAY msg3 AT 3,1 ATTRIBUTE(REVERSE) END IF
- DISPLAY msg4 AT 5,1 ATTRIBUTE(REVERSE)
- DISPLAY msg5 AT 6,1 ATTRIBUTE(REVERSE)
- DISPLAY ARRAY pa_prosp to sr_decide.*
- LET cnt = ARR_CURR()
- IF (cnt = 1) THEN
- INITIALIZE pr_prospect.* TO NULL
- ELSE
- SELECT *
- INTO pr_prospect.*
- FROM prospect
- WHERE prospect.ref = pa_ref[cnt]
- END IF
- END IF
- END FUNCTION
-