home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 99.img / PDOX3-08.ZIP / TOOLKIT1 / INVDEMO.SC < prev    next >
Text File  |  1989-09-15  |  31KB  |  679 lines

  1. ; Copyright (c) 1988, 1989 Borland International.  All Rights Reserved.
  2. ;
  3. ; General permission to re-distribute all or part of this script is granted,
  4. ; provided that this statement, including the above copyright notice, is not
  5. ; removed.  You may add your own copyright notice to secure copyright
  6. ; protection for new matter that you add to this script, but Borland
  7. ; International will not support, nor assume any legal responsibility for,
  8. ; material added or changes made to this script.
  9. ;
  10. ; Revs.: MJP 2/29/88, DCY 12/18/88, DCY 4/20/89
  11. ; ****************************************************************************
  12. ;  NAME: SetInvPrompt
  13. ; EVENT: Table Arrive
  14. ; TABLE: Invoice
  15. ;  FORM: F
  16. ; NOTES: SetInvPrompt customizes the display prompt for the Invoice table.
  17. ;        Because we've designated SetInvPrompt as a Table Arrive procedure,
  18. ;        each time a user enters the Invoice table DoWait will activate it,
  19. ;        displaying our customized prompt.
  20. ; ****************************************************************************
  21. Proc SetInvPrompt()
  22.  
  23.    Prompt "Entering invoice information into Invoice table.",
  24.           "Press [F1] for help, [F2] when done, [F10] for menu."
  25.  
  26.    If IsBlank([Invoice No.])  ;If [Invoice No.] is blank, we must be
  27.       Then TKHoldCanvas = True ; initializing a new master invoice record.
  28.    Endif                     ; We want to hold the canvas up so a user won't
  29.                              ; see fill in of the Invoice No. and Date fields.
  30.  
  31. Endproc
  32. Writelib DemoLib SetInvPrompt
  33. Release Procs SetInvPrompt
  34.  
  35. ; ****************************************************************************
  36. ;  NAME: InitInvRec
  37. ; EVENT: Record Arrive
  38. ; TABLE: Invoice
  39. ;  FORM: F
  40. ; NOTES: Called upon arrival into a record of the Invoice table, InitInvRec
  41. ;        initializes information required for each invoice record.  For
  42. ;        example, it fills the Invoice No. with the next sequential invoice
  43. ;        number and fills the Date field with the current date.
  44. ;        InitInvRec also initializes the CustLink and NewCust variables.
  45. ;        CustLink specifies whether a Cust record is currently linked on the
  46. ;        Customer No. field.  NewCust specifies whether a linked Cust record
  47. ;        is a new or existing customer record.
  48. ;        IMPORTANT:  InitInvRec does minimal checking for conditions which can
  49. ;                    occur due to competition on a network. (We're assuming
  50. ;                    you won't be running this demo on a network).
  51. ; ****************************************************************************
  52. Proc InitInvRec()
  53.  
  54.    If IsBlank([Invoice No.]) ;If Invoice No. is blank, we're entering a new
  55.       Then Echo Off          ; invoice record.
  56.            End            ;Pick up the last invoice number
  57.            InvNo = 1
  58.            If not IsBlank([Invoice No.])
  59.               Then InvNo = [Invoice No.] + 1    ;Make new invoice number
  60.                    CtrlPgDn
  61.            Endif
  62.            [Invoice No.] = InvNo
  63.            LockRecord
  64.            While not Retval
  65.               InvNo = [Invoice No.] + 1    ;Make new invoice number
  66.               CtrlPgDn
  67.               [Invoice No.] = InvNo  ;Assign new number and attempt to post
  68.               LockRecord             ; and lock record.  If not successful,
  69.            Endwhile                  ; try, try again.
  70.            [Date] = Today()   ;Secured a record, fill in the current date
  71.            [Subtotal] = 0     ;Zero summary info for the record
  72.            [Tax %] = 0
  73.            [Tax] = 0
  74.            [Discount] = 0
  75.            [Shipping] = 0
  76.            [Total] = 0
  77.            NOrderRec = 1      ;Initialize first order record key
  78.            NewCust = True     ; Currently linked Cust record is a "new" record
  79.            DelCustLink = False ; Cannot delete linked Cust record
  80.            CustLink = False   ; We don't yet have a customer record linked to
  81.    Endif                      ;  this invoice
  82.  
  83. Endproc
  84. Writelib DemoLib InitInvRec
  85. Release Procs InitInvRec
  86.  
  87. ; ****************************************************************************
  88. ;  NAME: GetCustNo
  89. ; EVENT: Good Depart (field level)
  90. ; FIELD: Customer Id
  91. ; TABLE: Invoice
  92. ;  FORM: F
  93. ; NOTES: GetCustNo perform several functions.  First, it puts up
  94. ;        an application-sensitive message about invalid customer data
  95. ;        rather than allowing Paradox to put up its default message.
  96. ;        Second, it provides a menu which prompts the user to view the
  97. ;        current customer list or to interactively add information to the
  98. ;        customer master file.
  99. ; ****************************************************************************
  100. Proc GetCustNo()
  101.  
  102.    Switch
  103.       Case TKChar = TKUndo or TKChar = TKDel or TKChar = TKCancel:
  104.          ; (The record depart procedure handles these keys)
  105.       Case IsBlank([]):
  106.          TKAccept = False     ;Ignore movement key pressed (remain in field)
  107.          If TKChar = TKDo_It!
  108.             Then TKChar = TKCancel
  109.                  TKKeyType = "X"
  110.                  Return
  111.          Endif
  112.          TKMessage = "Please enter a Customer number, or press [F1] for a list of customers"
  113.          If TKChanged       ;New value-
  114.             Then ReSyncKey  ; Attempt to link a customer to this Cust No.
  115.                  RefreshCanvas()   ;Update the canvas
  116.                  [Discount %] = BlankNum()  ;Zero the summary fields
  117.                  [Discount] = 0
  118.                  [Tax %] = 0
  119.                  [Tax] = 0
  120.                  CustLink = False  ;Must re-check validity of this Cust No.
  121.                  NewCust = True    ;Determines whether linked Cust record
  122.                                    ; can be edited.  NewCust remains True
  123.                                    ; until an existing Customer No. is linked.
  124.          Endif
  125.       Case TKChanged or not CustLink: ;Must re-link on Customer No. if user
  126.          RefreshCanvas()              ; has changed Cust No.
  127.          If TKChanged
  128.             Then Message "Locating customer information..."
  129.                  ReSyncKey
  130.                  CustLink = IsRecLinked("Cust","Last Name") ;Cust linked?
  131.                  If CustLink    ;Customer is linked--update Invoice fields
  132.                     Then [Discount %] = [Cust->Discount %]
  133.                          [Tax %] = 0
  134.                          If [Cust->State] = "CA"      ;If CA resident, add
  135.                             Then [Tax %] = TaxRate    ; CA sales tax
  136.                          Endif
  137.                          NewCust = False ;Since customer already exists
  138.                                          ; in master Cust table, don't
  139.                                          ; allow user to edit info
  140.                          Enter           ;Skip over Discount % field since
  141.                          Enter           ;it's filled in above
  142.                          ArriveField()   ;Inform DoWait of explicit field
  143.                          Return          ; change.  ArriveField will also set
  144.                  Endif                   ; TKAccept False for us.
  145.                  RefreshCanvas()   ;Clear message window
  146.          Endif   ;Since TKChanged is True, CustLink must be False,
  147.                  ; indicating that we no longer have a valid Cust No.
  148.          Message "Customer number ",[]," is not in the current customer list"
  149.          ShowMenu
  150.              "Reenter" : "Reenter the customer number.",
  151.              "NewCustomer" : "New customer, add to master customer list.",
  152.              "ShowCustomers" : "Show or search the current customer list."
  153.          To Choice
  154.          Switch
  155.             Case Choice = "ShowCustomers":
  156.                CustLookUp()     ;Show lookup help
  157.             Case Choice = "NewCustomer":
  158.                Moveto "Cust"    ;Add new customer info
  159.                Message "Preparing to add customer to master customer list..."
  160.                Echo Off
  161.                TKHoldCanvas = True
  162.                NewCust = True   ;Specify linked Cust rec is "editable"
  163.                ArriveTable()    ;Inform DoWait we've explicitly entered
  164.                                 ; another table.  Note that since we
  165.                                 ; know we haven't assigned a Record Arrive
  166.                                 ; or Field Arrive procedure for the Cust
  167.                                 ; table, we won't call ArriveRecord or
  168.                                 ; ArriveField.  ArriveTable() will call
  169.                                 ; NewField() for us.
  170.             Otherwise:
  171.                ArriveField()
  172.         ;NOTE: We need to call NewField here because although we have not
  173.         ;      actually moved the cursor out of the current field, the
  174.         ;      contents of the field could have possibly changed. For
  175.         ;      example, if a user enters two non-existing Customer No.'s
  176.         ;      in a row but selects "Reenter" from the menu, the field value
  177.         ;      will have changed--we'll be in a "different" field.
  178.          Endswitch
  179.    Endswitch
  180.  
  181. Endproc
  182. Writelib DemoLib GetCustNo
  183. Release Procs GetCustNo
  184.  
  185. ; ****************************************************************************
  186. ;  NAME: IsRecLinked
  187. ; EVENT: N/A
  188. ; NOTES: IsRecLinked is a general-purpose procedure which determines whether
  189. ;        there are any records in a given table image.  It is especially
  190. ;        useful for cases in which you want to know whether any records are
  191. ;        linked to a field in a multi-table form.
  192. ;        IsRecLinked requires the name of the table of interest and the name
  193. ;        of a field within the table.  It returns a value of True if there
  194. ;        is at least one record within the table.  Otherwise, it returns a
  195. ;        value of False.
  196. ; ****************************************************************************
  197. Proc IsRecLinked(LinkTbl,LinkFld)
  198.    Private;LinkTbl,      ;Table with linked record in question
  199.           ;LinkFld,      ;Arbitrary field in LinkTbl
  200.            RecExists,    ;Specifies link status of a record
  201.            ErrorProc     ;Name of error-handling procedure
  202.  
  203.    Proc NoRecExists()         ;If there are no records in the specified
  204.       RecExists = False       ; image, Paradox will invoke this errorproc.
  205.       Return 1                ; The errorproc then sets RecExists false.
  206.    Endproc                    ; Otherwise, RecExists will remain True.
  207.    ErrorProc = "NoRecExists"
  208.    RecExists = True
  209.    Execute "FldVal = ["+LinkTbl+"->"+LinkFld+"]"
  210.    Release Procs NoRecExists
  211.    If RecExists               ;Errorproc set RecExists False, no records
  212.       Then Return True        ; are in the specified image.
  213.    Endif
  214.    Return False
  215.  
  216. Endproc
  217. Writelib DemoLib IsRecLinked
  218. Release Procs IsRecLinked
  219.  
  220. ; ****************************************************************************
  221. ;  NAME: CustLookUp
  222. ; EVENT: N/A
  223. ; FIELD: Customer No.
  224. ; TABLE: Invoice
  225. ; NOTES: Ordinarily a procedure to invoke lookup-style help from within DoWait
  226. ;        can actually issue a Help command and enter true Paradox lookup help.
  227. ;        However, because in our demonstration we allow for dynamic additions
  228. ;        to the Cust table through a multi-table form, we can't assign an
  229. ;        actual Paradox lookup help table to the Customer No. field.  Doing so
  230. ;        would not allow us to move to the embedded Cust table and add a new
  231. ;        Cust record. (We could not leave an invalid value in the Customer No.
  232. ;        field.)
  233. ;        To allow for lookup-style help, we place the Cust table on the
  234. ;        workspace along with the Invoice table before beginning to edit. Then
  235. ;        to view the existing customer list, we toggle out of the Invoice form
  236. ;        and move to the Cust table.  We use the Toolkit's LookupSelect
  237. ;        procedure to determine the key a user presses to exit help.
  238. ; ****************************************************************************
  239. Proc CustLookUp()
  240.  
  241.    RefreshCanvas()
  242.    UnLockRecord      ;Need to unlock record before toggling to table view
  243.    FormKey                   ;Move to "lookup" table
  244.    Moveto [Cust->Last Name]
  245.    Prompt "Viewing current master customer list.", ;Set customized prompt
  246.           "Press [F2] to select a customer or [Esc] to cancel."
  247.  
  248.    LookupSelect()            ;Begin "lookup" help interaction
  249.    ExitKey = Retval
  250.  
  251.    CustNo = [Customer No.]
  252.    DownImage   ;Return to Invoice table
  253.    FormKey
  254.    LockRecord
  255.    SetInvPrompt()      ;Reset editing prompt
  256.  
  257.    TKAccept = False  ;Instruct DoWait to ignore key that invoked lookup help
  258.    If ExitKey = TKDo_It!         ;User pressed Do-It!
  259.       Then [Customer No.] = CustNo  ;Copy Customer No. into Invoice record
  260.            ReSyncKey                ;Link the customer information
  261.            [Discount %] = [Cust->Discount %]   ;Copy default discount value
  262.            [Tax %] = 0
  263.            If [Cust->State] = "CA"   ;Only charge CA sales tax to CA residents
  264.               Then [Tax %] = TaxRate
  265.            Endif
  266.            CustLink = True            ;We now have a valid customer linked
  267.            NewCust = False            ;Customer already exists in master file
  268.            Enter                      ;Move user to Method of Payment field
  269.            Enter                      ; and inform DoWait we've arrived in a
  270.            ArriveField()              ; new field.
  271.    Endif
  272.  
  273. Endproc
  274. Writelib DemoLib CustLookUp
  275. Release Procs CustLookUp
  276.  
  277. ; ****************************************************************************
  278. ;  NAME: ReCalcDisc
  279. ; EVENT: Good Depart (field level)
  280. ; FIELD: Discount  %
  281. ; TABLE: Invoice
  282. ;  FORM: F
  283. ; NOTES: ReCalcDisc examines TKChanged to determine if a user has changed the
  284. ;        value of the field since entering it.  If so, it calls the CalcTotals
  285. ;        procedure which recalculates the totals for the invoice record.
  286. ; ****************************************************************************
  287. Proc ReCalcDisc()
  288.  
  289.    If IsBlank([])
  290.       Then [] = 0
  291.    Endif
  292.  
  293.    If TKChanged
  294.       Then CalcTotals()
  295.    Endif
  296.  
  297. Endproc
  298. Writelib DemoLib ReCalcDisc
  299. Release Procs ReCalcDisc
  300.  
  301. ; ****************************************************************************
  302. ;  NAME: BadPayMethod
  303. ; EVENT: Bad Depart (field level)
  304. ; FIELD: Method of Payment
  305. ; TABLE: Invoice
  306. ;  FORM: F
  307. ; NOTES: BadPayMethod diplays a customized message in lieu of a standard
  308. ;        Paradox message when a user attempts to leave the Method of
  309. ;        Payment field and the field data is not one of the valid choices.
  310. ;        Note we did not set TKAccept to False.  Accepting a movement key
  311. ;        when a field is invalid will simply cause Paradox to put up its
  312. ;        standard message.  Since we have provided our own message, DoWait
  313. ;        will suppress Paradox's message and display ours.
  314. ; ****************************************************************************
  315. Proc BadPayMethod()
  316.  
  317.    TKMessage = "Enter a valid payment method, or press [F1] for a list of payment options"
  318.    ArriveField()  ;Reinitialize field value; we're now in a "new" field since
  319.                   ; the value must have changed
  320.  
  321. Endproc
  322. Writelib DemoLib BadPayMethod
  323. Release Procs BadPayMethod
  324.  
  325. ; ****************************************************************************
  326. ;  NAME: SkipCredInfo()
  327. ; EVENT: Arrive (field level)
  328. ; FIELD: Credit Card No.
  329. ; TABLE: Invoice
  330. ;  FORM: F
  331. ; NOTES: If a user has not entered a credit card as the method of payment,
  332. ;        SkipCredInfo will clear out the credit card information fields and
  333. ;        move the user to the Orders table on the next page.
  334. ; ****************************************************************************
  335. Proc SkipCredInfo()
  336.  
  337.    If [Method of Payment] = "Check" or [Method of Payment] = "Money Order"
  338.       Then [Credit Card No.] = ""
  339.            [Expiration Date] = BlankDate()
  340.            RefreshCanvas()
  341.            Moveto "Orders"   ; require credit card info.
  342.            ArriveTable()     ; Skip to Orders table.
  343.    Endif
  344.  
  345. Endproc
  346. Writelib DemoLib SkipCredInfo
  347. Release Procs SkipCredInfo
  348.  
  349. ; ****************************************************************************
  350. ;  NAME: ControlMvmnt
  351. ; EVENT: Good Depart (field level)
  352. ; FIELD: Ship Via
  353. ; TABLE: Invoice
  354. ;  FORM: F
  355. ; NOTES: ControlMvmnt zeroes the Shipping field of the Invoice table if a user
  356. ;        does not enter a carrier service.  It also redirects a user's move-
  357. ;        ment such that any attempt to move upwards will take the user to the
  358. ;        Orders table.  Since it is the last field of the record, moving to
  359. ;        the right (Enter) will initiate the record departure procedure for
  360. ;        the Invoice table.
  361. ;        Note that we need to zero the Shipping field since it plays a part in
  362. ;        the calculation of the total amount of the current invoice record.
  363. ;        The record depart procedure in this case will prevent a user from
  364. ;        posting his changes without specifying a valid carrier.
  365. ; ****************************************************************************
  366. Proc ControlMvmnt()
  367.  
  368.    If IsBlank([])
  369.       Then [Shipping] = 0
  370.    Endif
  371.  
  372.    If TKChanged
  373.       Then Echo Off
  374.            DownImage
  375.            Locate [Invoice->Ship Via]
  376.            UpImage
  377.            [Shipping] = [Carriers->Charge]
  378.            CalcTotals()
  379.    Endif
  380.  
  381.    If TKChar = TKLeft or TKChar = TKReverseTab or TKChar = TKUp
  382.       Then UpImage   ;Redirect movement to Orders table
  383.            ArriveTable() ;Note that resetting TKChar would instruct DoWait to
  384.                          ; process the TKUpImage key.  This would in turn re-
  385.                          ; invoke this procedure, the record depart procedure,
  386.                          ; and a table depart (if there were one).
  387.    Endif
  388.  
  389. Endproc
  390. Writelib DemoLib ControlMvmnt
  391. Release Procs ControlMvmnt
  392.  
  393. ; ****************************************************************************
  394. ;  NAME: PayOptions
  395. ; EVENT: N/A
  396. ; FIELD: Method of Payment
  397. ; TABLE: Invoice
  398. ;  FORM: F
  399. ; NOTES: PayOptions is called by the Invoice's Special key procedure when
  400. ;        the special key pressed is [F1] (Help) and the field is in the Ship
  401. ;        Via field.  PayOptions calls the Toolkit's Popup procedure to display
  402. ;        a popup-style menu.  If the user makes a selection from the popup
  403. ;        menu, PayOptions sets TKBuffer to [Enter] which will move the user to
  404. ;        the next field.  Note that the FillCarrier procedure, the Good Depart
  405. ;        procedure for the Method of Payment field, will then redirect the
  406. ;        user to either the Orders table or the credit card info fields as
  407. ;        appropriate.
  408. ; ****************************************************************************
  409. Proc PayOptions()
  410.  
  411.    TKAccept = False
  412.    Popup(16,25,1,5)
  413.    If not IsBlank(Retval)
  414.       Then [] = Retval        ;Fill the field with the value
  415.            If [] <> "Check" and [] <> "Money Order"  ;Do we need credit card
  416.               Then [Credit Card No.] = ""            ; info?  If not, clear
  417.                    [Expiration Date] = BlankDate()   ; it out.
  418.            Endif
  419.            If IsBlank(TKFieldVal)    ;If the field was empty on arrival, then
  420.                 or ([] <> "Check" and [] <> "Money Order")
  421.               Then TKBuffer = TKEnter  ; initiate controlled movement to next
  422.            Endif   ; appropriate field (DoWait will act upon TKBuffer BEFORE
  423.    Endif           ; TKChar, activating the ValidPay (Good Depart) procedure).
  424.    ArriveField()
  425.  
  426. Endproc
  427. Writelib DemoLib PayOptions
  428. Release Procs PayOptions
  429.  
  430. ; ****************************************************************************
  431. ;  NAME: ReqCredInfo
  432. ; EVENT: Good Depart (field level)
  433. ; FIELD: Credit Card No., Expiration Date
  434. ; TABLE: Invoice
  435. ;  FORM: F
  436. ; NOTES: This procedure ensures that a user enters a credit card number and
  437. ;        card expiration date before leaving the field.  It also displays a
  438. ;        customized message when the user attempts to leave the field empty.
  439. ;        If a user presses Del, it clears the Credit Card No. and Expiration
  440. ;        Date fields.  It also moves the user out of the Expiration Date field
  441. ;        (when the date is valid) and into the Orders table.
  442. ; ****************************************************************************
  443. Proc ReqCredInfo()
  444.  
  445.    If TKChar = TKDel       ;User wants to select another payment method
  446.       Then [Credit Card No.] = ""      ;Clear out credit card info
  447.            [Expiration Date] = BlankDate()
  448.            Moveto [Method of Payment]  ;Return to Method of Payment field
  449.       Else If IsBlank([])
  450.               Then TKAccept = False
  451.                    If TKFieldNum = 8   ;Is user in card no. or date field?
  452.                       Then TKMessage = "Please enter the customer's credit card number"
  453.                       Else TKMessage = "Please enter the expiration date for this customer's credit card"
  454.                    Endif
  455.               Else If TKFieldNum = 8
  456.                       Then Enter        ;Move to date field
  457.                       Else If [] >= Today()
  458.                               Then PgDn         ;Move to Orders table
  459.                                    UpImage
  460.                                    ArriveTable(); Inform DoWait
  461.                               Else TKMessage = "This credit card has expired"
  462.                            Endif
  463.                    Endif
  464.            Endif
  465.    Endif
  466.    ArriveField()   ;ArriveField sets TKAccept to False for us
  467.  
  468. Endproc
  469. Writelib DemoLib ReqCredInfo
  470. Release Procs ReqCredInfo
  471.  
  472. ; ****************************************************************************
  473. ;  NAME: LeaveFullDate
  474. ; EVENT: Keystroke (field level)
  475. ; FIELD: Expiration Date
  476. ; TABLE: Invoice
  477. ;  FORM: F
  478. ; NOTES: LeaveFullDate examines the effect of each keystroke to determine
  479. ;        whether a date is complete.  When the date a user enters matches one
  480. ;        of the valid date patterns, LeaveFullDate automatically moves the
  481. ;        user to the Orders table on the next page of the form.
  482. ; ****************************************************************************
  483. Proc LeaveFullDate()
  484.  
  485.    Keypress TKChar  ;Let Paradox press the character (it will reject bad keys)
  486.    If Match(FieldStr(),"../../@@") ;Is the field complete?
  487.         or Match(FieldStr(),"..-..-@@")
  488.       Then If IsValid()   ;Pattern is complete, but is date valid?
  489.               Then If [] < Today() ;Credit card still valid?
  490.                       Then TKMessage = "This credit card has expired"
  491.                            ArriveField()
  492.                       Else Enter         ;Move to next page,
  493.                            UpImage       ; move to Orders table,
  494.                            ArriveTable() ; and inform DoWait.
  495.                    Endif
  496.               Else TKChar = TKRight ;Because we know the field contains
  497.            Endif  ; invalid data, pressing a movement key will display the
  498.                   ; standard Paradox message
  499.       Else TKAccept = False ;Since we already keypressed the character, we
  500.    Endif                    ; want DoWait to ignore it
  501.  
  502. Endproc
  503. Writelib DemoLib LeaveFullDate
  504. Release Procs LeaveFullDate
  505.  
  506. ; ****************************************************************************
  507. ;  NAME: SelectCarrier
  508. ; EVENT: N/A
  509. ; FIELD: Ship Via
  510. ; TABLE: Invoice
  511. ;  FORM: F
  512. ; NOTES: SelectCarrier facilitates lookup help for the Ship Via field.  It
  513. ;        applies the Toolkit's LookupSelect procedure to the embedded Carriers
  514. ;        table, copying a selected value into the Ship Via and Shipping fields
  515. ;        of the Invoice table.
  516. ; ****************************************************************************
  517. Proc SelectCarrier()
  518.  
  519.    If not IsValid()    ;Can't leave the Ship Via field if it's contains
  520.       Then CtrlBackspace ; invalid data
  521.    Endif
  522.  
  523.    DownImage    ;Move to Carriers table and display customized editing prompt
  524.    Prompt "Use cursor movement keys to select a carrier service.",
  525.           "Press [F2] to select, or [Esc] to cancel."
  526.    LookupSelect()
  527.    UpImage
  528.    If Retval = TKDo_It!
  529.       Then [Ship Via] = [Carriers->]
  530.            [Shipping] = [Carriers->Charge]
  531.            CalcTotals()
  532.    Endif
  533.    ArriveTable()  ;ArriveTable will call SetInvPrompt (which will reset the
  534.                   ; editing prompt) and set TKAccept to False
  535. Endproc
  536. Writelib DemoLib SelectCarrier
  537. Release Procs SelectCarrier
  538.  
  539. ; ****************************************************************************
  540. ;  NAME: PostInvRec
  541. ; EVENT: Record Depart
  542. ; TABLE: Invoice
  543. ;  FORM: F
  544. ; NOTES: PostInvRec illustrates several uses of a record depart procedure.
  545. ;        When a user attempts to delete a master invoice record, PostInvRec
  546. ;        will delete expendable detail records, keeping linked customer
  547. ;        information.
  548. ;        If a user attempts to post an invoice record, PostInvRec will
  549. ;        require that the Ship Via field be filled in.  We could have used a
  550. ;        departure procedure to prevent a user from leaving the Ship Via field
  551. ;        without entering a value.  This just demonstrates the use of a record
  552. ;        level procedure to enforce record-level validity checking.
  553. ;        If a user has filled in all necessary information and attempts to
  554. ;        leave the master invoice record, PostInvRec will ask for confirmation
  555. ;        before actually posting the changes.
  556. ; ****************************************************************************
  557. Proc PostInvRec()
  558.  
  559.    Switch
  560.       Case TKChar = TKDel:
  561.          RefreshCanvas()
  562.          TKAccept = False
  563.          ShowMenu
  564.             "Cancel" : "Do not delete the current invoice record.",
  565.             "OK" : "Go ahead and delete the current invoice record."
  566.          To C
  567.  
  568.          If C = "OK"
  569.             Then Message "Deleting invoice record..."
  570.                  If TKFieldNum = 7    ;If we're in the required field, we'll
  571.                     Then RequiredCheck Off  ; need to be sure we can delete
  572.                  Endif                      ; the record.
  573.                  Moveto "Orders"
  574.                  While NImageRecords() <> 1 ;Delete linked order records
  575.                     Del
  576.                  Endwhile
  577.                  Del
  578.                  Moveto [Invoice->Customer No.]
  579.                  If RecNo() = 1    ;If there's only one record in the table
  580.                     Then Del       ; before we delete it, a new record will
  581.                          Do_It!    ; automatically be opened up for us.
  582.                          CoEditKey
  583.                          FormKey
  584.                     Else Del       ;Otherwise, we need to open up a record
  585.                          Do_It!    ; at the end of the table
  586.                          End
  587.                          CoEditKey
  588.                          CtrlPgDn  ;Open up new record
  589.                  Endif
  590.                  RequiredCheck On
  591.                  TKHoldCanvas = True ;Hide canvas until record is re-filled
  592.                  ArriveRecord()    ;Initialize new master invoice record
  593.          Endif
  594.       Case IsBlank([Ship Via]):  ;Don't allow user to post record if Ship Via
  595.          TKMessage = "Enter a carrier service or press [F1] for a list of possible carriers"
  596.          Moveto [Ship Via] ; field is blank.
  597.          ArriveField() ;Inform DoWait we're in a new field.  ArriveField
  598.                           ; will set TKAccept False, rejecting the pending key
  599.       Otherwise:  ;Assume that cursor movement attempting to move to the next
  600.          RefreshCanvas()    ; invoice record is an attempt to post the record
  601.          TKAccept = False
  602.          C = "Post"
  603.          If TKChar <> TKDo_It!   ;Otherwise, ask for confirmation...
  604.             Then ShowMenu
  605.                     "Resume" : "Resume adding information to invoice.",
  606.                     "Post" : "Post changes made to this invoice to the master file."
  607.                  To C
  608.          Endif
  609.          If C = "Post"
  610.             Then Message "Posting invoice record..."
  611.                  CtrlHome
  612.                  CtrlPgDn        ;Open up a new record
  613.                  ArriveRecord()  ;Initialize new master invoice record
  614.          Endif
  615.    Endswitch
  616.  
  617. Endproc
  618. Writelib DemoLib PostInvRec
  619. Release Procs PostInvRec
  620.  
  621. ; ****************************************************************************
  622. ;  NAME: InvSpclKey
  623. ; EVENT: Special key
  624. ; TABLE: Invoice
  625. ; NOTES: InvSpclKey is called whenever a Special key is pressed within the
  626. ;        Invoice table.  Because many special keys can be classified as
  627. ;        Special keys, InvSpclKey must first determine which key the user
  628. ;        pressed.
  629. ; ****************************************************************************
  630. ;
  631. Proc InvSpclKey()
  632.  
  633.    RefreshCanvas()
  634.    Switch
  635.       Case TKChar = TKHelp :                  ;The special key was Help
  636.          Switch
  637.             Case TKFieldNum = 4 :    ;Help was pressed from Cust No. field
  638.                CustLookUp()          ;Show Cust lookup help
  639.             Case TKFieldNum = 7 :    ;Help for Method of Payment field
  640.                PayOptions()          ;Show popup help of payment options
  641.             Case TKFieldNum = 10 :   ;Help for Ship Via field
  642.                SelectCarrier()       ;Show Carrier help
  643.          Endswitch
  644.       Case (TKChar = TKDownImage or TKChar = TKUpImage) and IsValid():
  645.          If PageNo() = 1
  646.             Then If CustLink      ;Only allow movement into Cust table if
  647.                     Then UpImage  ; a customer record is linked
  648.                          ArriveTable()  ;Moved to a new table, inform DoWait
  649.                     Else TKMessage = "Cannot move to Cust table without a valid Customer No."
  650.                  Endif
  651.             Else UpImage   ;On second page, can only move to Orders
  652.                  ArriveTable()  ;Moved to a new table, inform DoWait
  653.          Endif
  654.       Case TKChar = TKMenu :            ;The special key was [F10] Menu
  655.          EditMenu()                     ;Show the Toolkit's simple edit menu
  656.          If TKChar = TKCancel           ;User selected Cancel,
  657.             Then TKHoldCanvas = True    ; Keep the canvas up until final exit
  658.                  TKKeyType = "X"        ; Want immediate exit from DoWait,
  659.          Endif                          ; skipping departure procedures
  660.       Case TKChar = TKUndo:
  661.          Undo
  662.          If IsBlank([Date])    ;Date will be empty if Undo undoes first
  663.             Then TKHoldCanvas = True    ; change to record
  664.                  RequiredCheck Off
  665.                  Del
  666.                  Message "Deleting invoice record..."
  667.                  CtrlHome
  668.                  CtrlPgDn        ;Open up a new record
  669.                  ArriveRecord()  ;Initialize new master invoice record
  670.                  RequiredCheck On
  671.          Endif
  672.          ArriveField()
  673.       Case TKChar = -46:          ;[Alt][C] should toggle commentary mode
  674.          ToggleCommentary()       ;Toggles commentary mode
  675.    Endswitch
  676. Endproc
  677. Writelib DemoLib InvSpclKey
  678. Release Procs InvSpclKey
  679.