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

  1.  
  2.  
  3. DATABASE stores
  4.  
  5. #    The GLOBALS statement defines two program records and
  6. #    a SMALLINT variabled used throughout the program.
  7.  
  8. GLOBALS
  9.  
  10.     DEFINE 
  11.     p_customer     RECORD LIKE customer.*,
  12.     p_orders     RECORD LIKE orders.*,
  13.     cur         SMALLINT
  14.  
  15. END GLOBALS
  16.  
  17.  
  18. #    The MAIN statement opens two windows and displays
  19. #    forms in each window.  It sets the global variable cur
  20. #    to 1 and calls the show_menu function.  Finally, it
  21. #    closes the forms and windows.
  22.  
  23. MAIN
  24.  
  25.  
  26.     OPEN WINDOW ow2 AT 10,15
  27.         WITH 11 ROWS,63 COLUMNS
  28.         ATTRIBUTE(BORDER)
  29.  
  30.     OPEN FORM ordcur FROM "ordcur"
  31.  
  32.     DISPLAY FORM ordcur
  33.  
  34.     OPEN WINDOW cw1 AT 5,5
  35.         WITH 11 ROWS,63 COLUMNS
  36.         ATTRIBUTE(BORDER)
  37.  
  38.     OPEN FORM custcur FROM "custcur"
  39.  
  40.     DISPLAY FORM custcur
  41.  
  42.     LET cur = 1
  43.  
  44.     CALL show_menu()
  45.  
  46.     CLOSE FORM custcur
  47.  
  48.     CLOSE FORM ordcur
  49.  
  50.     CLOSE WINDOW cw1
  51.  
  52.     CLOSE WINDOW ow2
  53.  
  54. END MAIN
  55.  
  56.  
  57. #    The show_menu function displays the SEARCH Menu.
  58. #    The SEARCH Menu is the "main" menu for the program
  59. #    and appears at the top of the current window.
  60.  
  61. FUNCTION show_menu()
  62.  
  63.     DEFINE win_flag SMALLINT
  64.  
  65.     LET win_flag = 1
  66.  
  67.     WHILE win_flag = 1
  68.  
  69.         LET win_flag = 0
  70.  
  71.         MENU "SEARCH"
  72.  
  73.             COMMAND "Query" "Search for rows."
  74.                 IF cur = 1 THEN
  75.                     CALL get_cust()
  76.                 ELSE 
  77.                     CALL get_ord()
  78.                 END IF
  79.  
  80.             COMMAND "Detail" "Get details."
  81.                 IF cur = 1 THEN
  82.                     CALL det_ord() 
  83.                 ELSE 
  84.                     CALL det_cust() 
  85.                 END IF
  86.  
  87.             COMMAND "Switch" "Change the window." 
  88.  
  89.                 LET win_flag = 1
  90.                 EXIT MENU
  91.  
  92.             COMMAND "Exit" "Leave the program."
  93.                 EXIT MENU
  94.  
  95.         END MENU
  96.  
  97.         IF win_flag = 1 THEN
  98.             CALL change_wind()    
  99.         END IF
  100.  
  101.     END WHILE
  102.  
  103. END FUNCTION
  104.  
  105.  
  106. #    The set_curs function uses a CASE statement to test
  107. #    the value of the argument passed to it by other functions
  108. #    in the program.  It prepares a SELECT statement, declares
  109. #    a scroll cursor for the SELECT statement, and opens the cursor.
  110.  
  111. FUNCTION set_curs(flag)
  112.  
  113.     DEFINE flag SMALLINT, 
  114.         query_1, query_str CHAR(300)
  115.  
  116.     CASE flag
  117.  
  118.         WHEN 1     # function called by get_cust 
  119.  
  120.             CONSTRUCT query_1 ON customer.* FROM customer.*
  121.             LET query_str = "SELECT * FROM customer WHERE ", 
  122.                 query_1 CLIPPED
  123.  
  124.         WHEN 2     # function called by get_ord
  125.  
  126.             CONSTRUCT query_1 ON orders.* FROM orders.*
  127.             LET query_str = "SELECT * FROM orders WHERE ", 
  128.                 query_1 CLIPPED
  129.  
  130.         WHEN 3     # function called by det_ord 
  131.  
  132.             LET query_str = 
  133.                       "SELECT * FROM orders WHERE orders.customer_num = ",
  134.             p_customer.customer_num USING "###"
  135.     END CASE
  136.  
  137.     PREPARE s_1 FROM query_str
  138.  
  139.     DECLARE q_curs SCROLL CURSOR FOR s_1
  140.  
  141.     OPEN q_curs
  142.  
  143. END FUNCTION
  144.  
  145.  
  146. #    The get_cust function allows the user to perform a 
  147. #    query by example on the cust_cur form displayed in the
  148. #    cw1 window.
  149.  
  150. FUNCTION get_cust()
  151.  
  152.     CALL clear_menu()
  153.  
  154.     CALL mess("Enter search criteria for one or more customers.")
  155.  
  156.     CALL set_curs(1)
  157.  
  158.     CALL view_cust()
  159.  
  160. END FUNCTION
  161.  
  162.  
  163. #    The view_cust function performs a fetch first and tests
  164. #    whether a customer row is returned.  If the active set is
  165. #    empty, the function ends.  If the active set contains at
  166. #    least one row, the function displays the row along with a 
  167. #    menu that allows the user to browse through the
  168. #    row(s) in the active set.
  169.  
  170. FUNCTION view_cust()
  171.  
  172.     FETCH FIRST q_curs INTO p_customer.*
  173.  
  174.     IF status = NOTFOUND THEN
  175.         CALL mess("No customers found.")
  176.         CLOSE q_curs
  177.         RETURN
  178.     ELSE
  179.         DISPLAY BY NAME p_customer.*
  180.     END IF
  181.  
  182.     MENU "BROWSE"
  183.  
  184.         COMMAND "Next" "View the next customer in the list."
  185.         FETCH NEXT q_curs INTO p_customer.*
  186.             IF status = NOTFOUND THEN
  187.                   CALL mess("No more customers in this direction.")
  188.                 FETCH LAST q_curs INTO p_customer.*
  189.             END IF
  190.             DISPLAY BY NAME p_customer.*
  191.  
  192.         COMMAND "Previous" "View the previous customer in the list."
  193.             FETCH PREVIOUS q_curs INTO p_customer.*
  194.             IF status = NOTFOUND THEN
  195.                  CALL mess("No more customers in this direction.")
  196.                 FETCH FIRST q_curs INTO p_customer.*
  197.             END IF
  198.             DISPLAY BY NAME p_customer.*
  199.  
  200.         COMMAND "First" "View the first customer in the list."
  201.             FETCH FIRST q_curs INTO p_customer.*
  202.             DISPLAY BY NAME p_customer.*
  203.  
  204.         COMMAND "Last" "View the last customer in the list."
  205.             FETCH LAST q_curs INTO p_customer.*
  206.             DISPLAY BY NAME p_customer.*
  207.  
  208.         COMMAND "Select-and-exit" "Select the current customer."
  209.             CALL clear_menu()
  210.             EXIT MENU
  211.     END MENU
  212.  
  213.     CLOSE q_curs
  214.  
  215. END FUNCTION
  216.  
  217.  
  218. #    The get_ord function allows the user to perform a 
  219. #    query by example on the ord_cur form displayed
  220. #    in the ow2 window.
  221.  
  222. FUNCTION get_ord()
  223.  
  224.     CALL clear_menu()
  225.  
  226.     CALL mess("Enter search criteria for one or more orders.")
  227.  
  228.     CALL set_curs(2)
  229.  
  230.     CALL view_ord()
  231.  
  232. END FUNCTION
  233.  
  234.  
  235. #    The view_ord function performs a fetch first and tests
  236. #    whether an order row is returned.  If the active set
  237. #    is empty, the function ends.  If the active set contains
  238. #    at least one row, the function displays the row along
  239. #    with a menu that allows the user to browse through
  240. #    the row(s) in the active set.
  241.  
  242. FUNCTION view_ord()
  243.  
  244.     FETCH FIRST q_curs INTO p_orders.*
  245.  
  246.     IF status = NOTFOUND THEN
  247.         CALL mess("No orders found.")
  248.         CLOSE q_curs
  249.         RETURN
  250.     ELSE
  251.         DISPLAY BY NAME p_orders.*
  252.     END IF
  253.  
  254.     MENU "BROWSE"
  255.  
  256.         COMMAND "Next" "View the next order in the list."
  257.             FETCH NEXT q_curs INTO p_orders.*
  258.             IF status = NOTFOUND THEN
  259.                 CALL mess("No more orders in this direction.")
  260.                 FETCH LAST q_curs INTO p_orders.*
  261.             END IF
  262.             DISPLAY BY NAME p_orders.*
  263.  
  264.         COMMAND "Previous" "View the previous order in the list."
  265.             FETCH PREVIOUS q_curs INTO p_orders.*
  266.             IF status = NOTFOUND THEN
  267.                 CALL mess("No more orders in this direction.")
  268.                 FETCH FIRST q_curs INTO p_orders.*
  269.             END IF
  270.             DISPLAY BY NAME p_orders.*
  271.  
  272.         COMMAND "First" "View the first order in the list."
  273.             FETCH FIRST q_curs INTO p_orders.*
  274.             DISPLAY BY NAME p_orders.*
  275.  
  276.         COMMAND "Last" "View the last order in the list."
  277.             FETCH LAST q_curs INTO p_orders.*
  278.             DISPLAY BY NAME p_orders.*
  279.  
  280.         COMMAND "Select-and-exit" "Select the current order."
  281.             CALL clear_menu()
  282.             EXIT MENU
  283.  
  284.     END MENU
  285.  
  286.     CLOSE q_curs
  287.  
  288. END FUNCTION
  289.  
  290.  
  291. #    The det_cust function is called when the user selects
  292. #    the Detail option on the SEARCH Menu and ow2 is 
  293. #    the current window.  The det_cust function provides
  294. #    information about the customer who placed the order
  295. #    currently displayed in the ow2 window.
  296.  
  297. FUNCTION det_cust()
  298.  
  299.     DEFINE answer CHAR(1)
  300.     
  301.     CURRENT WINDOW IS cw1
  302.  
  303.     SELECT * INTO p_customer.* FROM customer WHERE customer_num =
  304.         p_orders.customer_num
  305.  
  306.     DISPLAY BY NAME p_customer.*
  307.  
  308.     PROMPT "Press ENTER to return to the other window: " 
  309.         FOR answer
  310.  
  311. END FUNCTION
  312.  
  313.  
  314. #    The det_ord function is called when the user selects
  315. #    the Detail option on the SEARCH Menu and cw1 is
  316. #    the current window.  The det_ord function provides
  317. #    information about the orders placed by the customer
  318. #    currently displayed in the cw1 window.
  319.  
  320. FUNCTION det_ord()
  321.  
  322.     DEFINE answer CHAR(1)
  323.  
  324.     CURRENT WINDOW IS ow2
  325.  
  326.     CALL set_curs(3)
  327.  
  328.     CALL view_ord()
  329.  
  330.     PROMPT "Press ENTER to return to the other window: " 
  331.         FOR answer
  332.  
  333. END FUNCTION
  334.  
  335. #    The change_wind function is called when the user
  336. #    selects the Switch option on the SEARCH Menu.
  337. #    The function changes the current window.
  338.  
  339. FUNCTION change_wind()
  340.  
  341.      CALL clear_menu()
  342.  
  343.     IF cur = 1 THEN
  344.         CURRENT WINDOW IS ow2
  345.         LET cur = 2
  346.     ELSE 
  347.         CURRENT WINDOW IS cw1
  348.         LET cur = 1
  349.     END IF
  350.  
  351. END FUNCTION
  352.  
  353. #    The clear_menu function clears the top two
  354. #    lines in the current window of text.
  355.  
  356. FUNCTION clear_menu()
  357.  
  358.     DISPLAY "" AT 1, 1 
  359.     DISPLAY "" AT 2, 1 
  360.  
  361. END FUNCTION
  362.  
  363. #    The mess function is passed a character string as an argument
  364. #    and displays the characters on the 11th (last) line of the
  365. #    current window.
  366.  
  367. FUNCTION mess(str)
  368.  
  369.     DEFINE str CHAR(50)
  370.  
  371.     DISPLAY str CLIPPED AT 11,1
  372.  
  373.     SLEEP 3
  374.  
  375.     DISPLAY "" AT 11,1
  376.  
  377. END FUNCTION    
  378.