home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a114 / 2.img / TOOLKIT / TOOLKIT.ZIP / ORDRDEMO.SC < prev    next >
Encoding:
Text File  |  1990-08-25  |  10.8 KB  |  262 lines

  1. ; Copyright (c) 1988 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
  11. ; ****************************************************************************
  12. ;  NAME: SetOrdrPrompt
  13. ; EVENT: Table Arrive
  14. ; TABLE: Orders
  15. ; NOTES: SetOrdrPrompt customizes the prompt for editing within the Orders
  16. ;        table.  DoWait will call it whenever a user enters the Orders table.
  17. ;        Since many of our procedures explicitly move to the Orders table, we
  18. ;        call the Record Arrive procedure within SetOrdrPrompt to increase the
  19. ;        efficiency of our code and to ensure that we always call it.
  20. ; ****************************************************************************
  21. Proc SetOrdrPrompt()
  22.  
  23.    Prompt "Entering order information into Orders table.",
  24.           "Press [F1] for help or [F2] to return to Invoice table."
  25.    InitOrdrRec()
  26.    TKHoldCanvas = True
  27.  
  28. Endproc
  29. Writelib DemoLib SetOrdrPrompt
  30. Release Procs SetOrdrPrompt
  31.  
  32. ; ****************************************************************************
  33. ;  NAME: InitOrdrRec
  34. ; EVENT: Record Arrive
  35. ; TABLE: Orders
  36. ;  FORM: F
  37. ; NOTES: The Orders table is linked to the Invoice table via its Invoice No.
  38. ;        field.  In order to create a one-to-many link, i.e., have several
  39. ;        order records for each invoice record, we maintain a secondary index
  40. ;        field, the Key field.  InitOrdrRec fills the Key field of the Orders
  41. ;        table with the next available number.  InitOrdrRec also assigns a
  42. ;        value to the CRecTotal variable used by ChngOrdrRec to determine the
  43. ;        total for the current order record.
  44. ; ****************************************************************************
  45. Proc InitOrdrRec()
  46.  
  47.    RefreshCanvas()
  48.    If IsBlank([Key])          ;Is the Key field blank?
  49.       Then [Key] = NOrderRec  ;Give it next order number
  50.            NOrderRec = NOrderRec + 1
  51.    Endif
  52.  
  53.    If IsBlank([Unit Price]) or IsBlank([Quantity])
  54.       Then CRecTotal = 0
  55.       Else CRecTotal = Round([Unit Price] * [Quantity],2)
  56.    Endif
  57.  
  58. Endproc
  59. Writelib DemoLib InitOrdrRec
  60. Release Procs InitOrdrRec
  61.  
  62. ; ****************************************************************************
  63. ;  NAME: ChngOrdrRec
  64. ; EVENT: Record Depart
  65. ; TABLE: Orders
  66. ;  FORM: F
  67. ; NOTES: ChngOrdrRec illustrates many uses of a record depart procedure.  For
  68. ;        example, not only does it update running calculations for the
  69. ;        current invoice record, it also controls a user's movements
  70. ;        through order records.  If a user moves upward while on the first
  71. ;        record, ChngOrdrRec moves the user to the Method of Payment field on
  72. ;        the first page.  An attempt to move downward while on the last
  73. ;        order record moves the user to the Ship Via field of the Invoice
  74. ;        table.  Additionally, ChngOrdrRec only allows a user to leave the
  75. ;        current record if both the Item No. and Quantity fields are either
  76. ;        empty or filled.
  77. ; ****************************************************************************
  78. Proc ChngOrdrRec()
  79.  
  80.   ;This first SWITCH handles abnormal attempts to leave an order record.  A
  81.   ; user is only allowed to leave a half-filled record by pressing Del or
  82.   ; Undo.
  83.    Switch
  84.       Case TKChar = TKDel:
  85.          RefreshCanvas()
  86.          Message "Recalculating totals..."
  87.          Del
  88.          NOrderRec = NOrderRec + 1
  89.          DownImage   ; Update total stored in invoice record
  90.          [Subtotal] = Round([Subtotal] - CRecTotal,2)
  91.          CalcTotals()
  92.          UpImage
  93.          ArriveRecord() ;Arriving in new record, set TKAccept False
  94.       Case TKChar = TKUndo: ;Need to update summary info after an undo
  95.          UpdtAftrUndo()
  96.       Case not IsValid() ;Only allow user to leave field if both fields are
  97.            or (IsBlank([Item]) and not IsBlank([Quantity]))  ; empty or both
  98.            or (not IsBlank([Item]) and IsBlank([Quantity])): ; are filled
  99.          TKAccept = False   ;Reject user's attempt to leave the current record
  100.          TKMessage = "Please enter both an Item No. and Quantity for this order record"
  101.    Endswitch
  102.  
  103.   ;This SWITCH performs special record exit processing.  It deletes blank
  104.   ; order records and recalculates invoice summary fields for records whose
  105.   ; totals change after entry.
  106.  
  107.    Switch
  108.       Case TKAccept = False:  ;Cases above which set TKAccept False have
  109.          Return               ; completed special handling.
  110.       Case IsBlank([Quantity]):
  111.          Echo Off
  112.          Del        ;Delete empty record and reinsert a blank record
  113.          If AtLast()  ; without rejecting key.
  114.             Then Down         ; Allow Paradox to process movement key.
  115.             Else If RecNo() <> 1
  116.                     Then Ins
  117.                  Endif
  118.          Endif
  119.          ;NOTE: Since we require a user to fill both the Item No. and Quantity
  120.          ;      fields in order to leave an order record, we know that if the
  121.          ;      Quantity field is empty the Item No. field must also be empty.
  122.       Case Round([Quantity] * [Unit Price],2) <> CRecTotal: ;Has current total
  123.          RefreshCanvas()                           ; changed since arrival?
  124.          [Amount] = Round([Quantity] * [Unit Price],2)
  125.          CRecTotal = Round(CRecTotal - [Amount],2)
  126.          Message "Recalculating totals..."         ;Update running total
  127.          DownImage
  128.          [Subtotal] = Round([Subtotal] - CRecTotal,2)
  129.          CalcTotals()
  130.          UpImage
  131.    Endswitch
  132.  
  133.   ;This final SWITCH redirects movement for special exit cases.  An attempt
  134.   ; to move upward from the first order record takes the user to the first
  135.   ; page of the Invoice table.  Moving downward (but not with [Right] or
  136.   ; [Enter]) from the last order record takes a user to the Ship Via field on
  137.   ; the current page.
  138.  
  139.    Switch
  140.       Case RecNo() = 1 and TKChar = TKUp: ;Moving to first page
  141.          Moveto [Invoice->Method of Payment]
  142.          ArriveTable()  ;ArriveTable sets TKAccept False
  143.       Case (AtLast() and TKChar = TKDown)  ;Moving down to Ship Via field?
  144.         or TKChar = TKUpImage:             ;Moving to Carriers table?
  145.          DownImage         ;Redirect movement to Invoice table...
  146.          ArriveTable()
  147.    Endswitch
  148. Endproc
  149. Writelib DemoLib ChngOrdrRec
  150. Release Procs ChngOrdrRec
  151.  
  152. ; ****************************************************************************
  153. ;  NAME: SelectItem
  154. ; EVENT: N/A
  155. ; FIELD: Item
  156. ; TABLE: Orders
  157. ;  FORM: F
  158. ; NOTES: SelectItem invokes the LookupSelect procedure so that we can
  159. ;        determine the key a user presses to exit lookup help.  We do this so
  160. ;        that we can automatically move the user to the next field if
  161. ;        appropriate.
  162. ; ****************************************************************************
  163. Proc SelectItem()
  164.  
  165.    Help                ;Enter lookup help, show items in stock
  166.    LookUpSelect()      ;Begin lookup help interaction
  167.  
  168.    If Retval = TKDo_It!     ;User pressed Do-It!
  169.       Then Do_It!           ; Exit lookup help, reassign pending key to
  170.            TKChar = TKEnter ; Enter to move user to next field
  171.       Else Esc              ;User pressed Esc, exit lookup help
  172.            TKAccept = False
  173.    Endif
  174.  
  175. Endproc
  176. Writelib DemoLib SelectItem
  177. Release Procs SelectItem
  178.  
  179. ; ****************************************************************************
  180. ;  NAME: OrdrSpclKey
  181. ; EVENT: Special key
  182. ; TABLE: Orders
  183. ; NOTES: OrdrSpclKey handles special keys a user presses while within the
  184. ;        Orders table.
  185. ; ****************************************************************************
  186. Proc OrdrSpclKey()
  187.  
  188.    Switch
  189.       Case TKChar = TKHelp:
  190.          If TKFieldNum = 4     ;Help for the Item field or Quantity field?
  191.             Then SelectItem()
  192.             Else Echo Off
  193.                  Style Attribute SysColor(9)
  194.                  OrdersBox()   ;Show general help box
  195.                  Style
  196.                  SyncCursor
  197.                  TKHoldCanvas = True    ;Hold canvas until a keypress
  198.                  TKAccept = False ;Don't let Paradox display its own help
  199.          Endif
  200.       Case TKChar = TKDo_It!: ;Finished adding orders, move to Invoice table
  201.          TKChar = TKDownImage  ;Reassign pending key to DownImage
  202.       Case TKChar = -46:      ;[Alt][C], commentary key--
  203.          ToggleCommentary()   ; Need to toggle the commentary state
  204.    Endswitch
  205. Endproc
  206. Writelib DemoLib OrdrSpclKey
  207. Release Procs OrdrSpclKey
  208.  
  209. ; ****************************************************************************
  210. ;  NAME: UpdtAftrUndo
  211. ; EVENT: N/A
  212. ; NOTES: UpdtAftrUndo is called by ChngOrdrRec when a user presses Undo while
  213. ;        editing order records.  When a user presses Undo within the Orders
  214. ;        table, we have no way of knowing what changes will be undone.  Thus
  215. ;        we must re-scan the linked records to update the invoice record
  216. ;        subtotal.  UpdtAftrUndo examines the message window after doing an
  217. ;        Undo for a user and continues to do Undos until a deleted record is
  218. ;        resinserted or the current, unposted record is deleted.
  219. ; ****************************************************************************
  220. Proc UpdtAftrUndo()
  221.  
  222.    RefreshCanvas()
  223.    CRecNo = RecNo()   ;Save cursor position within table
  224.    CRowNo = RowNo()
  225.    Undo ;
  226.    If Search("Resinserted record",Window()) <> 0
  227.       Then Undo   ;Doing undo three Undos will guarantee that change to a
  228.            Undo   ; record will be undone and the record will be deleted.
  229.    Endif
  230.    CImgTotl = 0
  231.    Scan For Not IsBlank([Amount])
  232.       CImgTotl = CImgTotl + [Amount]  ;Recalculate total
  233.    Endscan
  234.    DownImage
  235.    [Subtotal] = Round(CImgTotl,2)
  236.    CalcTotals()
  237.    UpImage
  238.    If RecNo() < NImageRecords()
  239.       Then SetRecordPosition CRecNo CRowNo  ;Restore cursor position
  240.    Endif
  241.    ArriveRecord()   ;ArriveRecord will set TKAccept False
  242.  
  243. Endproc
  244. Writelib DemoLib UpdtAftrUndo
  245. Release Procs UpdtAftrUndo
  246.  
  247. ; ****************************************************************************
  248. ;  NAME: CalcTotals
  249. ; EVENT: N/A
  250. ; NOTES: CalcTotals computes the absolute Discount, Tax, and Total fields for
  251. ;        the current invoice record.
  252. ; ****************************************************************************
  253. Proc CalcTotals()
  254.  
  255.    [Discount] = Round([Subtotal] * [Discount %] / 100,2)
  256.    [Tax] = Round( ([Subtotal] - [Discount]) * [Tax %] / 100,2 )
  257.    [Total] = Round([Subtotal] - [Discount] + [Tax] + [Shipping],2)
  258.  
  259. Endproc
  260. Writelib DemoLib CalcTotals
  261. Release Procs CalcTotals
  262.