home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a039 / 1.ddi / SAMPAPP.ZIP / SAMPLE.SC < prev    next >
Encoding:
Text File  |  1992-08-08  |  28.7 KB  |  787 lines

  1. ; Script      : SAMPLE.SC
  2. ; Description : Paradox sample application
  3.  
  4.   
  5. ; Begin by clearing any stray procedures and/or variables which
  6. ; may have been created in previous Paradox work.
  7. RELEASE VARS ALL
  8. RELEASE PROCS ALL
  9. ; Empty the desktop to make sure the workspace is in Main mode, revoke
  10. ; passwords in effect but cancelled, flush memory buffers, write changes
  11. ; to disk, and remove explicit table locks.
  12. ALTSPACE {Desktop} {Empty}
  13. ECHO NORMAL      ; display the empty desktop
  14. ECHO OFF         ; then turn echo off to freeze the screen display
  15.  
  16. ; --------------------------------------------------------------------------
  17. ; Procedure   : Main()
  18. ; Description :
  19. ;    When a user plays the SAMPLE.SC script, the Main() procedure is called
  20. ;    to start the application. The Main() procedure displays a simple
  21. ;    "splash" screen describing the application, then displays the
  22. ;    application's main menu. The user interacts with the main menu, and
  23. ;    the Main() procedure performs appropriate actions based on the item
  24. ;    selected from the menu.
  25. ; --------------------------------------------------------------------------
  26.  
  27. PROC Main()
  28.    PRIVATE MenuItemSelected,
  29.            ExitApplication
  30.  
  31.    ; Draw a "splash" screen.
  32.    ShowSplashScreen()
  33.  
  34.    ; Display and maintain the application's main menu
  35.    DisplayMainMenu()
  36.  
  37.    ;   Now that we've displayed the menu, we wait until the user makes a
  38.    ;   selection from the menu and process it accordingly.  We repeat
  39.    ;   this process, executing the commands contained within the
  40.    ;   WHILE...ENDWHILE loop, until the user wants to exit the application.
  41.    ;   We use the logical variable ExitApplication as a signal to tell us
  42.    ;   when to exit the loop.  Initially we assign the value False to
  43.    ;   ExitApplication so we'll enter the loop the first time through.
  44.    ;   Each time we return to the start of the WHILE loop to process
  45.    ;   another menu selection, we check the value of ExitApplication.  If
  46.    ;   the value is still False we enter the loop once again, processing
  47.    ;   another menu selection.  Otherwise, we exit the loop, executing
  48.    ;   the first statement following the ENDWHILE at the end of the loop.
  49.    ;   When the user selects Exit|Yes from the main menu, we assign the
  50.    ;   value True to the variable ExitApplication.
  51.    ExitApplication = False
  52.  
  53.    WHILE (ExitApplication <> True)
  54.  
  55.    ; Grey out items which are not applicable from the main menu.
  56.    GreyMainMenuItems()
  57.  
  58.       ; Wait for the user to select an item from the main menu. The menu
  59.       ; was displayed by DisplayMainMenu().
  60.  
  61.       GETMENUSELECTION TO MenuItemSelected
  62.  
  63.       ;  Examine the MenuItemSelected and execute the proper procedure or
  64.       ;  (in the case of Exit Selections) set the proper flag.  Note that
  65.       ;  the string in the switch statement must be typed in EXACTLY as
  66.       ;  it is in the menu procedure itself, including case and spaces.
  67.       SWITCH
  68.          CASE (MenuItemSelected = "Exit/Yes") : ; user wants to exit
  69.             ExitApplication = True
  70.  
  71.          CASE (MenuItemSelected = "Exit/No") :  ; user has decided not to exit
  72.             ExitApplication = False
  73.  
  74.          CASE (MenuItemSelected = "AltSpace/About") : ; user wants info about
  75.                                                       ; program
  76.             DisplayAboutBox()
  77.  
  78.          CASE (MenuItemSelected = "Table/Modify") :   ; user wants to modify
  79.             LetUserModifyTable()                      ; the Invoice table
  80.  
  81.          CASE (MenuItemSelected = "Report/All") :     ; user wants to create
  82.             PrintAllRecords()                         ; a report on ALL
  83.                                                       ; customers
  84.  
  85.          CASE (MenuItemSelected = "Report/West Coast") : ; user wants to
  86.             PrintWestCoastRecords()                      ; create a report
  87.                                                          ; on West Coast
  88.                                                          ; customers only.
  89.  
  90.       ENDSWITCH
  91.  
  92.    ENDWHILE
  93.  
  94.    ; Before we leave the program we explicitly remove the menu. CLEARPULLDOWN
  95.    ; is not required here, but using the command is good programming
  96.    ; practice.
  97.    CLEARPULLDOWN
  98.  
  99. ENDPROC
  100.  
  101.  
  102.  
  103. ; --------------------------------------------------------------------------
  104. ; Procedure   : DisplayMainMenu()
  105. ; Description :
  106. ;    Displays the main menu for the application. Note that the tags created
  107. ;    in this procedure must be typed EXACTLY in the calling procedure for
  108. ;    them to be processed properly.
  109. ; Called By   : Main()
  110. ; --------------------------------------------------------------------------
  111.  
  112. PROC DisplayMainMenu()
  113.  
  114.    ; Display the main pulldown menu.
  115.    SHOWPULLDOWN
  116.       "≡"      : "Program Information."          : "AltSpace"
  117.          SUBMENU
  118.             "Utilities" : "System Utilities"   : "Utilities"
  119.                SUBMENU
  120.                   "Calculator" : "Popup Calculator" : "Calculator",
  121.                   "Help Interval" : "Set AutoHelp Interval" : "Help Interval"
  122.                ENDSUBMENU,
  123.             SEPARATOR,
  124.             "About" : "About this application." : "AltSpace/About"
  125.          ENDSUBMENU,
  126.       "Table"  : "Work with the Invoice table." : "Table"
  127.          SUBMENU
  128.             "Modify" : "Modify Invoice table." : "Table/Modify",
  129.             "Close"  : "Close Invoice table."  : "Table/Close"
  130.          ENDSUBMENU,
  131.       "Report" : "Report on Customer Table."     : "Report"
  132.          SUBMENU
  133.             "All"        : "Print report of all customers."  :
  134.                            "Report/All",
  135.             "West Coast" : "Print report of only West Coast customers" :
  136.                            "Report/West Coast"
  137.          ENDSUBMENU,
  138.       "Exit"   : "Exit this application."        : "Exit"
  139.          SUBMENU
  140.             "No"  : "Do not exit application." : "Exit/No",
  141.             "Yes" : "Exit this application."   : "Exit/Yes"
  142.          ENDSUBMENU
  143.    ENDMENU
  144.  
  145. ENDPROC
  146.  
  147.  
  148.  
  149. ; --------------------------------------------------------------------------
  150. ; Procedure   : GreyMainMenuItems()
  151. ; Description : This procedure greys out (dims) menu items which are not
  152. ;               applicable from the Main Menu. These items are no longer
  153. ;               selectable from the menu.
  154. ; Called By   : Main()
  155. ; --------------------------------------------------------------------------
  156.  
  157. PROC GreyMainMenuItems()
  158.  
  159. ;  Disable items not available in the Sample application. The Utilities
  160. ;  item is available only in the Advanced application. The Table/Close
  161. ;  item is available only when a table is on the workspace.
  162.    MENUDISABLE "Utilities"
  163.    MENUDISABLE "Table/Close"
  164.  
  165. ;  Enable main menu selections
  166.    MENUENABLE "Table/Modify"
  167.    MENUENABLE "Report/All"
  168.    MENUENABLE "Report/West Coast"
  169.    MENUENABLE "Exit/No"
  170.    MENUENABLE "Exit/Yes"
  171.  
  172. ENDPROC
  173.  
  174.  
  175.  
  176. ; --------------------------------------------------------------------------
  177. ; Procedure   : DisplayAboutBox()
  178. ; Description :
  179. ;    Creates a simple dialog box displaying information about the
  180. ;    application.  It uses the SHOWDIALOG command to create the box
  181. ;    with  a single button which, when pressed, clears the box.
  182. ; Called by   : Main(),
  183. ; --------------------------------------------------------------------------
  184.  
  185. PROC DisplayAboutBox()
  186.  
  187.    ; Create a dialog box with the following dimensions...
  188.    SHOWDIALOG "Sample Application"
  189.       @ 5, 10
  190.       HEIGHT 12
  191.       WIDTH 60
  192.  
  193.       @ 1, 0 ?? FORMAT("W58,AC", "Sample Application")
  194.       @ 3, 0 ?? FORMAT("W58,AC", "Paradox 4.0")
  195.       @ 5, 0 ?? FORMAT("W58,AC", "Borland International")
  196.  
  197.  
  198.       ; The following creates the single OK button at the noted
  199.       ; coordinates. The "~" character assigns Alt-O as the button hot key.
  200.       ; Because this is the only push button in the dialog box there
  201.       ; is no need to analyze the results.
  202.       PUSHBUTTON @ 8, 23
  203.          WIDTH 12
  204.          "~O~K"
  205.          OK
  206.          VALUE "OKButtonPressed"
  207.          TAG "OKButton"
  208.       TO OKButton
  209.  
  210.    ENDDIALOG
  211.  
  212. ENDPROC
  213.  
  214.  
  215.  
  216. ; --------------------------------------------------------------------------
  217. ; Procedure  : LetUserModifyTable()
  218. ; Description:
  219. ;    Wait on table. Allow the user to work with the
  220. ;              table until s/he presses Formkey, Do_It!, Del,
  221. ;              Ctrl-T, or F10. F10 activates the SHOWPULLDOWN menu and
  222. ;              temporarily suspends the WAIT until the menu interaction
  223. ;              is complete.
  224. ; Called By  : Main
  225. ; --------------------------------------------------------------------------
  226.  
  227. PROC LetUserModifyTable()
  228.  
  229.    ; Place the Invoice table in CoEdit mode, pick the "F" form, and
  230.    ; set the window conditions.
  231.    COEDIT "Invoice"
  232.  
  233.    ;  Move the table to a location where the user will not accidentally
  234.    ;  display it.
  235.    WINDOW MOVE GETWINDOW() TO -100, -100
  236.  
  237.    PICKFORM "F"
  238.  
  239.    ; Get the handle of the form window.
  240.    WINDOW HANDLE CURRENT TO InvoiceWindow
  241.  
  242.    ; Specify attributes of the form window in a dynamic array.
  243.    DYNARRAY WindowAttributes[]
  244.    WindowAttributes["HEIGHT"]    = 21
  245.    WindowAttributes["ORIGINROW"] = 1
  246.    WindowAttributes["ORIGINCOL"] = 0
  247.    WindowAttributes["CANMOVE"]   = True
  248.    WindowAttributes["CANRESIZE"] = True
  249.    WindowAttributes["CANCLOSE"]  = False
  250.  
  251.    ; Now apply these attributes to the form window
  252.    WINDOW SETATTRIBUTES InvoiceWindow FROM WindowAttributes
  253.  
  254.    ; Enable/Disable menu selections.
  255.    GreyModifyMenuItems()
  256.  
  257.    ; Wait on the workspace table. The prompt line is placed at the
  258.    ; bottom of the screen, telling the users what shortcut keys are
  259.    ; available.
  260.    ; When an event is "trapped" by the wait, the procedure
  261.    ; "ProcessWaitEvents" is called. This procedure acts as a handler,
  262.    ; deciding what to do with the particular event. In turn
  263.    ; a value of 0, 1, or 2 is returned to the wait.
  264.    ;     0 - processes the event and proceeds to the next event in the
  265.    ;         trigger cycle.
  266.    ;     1 - does NOT process the current event and breaks out of the
  267.    ;         trigger cycle, but does NOT break out of the wait.
  268.    ;     2 - does NOT process the current event and breaks out of the
  269.    ;         trigger cycle AND the wait.
  270.  
  271.    PROMPT " [F2] Close │ [F10] Menu │ [Ctrl-T] Update Totals │" +
  272.           " [Ctrl-L] Update Customer"                           ; set PROMPT
  273.    MESSAGE "Press [F1] for lookup help in fields followed by *" ; and MESSAGE
  274.    WAIT WORKSPACE
  275.       PROC "ProcessWaitEvents" ; call the wait procedure when any of the
  276.                                ; specified events occurs. The procedure must
  277.                                ; return a 2 to break out of the wait.
  278.  
  279.          ; Trap the following keypresses. Note that we use numeric keycodes
  280.          ; that are explained in the comment following the KEY statement.
  281.          KEY -83, -60, 15, 20, -24, -18, -31, 26, -44, -97
  282.  ; Del, Do_It!, Ctrl-O, Ctrl-T, Alt-O, Alt-E, Alt-S, Ctrl-Z, Alt-Z, Ctrl-F4
  283.  
  284.          ; Trap the following message event. If the user interacts with a
  285.          ; SHOWPULLDOWN menu and either selects an item or presses a MenuKey,
  286.          ; a MENUSELECT message will occur and the WAIT procedure will be
  287.          ; called.
  288.          MESSAGE "MENUSELECT"
  289.    ENDWAIT
  290.  
  291.    PROMPT ""   ; clear the PROMPT after leaving the WAIT
  292.    DO_IT!      ; close the edit session
  293.    CLEARALL    ; clear the table from the workspace.
  294.  
  295.    ; Because this is a sample application, we empty the Invoice and Orders
  296.    ; tables so they can be used again.
  297.    EMPTY "Invoice"
  298.    EMPTY "Orders"
  299.  
  300.    ; ECHO NORMAL displays the empty workspace. ECHO OFF hides the
  301.    ; workspace again but leaves the empty workspace displayed on the full
  302.    ; screen canvas.
  303.    ECHO NORMAL
  304.    ECHO OFF
  305.  
  306. ENDPROC
  307.  
  308.  
  309. ; --------------------------------------------------------------------------
  310. ; Procedure   : GreyModifyMenuItems()
  311. ; Description : This procedure greys out (dims) items on the SHOWPULLDOWN
  312. ;               menu which are not available while the user is coediting
  313. ;               the multi-table form. Greyed items cannot be selected
  314. ;               from the menu.
  315. ; Called By   : LetUserModifyTable()
  316. ; --------------------------------------------------------------------------
  317.  
  318. PROC GreyModifyMenuItems()
  319.  
  320.    ; Disable the following menu items.
  321.    MENUDISABLE "Table/Modify"
  322.    MENUDISABLE "Report/All"
  323.    MENUDISABLE "Report/West Coast"
  324.    MENUDISABLE "Exit/No"
  325.    MENUDISABLE "Exit/Yes"
  326.  
  327.    ; Enable the following menu item.
  328.    MENUENABLE "Table/Close"
  329.  
  330. ENDPROC
  331.  
  332.  
  333.  
  334. ; --------------------------------------------------------------------------
  335. ; Procedure   : ProcessWaitEvents()
  336. ; Description :
  337. ;    Proc is called when an event is triggered from the modify table wait.
  338. ;         The procedure evaluates the kind of message and does the appropriate
  339. ;         processing, then returns a value of 0, 1, or 2 to the wait (See
  340. ;         LetUserModifyTable proc for details on the return values).
  341.  
  342. ; Called By   : LetUserModifyTable()
  343. ; --------------------------------------------------------------------------
  344.  
  345. PROC ProcessWaitEvents(TriggerType, EventInfo, CycleNumber)
  346.  
  347. ;  The TriggerType argument is assigned a value based on the type of event
  348. ;  or trigger that the procedure was called for. The dynamic array
  349. ;  EventInfo contains information about the event which occurred during
  350. ;  the wait. If the EventInfo element "Type" is "KEY", then we examine the
  351. ;  element "KEYCODE" to determine the numeric keycode that the WAIT command
  352. ;  trapped. For example, if the user pressed Ctrl-Z, the dynamic array will
  353. ;  contain the following elements:
  354. ;    Dynarray EventInfo[]
  355. ;    EventInfo["TYPE"] = "KEY"
  356. ;    EventInfo["KEYCODE"] = 26
  357.  
  358.    SWITCH
  359.       CASE (EventInfo["TYPE"] = "KEY") :
  360.  
  361.          ; The following SWITCH...CASE...ENDSWITCH statement performs a
  362.          ; series of tests to determine what key was pressed and what mode
  363.          ; Paradox was in when the key was pressed.
  364.          SWITCH
  365.  
  366.             ; The following CASE executes when the user presses the
  367.             ; Delete key (Keycode -83). This CASE calls the custom "Confirm
  368.             ; Delete" dialog box before deleting the invoice.
  369.             ; Because the delete is processed in the DisplayDeleteBox()
  370.             ; procedure, we return 1 to go back to the WAIT, deny the
  371.             ; pending event, and cancel the current trigger cycle.
  372.             CASE (EventInfo["KEYCODE"] = -83) :     ; Del
  373.                DisplayDeleteBox()
  374.                RETURN 1
  375.  
  376.             ; The following CASE executes when the user presses the
  377.             ; Do_It! F2 key. Each IF statement within this CASE tests
  378.             ; to see what state Paradox was in when the F2 key was
  379.             ; pressed, so the application can take the appropriate action.
  380.             CASE (EventInfo["KEYCODE"] = -60) :    ; Do_It!
  381.  
  382.                ; It is possible that the user was in Field View, and
  383.                ; chose F2 to get out of Field View, not out of the
  384.                ; current wait.
  385.                IF (ISFIELDVIEW() = True)
  386.                   THEN RETURN 0
  387.                ENDIF
  388.  
  389.                ; It's also possible the user was in LookupHelp, and
  390.                ; pressed F2 to select a value from the lookup table.
  391.                IF (HELPMODE() = "LookupHelp")
  392.                   THEN RETURN 0
  393.                ENDIF
  394.  
  395.                ; It's possible the user was in CoEdit mode. We can't
  396.                ; leave CoEdit if the field data is invalid (e.g.
  397.                ; invalid date or incomplete picture). Before we
  398.                ; leave, we want to make sure that the value in
  399.                ; the current field is valid.
  400.                IF (ISVALID() <> True)
  401.                   THEN RETURN 0
  402.                ENDIF
  403.  
  404.                ; If the record passes the previous validity test,
  405.                ; we execute a Do_It! to try to post the record.
  406.                ; The following IF statement then evaluates the mode
  407.                ; the system is in. If the system is in Main mode, the
  408.                ; Do_It! was successful and we terminate the WAIT
  409.                ; with a RETURN 2.
  410.                Do_It!
  411.                IF (SYSMODE() = "Main")
  412.                   THEN RETURN 2  ; exit the WAIT
  413.                ENDIF
  414.  
  415.                ; If the Do_It! does not put the system in Main mode
  416.                ; and terminate the WAIT, a key violation exists. We then
  417.                ; issue an ECHO NORMAL to display the desktop to the user,
  418.                ; issue a Do_It! again so Paradox displays the KeyViol
  419.                ; message to the user, and RETURN 1 to go back to the
  420.                ; WAIT to let the user resolve the KeyViol.
  421.                ECHO NORMAL
  422.                Do_It!
  423.                RETURN 1    ; couldn't leave CoEdit, let user resolve KeyViol
  424.  
  425.             ; The following CASE executes when the user presses the
  426.             ; Ctrl-T Total key (Keycode 20). This CASE calls the proc
  427.             ; that totals the order lines.
  428.             CASE (EventInfo["KEYCODE"] = 20)  :       ; Ctrl-T (Total)
  429.                CalculateOrderTotal()
  430.                RETURN 1
  431.  
  432.             ; The following CASE executes when the user presses
  433.             ; Ctrl-O or Alt-O. This CASE denies the event so the user
  434.             ; doesn't inadvertently shell to DOS.
  435.             CASE (EventInfo["KEYCODE"] = 15) OR    ; Dos
  436.                  (EventInfo["KEYCODE"] = -24) :    ; DosBig
  437.                ; Stay within the wait but don't process any more
  438.                ; events in the current cycle.
  439.                RETURN 1
  440.  
  441.             OTHERWISE:
  442.                SOUND 400 100   ; issue a beep in other situations
  443.                RETURN 1
  444.  
  445.          ENDSWITCH
  446.  
  447.       ; If the EventInfo["MESSAGE"] element is "MENUSELECT", then the user
  448.       ; has chosen from the menu.
  449.       CASE (EventInfo["MESSAGE"] = "MENUSELECT") :
  450.  
  451.          ; The following SWITCH...CASE...ENDSWITCH statement performs a
  452.          ; series of tests to determine what the user chose from the menu.
  453.          SWITCH
  454.  
  455.             ; The following CASE executes when the user chooses ≡|About.
  456.             ; This CASE calls a proc to display a dialog box containing
  457.             ; information about the application. It then returns 0 to
  458.             ; go back to the WAIT.
  459.             CASE (EventInfo["MENUTAG"] = "AltSpace/About") :
  460.                DisplayAboutBox()
  461.                RETURN 0
  462.  
  463.             ; The following CASE executes when the user chooses
  464.             ; Table|Close. The IF statement tests to see if the user is
  465.             ; in Field View (in the Shipping instructions memo) and closes
  466.             ; the memo, if necessary.
  467.             CASE (EventInfo["MENUTAG"] = "Table/Close") :
  468.                IF (ISFIELDVIEW() = True) ; if the user is in Field View
  469.                   THEN Do_It!            ; save the memo and close it
  470.                ENDIF
  471.  
  472.                ; We execute a Do_It! to try to post the record.
  473.                ; The following IF statement then evaluates the mode
  474.                ; the system is in. If the system is in Main mode, the
  475.                ; Do_It! was successful and we terminate the WAIT
  476.                ; with a RETURN 2.
  477.                Do_It!
  478.                IF (SYSMODE() = "Main")
  479.                   THEN RETURN 2  ; exit the WAIT
  480.                ENDIF
  481.  
  482.                ; If the Do_It! does not put the system in Main mode
  483.                ; and terminate the WAIT, a key violation exists. We then
  484.                ; issue an ECHO NORMAL to display the desktop to the user,
  485.                ; issue a Do_It! again so Paradox displays the KeyViol
  486.                ; message to the user, and RETURN 1 to go back to the
  487.                ; WAIT to let the user resolve the KeyViol.
  488.                ECHO NORMAL
  489.                Do_It!
  490.                RETURN 1   ; couldn't leave CoEdit, let user resolve problem
  491.  
  492.             OTHERWISE:
  493.                SOUND 400 100
  494.                RETURN 1
  495.  
  496.          ENDSWITCH
  497.  
  498.       ; This is the proc's safety valve. If the wait sends a message
  499.       ; we haven't planned on, then beep, process any further events
  500.       ; in the cycle, and remain within the wait.
  501.       OTHERWISE :
  502.          SOUND 400 100
  503.          RETURN 1    ; for safety, ignore events we don't recognize
  504.  
  505.    ENDSWITCH
  506.  
  507. ENDPROC
  508.  
  509.  
  510.  
  511. ; --------------------------------------------------------------------------
  512. ; Procedure   : DisplayDeleteBox()
  513. ; Description :
  514. ;     Brings up a dialog box prompting the user to confirm that s/he
  515. ;     wants to Delete the record. If the user chooses Ok, then we
  516. ;     can go ahead and delete the user. If not, then just return.
  517. ; Called By   : ProcessWaitEvents()
  518. ; --------------------------------------------------------------------------
  519.  
  520. PROC DisplayDeleteBox()
  521.  
  522.    ; Define the "Delete" dialog box.
  523.    SHOWDIALOG "Delete Record"
  524.       @ 6, 10
  525.       HEIGHT 7
  526.       WIDTH 54
  527.  
  528.       ; Text within the box itself.
  529.       @ 1, 4 ?? "Are you sure you want to delete this record?"
  530.  
  531.       PUSHBUTTON @ 3, 30 WIDTH 12
  532.          "~C~ancel"
  533.          CANCEL
  534.          VALUE "CancelButton"
  535.          TAG "Cancel"
  536.       TO CancelButton
  537.  
  538.       ; Place the OK and CANCEL buttons.
  539.       PUSHBUTTON @ 3, 11 WIDTH 12
  540.          "~O~K"
  541.          OK
  542.          VALUE "OK"
  543.          TAG "OKButton"
  544.       TO OKButton
  545.  
  546.    ENDDIALOG
  547.  
  548.    ; If the user accepted the dialog, then we go ahead and delete
  549.    ; this Invoice record. We then issue an ECHO NORMAL so the user
  550.    ; can see Paradox display the Delete message.
  551.    IF (RetVal = True)
  552.       THEN ECHO NORMAL
  553.            Del
  554.    ENDIF
  555.  
  556. ENDPROC
  557.  
  558.  
  559.  
  560. ; --------------------------------------------------------------------------
  561. ; Procedure  : CalculateOrderTotal()
  562. ; Description:
  563. ;     When the user presses Ctrl-T, the line items are totaled and added
  564. ;     to the relevent order fields to create an Invoice total.
  565. ; Called By  : ProcessWaitEvents()
  566. ; --------------------------------------------------------------------------
  567.  
  568. PROC CalculateOrderTotal()
  569. PRIVATE LineTotal
  570.  
  571.    ; initialize the line item amount
  572.    LineTotal = 0
  573.  
  574.    ; If we're not on the Invoice table, then inform the user that Order
  575.    ; totalling can only occur from there.
  576.    IF (TABLE() <> "Invoice")
  577.       THEN BEEP
  578.            MESSAGE "You must be in the Invoice table to calculate totals"
  579.            SLEEP 2500     ; pause to display message
  580.            MESSAGE ""     ; clear the message
  581.            RETURN
  582.    ENDIF
  583.  
  584.    ; we can subtotal the line items. Move to the Orders table.
  585.    MOVETO "Orders"
  586.  
  587.    ; calculate the extended price for each item number ordered,
  588.    ; and accumulate the running line total in the LineTotal variable.
  589.    SCAN
  590.       IF ((ISBLANK([Quantity]) = False) AND  ; only update totals for
  591.           (ISBLANK([Item_No.]) = False))     ; records with qty and item
  592.          THEN [Amount] = ROUND([Unit_Price] * [Quantity], 2)
  593.               LineTotal = ROUND(LineTotal + [Amount], 2)
  594.       ENDIF
  595.    ENDSCAN
  596.  
  597.    ; Now we need to update the Invoice totalling fields
  598.    MOVETO "Invoice"
  599.    [Subtotal] = LineTotal                                 ; update subtotal
  600.    IF (ISBLANK([Discount_%]) = True)                      ; discount amount
  601.       THEN [Discount_%] = 0
  602.    ENDIF
  603.    [Discount] = ROUND([Subtotal] * [Discount_%] / 100, 2)
  604.    IF (ISBLANK([Tax_%]) = True)
  605.       THEN [Tax_%] = 0
  606.    ENDIF
  607.    [Tax] = ROUND(([Subtotal] - [Discount]) * [Tax_%] / 100, 2)  ; Tax Amount
  608.    IF (ISBLANK([Shipping]) = True)
  609.       THEN [Shipping] = 0
  610.    ENDIF
  611.    [Total] = ([Subtotal] - [Discount]) + [Tax] + [Shipping]     ; Order Total
  612.  
  613. ENDPROC
  614.  
  615.  
  616.  
  617. ; --------------------------------------------------------------------------
  618. ; Procedure  : PrintAllRecords()
  619. ; Description:
  620. ;     The user wants to print a report on all Customer records. This
  621. ;     proc checks that the printer is ready and, if it is, then plays
  622. ;     a "pre-recorded" script to send the report to the printer.
  623. ; Called By  : Main()
  624. ; --------------------------------------------------------------------------
  625.  
  626. PROC PrintAllRecords()
  627.  
  628.    ; Call the procedure IsPrinterReady() to check if a printer is on-line
  629.    ; and ready to receive the report. The IsPrinterReady() procedure returns
  630.    ; logical TRUE if the printer is ready and logical FALSE if it is not
  631.    ; ready. If the printer is not ready, then the PrintAllRecords()
  632.    ; procedure returns.
  633.    IF (IsPrinterReady() = False)
  634.       THEN RETURN
  635.    ENDIF
  636.  
  637.    ; Open the currently set printer device for output. This command is
  638.    ; useful when working on a network.
  639.    OPEN PRINTER
  640.    ; RptAll.sc is a recorded script for printing the standard report
  641.    ; on the customer table.
  642.    Play "RptAll"
  643.  
  644.    ; Close the currently opened printer.
  645.    CLOSE PRINTER
  646. ENDPROC
  647.  
  648.  
  649.  
  650. ; --------------------------------------------------------------------------
  651. ; Procedure  : PrintWestCoastRecords()
  652. ; Description:
  653.    ; We only want West Coast, so we'll bring up a query save
  654.    ; we've previously done, run it, and copy the report to the answer
  655.    ; table, then print the report.
  656. ; Called By  : Main()
  657. ; --------------------------------------------------------------------------
  658.  
  659. PROC PrintWestCoastRecords()
  660.  
  661.    ; Make sure that the printer is ready to receive information.
  662.    IF (IsPrinterReady() = False)
  663.       THEN RETURN
  664.    ENDIF
  665.  
  666.    ; Open the Printer
  667.    OPEN PRINTER
  668.  
  669. ; The following query was created interactively and saved using
  670. ; QuerySave. It was then copied into our script.
  671. Query
  672.  
  673.  Customer | Customer_No. | Last_Name | First_Name | Address |  City  |
  674.           | Check        | Check     | Check      | Check   | Check  |
  675.  
  676.  Customer | State/Prov.  | Postal_Code  | Telephone | Discount_% |
  677.           | Check        | Check 9..    | Check     | Check      |
  678.  
  679. Endquery
  680.  
  681. ; remember that the saved query ONLY places the query on the workspace.
  682. ; It is still up to the programmer to execute the Do_It! which will run
  683. ; the query...
  684.   Do_It!
  685.  
  686.    ; the following can be produced by using ScriptRecord
  687.    ;Menu {Tools} {Copy} {Report} {DifferentTable}
  688.    ;     {Customer} {R} {Answer} {R}
  689.    ;Menu {Report} {Output} {Answer} {R} {Printer}
  690.    ; But this can be done with PAL commands, and much more concisely.
  691.    COPYREPORT "Customer" "R" "Answer" "R"
  692.    REPORT "Answer" "R"
  693.  
  694.    ; close the printer
  695.    CLOSE PRINTER
  696.  
  697.    CLEARALL   ; to clear query image and answer table
  698.  
  699. ENDPROC
  700.  
  701.  
  702. ; --------------------------------------------------------------------------
  703. ; Procedure  : ShowSplashScreen
  704. ; Description:
  705. ;    Creates a window showing the application's "splash" screen.
  706. ;
  707. ; Called By  : Main()
  708. ; --------------------------------------------------------------------------
  709.  
  710. PROC ShowSplashScreen()
  711.  
  712. ; define the display attributes of the splash screen window
  713.    DYNARRAY WindowAttributes[]
  714.    WindowAttributes["ORIGINROW"] = 7
  715.    WindowAttributes["ORIGINCOL"] = 13
  716.    WindowAttributes["WIDTH"] = 56
  717.    WindowAttributes["HEIGHT"] = 11
  718.    WindowAttributes["STYLE"] = 30           ; yellow on blue
  719.    WindowAttributes["HASFRAME"] = False     ; creates a frameless window
  720.    WindowAttributes["FLOATING"] = True      ; sets the window "above" the
  721.                                             ; echo layer
  722.  
  723. ; show the splash screen window
  724.    WINDOW CREATE ATTRIBUTES WindowAttributes TO SplashWindow
  725.  
  726. ; paint information inside the splash screen window
  727.    @ 2,0 ?? FORMAT("W56,AC", "B O R L A N D")
  728.    @ 3,0 ?? FORMAT("W56,AC", "Sample Application")
  729.  
  730.  
  731. ; pause to show the window
  732.    SLEEP 2500
  733.  
  734. ; close the window
  735.    WINDOW CLOSE
  736.  
  737. ENDPROC
  738.  
  739.  
  740.  
  741. ; --------------------------------------------------------------------------
  742. ; Procedure   : IsPrinterReady
  743. ; Description :
  744. ;    Checks to see if the printer is ready.
  745. ; Called By  : PrintAllRecords, PrintWestCoastRecords
  746. ; --------------------------------------------------------------------------
  747.  
  748. PROC IsPrinterReady()
  749.  
  750.    ; check that the printer is ready
  751.    ; give user a message that we're checking the printer
  752.    Message "Checking printer status..."
  753.  
  754.    ; PRINTERSTATUS() returns a value of True if the printer is ready,
  755.    ;    False otherwise.
  756.    IF (PRINTERSTATUS() <> True)
  757.       THEN BEEP
  758.            MESSAGE "Printer is not ready"
  759.            SLEEP 2500     ; pause to display message
  760.            MESSAGE ""     ; remove message
  761.            ; Tell the calling procedure NOT to continue sending the report.
  762.            RETURN False
  763.    ENDIF
  764.  
  765.    MESSAGE ""     ; remove "Checking..." message
  766.  
  767.    ; Tell the calling procedure that the printer is ready to receive
  768.    ; report data.
  769.    RETURN True
  770.  
  771. ENDPROC
  772.  
  773.  
  774. ; The Main Event
  775. ; ----------------------------------
  776. ; The following line calls the Main() procedure. The Main() procedure
  777. ; starts the Sample application.
  778. Main()
  779.  
  780. ; Clean Up
  781. ; ----------------------------------
  782. ; We're done. Close any open images and release any variables and procedures
  783. ; before we exit.
  784. RESET
  785. RELEASE PROCS ALL
  786. RELEASE VARS ALL
  787.