home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / CLATPL.ZIP / CLARION4.TPX < prev    next >
Text File  |  1993-07-26  |  52KB  |  1,205 lines

  1. #!-------------------------------------------------------------------------------#!
  2. #!      CLARION4.TPX
  3. #!
  4. #!    Form                 : Update a browse or lookup with a form
  5. #!    MultiPage Template   : Update a file with a multiple page entry form
  6. #!    PageOf Template      : data entry 'Page' used with the MultiPage Form
  7. #!
  8. #!------------------------------------------------------------------------------
  9. #!
  10. #PROCEDURE(Form,'Update a browse or lookup with a form'),SCREEN,PULLDOWN
  11. #!------------------------------------------------------------------------------
  12. #!
  13. #!                           The Form Template
  14. #!
  15. #!------------------------------------------------------------------------------
  16. #PROTOTYPE('')
  17. #PROMPT('Insert message',@S20),%InsertMsg
  18. #PROMPT('Chan&ge message',@S20),%ChangeMsg
  19. #PROMPT('De&lete message',@S20),%DeleteMsg
  20. #PROMPT('Action after ADD',OPTION),%AddAction
  21. #PROMPT('Return to caller ',RADIO)
  22. #PROMPT('Retain Record    ',RADIO)
  23. #PROMPT('Clear Record     ',RADIO)
  24. #PROMPT('Copy field hot&key:',KEYCODE),%CopyKey
  25. #PROMPT('Next Procedure ',PROCEDURE),%NextProcedure
  26. #INSERT(%StandardHeader)
  27. #INSERT(%InitFormSymbols)
  28. %Procedure      PROCEDURE
  29.  
  30. %LocalData
  31.  
  32. #INSERT(%CloseFilesFlags)                        #!Primary or Secondary Opened
  33. #SET(%SetFile,%Primary)
  34. #INSERT(%CloseRelatedFlags)                      #!Related file Opened
  35.  
  36. NoMoreFields     BYTE(0)                         !No more fields flag
  37. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  38.  #IF(%CopyKey)
  39. SCREEN    %ScreenAttributes,ALRT(%CopyKey)
  40. %ScreenPaintDeclarations
  41. %ScreenStringDeclarations
  42. %ScreenFieldDeclarations
  43.           .
  44.   #IF(%SharedFiles = %NULL)
  45. SAV:SaveRecord LIKE(%FilePre:Record),PRE(SAV)
  46.   #ENDIF
  47.  #ELSE
  48. %ScreenStructure
  49.   #IF(%SharedFiles = %NULL)
  50. SAV:SaveRecord LIKE(%FilePre:Record),PRE(SAV)
  51.   #ENDIF
  52.  #ENDIF
  53. #ELSE
  54. %ScreenStructure
  55. #ENDIF
  56. %PullDownStructure
  57. #IF(%SharedFiles)
  58. RecordQueue   QUEUE,PRE(SAV)                     !Queue for concurrency checking
  59. SaveRecord    LIKE(%FilePre:Record),PRE(SAV)     #<!size of primary file record
  60. #FOR(%Field)
  61. #IF(%FieldType = 'MEMO')
  62. SAV:%FieldID   STRING(SIZE(%Field))
  63. #ENDIF
  64. #ENDFOR
  65.               .                                  #<!End Queue structure
  66. #ENDIF
  67. #IF(%RelatedFiles)
  68. #SET(%SetFile,%Primary)
  69. #INSERT(%RelationalAccessFlds)                   #<!Declare link fields
  70.  #IF(%PrimaryDriver = 'Paradox')
  71. #FIX(%File,%Primary)
  72. UpdRelation   STRING(SIZE(%FilePre:Record))      #<!Position of last related record
  73.  #ELSE
  74. UpdRelation   STRING(10)                         #<!Position of last related record
  75.  #ENDIF
  76. #ENDIF
  77. #IF(%PrimaryDriver = 'Paradox')
  78. #FIX(%File,%Primary)
  79. SavePointer   STRING(SIZE(%FilePre:Record))      !Position of current record
  80. AutoAddPtr    STRING(SIZE(%FilePre:Record))      !Position of Autoinc record
  81. #ELSE
  82. SavePointer   STRING(10)                         !Position of current record
  83. AutoAddPtr    STRING(10)                         !Position of Autoinc record
  84. #ENDIF
  85. AutoIncAdd    BYTE(0)                            !On for Autoincrement add
  86. #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  87. LastPosition  STRING(10)                         !Position of last ADD
  88. #ENDIF
  89. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  90.  #IF(%CopyKey)
  91. #INSERT(%FieldDups)
  92.  #ENDIF
  93. #ENDIF
  94. #IF(%PrimeKeysExist)
  95. #INSERT(%SavePrimedFields)
  96. #ENDIF
  97. #EMBED('Data Section')
  98.  
  99.   CODE
  100.  
  101.   #EMBED('Setup Procedure')
  102.   #INSERT(%OpenPrimary)                          #<!Ensure Primary file is OPEN
  103.   #INSERT(%OpenSecondaryFiles)                   #!Group from Clarion9.tpx
  104.   #INSERT(%FieldLookupOpen)                      #!Check for Must be in File
  105.   CASE KEYCODE()                                 !What Key was pressed?
  106.     OF InsKey                                    !Insert a new record
  107.  
  108.       Action = AddRecord                         !Set action code 1 (ADD)
  109.       #INSERT(%InsertMessage)                    #<!Message for ADD RECORD
  110.       #INSERT(%ClearValues)                      #<!Clear RECORD and MEMO(s)
  111.       #IF(%AutoInc)
  112.       DO AutoNumber                              !Set autonumber key field(s)
  113.       #ENDIF
  114.       #IF(%InitRoutine)                          #<!Field(s) initial value
  115.       DO InitializeFields                        !Initial values from dictionary
  116.       #ENDIF
  117.  
  118.     OF EnterKey                                  !Process a CHANGE request
  119.     OROF MouseLeft2                              !on EnterKey or double mouse
  120.  
  121.       Action = ChangeRecord                      !Set action code 2 (CHANGE)
  122.       #INSERT(%ChangeMessage)                    #<!Message for CHANGE RECORD
  123.       #IF(%SharedFiles)
  124.       #INSERT(%SetupConcurrency)                 #<!Setup multi-user Concurrency
  125.       #ENDIF
  126.       #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  127.       DO RelationAccessSave                      !Save LINKS for relational update
  128.       #SET(%RelUpdateRoutine,'TRUE')
  129.       #ENDIF
  130.  
  131.     OF DelKey                                    !Process a DELETE request
  132.  
  133.       Action = DeleteRecord                      !Set action code 3 (DELETE)
  134.       #INSERT(%DeleteMessage)                    #<!Message for DELETE RECORD
  135.       SavePointer = POSITION(%Primary)           #<!Position in PRIMARY file
  136.       #IF(%CascadeDelete OR %ClearOnDelete OR %RestrictDelete)
  137.       DO RelationAccessSave                      !Save LINKS for relational update
  138.       #SET(%RelDeleteRoutine,'TRUE')
  139.       #ENDIF
  140.  
  141.   END                                            !End CASE Keycode
  142.  
  143.   #FOR(%Formula)
  144.     #IF(UPPER(%FormulaClass) = 'SETUP')
  145.   #INSERT(%GenerateFormula)
  146.     #ENDIF
  147.   #ENDFOR
  148.   #IF(%SecondaryExist)                           #<!IF schema has a Secondary
  149.   DO SecondaryLookups                            !Read any lookup fields
  150.   #ENDIF
  151.   #IF(%PullDownStructure)
  152.   OPEN(%PullDown)
  153.   #ENDIF
  154.   OPEN(Screen)                                   !Open the FORM screen
  155.   IF Action = DeleteRecord                       !IF request for DELETE
  156.     DISABLE(1,FIELDS())                          !Disable all screen fields
  157.     ENABLE(?OK)                                  !Enable the OK and the
  158.     ENABLE(?Cancel)                              !Cancel buttons
  159.   END                                            !End IF request for delete
  160.   #EMBED('Setup Screen')
  161.   DISPLAY                                        !Display screen fields
  162.  
  163.   LOOP                                           !Begin Main process loop
  164.  
  165.     #IF(%SecondaryExist)                         #<!IF File schema has Secondary
  166.     #INSERT(%SecondaryChanged)
  167.     #ENDIF
  168.     #IF(%LoopFormulasExist = 'TRUE')             #<!Are there Formula fields?
  169.      #SET(%GenerateFormulasOn,'TRUE')
  170.     DO FormulaFields                             !Calculate Formula fields
  171.     #ENDIF
  172.  
  173.     CASE SELECTED()                              !Process selected Field
  174.     #INSERT(%ScreenSetupRoutines)
  175.       OF NoMoreFields                            !User pressed Enter or OK
  176.         CASE Action                              !Process requested Action
  177.           OF AddRecord                           !Action = 1 (ADD)
  178.  
  179.             ADD(%Primary)                        #<!Add Record to Primary file
  180.  
  181.           OF ChangeRecord                        !Action = 2 (Change)
  182.  
  183.           #IF(%RestrictUpdate)
  184.           #SET(%ChkRestrictUpdate,'TRUE')      #!Check for relational RESTRICT
  185.           #ENDIF
  186.           #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  187.           #SET(%RelatedUpdateRoutine,'TRUE')
  188.           #ENDIF
  189.           #IF((%AutoInc AND %SharedFiles) OR (%AutoInc AND %RelatedUpdateRoutine))
  190.             IF AutoIncAdd                        #<!Was this an Autonumber?
  191.             #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  192.               LastPosition = POSITION(%Primary)  #<!Save last record position
  193.             #ENDIF
  194.               PUT(%Primary)                      #<!Write the Record
  195.             ELSE                                 #<!not AutoincAdd
  196.           #ENDIF
  197.           #IF(%SharedFiles)
  198.           #SET(%ConcurrentWriteOn,'TRUE')
  199.               DO ConcurrentWrite                 !Concurrent update ROUTINE
  200.               IF AbortWrite#                     !AbortWrite is on
  201.                 CYCLE                            !Let user choose response
  202.               END                                !End AbortWrite#
  203.           #IF(%RelatedUpdateRoutine = %NULL)
  204.               PUT(%Primary)                      #<!Write the Record
  205.           #ENDIF
  206.           #ENDIF
  207.           #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  208.             DO RelationalUpdate                  !Relational update ROUTINE
  209.             IF AbortTransaction#                 !AbortTransaction# is ON
  210.               SELECT(?Cancel)                    !Place cursor on Cancel
  211.               CYCLE                              !and restart Accept Loop
  212.             END                                  !End AbortTransaction#
  213.           #ENDIF
  214.           #IF((%AutoInc AND %SharedFiles) OR (%AutoInc AND %RelatedUpdateRoutine))
  215.             END                                  #<!IF AutoIncAdd
  216.           #ENDIF
  217.           #IF(%SharedFiles = %NULL)
  218.             #IF(%RelatedUpdateRoutine = %NULL)
  219.               #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  220.             LastPosition = POSITION(%Primary)    #<!Save last record position
  221.               #ENDIF
  222.             PUT(%Primary)                        #<!Write the Record
  223.             #ENDIF
  224.           #ENDIF
  225.  
  226.           OF DeleteRecord                        !Action = 3 (Delete)
  227.  
  228.             #IF(%RestrictDelete)                  #<!IF RESTRICT Constraint
  229.             DO CheckRestrictedDelete             !Check RESTRICT delete
  230.             IF RestrictDelete#                   !If RestrictDelete# is ON
  231.               SELECT(?Cancel)                    !Place cursor on cancel
  232.               CYCLE                              !Restart Loop
  233.             END                                  !End IF RestrictDelete#
  234.             #SET(%ChkRestrictDelete,'TRUE')      #<!RESTRICT delete code
  235.             #ENDIF
  236.             #IF(%CascadeDelete OR %ClearOnDelete)
  237.             #SET(%RelatedDeleteRoutine,'TRUE')
  238.             DO RelationalDelete                  !Relational delete ROUTINE
  239.             IF AbortTransaction#                 !AbortTransaction is on
  240.               CYCLE                              !Let user try again
  241.             END                                  !End AbortTransaction
  242.             #ELSIF(%SharedFiles)
  243.             #SET(%ConcurrentDeleteOn,'TRUE')
  244.             DO ConcurrentDelete                  !Concurrent update ROUTINE
  245.             IF AbortDelete#                      !AbortWrite is on
  246.               CYCLE                              !Restart main Loop
  247.             ELSE                                 !Its OK to Delete
  248.               DELETE(%Primary)                   !Delete this record
  249.             END                                  !End AbortWrite#
  250.             #ELSE
  251.             DELETE(%Primary)                     !Delete this record
  252.             #ENDIF
  253.         END                                      !End CASE Action
  254.  
  255.       IF ERRORCODE()                             !Error check on File I/O
  256.         #IF(%DupKeyCheck)
  257.         #INSERT(%DupKeyCode)
  258.         #ENDIF
  259.         CASE Action                              !Error message based on Action
  260.           OF AddRecord
  261.             GLO:Message1 = 'Error attempting to ADD Record'
  262.           OF ChangeRecord
  263.             GLO:Message1 = 'Error attempting to CHANGE Record'
  264.           OF DeleteRecord
  265.             GLO:Message1 = 'Error attempting to DELETE Record'
  266.         END                                      !End CASE Action
  267.         GLO:Message2 = 'The file: %Primary could not be updated'
  268.         GLO:Message3 = 'Code:'&Errorcode()&': '&Error()
  269.         ShowWarning                              !Notify the user
  270.         #IF(%SharedFiles)
  271.         RELEASE(%Primary)                        #<!Release the held record
  272.         FREE(RecordQueue)                        !FREE the memory Queue
  273.         #ENDIF
  274.         DISABLE(1,FIELDS())                      !Disable all the fields
  275.         ENABLE(?Cancel)                          !Enable Cancel button
  276.         SELECT(?Cancel)                          !and place cursor on Cancel
  277.         DISPLAY                                  !Re-display the screen
  278.         CYCLE                                    !Re-start main LOOP
  279.       ELSE                                       !Else no errorcode()
  280.         #IF(%SharedFiles)
  281.         FREE(RecordQueue)                        !Free memory from Queue
  282.         #ENDIF
  283.         #IF(%NextProcedure)
  284.         #EMBED('Setup Next Procedure')
  285.         %NextProcedure                           #<!Call the Next Procedure
  286.         #EMBED('Return from Next Procedure')
  287.         #ENDIF
  288.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  289.         IF Action = AddRecord                    #<!If Action is AddRecord
  290.           LastPosition = POSITION(%Primary)      #<!Save position of last ADD
  291.         END                                      #<!End IF Action = AddRecord
  292.         #ENDIF
  293.         #IF(UPPER(CLIP(%AddAction)) = 'CLEAR RECORD')
  294.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  295.           ERASE                                  #<!Erase screen fields
  296.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  297.           DISPLAY                                !Update screen display
  298.           #FIX(%File,%Primary)
  299.           CLEAR(%FilePre:Record)                 #<!Clear the record buffer
  300.           #IF(%AutoInc)
  301.           DO AutoNumber                          !Increment autonumber key
  302.           #IF(%InitRoutine)
  303.           DO InitializeFields                    !Initial value from DataDictionary
  304.           #ENDIF
  305.           DISPLAY                                !Display screen field
  306.           #ENDIF
  307.           SELECT(1)                              !Place cursor on 1st field
  308.           CYCLE                                  !Re-start main LOOP
  309.         END                                      !End IF (Action = ....)
  310.         #ELSIF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  311.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  312.          #IF(%CopyKey <> %NULL)
  313.           DO SaveScrFlds                         #<!Save the Screen fields
  314.           ERASE
  315.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  316.           DISPLAY                                !Update screen display
  317.           #FIX(%File,%Primary)
  318.           CLEAR(%FilePre:Record)                 #<!Clear the record buffer
  319.          #ELSE
  320.           #IF(%AutoInc)
  321.           SAV:SaveRecord = %FilePre:Record       #<!Save the record buffer
  322.           #ENDIF
  323.          #ENDIF
  324.           #IF(%AutoInc)
  325.           DO AutoNumber                          !Increment autonumber key
  326.           %FilePre:Record = SAV:SaveRecord       #<!Restore saved record
  327.           #INSERT(%RestoreAuto)                  #<!Restore AutoNumber(s)
  328.           DISPLAY                                !Display screen fields
  329.           #ENDIF
  330.           SELECT(1)                              !Place cursor on 1st field
  331.           CYCLE                                  !Re-start main LOOP
  332.         END                                      !End IF (Action = ....)
  333.         #ENDIF                                   #!End %AddAction code
  334.         BREAK                                    !Break from main Loop
  335.       END                                        !End IF Errorcode()
  336.  
  337.     END                                          !End CASE Selected()
  338.  
  339.     ACCEPT                                       !Enable screen entry
  340.     #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  341.      #IF(%CopyKey)
  342.     #INSERT(%DupFldCall)
  343.      #ENDIF
  344.     #ENDIF
  345.     CASE KEYCODE()
  346.       OF EscKey                                  !User pressed Escape key
  347.         IF FIELD() <> ?Cancel                    !If user pressed Escape
  348.           SELECT(?Cancel)                        !Select Cancel button
  349.           PRESS(EnterKey)                        !Process Cancel button code
  350.           CYCLE                                  !Cycle to Accept
  351.         END                                      !Field was not Cancel button
  352.     #IF(%HotKeysExist)
  353.     #FOR(%HotKey)
  354.       OF %HotKey                                 !User defined HotKey
  355.         %HotKeyProc                              !HotKey Procedure
  356.     #ENDFOR
  357.     #ENDIF
  358.     END                                          !End CASE Keycode
  359.  
  360.  
  361.     CASE FIELD()                                 !Process fields
  362.     #INSERT(%FormEditRoutines)
  363.       OF ?Ok                                     !On the OK button
  364.  
  365.         #EMBED('OK Button Press')
  366.         #FOR(%ScreenField)
  367.           #IF(%ScreenFieldUse = '?Ok')
  368.           #IF(%ScreenFieldEdit <> %NULL)
  369.         %ScreenFieldEdit                         #<!Field Edit procedure
  370.           #ENDIF
  371.           #ENDIF
  372.         #ENDFOR
  373.         SELECT(1)                                !Start with the first field
  374.         SELECT                                   !and cycle non-stop
  375.         CYCLE                                    !restart main process loop
  376.  
  377.       OF ?Cancel                                 !On Cancel button
  378.  
  379.       #IF(%AutoInc = 'TRUE')
  380.         IF AutoIncAdd                            !ADDed autoincrement record?
  381.           RESET(%Primary,AutoAddPtr)             #<!Re-position record pointer
  382.           NEXT(%Primary)                         #<!Re-read the record we added
  383.           IF DiskError('Could not READ Record')  !Check for file I/O error
  384.             #IF(%SharedFiles = 'TRUE')
  385.             FREE(RecordQueue)                    !Free the memory Queue
  386.             #ENDIF
  387.            #IF(%PullDownStructure)
  388.             CLOSE(%PullDown)
  389.            #ENDIF
  390.             #INSERT(%CloseOpenedFiles)
  391.             #SET(%SetFile,%Primary)
  392.             #INSERT(%CloseRelatedFiles)
  393.             RETURN                               !Return to caller
  394.           END                                    !End IF Diskerror
  395.           DELETE(%Primary)                       #<!DELETE the record
  396.           IF DiskError('Record could not be Deleted')
  397.             #IF(%SharedFiles = 'TRUE')
  398.             FREE(RecordQueue)                    !Free the memory Queue
  399.             #ENDIF
  400.             #IF(%PullDownStructure)
  401.             CLOSE(%PullDown)
  402.             #ENDIF
  403.             #INSERT(%CloseOpenedFiles)
  404.             #SET(%SetFile,%Primary)
  405.             #INSERT(%CloseRelatedFiles)
  406.             RETURN                               !Return to caller
  407.           END                                    !End IF Diskerror
  408.         END                                      !End IF AutoIncAdd
  409.       #ENDIF
  410.         #FOR(%ScreenField)
  411.           #IF(%ScreenFieldUse = '?Cancel')
  412.           #IF(%ScreenFieldEdit <> %NULL)
  413.         %ScreenFieldEdit                         #<!Field edit procedure
  414.           #ENDIF
  415.           #ENDIF
  416.         #ENDFOR
  417.         #IF(%SharedFiles = 'TRUE')
  418.         FREE(RecordQueue)                        !Free the memory Queue
  419.         #ENDIF
  420.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  421.         IF LastPosition                          #<!IF a record was added
  422.           RESET(%Primary,LastPosition)           #<!Position to the record
  423.           NEXT(%Primary)                         #<!and read it
  424.         ELSE                                     #<!Else no LastPosition
  425.           GET(%Primary,0)                        #<!signal Browse to re-read
  426.         END                                      #<!END If LastPosition
  427.         #ELSE
  428.         GET(%Primary,0)                          #<!signal Browse to re-read
  429.         #ENDIF
  430.         BREAK                                    !Break from main LOOP
  431.     END                                          !End CASE FIELD
  432.  
  433.   END                                            !END MAIN PROCESS LOOP
  434.  
  435.   #IF(%PullDownStructure)
  436.   CLOSE(%PullDown)
  437.   #ENDIF
  438.   #FOR(%Formula)
  439.     #IF(UPPER(%FormulaClass) = 'RETURN')
  440.   #INSERT(%GenerateFormula)                      #<!Return Class formula
  441.     #ENDIF
  442.   #ENDFOR
  443.  
  444.   #IF(%CloseFiles)
  445.   #INSERT(%CloseOpenedFiles)                     #<!Close files Opened here
  446.   #SET(%SetFile,%Primary)
  447.   #INSERT(%CloseRelatedFiles)                    #<!Close related Opened here
  448.   #ENDIF
  449. #EMBED('End of Procedure ')
  450.  
  451. #INSERT(%AutoIncCode)
  452. #INSERT(%ConcurrentWrite)
  453. #IF(%RelUpdateRoutine OR %RelDeleteRoutine)
  454. #INSERT(%RelUpdSave)
  455. #ENDIF
  456. #INSERT(%RelUpdate)
  457. #IF(%ChkRestrictUpdate)
  458. #INSERT(%RestrictUpdateCheck)
  459. #ENDIF
  460. #INSERT(%RelDelete)
  461. #INSERT(%ConcurrentDelete)
  462. #INSERT(%ClearOnDeleteCode)
  463. #IF(%CascadeUpdate = 'TRUE')
  464. #INSERT(%CheckTransaction)
  465. #ELSIF(%ClearOnUpdate = 'TRUE')
  466. #INSERT(%CheckTransaction)
  467. #ELSIF(%ClearOnDelete = 'TRUE')
  468. #INSERT(%CheckTransaction)
  469. #ELSIF(%CascadeDelete = 'TRUE')
  470. #INSERT(%CheckTransaction)
  471. #ENDIF
  472. #IF(%CascadeDeleteOn)
  473. #INSERT(%CascadeDeleteCode)
  474. #ENDIF
  475. #IF(%ChkRestrictDelete)
  476. #INSERT(%RestrictDeleteCode)
  477. #ENDIF
  478. #INSERT(%InitQue)
  479. #INSERT(%InitFields)
  480. #INSERT(%GenFormulas)
  481. #IF(%SecondaryExist)
  482. #INSERT(%SecondaryLookups)
  483. #ENDIF
  484. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  485.  #IF(%CopyKey)
  486. #INSERT(%SaveScrFlds)
  487. #INSERT(%DupField)
  488.  #ENDIF
  489. #ENDIF
  490. #!***************************************************************************
  491. #!-------------------------------------------------------------------------------#!
  492. #!
  493. #!      Multi-Page Form    Update a browse or lookup with multiple pages
  494. #!
  495. #!------------------------------------------------------------------------------
  496. #!
  497. #PROCEDURE(MultiPage,'Multiple Page update form '),SCREEN,PULLDOWN
  498. #!------------------------------------------------------------------------------
  499. #!      CLARION4.TPX
  500. #!
  501. #!      Multi-Page Template: Update a file with a multiple page entry form
  502. #!
  503. #!------------------------------------------------------------------------------
  504. #PROTOTYPE('')
  505. #PROMPT('Insert message',@S20),%InsertMsg
  506. #PROMPT('Chan&ge message',@S20),%ChangeMsg
  507. #PROMPT('De&lete message',@S20),%DeleteMsg
  508. #PROMPT('2nd Page Procedure ',PROCEDURE),%Page2Proc
  509. #PROMPT('3rd Page Procedure ',PROCEDURE),%Page3Proc
  510. #PROMPT('4th Page Procedure ',PROCEDURE),%Page4Proc
  511. #PROMPT('5th Page Procedure ',PROCEDURE),%Page5Proc
  512. #PROMPT('6th Page Procedure ',PROCEDURE),%Page6Proc
  513. #PROMPT('7th Page Procedure ',PROCEDURE),%Page7Proc
  514. #PROMPT('8th Page Procedure ',PROCEDURE),%Page8Proc
  515. #PROMPT('9th Page Procedure ',PROCEDURE),%Page9Proc
  516. #PROMPT('Next Procedure ',PROCEDURE),%NextProcedure
  517. #INSERT(%StandardHeader)
  518. #INSERT(%InitFormSymbols)
  519. #INSERT(%ProcCounter)
  520.  
  521. %Procedure      PROCEDURE
  522.  
  523. %LocalData
  524. #INSERT(%CloseFilesFlags)                        #!Primary or Secondary Opened
  525. #INSERT(%CloseRelatedFlags)                      #!Related file Opened flag
  526. SaveAction       BYTE
  527. CheckRequired    BYTE(4)
  528. NoMoreFields     BYTE(0)                         !No more fields flag
  529.  
  530. SCREEN    %ScreenAttributes,ALRT(Alt2,Alt%ProcCount)
  531. %ScreenPaintDeclarations
  532. %ScreenStringDeclarations
  533. %ScreenFieldDeclarations
  534.           .
  535. %PullDownStructure
  536. #IF(%SharedFiles)
  537. RecordQueue   QUEUE,PRE(SAV)
  538. SaveRecord    LIKE(%FilePre:Record),PRE(SAV)
  539. #FOR(%Field)
  540. #IF(%FieldType = 'MEMO')
  541. SAV:%FieldID   STRING(SIZE(%Field))
  542. #ENDIF
  543. #ENDFOR
  544.               .                                  #<!End Queue structure
  545. #ENDIF
  546. #IF(%RelatedFiles)
  547. #SET(%SetFile,%Primary)
  548. #INSERT(%RelationalAccessFlds)                   #<!Declare link fields
  549.  #IF(%PrimaryDriver = 'Paradox')
  550. #FIX(%File,%Primary)
  551. UpdRelation   STRING(SIZE(%FilePre:Record))      #<!Position of last related record
  552.  #ELSE
  553. UpdRelation   STRING(10)                         #<!Position of last related record
  554.  #ENDIF
  555. #ENDIF
  556. #IF(%PrimaryDriver = 'Paradox')
  557. #FIX(%File,%Primary)
  558. SavePointer   STRING(SIZE(%FilePre:Record))      !Position of current record
  559. AutoAddPtr    STRING(SIZE(%FilePre:Record))      !Position of autoinc record
  560. #ELSE
  561. SavePointer   STRING(10)                         !Position of current record
  562. AutoAddPtr    STRING(10)                         !Position of autoinc record
  563. #ENDIF
  564. AutoIncAdd    BYTE(0)                            !On for Autoincrement add
  565. ProcCalls     BYTE,DIM(%ProcCount)
  566.  
  567. #EMBED('Data Section')
  568.  
  569.   CODE
  570.  
  571.   #EMBED('Setup Procedure')
  572.   #INSERT(%OpenPrimary)                          #<!Ensure Primary file is OPEN
  573.   #INSERT(%OpenSecondaryFiles)
  574.   LOC:Pages = %ProcCount                         #<!PageOf procedure count
  575.   LOC:Page = 1                                   !Initialize page
  576.  
  577.   CASE KEYCODE()                                 !What Key was pressed?
  578.     OF InsKey                                    !Insert a new record
  579.  
  580.       Action = AddRecord                         !Set action code 1 (ADD)
  581.       #INSERT(%InsertMessage)                    #<!Message for ADD RECORD
  582.       #INSERT(%ClearValues)                      #<!Clear RECORD and MEMO(s)
  583.       #IF(%AutoInc)
  584.       DO AutoNumber                              !Set autonumber key field(s)
  585.       #ENDIF
  586.       #IF(%InitRoutine)                          #<!Field(s) initial value
  587.       DO InitializeFields                        !Initial values from dictionary
  588.       #ENDIF
  589.  
  590.     OF EnterKey                                  !Process a CHANGE request
  591.     OROF MouseLeft2                              !on EnterKey or double mouse
  592.  
  593.       Action = ChangeRecord                      !Set action code 2 (CHANGE)
  594.       #INSERT(%ChangeMessage)                    #<!Message for CHANGE RECORD
  595.       #IF(%SharedFiles)
  596.       #INSERT(%SetupConcurrency)                 #<!Setup multi-user Concurrency
  597.       #ENDIF
  598.       #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  599.       DO RelationAccessSave                      !Save LINKS for relational update
  600.       #SET(%RelUpdateRoutine,'TRUE')
  601.       #ENDIF
  602.       #IF(%SecondaryExist)                       #<!IF File schema Secondary
  603.       DO SecondaryLookups                        !Read any lookup fields
  604.       #ENDIF
  605.  
  606.     OF DelKey                                    !Process a DELETE request
  607.  
  608.       Action = DeleteRecord                      !Set action code 3 (DELETE)
  609.       #INSERT(%DeleteMessage)                    #<!Message for DELETE RECORD
  610.       SavePointer = POSITION(%Primary)           #<!Position in PRIMARY file
  611.       #IF(%CascadeDelete OR %ClearOnDelete OR %RestrictDelete)
  612.       DO RelationAccessSave                      !Save LINKS for relational update
  613.       #SET(%RelDeleteRoutine,'TRUE')
  614.       #ENDIF
  615.       #IF(%SecondaryExist)                       #<!IF File schema Secondary
  616.       DO SecondaryLookups                        !Read any lookup fields
  617.       #ENDIF
  618.   END                                            !End CASE Keycode
  619.  
  620.   #IF(%PullDownStructure)
  621.   OPEN(%PullDown)
  622.   #ENDIF
  623.   OPEN(Screen)                                   !Open the FORM screen
  624.   IF Action = DeleteRecord                       !IF request for DELETE
  625.     DISABLE(1,FIELDS())                          !Disable all screen fields
  626.     ENABLE(?OK)                                  !Enable the OK and the
  627.     ENABLE(?Cancel)                              !Cancel buttons
  628.     ENABLE(?Next_Page)
  629.   END                                            !End IF request for delete
  630.   #FOR(%Formula)
  631.     #IF(UPPER(%FormulaClass) = 'SETUP')
  632.   #INSERT(%GenerateFormula)
  633.     #ENDIF
  634.   #ENDFOR
  635.   #EMBED('Setup Screen')
  636.   DISPLAY                                        !Display screen fields
  637.  
  638.   LOOP                                           !Begin Main process loop
  639.  
  640.     #IF(%LoopFormulasExist = 'TRUE')             #<!Are there Formula fields?
  641.      #SET(%GenerateFormulasOn,'TRUE')
  642.     DO FormulaFields                             !Calculate Formula fields
  643.     #ENDIF
  644.     #IF(%SecondaryExist)                         #<!IF File schema Secondary
  645.     #INSERT(%SecondaryChanged)
  646.     #ENDIF
  647.  
  648.     CASE SELECTED()                              !Process selected Field
  649.     #INSERT(%ScreenSetupRoutines)
  650.       OF NoMoreFields                            !User pressed Enter or OK
  651.         CASE Action                              !Process requested Action
  652.           OF AddRecord                           !Action = 1 (ADD)
  653.  
  654.             ADD(%Primary)                        #<!Add Record to Primary file
  655.  
  656.           OF ChangeRecord                        !Action = 2 (Change)
  657.  
  658.           #IF(%RestrictUpdate)
  659.           #SET(%ChkRestrictUpdate,'TRUE')      #!Check for relational RESTRICT
  660.           #ENDIF
  661.           #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  662.           #SET(%RelatedUpdateRoutine,'TRUE')
  663.           #ENDIF
  664.           #IF((%AutoInc AND %SharedFiles) OR (%AutoInc AND %RelatedUpdateRoutine))
  665.             IF AutoIncAdd                        #<!Was this an Autonumber?
  666.               PUT(%Primary)                      #<!Write the Record
  667.             ELSE                                 #<!not AutoincAdd
  668.           #ENDIF
  669.           #IF(%SharedFiles)
  670.           #SET(%ConcurrentWriteOn,'TRUE')
  671.               DO ConcurrentWrite                 !Concurrent update ROUTINE
  672.               IF AbortWrite#                     !AbortWrite is on
  673.                 CYCLE                            !Let user choose response
  674.               END                                !End AbortWrite#
  675.           #IF(%RelatedUpdateRoutine = %NULL)
  676.               PUT(%Primary)                      #<!Write the Record
  677.           #ENDIF
  678.           #ENDIF
  679.           #IF(%CascadeUpdate OR %ClearOnUpdate OR %RestrictUpdate)
  680.             DO RelationalUpdate                  !Relational update ROUTINE
  681.             IF AbortTransaction#                 !AbortTransaction# is ON
  682.               SELECT(?Cancel)                    !Place cursor on Cancel
  683.               CYCLE                              !and restart Accept Loop
  684.             END                                  !End AbortTransaction#
  685.           #ENDIF
  686.           #IF((%AutoInc AND %SharedFiles) OR (%AutoInc AND %RelatedUpdateRoutine))
  687.             END                                  #<!IF AutoIncAdd
  688.           #ENDIF
  689.           #IF((%SharedFiles = %NULL) OR (%RelatedUpdateRoutine = %NULL))
  690.             PUT(%Primary)                        #<!Write the Record
  691.           #ENDIF
  692.  
  693.           OF DeleteRecord                        !Action = 3 (Delete)
  694.  
  695.             #IF(%RestrictDelete)                  #<!IF RESTRICT Constraint
  696.             DO CheckRestrictedDelete             !Check RESTRICT delete
  697.             IF RestrictDelete#                   !If RestrictDelete# is ON
  698.                SELECT(?Cancel)                   !Place cursor on cancel
  699.                CYCLE                             !Restart Loop
  700.             END                                  !End IF RestrictDelete#
  701.             #SET(%ChkRestrictDelete,'TRUE')      #<!RESTRICT delete code
  702.             #ENDIF
  703.             #IF(%CascadeDelete OR %ClearOnDelete)
  704.             #SET(%RelatedDeleteRoutine,'TRUE')
  705.             DO RelationalDelete                  !Relational delete ROUTINE
  706.             IF AbortTransaction#                 !AbortTransaction is on
  707.               CYCLE                              !Let user try again
  708.             END                                  !End AbortTransaction
  709.             #ELSIF(%SharedFiles)
  710.             #SET(%ConcurrentDeleteOn,'TRUE')
  711.             DO ConcurrentDelete                  !Concurrent update ROUTINE
  712.             IF AbortDelete#                      !AbortWrite is on
  713.               CYCLE                              !Restart main Loop
  714.             ELSE                                 !Its OK to Delete
  715.               DELETE(%Primary)                   !Delete this record
  716.             END                                  !End AbortWrite#
  717.             #ELSE
  718.             DELETE(%Primary)                     !Delete this record
  719.             #ENDIF
  720.         END                                      !End CASE Action
  721.  
  722.       IF ERRORCODE()                             !Error check on File I/O
  723.  
  724.         #IF(%DupKeyCheck)
  725.         #INSERT(%DupKeyCode)
  726.         #ENDIF
  727.         CASE Action                              !Error message based on Action
  728.           OF AddRecord
  729.             GLO:Message1 = 'Error attempting to ADD Record'
  730.           OF ChangeRecord
  731.             GLO:Message1 = 'Error attempting to CHANGE Record'
  732.           OF DeleteRecord
  733.             GLO:Message1 = 'Error attempting to DELETE Record'
  734.         END                                      !End CASE Action
  735.         GLO:Message2 = 'The file: %Primary could not be updated'
  736.         GLO:Message3 = 'Code:'&Errorcode()&': '&Error()
  737.         ShowWarning                              !Notify the user
  738.         #IF(%SharedFiles)
  739.         RELEASE(%Primary)                        #<!Release the held record
  740.         FREE(RecordQueue)                        !FREE the memory Queue
  741.         #ENDIF
  742.         DISABLE(1,FIELDS())                      !Disable all the fields
  743.         ENABLE(?Cancel)                          !Enable Cancel button
  744.         SELECT(?Cancel)                          !and place cursor on Cancel
  745.         DISPLAY                                  !Re-display the screen
  746.         CYCLE                                    !Re-start main LOOP
  747.       ELSE                                       !Else no errorcode()
  748.         #IF(%SharedFiles)
  749.         FREE(RecordQueue)                        !Free memory from Queue
  750.         #ENDIF
  751.         #IF(%NextProcedure)
  752.         #EMBED('Setup Next Procedure')
  753.         %NextProcedure                           #<!Call the Next Procedure
  754.         #EMBED('Return from Next Procedure')
  755.         #ENDIF
  756.         BREAK                                    !Break from main Loop
  757.       END                                        !End IF Errorcode()
  758.     END                                          !End CASE Selected()
  759.  
  760.     ACCEPT                                       !Enable screen entry
  761.  
  762.     CASE KEYCODE()
  763.       OF EscKey                                  !User pressed Escape key
  764.       IF FIELD() <> ?Cancel                      !If user pressed Escape
  765.         SELECT(?Cancel)                          !Select Cancel button
  766.         PRESS(EnterKey)                          !Process Cancel button
  767.         CYCLE                                    !Cycle to Accept
  768.       END
  769.     #FOR(%HotKey)
  770.       OF %HotKey                                 !User defined HotKey
  771.         %HotKeyProc                              #<!HotKey Procedure
  772.     #ENDFOR
  773.     #INSERT(%AltKeys)
  774.     END                                          !End CASE Keycode
  775.  
  776.     CASE FIELD()                                 !Process fields
  777.     #INSERT(%FormEditRoutines)
  778.       OF ?Ok                                     !On the OK button
  779.  
  780.         #EMBED('OK Button Press')
  781.         #FOR(%ScreenField)
  782.           #IF(%ScreenFieldUse = '?Ok')
  783.           #IF(%ScreenFieldEdit <> %NULL)
  784.         %ScreenFieldEdit                         #<!Field Edit procedure
  785.           #ENDIF
  786.           #ENDIF
  787.         #ENDFOR
  788.       #IF(%Page2Proc)
  789.       IF Action <> DeleteRecord
  790.         SaveAction = Action
  791.         Action = CheckRequired
  792.         LOC:Message = 'Verify Required Field(s)'
  793.         LOOP LOC:Page = 1 to %ProcCount
  794.           IF ProcCalls[LOC:Page]                 !If the Page has been called
  795.             CYCLE                                !then check the next page
  796.           ELSE                                   !Call the Page for CheckRequired
  797.       #IF(%Page2Proc)
  798.            EXECUTE (LOC:Page)
  799.             %Page2Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  800.         #IF(%Page3Proc)
  801.             %Page3Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  802.          #ENDIF
  803.          #IF(%Page4Proc)
  804.             %Page4Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  805.          #ENDIF
  806.          #IF(%Page5Proc)
  807.             %Page5Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  808.          #ENDIF
  809.          #IF(%Page6Proc)
  810.             %Page6Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  811.          #ENDIF
  812.          #IF(%Page7Proc)
  813.             %Page7Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  814.          #ENDIF
  815.          #IF(%Page8Proc)
  816.             %Page8Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  817.          #ENDIF
  818.          #IF(%Page9Proc)
  819.             %Page9Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  820.          #ENDIF
  821.            END                                   !End Execute LOC:Page
  822.           END                                    !END IF Page was called
  823.       #ENDIF
  824.       #ENDIF                                     #<!Are there any Pages?
  825.         END                                      !END LOOP for required fields
  826.        Action = SaveAction                       !Save the user Action
  827.       END                                        !End if Action <> delete
  828.       SELECT(1)                                  !Start with the first field
  829.       SELECT                                     !and cycle non-stop
  830.       CYCLE                                      !restart main process loop
  831.  
  832.       OF ?Next_Page                              !On the Next Page button
  833.  
  834.         #EMBED('Next Page Button Press')
  835.         #FOR(%ScreenField)
  836.           #IF(%ScreenFieldUse = '?Next_Page')
  837.           #IF(%ScreenFieldEdit <> %NULL)
  838.         %ScreenFieldEdit                         #<!Field Edit procedure
  839.           #ENDIF
  840.           #ENDIF
  841.         #ENDFOR
  842.       #IF(%Page2Proc)
  843.       LOC:Page += 1
  844.         LOOP
  845.           IF (LOC:Page - 1) = 0 THEN BREAK.
  846.           EXECUTE (LOC:Page - 1)
  847.            BEGIN
  848.             ProcCalls[LOC:Page - 1] = 1
  849.             %Page2Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  850.            .
  851.         #IF(%Page3Proc)
  852.            BEGIN
  853.             ProcCalls[LOC:Page] = 1
  854.             %Page3Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  855.            .
  856.          #ENDIF
  857.          #IF(%Page4Proc)
  858.            BEGIN
  859.             ProcCalls[LOC:Page] = 1
  860.             %Page4Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  861.            .
  862.          #ENDIF
  863.          #IF(%Page5Proc)
  864.            BEGIN
  865.             ProcCalls[LOC:Page] = 1
  866.             %Page5Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  867.            .
  868.          #ENDIF
  869.          #IF(%Page6Proc)
  870.            BEGIN
  871.             ProcCalls[LOC:Page] = 1
  872.             %Page6Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  873.            .
  874.          #ENDIF
  875.          #IF(%Page7Proc)
  876.            BEGIN
  877.             ProcCalls[LOC:Page] = 1
  878.             %Page7Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  879.            .
  880.          #ENDIF
  881.          #IF(%Page8Proc)
  882.            BEGIN
  883.             ProcCalls[LOC:Page] = 1
  884.             %Page8Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  885.            .
  886.          #ENDIF
  887.          #IF(%Page9Proc)
  888.            BEGIN
  889.             ProcCalls[LOC:Page] = 1
  890.             %Page9Proc(Action,LOC:Page,LOC:Pages,LOC:Message) !Call Page procedure
  891.            .
  892.          #ENDIF
  893.           .                                      !End Execute LOC:Page
  894.         END                                      !End LOOP
  895.       #ENDIF
  896.  
  897.       OF ?Cancel                                 !On Cancel button
  898.  
  899.       #IF(%AutoInc = 'TRUE')
  900.         IF AutoIncAdd                            !ADDed autoincrement record?
  901.           RESET(%Primary,AutoAddPtr)             #<!Re-position record pointer
  902.           NEXT(%Primary)                         #<!Re-read the record we added
  903.           IF DiskError('Could not READ Record')  !Check for file I/O error
  904.             #IF(%SharedFiles = 'TRUE')
  905.             FREE(RecordQueue)                    !Free the memory Queue
  906.             #ENDIF
  907.             #IF(%PullDownStructure)
  908.             CLOSE(%PullDown)
  909.             #ENDIF
  910.             #INSERT(%CloseOpenedFiles)           #<!Close files Opened here
  911.             #SET(%SetFile,%Primary)
  912.             #INSERT(%CloseRelatedFiles)          #<!Close files Opened here
  913.             RETURN                               !And return to caller
  914.           END                                    !End IF Diskerror
  915.           DELETE(%Primary)                       #<!DELETE the record
  916.           IF DiskError('Record could not be Deleted')
  917.             #IF(%SharedFiles = 'TRUE')
  918.             FREE(RecordQueue)                    !Free the memory Queue
  919.             #ENDIF
  920.             #IF(%PullDownStructure)
  921.             CLOSE(%PullDown)
  922.             #ENDIF
  923.             #INSERT(%CloseOpenedFiles)           #<!Close files Opened here
  924.             #SET(%SetFile,%Primary)
  925.             #INSERT(%CloseRelatedFiles)          #<!Close files Opened here
  926.             RETURN                               !And return to caller
  927.           END                                    !End IF Diskerror
  928.         END                                      !End IF AutoIncAdd
  929.       #ENDIF
  930.         #IF(%SharedFiles = 'TRUE')
  931.         FREE(RecordQueue)                        !Free the memory Queue
  932.         #ENDIF
  933.         #FOR(%ScreenField)
  934.           #IF(%ScreenFieldUse = '?Cancel')
  935.           #IF(%ScreenFieldEdit <> %NULL)
  936.         %ScreenFieldEdit                         #<!Field edit procedure
  937.           #ENDIF
  938.           #ENDIF
  939.         #ENDFOR
  940.         #IF(%PullDownStructure)
  941.         CLOSE(%PullDown)
  942.         #ENDIF
  943.         BREAK                                    !Break from main LOOP
  944.     END                                          !End CASE FIELD
  945.  
  946.   END                                            !END MAIN PROCESS LOOP
  947.   #EMBED('End of Procedure')
  948. #IF(%CloseFiles)
  949.   #INSERT(%CloseOpenedFiles)                     #<!Close files Opened here
  950.   #SET(%SetFile,%Primary)
  951.   #INSERT(%CloseRelatedFiles)                    #<!Close files Opened here
  952. #ENDIF
  953.  
  954. #INSERT(%AutoIncCode)
  955. #INSERT(%ConcurrentWrite)
  956. #IF(%RelUpdateRoutine OR %RelDeleteRoutine)
  957. #INSERT(%RelUpdSave)
  958. #ENDIF
  959. #INSERT(%RelUpdate)
  960. #IF(%ChkRestrictUpdate)
  961. #INSERT(%RestrictUpdateCheck)
  962. #ENDIF
  963. #INSERT(%RelDelete)
  964. #INSERT(%ConcurrentDelete)
  965. #INSERT(%ClearOnDeleteCode)
  966. #IF(%CascadeUpdate = 'TRUE')
  967. #INSERT(%CheckTransaction)
  968. #ELSIF(%ClearOnUpdate = 'TRUE')
  969. #INSERT(%CheckTransaction)
  970. #ELSIF(%ClearOnDelete = 'TRUE')
  971. #INSERT(%CheckTransaction)
  972. #ELSIF(%CascadeDelete = 'TRUE')
  973. #INSERT(%CheckTransaction)
  974. #ENDIF
  975. #IF(%CascadeDeleteOn)
  976. #INSERT(%CascadeDeleteCode)
  977. #ENDIF
  978. #IF(%ChkRestrictDelete)
  979. #INSERT(%RestrictDeleteCode)
  980. #ENDIF
  981. #INSERT(%InitQue)
  982. #INSERT(%InitFields)
  983. #INSERT(%GenFormulas)
  984. #IF(%SecondaryExist)
  985. #INSERT(%SecondaryLookups)
  986. #ENDIF
  987. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  988.  #IF(%CopyKey)
  989. #INSERT(%SaveScrFlds)
  990. #INSERT(%DupField)
  991.  #ENDIF
  992. #ENDIF
  993. #!***************************************************************************
  994. #!-------------------------------------------------------------------------------#!
  995. #!
  996. #!      PageOf the Multi-Page Form - A single page of a multiple page form
  997. #!
  998. #!------------------------------------------------------------------------------
  999. #!
  1000. #PROCEDURE(PageOf,'Page of Multi-Page forms '),SCREEN,PULLDOWN
  1001. #PROTOTYPE('(BYTE,*BYTE,BYTE,STRING)')
  1002. #!------------------------------------------------------------------------------
  1003. #!      CLARION4.TPX
  1004. #!
  1005. #!      PageOf Template:  a data entry 'Page' used with the MultiPage Form
  1006. #!
  1007. #!------------------------------------------------------------------------------
  1008. #INSERT(%StandardHeader)
  1009. #INSERT(%InitFormSymbols)
  1010. #INSERT(%ButtonCheck)
  1011. %Procedure      PROCEDURE(Action,Page,Pages,Message)
  1012.  
  1013. %LocalData
  1014. #IF(%CloseFiles)
  1015. #INSERT(%CloseFilesFlags)
  1016. #ENDIF
  1017. NoMoreFields     BYTE(0)                         !No more fields flag
  1018. CheckRequired    BYTE(4)
  1019. NonStop          BYTE
  1020.  
  1021. SCREEN    %ScreenAttributes
  1022. %ScreenPaintDeclarations
  1023. %ScreenStringDeclarations
  1024. %ScreenFieldDeclarations
  1025.           .
  1026. %PullDownStructure
  1027. #EMBED('Data Section')
  1028.  
  1029.   CODE
  1030.  
  1031.   #EMBED('Setup Procedure')
  1032.   #INSERT(%OpenPrimary)                          #<!Ensure Primary file is OPEN
  1033.   #INSERT(%OpenSecondaryFiles)
  1034.   #INSERT(%FieldLookupOpen)
  1035.   PAG:Message = Message                          !Move to local variable
  1036.   PAG:Page = Page                                !Move to local variable
  1037.   PAG:Pages = Pages                              !Move to local variable
  1038.   CASE Action                                    !What Action requested?
  1039.       #IF(%SecondaryExist)                       #<!IF File schema Secondary
  1040.     OF ChangeRecord                              !Process a CHANGE request
  1041.       DO SecondaryLookups                        !Read any lookup fields
  1042.       #ENDIF
  1043.  
  1044.       #IF(%SecondaryExist)                       #<!IF File schema Secondary
  1045.     OF DeleteRecord                              !Process a DELETE request
  1046.       DO SecondaryLookups                        !Read any lookup fields
  1047.       #ENDIF
  1048.  
  1049.     OF CheckRequired                             !Check REQ fields
  1050.  
  1051.       NonStop = 1
  1052.  
  1053.   END                                            !End CASE Action
  1054.  
  1055.   OPEN(Screen)                                   !Open the FORM screen
  1056.   IF Action = DeleteRecord                       !IF request for DELETE
  1057.     DISABLE(1,FIELDS())                          !Disable all screen fields
  1058.     ENABLE(?Next_Page)                           !Enable just the
  1059.     ENABLE(?Previous_Page)                       !useful buttons
  1060.     ENABLE(?Base_Page)                           !useful buttons
  1061.     ENABLE(?Last_Page)                           !useful buttons
  1062.   END                                            !End IF request for delete
  1063.   #EMBED('Setup Screen')
  1064.   DISPLAY                                        !Display screen fields
  1065.  
  1066.   LOOP                                           !Begin Main process loop
  1067.  
  1068.     #IF(%LoopFormulasExist = 'TRUE')             #<!Are there Formula fields?
  1069.       #SET(%GenerateFormulasOn,'TRUE')
  1070.     DO FormulaFields                             !Calculate Formula fields
  1071.     #ENDIF
  1072.     #IF(%SecondaryExist)                         #<!IF File schema Secondary
  1073.     #INSERT(%SecondaryChanged)
  1074.     #ENDIF
  1075.  
  1076.     IF NonStop                                   !Just check for required fields
  1077.       SELECT(1)                                  !Start at first field
  1078.       SELECT                                     !and enter Nonstop mode
  1079.       NonStop = 0                                !Switch indicator off
  1080.     END                                          #<!End If
  1081.     CASE SELECTED()                              !Process selected Field
  1082.       #INSERT(%ScreenSetupRoutines)
  1083.       OF NoMoreFields                            !All fields have been processed
  1084.  
  1085.       #IF(%DupKeyCheck)
  1086.        #INSERT(%DupKeyCode)
  1087.       #ENDIF
  1088.         #IF(%PullDownStructure)
  1089.         CLOSE(%PullDown)
  1090.         #ENDIF
  1091.         RETURN                                   !Return to caller
  1092.     END                                          !End CASE Selected()
  1093.  
  1094.     ACCEPT                                       !Enable screen entry
  1095.  
  1096.     CASE KEYCODE()                               !Process Alerted keys
  1097.     OF EscKey                                    !User pressed Escape key
  1098.         SELECT(?Previous_Page)                   !Select PreviousPage button
  1099.         PRESS(EnterKey)                          !Process PreviousPage button
  1100.         CYCLE                                    !Cycle to Accept
  1101.     #FOR(%HotKey)
  1102.     OF %HotKey                                   #<!User HotKey
  1103.       %HotKeyProc                                #<!Call HotKey procedure
  1104.     #ENDFOR
  1105.     OF CtrlPgUp
  1106.       Page = 1                                   !Decrement Page
  1107.       SELECT(1)                                  !Start with the first field
  1108.       SELECT                                     !and cycle non-stop
  1109.       CYCLE                                      !restart main process loop
  1110.     OF CtrlPgDn
  1111.       Page = Pages                               !Decrement Page
  1112.       SELECT(1)                                  !Start with the first field
  1113.       SELECT                                     !and cycle non-stop
  1114.       CYCLE                                      !restart main process loop
  1115.     OF EscKey
  1116.       Page -= 1                                  !Decrement Page
  1117.       #IF(%PullDownStructure)
  1118.       CLOSE(%PullDown)
  1119.       #ENDIF
  1120.       RETURN                                     !Return to caller
  1121.     END                                          ! End CASE
  1122.  
  1123.     CASE FIELD()                                 !Process fields
  1124.     #INSERT(%FormEditRoutines)
  1125.     #IF(%BasePageExists)
  1126.       OF ?Base_Page                              !On the Base Page button
  1127.  
  1128.         #EMBED('Base_Page Button Press')
  1129.         #FOR(%ScreenField)
  1130.           #IF(%ScreenFieldUse = '?Base_Page')
  1131.           #IF(%ScreenFieldEdit <> %NULL)
  1132.         %ScreenFieldEdit                         #<!Field Edit procedure
  1133.           #ENDIF
  1134.           #ENDIF
  1135.         #ENDFOR
  1136.         Page = 1                                 !Set to the MultiPage
  1137.         SELECT(1)                                !Start with the first field
  1138.         SELECT                                   !and cycle non-stop
  1139.         CYCLE                                    !restart main process loop
  1140.     #ENDIF
  1141.       OF ?Previous_Page                          !On Previous Page button
  1142.  
  1143.         #EMBED('Previous_Page Button Press')
  1144.         #FOR(%ScreenField)
  1145.           #IF(%ScreenFieldUse = '?Previous_Page')
  1146.           #IF(%ScreenFieldEdit <> %NULL)
  1147.         %ScreenFieldEdit                         #<!Field edit procedure
  1148.           #ENDIF
  1149.           #ENDIF
  1150.         #ENDFOR
  1151.         Page -= 1                                !Decrement Page number
  1152.         SELECT(1)                                !Start with the first field
  1153.         SELECT                                   !and cycle non-stop
  1154.         CYCLE                                    !restart main process loop
  1155.  
  1156.       OF ?Next_Page                              !On Next Page button
  1157.  
  1158.         #EMBED('Next_Page Button Press')
  1159.         #FOR(%ScreenField)
  1160.           #IF(%ScreenFieldUse = '?Next_Page')
  1161.           #IF(%ScreenFieldEdit <> %NULL)
  1162.         %ScreenFieldEdit                         #<!Field edit procedure
  1163.           #ENDIF
  1164.           #ENDIF
  1165.         #ENDFOR
  1166.         Page += 1                                !Increment Page number
  1167.         IF PAGE > PAGES THEN PAGE = 1.
  1168.         SELECT(1)                                !Start with the first field
  1169.         SELECT                                   !and cycle non-stop
  1170.         CYCLE                                    !restart main process loop
  1171.      #IF(%LastPageExists)
  1172.       OF ?Last_Page                              !On Last Page button
  1173.  
  1174.         #EMBED('Last_Page Button Press')
  1175.         #FOR(%ScreenField)
  1176.           #IF(%ScreenFieldUse = '?Last_Page')
  1177.           #IF(%ScreenFieldEdit <> %NULL)
  1178.         %ScreenFieldEdit                         #<!Field edit procedure
  1179.           #ENDIF
  1180.           #ENDIF
  1181.         #ENDFOR
  1182.         Page = Pages                             !Pages holds LAST page proc
  1183.         SELECT(1)                                !Start with the first field
  1184.         SELECT                                   !and cycle non-stop
  1185.         CYCLE                                    !restart main process loop
  1186.      #ENDIF
  1187.     END                                          !End CASE FIELD
  1188.  
  1189.   END                                            !END MAIN PROCESS LOOP
  1190.  
  1191.   #EMBED('End of Procedure')
  1192. #INSERT(%GenFormulas)
  1193. #IF(%SecondaryExist)
  1194. #INSERT(%SecondaryLookups)
  1195. #ENDIF
  1196. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  1197.  #IF(%CopyKey)
  1198. #INSERT(%SaveScrFlds)
  1199. #INSERT(%DupField)
  1200.  #ENDIF
  1201. #ENDIF
  1202. #INSERT(%InitFields)
  1203. #!***************************************************************************
  1204. #CHAIN('CLARION5.TPX')
  1205.