home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a114 / 2.img / TOOLKIT / TOOLKIT.ZIP / CUSTDEMO.SC < prev    next >
Encoding:
Text File  |  1990-08-25  |  13.1 KB  |  277 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/17/88
  11. ; ****************************************************************************
  12. ;  NAME: SetCustPrompt
  13. ; EVENT: Table Arrive
  14. ; TABLE: Cust
  15. ;  FORM: F
  16. ; NOTES: SetCustPrompt customizes the system prompt and sets image rights for
  17. ;        the Cust table depending upon whether a user is allowed to edit
  18. ;        customer information.  A user is not allowed to edit existing
  19. ;        customer records.  SetCustPrompt first calls LockNewCust to test for
  20. ;        competition for the new customer number.
  21. ;        The variable NewCust specifies whether the current customer was newly
  22. ;        added to the Cust table, or is an existing customer record.  The
  23. ;        variable CustLink specifies whether a customer record is currently
  24. ;        linked to the current invoice record.
  25. ; ****************************************************************************
  26. Proc SetCustPrompt()
  27.  
  28.    If NewCust and not CustLink  ;New customer, allow user to edit record and
  29.       Then LockNewCust()        ; display appropriate prompt
  30.            ImageRights
  31.            Prompt "Entering customer information into Cust table.",
  32.                   "Press [F2] to add order information, or [Esc] to cancel."
  33.            Readlib SDir()+"DoW8Demo" NormalizePhone,LeaveFullField,FillPhoneNo
  34.            DelCustLink = True
  35.       Else If not NewCust   ;If customer already exists, don't allow user to
  36.               Then ImageRights ReadOnly ; edit information
  37.            Endif
  38.            Prompt "Viewing existing customer information in Cust table.",
  39.                   "Press [F3] or [F4] to return to Invoice table."
  40.    Endif
  41.    TKHoldCanvas = True
  42.    Readlib SDir()+"DoW8Demo" EditCustRec,CustSpclKey
  43.  
  44. Endproc
  45. Writelib DemoLib SetCustPrompt
  46. Release Procs SetCustPrompt
  47.  
  48. ; ****************************************************************************
  49. ;  NAME: LockNewCust
  50. ; EVENT: N/A
  51. ; TABLE: Cust
  52. ;  FORM: F
  53. ; NOTES: If a user enters a new Customer No., the GetCustNo procedure (see
  54. ;        INVDEMO.SC) moves the user to the Cust table to enter customer data
  55. ;        for the new customer.  The table arrival procedure for the Cust
  56. ;        table, SetCustPrompt, then calls this procedure to check if another
  57. ;        user has entered the same Customer No. BETWEEN the time GetCustNo
  58. ;        determined that the new customer number did not exist and when the
  59. ;        user is actually about to enter customer data.  Without this check,
  60. ;        more than one user on a network could enter the same new customer
  61. ;        number simultaneously, and the second user to post a customer record
  62. ;        would be entering a duplicate key into Cust.
  63. ; ****************************************************************************
  64. Proc LockNewCust()
  65.  
  66.    LockRecord     ;Attempt to post and lock the customer record.  If we can't,
  67.    If not Retval  ; another user must have already done so.
  68.       Then NewCust = False    ;We're now linked to an existing customer record
  69.            CustLink = True    ;A customer record is linked to the current rec.
  70.            Moveto [Invoice->Customer No.] ;Return to Customer No. field of
  71.            ArriveTable()            ; Invoice table, issue relevant message...
  72.            TKMessage = "User "+ErrorUser()+
  73.                      " has just entered a new customer with this Customer No."
  74.    Endif
  75.  
  76. Endproc
  77. Writelib DemoLib LockNewCust
  78. Release Procs LockNewCust
  79.  
  80. ; ****************************************************************************
  81. ;  NAME: EditCustRec
  82. ; EVENT: Depart Record
  83. ; TABLE: Cust
  84. ;  FORM: F
  85. ; NOTES: Because DoWait calls record depart procedures before calling table
  86. ;        depart procedures, we let EditCustRec process attempts to leave the
  87. ;        Cust table.  Note that DoWait only calls table depart procedures
  88. ;        when a user presses [F3] or [F4] (UpImage or DownImage).  Thus if we
  89. ;        didn't trap [F3] and [F4] at the record level, we would need to
  90. ;        designate them as Special keys and handle them in a Special key
  91. ;        procedure.  DoWait calls Special key procedures before calling field,
  92. ;        record, and table level procedures.
  93. ; ****************************************************************************
  94. Proc EditCustRec()
  95.  
  96.    TKAccept = False   ;We're only allowing a few keys to exit the Cust table.
  97.    Switch             ;  Thus we'll reject any keys we don't process specially
  98.       Case NewCust and DelCustLink ;[F2] is only valid for new customer entry
  99.        and (TKChar = TKDo_It! or (TKFieldNum = 10 and TKChar = 13)):
  100.          RefreshCanvas()
  101.          CtrlHome
  102.          For X From 1 to 7    ;Verify that all fields have data, display a
  103.              If IsBlank([])   ; message for fields which are empty
  104.                 Then TKMessage = "Please enter the customer's "
  105.                                + Lower(Field())
  106.                      If ColNo() = 6 or ColNo() = 7
  107.                         Then TKMessage = TKMessage + " of residence"
  108.                      Endif
  109.                      NewField() ;Moved explicitly to a new field, alert DoWait
  110.                      Return
  111.              Endif
  112.              Right
  113.           Endfor
  114.           If IsBlank([])
  115.              Then TKMessage = "Please enter a standard discount rate for this customer"
  116.                   NewField()
  117.                   Return
  118.           Endif
  119.           UnlockRecord
  120.           CustLink = True   ;All fields are filled, we have valid cust data
  121.           DelCustLink = False ;Don't allow user to delete linked customer now
  122.           Moveto [Invoice->Discount %];Copy the default discount rate into the
  123.           [] = [Cust->Discount %]     ; discount rate for the current invoice
  124.           If [Cust->State] = "CA"     ;If the customer is not a CA resident,
  125.              Then [Tax %] = TaxRate   ; doesn't need to pay sales tax
  126.              Else [Tax %] = 0
  127.           Endif
  128.           CalcTotals()
  129.           Enter                       ;Move to [Method of Payment] field
  130.           ArriveTable()      ;Inform DoWait we've just entered a new table
  131.          ; NOTE: ArriveTable calls NewField, thus we don't need to call
  132.          ;       ArriveField or NewField.  However, had we assigned an arrival
  133.          ;       procedure to the [Method of Payment] field we would have
  134.          ;       needed to call either ArriveField or our arrival procedure
  135.          ;       to invoke it.
  136.       Case CustLink and TKChar = TKDownImage or TKChar = TKUpImage:
  137.          If not DelCustLink
  138.             Then TKAccept = True  ;Accept the attempt to move to Invoice table
  139.          Endif
  140.          ; If NewCust is False, we're viewing an existing customer record.  In
  141.          ;  view-only mode, [F3] and [F4] are enabled.
  142.       Case TKChar = TKUndo :
  143.          UpdtAftrUndo()
  144.       Otherwise :  ;Reject with emphasis!
  145.          Beep
  146.    Endswitch
  147.  
  148. Endproc
  149. Writelib DemoLib EditCustRec
  150. Release Procs EditCustRec
  151.  
  152. ; ****************************************************************************
  153. ;  NAME: LeaveFullField()
  154. ; EVENT: Keystroke
  155. ; TABLE: Cust
  156. ;  FORM: F
  157. ; NOTES: LeaveFullField determines whether the pending key (in TKChar) will
  158. ;        complete the State or Zip Code fields.  This kind of procedure
  159. ;        generally works well for alphanumeric fields in which we expect a
  160. ;        user to enter fixed-length data.  See the LeaveFullDate procedure in
  161. ;        INVDEMO.SC for a procedure that works for date fields.  See also the
  162. ;        FillPhoneNo procedure below for a more complex example of a keystroke
  163. ;        procedure.  Note that because DoWait calls keystroke procedures when
  164. ;        a user presses "regular" keys, we can be sure that we'll only
  165. ;        keypress visible characters, not movement or control characters.
  166. ; ****************************************************************************
  167. Proc LeaveFullField()
  168.  
  169.    If NewCust
  170.       Then Switch
  171.               Case TKFieldNum = 7 : ;[State] field is complete when it
  172.                  MaxLen = 2         ; contains two characters
  173.               Case TKFieldNum = 8 : ;[Zip Code] field requires 5 characters
  174.                  MaxLen = 5
  175.            Endswitch
  176.            Keypress TKChar          ;Type the character
  177.            If Len(FieldStr()) = MaxLen and IsValid()
  178.               Then TKChar = TKEnter  ;Field is full, move to next field
  179.               Else TKAccept = False  ;We've already keypressed the key, we
  180.            Endif                     ; don't want DoWait to press it again
  181.    Endif
  182.  
  183. Endproc
  184. Writelib DemoLib LeaveFullField
  185. Release Procs LeaveFullField
  186.  
  187. ; ****************************************************************************
  188. ;  NAME: FillPhoneNo
  189. ; EVENT: Keystroke
  190. ; FIELD: Telephone
  191. ; TABLE: Cust
  192. ;  FORM: F
  193. ; NOTES: FillPhoneNo serves two purposes.  First, it enhances the PICTURE
  194. ;        validity check by allowing after-the-fact reformatting of data in the
  195. ;        field.  Second, it automatically moves the user out of the field if
  196. ;        the phone number completes a valid pattern.
  197. ; ****************************************************************************
  198. Proc FillPhoneNo()
  199.  
  200.    Switch
  201.       Case not NewCust : ;Disable field formatting if user is in view mode
  202.       Case TKChar < 48 or TKChar > 57 :  ;Make sure the pending key is a digit
  203.       Case Len([]) = 8 and                       ;If there is a digit pending
  204.            Substr([],1,1) <> "(" and             ; and the partial data looks
  205.            Substr([],8,1) <> "-" :               ; like ###-####, then we want
  206.          [] = Substr([],1,7)+"-"+Substr([],8,1)  ; to change it to ###-###-#
  207.       Case Len([]) = 12 or Len([]) = 11 and
  208.            Substr([],4,1) = "-" :       ;Field complete?
  209.          Keypress TKChar   ;Accept the character which will complete the field
  210.          TKChar = TKEnter  ;Instruct DoWait to press the [Enter] character,
  211.    Endswitch               ; moving the cursor to the next field
  212.   ;In this procedure we could have easily explicitly moved the user to the
  213.   ; [Discount %] field (the next field).  But by allowing DoWait to act upon
  214.   ; the key, we don't need to call ArriveField or NewField.
  215.  
  216. Endproc
  217. Writelib DemoLib FillPhoneNo
  218. Release Procs FillPhoneNo
  219.  
  220. ; ****************************************************************************
  221. ;  NAME: NormalizePhone
  222. ; EVENT: Good Depart (field level)
  223. ; FIELD: Telephone
  224. ; TABLE: Cust
  225. ;  FORM: F
  226. ; NOTES: A user can enter telephone numbers in any one of three formats;
  227. ;        (###)###-####, ###-###-####, or ###-####.  NormalizePhone converts
  228. ;        telephone numbers to a standard (###)###-#### format.
  229. ;        NormalizePhone illustrates how using a Paradox's validity checks can
  230. ;        simplify your custom procedures.  For example, at first glance, the
  231. ;        checks NormalizePhone performs may seem inadequate.  The fact that a
  232. ;        number is 8 characters long does not guarantee that it is in the form
  233. ;        ###-####.  (It could be (###)###.)  However, we have defined this
  234. ;        "picture" for the [Telephone] field: (###)###-####,###-###{#,-####}.
  235. ;        Since DoWait calls NormalizePhone only if the user leaves valid data
  236. ;        in the field (NormalizePhone is a Good Depart procedure), the field
  237. ;        must look like ###-#### if it only contains 8 characters.
  238. ; ****************************************************************************
  239. Proc NormalizePhone()
  240.  
  241.    Switch
  242.       Case Len([]) = 12 :                              ;###-###-####
  243.          [] = "("+Substr([],1,3)+")"+Substr([],5,8)  ;Reformat the area code
  244.       Case Len([]) = 8 :                               ;###-####
  245.          [] = AreaCode+[]   ;AreaCode is defined to be "(###)"
  246.    Endswitch
  247.  
  248. Endproc
  249. Writelib DemoLib NormalizePhone
  250. Release Procs NormalizePhone
  251.  
  252. ; ****************************************************************************
  253. ;  NAME: CustSpclKey
  254. ; EVENT: Special key
  255. ; TABLE: Cust
  256. ; NOTES: CustSpclKey handles special keys a user presses while within the
  257. ;        Cust table.
  258. ; ****************************************************************************
  259. Proc CustSpclKey()
  260.  
  261.    Switch
  262.       Case TKChar = -46:      ;[Alt][C], commentary key--
  263.          ToggleCommentary()   ; Need to toggle the commentary state
  264.       Case DelCustLink and TKChar = TKEsc :  ;User wants to cancel new cust
  265.          Del           ;Delete the customer record
  266.          Moveto [Invoice->Customer No.]
  267.          ReSyncKey      ;Update Cust table link
  268.          [Discount %] = BlankNum()  ;Reset discount and tax rates
  269.          [Tax %] = BlankNum()
  270.          CustLink = False     ;We no longer have a linked customer record
  271.          DelCustLink = False
  272.          ArriveTable()    ;See note above
  273.    Endswitch
  274. Endproc
  275. Writelib DemoLib CustSpclKey
  276. Release Procs CustSpclKey
  277.