home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / C7101.ZIP / FORM.TPX < prev    next >
Text File  |  1994-02-01  |  22KB  |  464 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                                Form.TPX                │Version: 3007.101│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│                      PROCEDURE  Update a browse or lookup with a form    │
  7. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  8. #!│Version   Comments                                                        │
  9. #!│────────  ────────────────────────────────────────────────────────────────│
  10. #!│3007.000  Release of CDD3 version 3007 templates                          │
  11. #!│3007.100  Repaired Form Procedure                                         │
  12. #!│3007.101  Added #PROMPT to Form Procedure                                 │
  13. #!└──────────────────────────────────────────────────────────────────────────┘
  14. #!
  15. #PROCEDURE(Form,'Update a browse or lookup with a form'),SCREEN,PULLDOWN
  16. #!
  17. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  18. #!│                                  Form                  │Version: 3007.101│
  19. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  20. #!│The Form Template generates a file update procedure.  A procedure         │
  21. #!│generated with this template assumes that:                                │
  22. #!│ 1.  Keycode will be Enter, Insert or Delete upon procedure initialization│
  23. #!│ 2.  If Keycode is Enter or Delete, the record buffer contains a valid    │
  24. #!│     record, and that record reflects the current active record of Primary│
  25. #!│ 3.  If Keycode is Insert, the record buffer contains a cleared record,   │
  26. #!│     with any necessary key fields primed.                                │
  27. #!│Upon completion of Editing or deleting a record, the Form procedure will  │
  28. #!│process any files referenced to Primary in a 1:Many constrained           │
  29. #!│relationship.                                                             │
  30. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  31. #!│Version   Comments                                                        │
  32. #!│────────  ────────────────────────────────────────────────────────────────│
  33. #!│3007.000  Release of CDD3 version 3007 templates                          │
  34. #!│3007.100  Repaired CANCEL code (on single entry forms, called as deletes, │
  35. #!│          the CANCEL field code should not perform a GET(file,0).  This   │
  36. #!│          repair fixes a problem with cancelled deletes affecting totals  │
  37. #!│          on the calling browse procedure.                                │
  38. #!│3007.101  Added "Disable RI Logout" Prompt.  This prompt is added to allow│
  39. #!│          the disabling of the LOGOUT function during RI Updates and      │
  40. #!│          Deletes.  This is necessary if RI Code is generated to handle   │
  41. #!│          multiple relations between files.                               │
  42. #!└──────────────────────────────────────────────────────────────────────────┘
  43. #!
  44. #PROTOTYPE('')
  45. #PROMPT('Insert message',@S30),%InsertMsg
  46. #PROMPT('Chan&ge message',@S30),%ChangeMsg
  47. #PROMPT('De&lete message',@S30),%DeleteMsg
  48. #PROMPT('Action after ADD',OPTION),%AddAction
  49. #PROMPT('Return to caller ',RADIO)
  50. #PROMPT('Retain Record    ',RADIO)
  51. #PROMPT('Clear Record     ',RADIO)
  52. #PROMPT('Copy field hot&key:',KEYCODE),%CopyKey
  53. #PROMPT('Next &Procedure ',PROCEDURE),%NextProcedure
  54. #PROMPT('Disable RI Logout',CHECK),%NoLogoutSupport
  55. #INSERT(%StandardHeader)
  56. #INSERT(%InitFormSymbols)
  57. #INSERT(%PrimaryDriverCheck)
  58. #IF(%Primary = %NULL)
  59.   #SET(%ErrorMessage,(' WARNING during Code Generation in Procedure: '& %Procedure ))
  60.   #ERROR(%ErrorMessage)
  61.   #SET(%ErrorMessage,( ' No File Defined In File Schematic For FORM Template '))
  62.   #ERROR(%ErrorMessage)
  63. #ENDIF
  64. %Procedure      PROCEDURE
  65.  
  66. %LocalData
  67.  
  68. NoMoreFields       BYTE(0)                       !No more fields flag
  69. NonStopSelect      BYTE(0)
  70. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  71.   #IF(%CopyKey)
  72. SCREEN    %ScreenAttributes,ALRT(%CopyKey)
  73. %ScreenPaintDeclarations
  74. %ScreenStringDeclarations
  75. %ScreenFieldDeclarations
  76.           .
  77.     #IF(%SharedFiles = %NULL)
  78.       #IF(%PrimaryDriver <> 'Btrieve')
  79. SAV:SaveRecord LIKE(%FilePre:Record),PRE(SAV)
  80.       #ENDIF
  81.     #ENDIF
  82.   #ELSE
  83. %ScreenStructure
  84.     #IF(%SharedFiles = %NULL)
  85.       #IF(%PrimaryDriver <> 'Btrieve')
  86. SAV:SaveRecord LIKE(%FilePre:Record),PRE(SAV)
  87.       #ENDIF
  88.     #ENDIF
  89.   #ENDIF
  90. #ELSE
  91. %ScreenStructure
  92. #ENDIF
  93. %PullDownStructure
  94. #IF(%SharedFiles OR %PrimaryDriver = 'Btrieve')
  95. RecordQueue   QUEUE,PRE(SAV)                     !Queue for concurrency checking
  96. SaveRecord    LIKE(%FilePre:Record),PRE(SAV)     #<!size of primary file record
  97. #FOR(%FileMemo)
  98. #FIX(%Field,%FileMemo)
  99. SAV:%FieldID STRING(SIZE(%FileMemo))
  100. #ENDFOR
  101.               .                                  #<!End Queue structure
  102. #ENDIF
  103. #INSERT(%FileControl)                            #!Declare Flags for file access
  104. AbortTransaction byte
  105. #IF(%RelatedChildList)
  106.   #SET(%ProcessingFile,%Primary)
  107. #INSERT(%RelationalAccessFlds)                   #<!Declare link fields
  108. RI:RestrictUpdate byte
  109. RI:RestrictDelete byte
  110.   #IF(%PrimaryDriver = 'Paradox3')
  111.     #FIX(%File,%Primary)
  112. UpdRelation   STRING(SIZE(%FilePre:Record))      #<!Position of last related record
  113.   #ELSE
  114. UpdRelation   STRING(10)                         #<!Position of last related record
  115.   #ENDIF
  116.   #IF(%PrimaryDriver='Btrieve')
  117. SAV:Position  string(255)
  118.   #ENDIF
  119. #ENDIF
  120. #IF(%PrimaryDriver = 'Paradox3')
  121.   #FIX(%File,%Primary)
  122. SavePointer   STRING(SIZE(%FilePre:Record))      !Position of current record
  123. AutoAddPtr    STRING(SIZE(%FilePre:Record))      !Position of Autoinc record
  124. #ELSE
  125. SavePointer   STRING(10)                         !Position of current record
  126. AutoAddPtr    STRING(10)                         !Position of Autoinc record
  127. #ENDIF
  128. AutoIncAdd    BYTE(0)                            !On for Autoincrement add
  129. #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  130. LastPosition  STRING(10)                         !Position of last ADD
  131. #ENDIF
  132. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  133.   #IF(%CopyKey)
  134. #INSERT(%FieldDups)
  135.   #ENDIF
  136. #ENDIF
  137. #IF(%PrimeKeysExist)
  138. #INSERT(%SavePrimedFields)
  139. #ENDIF
  140. #EMBED('Data Section')
  141.  
  142.   CODE
  143.  
  144.   #EMBED('Setup Procedure')
  145.   #INSERT(%FileControl)                          #!Open files
  146.   #INSERT(%SavePrimaryLinks)
  147.   NonStopSelect = FALSE
  148.   CASE KEYCODE()                                 !What Key was pressed?
  149.   OF InsKey                                      !Insert a new record
  150.     Action = AddRecord                           !Set action code 1 (ADD)
  151.     #INSERT(%InsertMessage)                      #<!Message for ADD RECORD
  152.   #IF(%AutoInc)
  153.     DO AutoNumber                                !Set autonumber key field(s)
  154.   #ENDIF
  155.     #EMBED('On Add After Record Buffer Is Cleared')
  156.   #IF(%InitRoutine)                              #<!Field(s) initial value
  157.     DO InitializeFields                          !Initial values from dictionary
  158.   #ENDIF
  159.   OF EnterKey                                    !Process a CHANGE request
  160.   OROF MouseLeft2                                !on EnterKey or double mouse
  161.     Action = ChangeRecord                        !Set action code 2 (CHANGE)
  162.     #INSERT(%ChangeMessage)                      #<!Message for CHANGE RECORD
  163.   #IF(%SharedFiles)
  164.     #INSERT(%SetupConcurrency)                   #<!Setup multi-user Concurrency
  165.   #ENDIF
  166.   OF DelKey                                      !Process a DELETE request
  167.     Action = DeleteRecord                        !Set action code 3 (DELETE)
  168.     #INSERT(%DeleteMessage)                      #<!Message for DELETE RECORD
  169.     SavePointer = POSITION(%Primary)             #<!Position in PRIMARY file
  170.   END                                            !End CASE Keycode
  171.   #FOR(%Formula)
  172.     #IF(UPPER(%FormulaClass) = 'SETUP')
  173.   #INSERT(%GenerateFormula)
  174.     #ENDIF
  175.   #ENDFOR
  176.   #IF(%SecondaryExist)                           #<!IF schema has a Secondary
  177.   DO SecondaryLookups                            !Read any lookup fields
  178.   #ENDIF
  179.   #IF(%PullDownStructure)
  180.   OPEN(%PullDown)
  181.   #ENDIF
  182.   OPEN(%Screen)                                  !Open the FORM screen
  183.   IF Action = DeleteRecord                       !IF request for DELETE
  184.     DISABLE(1,FIELDS())                          !Disable all screen fields
  185.     ENABLE(?OK)                                  !Enable the OK and the
  186.     ENABLE(?Cancel)                              !Cancel buttons
  187.   END                                            !End IF request for delete
  188.   #EMBED('Setup Screen')
  189.   #SET(%ProcessingFile,%Primary)
  190.   DISPLAY                                        !Display screen fields
  191.   LOOP                                           !Begin Main process loop
  192.     #EMBED('Beginning of Accept Loop')
  193.     #IF(%SecondaryExist)                         #<!IF File schema has Secondary
  194.     #INSERT(%SecondaryChanged)
  195.     #ENDIF
  196.     #IF(%LoopFormulasExist = 'Y')             #<!Are there Formula fields?
  197.       #SET(%GenerateFormulasOn,'Y')
  198.     DO FormulaFields                             !Calculate Formula fields
  199.     #ENDIF
  200.     CASE SELECTED()                              !Process selected Field
  201.     #INSERT(%ScreenSetupRoutines)
  202.     OF NoMoreFields                              !User pressed Enter or OK
  203.       #EMBED('Before File I/O')
  204.       CASE Action                                !Process requested Action
  205.       OF AddRecord                               !Action = 1 (ADD)
  206.         ADD(%Primary)                            #<!Add Record to Primary file
  207.       OF ChangeRecord                            !Action = 2 (Change)
  208.         #IF(%SharedFiles)                        #!If making a network app
  209.           #IF(%AutoInc)
  210.         IF AutoIncAdd                            #<!Was this an Autonumber?
  211.             #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  212.           LastPosition = POSITION(%Primary)      #<!Save last record position
  213.             #ENDIF
  214.           PUT(%Primary)                          #<!Write the Record
  215.         ELSE                                     #<!not AutoincAdd
  216.           #ENDIF
  217.           DO ConcurrentWrite                     !Concurrent update ROUTINE
  218.           IF AbortTransaction                    !AbortWrite is on
  219.             SELECT(?Cancel)
  220.             CYCLE                                !Let user choose response
  221.           END                                    !End AbortWrite#
  222.         #ELSE
  223.           #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  224.           LastPosition = POSITION(%Primary)      #<!Save last record position
  225.           #ENDIF
  226.         #ENDIF
  227.         #IF(%UpdateChildList)
  228.           DO ConstrainedUpdate                   #<!Write the Record
  229.           IF AbortTransaction
  230.             SELECT(?Cancel)
  231.             CYCLE
  232.           END
  233.         #ELSE
  234.           PUT(%Primary)
  235.         #ENDIF
  236.         #IF((%SharedFiles AND %AutoInc))
  237.         END                                      #<!IF AutoIncAdd
  238.         #ENDIF
  239.       OF DeleteRecord                            !Action = 3 (Delete)
  240.         #IF(%SharedFiles)
  241.         DO ConcurrentDelete
  242.         IF AbortTransaction
  243.           SELECT(?Cancel)
  244.           CYCLE
  245.         END
  246.         #ENDIF
  247.         #IF(%DeleteChildList)
  248.         DO ConstrainedDelete                     #<!Write the Record
  249.         IF AbortTransaction
  250.           SELECT(?Cancel)
  251.           CYCLE
  252.         END
  253.         #ELSE
  254.         DELETE(%Primary)
  255.         #ENDIF
  256.       ELSE
  257.         DO ProcedureReturn
  258.       END                                        !End CASE Action
  259.       IF ERRORCODE()                             !Error check on File I/O
  260.         #IF(%DupKeyCheck)
  261.         #INSERT(%DupKeyCode)
  262.         #ENDIF
  263.         CASE Action                              !Error message based on Action
  264.           OF AddRecord
  265.             GLO:Message1 = 'Error attempting to ADD Record'
  266.           OF ChangeRecord
  267.             GLO:Message1 = 'Error attempting to CHANGE Record'
  268.           OF DeleteRecord
  269.             GLO:Message1 = 'Error attempting to DELETE Record'
  270.         END                                      !End CASE Action
  271.         GLO:Message2 = 'The file: %Primary could not be updated'
  272.         GLO:Message3 = 'Code:'&Errorcode()&': '&Error()
  273.         ShowWarning                              !Notify the user
  274.         #IF(%SharedFiles)
  275.         RELEASE(%Primary)                        #<!Release the held record
  276.         FREE(RecordQueue)                        !FREE the memory Queue
  277.         #ENDIF
  278.         DISABLE(1,FIELDS())                      !Disable all the fields
  279.         ENABLE(?Cancel)                          !Enable Cancel button
  280.         SELECT(?Cancel)                          !and place cursor on Cancel
  281.         DISPLAY                                  !Re-display the screen
  282.         CYCLE                                    !Re-start main LOOP
  283.       ELSE                                       !Else no errorcode()
  284.         #IF(%SharedFiles)
  285.         FREE(RecordQueue)                        !Free memory from Queue
  286.         #ENDIF
  287.         #IF(%NextProcedure)
  288.         #EMBED('Setup Next Procedure')
  289.         %NextProcedure                           #<!Call the Next Procedure
  290.         #EMBED('Return from Next Procedure')
  291.         #ENDIF
  292.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  293.         IF Action = AddRecord                    #<!If Action is AddRecord
  294.           LastPosition = POSITION(%Primary)      #<!Save position of last ADD
  295.         END                                      #<!End IF Action = AddRecord
  296.         #ENDIF
  297.         #IF(UPPER(CLIP(%AddAction)) = 'CLEAR RECORD')
  298.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  299.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  300.           #FIX(%File,%Primary)
  301.           #INSERT(%ClearValues)
  302.           DISPLAY                                !Update screen display
  303.           #IF(%AutoInc)
  304.           DO AutoNumber                          !Increment autonumber key
  305.           #IF(%InitRoutine)
  306.           DO InitializeFields                    !Initial value from DataDictionary
  307.           #ENDIF
  308.           DISPLAY                                !Display screen field
  309.           #ENDIF
  310.           SELECT(1)                              !Place cursor on 1st field
  311.           #EMBED('After ADD on Retain and Clear record')
  312.           CYCLE                                  !Re-start main LOOP
  313.         END                                      !End IF (Action = ....)
  314.         #ELSIF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  315.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  316.          #IF(%CopyKey <> %NULL)
  317.           DO SaveScrFlds                         #<!Save the Screen fields
  318.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  319.           DISPLAY                                !Update screen display
  320.           #FIX(%File,%Primary)
  321.           CLEAR(%FilePre:Record)                 #<!Clear the record buffer
  322.          #ELSE
  323.           #IF(%AutoInc)
  324.           SAV:SaveRecord = %FilePre:Record       #<!Save the record buffer
  325.           #ENDIF
  326.          #ENDIF
  327.           DISPLAY
  328.           #IF(%AutoInc)
  329.           DO AutoNumber                          !Increment autonumber key
  330.           %FilePre:Record = SAV:SaveRecord       #<!Restore saved record
  331.           #INSERT(%RestoreAuto)                  #<!Restore AutoNumber(s)
  332.           DISPLAY                                !Display screen fields
  333.           #ENDIF
  334.           SELECT(1)                              !Place cursor on 1st field
  335.           #EMBED('After ADD on Retain and Clear record')
  336.           CYCLE                                  !Re-start main LOOP
  337.         END                                      !End IF (Action = ....)
  338.         #ENDIF                                   #!End %AddAction code
  339.         BREAK                                    !Break from main Loop
  340.       END                                        !End IF Errorcode()
  341.     END                                          !End CASE Selected()
  342.     ACCEPT                                       !Enable screen entry
  343.     IF NonStopSelect
  344.       IF KEYCODE()
  345.         NonStopSelect = FALSE
  346.       END
  347.     END
  348.     #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  349.      #IF(%CopyKey)
  350.     #INSERT(%DupFldCall)
  351.      #ENDIF
  352.     #ENDIF
  353.     CASE KEYCODE()
  354.       OF EscKey                                  !User pressed Escape key
  355.         IF FIELD() <> ?Cancel                    !If user pressed Escape
  356.           SELECT(?Cancel)                        !Select Cancel button
  357.           PRESS(EnterKey)                        !Process Cancel button code
  358.           CYCLE                                  !Cycle to Accept
  359.         END                                      !Field was not Cancel button
  360.     #IF(%HotKeysExist)
  361.     #FOR(%HotKey)
  362.       OF %HotKey                                 !User defined HotKey
  363.         %HotKeyProc                              !HotKey Procedure
  364.     #ENDFOR
  365.     #ENDIF
  366.     END                                          !End CASE Keycode
  367.     CASE FIELD()                                 !Process fields
  368.    #FOR(%ScreenField)
  369.     #IF(%ScreenFieldUse = '?Ok')
  370.      OF ?Ok                                      !On the OK button
  371.           #IF(%ScreenFieldEdit <> %NULL)
  372.         %ScreenFieldEdit                         #<!Field Edit procedure
  373.           #ENDIF
  374.         SELECT(1)                                !Start with the first field
  375.         SELECT                                   !and cycle non-stop
  376.         NonStopSelect = TRUE                     !Set Up for Non-Stop Select
  377.         SETKEYCODE(0)                            !Clear the KeyCode
  378.         CYCLE                                    !restart main process loop
  379.     #ELSIF(%ScreenFieldUse = '?Cancel')
  380.      OF ?Cancel                                  !On Cancel button
  381.       #IF(%AutoInc = 'Y')
  382.         IF AutoIncAdd                            !ADDed autoincrement record?
  383.           RESET(%Primary,AutoAddPtr)             #<!Re-position record pointer
  384.           NEXT(%Primary)                         #<!Re-read the record we added
  385.           IF DiskError('Could not READ Record')  !Check for file I/O error
  386.             DO ProcedureReturn
  387.           END                                    !End IF Diskerror
  388.           DELETE(%Primary)                       #<!DELETE the record
  389.           IF DiskError('Record could not be Deleted')
  390.             DO ProcedureReturn
  391.           END                                    !End IF Diskerror
  392.         END                                      !End IF AutoIncAdd
  393.       #ENDIF
  394.           #IF(%ScreenFieldEdit <> %NULL)
  395.         %ScreenFieldEdit                         #<!Field edit procedure
  396.           #ENDIF
  397.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  398.         IF LastPosition                          #<!IF a record was added
  399.           RESET(%Primary,LastPosition)           #<!Position to the record
  400.           NEXT(%Primary)                         #<!and read it
  401.         ELSE                                     #<!Else no LastPosition
  402.           GET(%Primary,0)                        #<!signal Browse to re-read
  403.         END                                      #<!END If LastPosition
  404.         #ELSE
  405.         IF Action <> DeleteRecord                #<! IF not called to delete
  406.           GET(%Primary,0)                        #<! signal Browse to re-read
  407.         END                                      #<! END (IF not called...)
  408.         #ENDIF
  409.         DO ProcedureReturn
  410.     #ELSE
  411.     #INSERT(%ScreenEditRoutines)
  412.     #ENDIF
  413.    #ENDFOR
  414.    #FOR(%PulldownField)                         #! add all procedure or
  415.     #IF(%PulldownFieldType = 'PROCEDURE')       #! source code calls
  416.      OF %PulldownField                         #<!For a Pulldown field
  417.        %PulldownFieldProc                      #<!  execute its procedure
  418.     #ENDIF
  419.    #ENDFOR
  420.     END                                          !End CASE FIELD
  421.   END                                            !END MAIN PROCESS LOOP
  422.   #FOR(%Formula)
  423.     #IF(UPPER(%FormulaClass) = 'RETURN')
  424.   #INSERT(%GenerateFormula)                      #<!Return Class formula
  425.     #ENDIF
  426.   #ENDFOR
  427.   DO ProcedureReturn
  428. !─────────────────────────────────────────────────────────────────────────────
  429. ProcedureReturn ROUTINE
  430.   #IF(%PullDownStructure)
  431.   CLOSE(%PullDown)
  432.   #ENDIF
  433.   #IF(%SharedFiles)
  434.   FREE(RecordQueue)
  435.   #ENDIF
  436.   #EMBED('Before Closing Screen')
  437.   CLOSE(%Screen)
  438.   #EMBED('Before Closing Files')
  439.   #INSERT(%FileControl)                          #!Open files
  440.   DO EndOfProcedureEmbed
  441.   RETURN
  442. !─────────────────────────────────────────────────────────────────────────────
  443. EndOfProcedureEmbed ROUTINE
  444. #EMBED('End of Procedure')
  445. #EMBED('Custom Routines')
  446. #INSERT(%AutoIncCode)
  447. #INSERT(%ConcurrentWrite)
  448. #INSERT(%ConcurrentDelete)
  449. #INSERT(%RIUpdates)
  450. #INSERT(%RIDeletes)
  451. #INSERT(%InitQue)
  452. #INSERT(%InitFields)
  453. #INSERT(%GenFormulas)
  454. #IF(%SecondaryExist)
  455. #INSERT(%SecondaryLookups)
  456. #ENDIF
  457. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  458.  #IF(%CopyKey)
  459. #INSERT(%SaveScrFlds)
  460. #INSERT(%DupField)
  461.  #ENDIF
  462. #ENDIF
  463. #CHAIN('MultiPg.tpx')
  464.