home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / visilotu.zip / BATONOT.PRG < prev    next >
Text File  |  1995-12-21  |  25KB  |  828 lines

  1. !.HEADER
  2. ! ! Code generated  4-17-95 at 10:39 P.M.
  3. ! ! from WINDOW 'E:\visqdevt\LotNotes\visnote\ToNotes.wdw'
  4. ! ! Windows referred:-
  5. ! ! 'E:\visqdevt\LotNotes\visnote\ToNotes.wdw' established as main window
  6. !.spec winsize 436 244
  7. !.spec textcol 0 17
  8. !.spec appdest 1 D:\temp\batnot
  9. !.HEADER
  10. !
  11. ! DEFINITION
  12. ! Some ASL commands can be placed outside of the normal block
  13. ! structure. This block is provided to allow such commands to
  14. ! be accomodated
  15. !
  16. ! Assign boolean variables
  17. !
  18. DECLARE TASK NUMERIC yes = 1
  19. DECLARE TASK NUMERIC no  = 0
  20. !
  21. DECLARE TASK CHAR[4] ThisTask = A.System.ThisTask
  22. !
  23. ! Open the library and declare the required functions
  24. !
  25. LIBRARY ASL "MyLib..AppDevL",
  26.  App_Icon
  27.  
  28. !
  29. ! ON START
  30. ! This block is executed when the program is initially invoked.
  31. ! It is normally used to initialize variables needed during
  32. ! program execution and to open the main window of the
  33. ! application.
  34. !
  35. !
  36. ON START(FileName, AppIdentifier, AppName)
  37. DO
  38.  
  39.   ! Open the library with the prompter for global variables
  40.   LIBRARY ASL "G..GeneralLib",
  41.    VALID_NAME
  42.  
  43.   OPEN objectstore p,
  44.    name = s.control.mribase,
  45.    location = s.control.path
  46.  
  47.  
  48.   ! Disable BREAKs so that they may only be collected in the Batch_proc
  49.   BREAK DISABLE
  50.  
  51.   ! Define Current Position
  52.   g_CurLoc = A.System.StartDs'Location
  53.   IF Split(g_CurLoc,Length(g_CurLoc),1) = "\"
  54.     g_CurLoc = Split(g_CurLoc,1,Length(g_CurLoc)-1)
  55.  
  56.     ! Set the full path and name for the batch data table from the
  57.     ! @Path variable passed to the programme at startup
  58.     !
  59.   LET BatchPath = GLOBAL("BatchName")
  60.   !
  61.  
  62.   !
  63.   ! Validate the path that the user has given
  64.   !
  65.   LET vname = name(BatchPath)
  66.   LET vpath = location(BatchPath)
  67.   IF novalue(vname) | novalue(vpath)
  68.     LET validate = 1
  69.   ELSE
  70.     LET Validate = VALID_NAME(vname,vpath)
  71.   IF validate \= 0
  72.   DO
  73.     ! If invalid get the user to enter one
  74.     OPEN FILEDLG FileSelect,
  75.      name = "*.*",
  76.      EA = "IBMTABLE"
  77.  
  78.     LET BatchPath = FileSelect'OPEN()
  79.     SHUT FileSelect
  80.     ! If still invalid, or user quits then stop
  81.     LET vname = name(BatchPath)
  82.     LET vpath = location(BatchPath)
  83.     IF novalue(vname) | novalue(vpath)
  84.       LET validate = 1
  85.     ELSE
  86.       LET Validate = VALID_NAME(vname,vpath)
  87.     IF validate \= 0
  88.     DO
  89.       ERROR 1,"No valid Batch File was selected.  Program terminated."
  90.       STOP
  91.     END
  92.   END
  93.  
  94.   ! Stop the programme if none was specified
  95.   !
  96.   IF BatchPath = ""
  97.   DO
  98.     ERROR 1,"No full name was specied for the batch table at startup (@Path=...)."
  99.     STOP
  100.   END
  101.  
  102.   !
  103.   ! Open the object store holding the user library
  104.   !
  105.   OPEN OBJECTSTORE MyLib,
  106.    NAME ="UserLib.A95",
  107.    LOCATION = S.Control.Path
  108.  
  109.   OPEN SYSTEM Sys                                 ! establish connection with OS/2
  110.  
  111.   !
  112.   ! Assign all variables referred by the windows
  113.   !
  114.   LET now = ""~TIME(,"hhmm")
  115.   LET date = DATE()                               ! used by SLE control named 'T.W_BATONOT.SLE3'
  116.   LET hours = SPLIT(now,1,2)                      ! used by SLE control named 'T.W_BATONOT.SLE1'
  117.   LET MESSAGE = "Establishing connection with Lotus Notes..."! used by Text control named 'T.W_BATONOT.TEXT3'
  118.   LET minutes = SPLIT(now,3,2)                    ! used by SLE control named 'T.W_BATONOT.SLE2'
  119.  
  120.   ! Set the default radio variables in case they are not changed
  121.   LET ErrorNotify = 0
  122.   LET TimerFunction = "Today"
  123.  
  124.   ! Open the main window
  125.   OPEN WINDOW W_BATONOT, , "I.Windows.BATONOT"
  126.  
  127.   ! Disable the modify button
  128.   LET T.W_BATONOT.STD_PUSH[2]'enabled = 0
  129.  
  130.   FORGIVE
  131.     LET NotesPath = Sys'SEARCHPATH(               ! locate the Notes directory
  132.      "NOTES.EXE",                                 ! by searching for the Notes program file
  133.      "PATH")                                      ! in the PATH setting of CONFIG.SYS
  134.   IF A.System.ErrorNumber
  135.   DO
  136.     ERROR 1,"Unable to open LotusNotes Object. Check that Lotus Notes is installed." ||
  137.      " correctly. The Lotus Notes directory must be in PATH and LIBPATH."
  138.     STOP
  139.   END
  140.  
  141.   FORGIVE                                         !Open the lotus notes object and check status
  142.     OPEN LOTUSNOTES Lotus
  143.  
  144.   IF Lotus'CODE > 0
  145.   DO
  146.     MESSAGE "FTB0003",0,Lotus'REASON
  147.     SHUT Lotus
  148.     STOP
  149.   END
  150.  
  151.   ! Display status
  152.   LET MESSAGE = "Connecting to required servers..."
  153.   CALL T.W_BATONOT.TEXT3'REFRESH
  154.  
  155.   !
  156.   CALL App_Icon(POINTER(W_ToNotes[0]))
  157.  
  158.   !Open the Batch Table
  159.   OPEN TABLE BatchTab,                            !Open the batch table
  160.    LOCATION = LOCATION(BatchPath),
  161.    NAME = NAME(BatchPath)
  162.  
  163.   ! Establish connection with all servers listed in batch table
  164.   CALL Connect
  165.  
  166.  
  167.   ! Display status
  168.   LET MESSAGE = "Connected successfully to Lotus Notes and Servers. Modify the settings and press 'Activate'"
  169.   CALL T.W_BATONOT.TEXT3'REFRESH
  170.  
  171. END
  172. !
  173. ! ON DATA
  174. ! This block responds to controls which can accept data entry.
  175. ! It is executed whenever the cursor leaves the control after
  176. ! data has been changed. This is normally used to provide input
  177. ! validation.
  178. !
  179. ON DATA
  180. DO
  181.   CASE A.System.Object
  182.     !
  183.     WHEN "T.W_BATONOT.SLE1"
  184.     DO
  185.       ! React to change to data variable 'hours'
  186.     END
  187.     !
  188.     WHEN "T.W_BATONOT.SLE2"
  189.     DO
  190.       ! React to change to data variable 'minutes'
  191.     END
  192.     !
  193.     WHEN "T.W_BATONOT.SLE3"
  194.     DO
  195.       ! React to change to data variable 'date'
  196.     END
  197.     !
  198.  
  199.   END
  200. END
  201. !
  202. ! ON SOURCE
  203. ! This event is signalled when there has been Direct Manipulation
  204. ! between this application and some other application.
  205. ! This applications Source window has been dropped onto a target
  206. ! window. The owner of the target window is asking for data about
  207. ! this application.
  208. !
  209. ON SOURCE(pStream)
  210. DO
  211.   DECLARE POINTER pStream
  212.   !
  213.   CASE (?pStream)'FORMAT
  214.     !
  215.     WHEN "IBMAPPLICATN"
  216.     DO
  217.       IF (?pStream)'REFERENCE
  218.       DO
  219.         OPEN REFERENCE Reference,
  220.          SOURCETYPE = "FILE",
  221.          NAME       = NAME(AppIdentifier),
  222.          LOCATION   = LOCATION(AppIdentifier)
  223.  
  224.         CALL Reference'SAVE(pStream)
  225.         SHUT Reference
  226.       END
  227.     END
  228.     !
  229.     ! Add code for any other formats here
  230.     !
  231.   END
  232.   !
  233.   CALL (?pStream)'FINISHED()
  234.   SHUT(?pStream)
  235. END
  236. !
  237. ! ERROR event
  238. ! This block is executed when there is a run-time error.
  239. ! You can trap errors here or allow the error message provided
  240. ! to identify the error and stop the program.
  241. !
  242.  
  243. ON ERROR
  244. DO
  245.   DECLARE CHAR[7] ans
  246.   DECLARE NUMERIC i
  247.   !
  248.   ! Message to identify failing module and line
  249.   !
  250.   LET ans = DIALOG("FTB7004", 0,
  251.    A.System.ErrorModule,
  252.    A.System.ErrorLine)
  253.  
  254.   DO i = 1 : A.System.ErrorNumber[0]'ENTRIES
  255.     IF ans = "CANCEL"
  256.       TERMINATE
  257.       !
  258.       ! Display system message corresponding to error
  259.       !
  260.     LET ans = DIALOG ("FTB" || A.System.Errornumber[i], 0,
  261.      A.System.ErrorInfo[i])
  262.   END
  263.  
  264.   STOP
  265. END
  266. !
  267. ! ON STOP
  268. ! This block is executed when the program is terminated.
  269. ! You should use the block to carry out any housekeeping
  270. ! required before closing
  271. !
  272. ON STOP
  273. DO
  274.  
  275.   SHUT W_tonotbat
  276.   SHUT BatchTimer
  277.   SHUT BatchTable
  278.   SHUT Lotus
  279.   !
  280.   STOP
  281.   !
  282.  
  283. END
  284. !
  285. ! User specified procedures may have up to 20 passed parameters.
  286. ! Procedures may be called as functions (using the RETURN
  287. ! facility to return a value) or may be called as normal
  288. ! procedures.
  289. !
  290. ! This procedure validates key notes' fields
  291. !
  292. PROCEDURE Valid_Parms
  293. DO
  294.   IF NOVALUE(NotesServer)=Yes |                   ! is the database name empty?
  295.    NOVALUE(NotesDB)=Yes |                         ! is the Formname empty?
  296.    NOVALUE(NotesForm)=Yes |                       ! is the RichTextField name empy?
  297.    NOVALUE(FieldName)=Yes                         ! is the FieldName empty?
  298.     RETURN No                                     ! if so, then return a 0 (No)
  299.   ELSE
  300.     RETURN Yes                                    ! if not return a 1 (Yes)
  301. END
  302. !
  303. ! User specified procedures may have up to 20 passed parameters.
  304. ! Procedures may be called as functions (using the RETURN
  305. ! facility to return a value) or may be called as normal
  306. ! procedures.
  307. !
  308. ! This procedure handles the batch process reading each row of data in from the specified table
  309. ! and then calling the transfer routine
  310. !
  311. PROCEDURE Batch_proc
  312. DO
  313.   LET ErrorCount = 0
  314.   DEFINE errors[0]
  315.   DO row = 1 : BatchTab.FileName[0]'ENTRIES       !Repeat the transfer procedure for every row in the table
  316.  
  317.     !Scan the columns into the data variables
  318.     LET NotesServer = BatchTab.NotesServer[row]
  319.     LET NotesDB = BatchTab.NotesDB[row]
  320.     LET NotesForm = BatchTab.NotesForm[row]
  321.     LET FieldName = BatchTab.FieldName[row]
  322.     LET NotesDocumentId = BatchTab.NotesDocument[row]
  323.     LET FullFileName = BatchTab.FileName[row]
  324.     LET FileType = BatchTab.FileType[row]
  325.     LET UpdateMode = BatchTab.UpdateMode[row]
  326.  
  327.     IF LOCATION(FullFileName) = ""                !Use the batch table's path if a full path is not specified in the table
  328.     THEN LET FullFileName = LOCATION(BatchPath)||"\"||FullFileName
  329.       MODIFY Lotus,                               !Modify the lotus object's settings
  330.        SERVERNAME = NotesServer,
  331.        DIRECTORY = "",
  332.        DATABASE = NotesDB,
  333.        FORMNAME = NotesForm
  334.  
  335.       ! Display status
  336.     LET MESSAGE = STRING("Transferring '_' to Notes."||CHAR(13)||"Press 'Ctrl' + 'Break' to abort transfer.",FullFileName)
  337.     CALL T.W_BATONOT.TEXT3'REFRESH
  338.  
  339.     ! Call the file transfer routine
  340.     CALL transfer
  341.  
  342.     ! Enable 'Ctrl + Break' abortion of transfer
  343.     IF BREAK()
  344.     DO
  345.       LET ErrorFlag = "Break"
  346.       CALL log_error
  347.       RETURN
  348.     END
  349.   END
  350. END
  351. !
  352. ! User specified procedures may have up to 20 passed parameters.
  353. ! Procedures may be called as functions (using the RETURN
  354. ! facility to return a value) or may be called as normal
  355. ! procedures.
  356. !
  357. ! This procedure handles the transfer of all the supported formats to Lotus notes
  358. ! using the data supplied by the Batch_proc
  359. !
  360. PROCEDURE transfer
  361. DO
  362.   TRACE STATEMENT
  363.   IF Valid_Parms()=No                             ! check to ensure that all necessary
  364.   DO                                              ! parameters are entered
  365.     LET ErrorFlag = "Parameters"
  366.     CALL log_error
  367.     RETURN                                        ! return to Wait state
  368.   END
  369.  
  370.   ! Check for extended attributes and existance of specified file
  371.   FORGIVE
  372.     OPEN file attrib,
  373.      name = name(FullFileName),
  374.      location = location(FullFileName),
  375.      mode = "READ"
  376.   IF A.System.ErrorNumber \= 0
  377.   DO
  378.     LET ErrorFlag = "Path"                        ! Checks for the existance of the file
  379.     CALL log_error
  380.     SHUT attrib
  381.     RETURN
  382.   END
  383.   LET Eattribute = attrib'OBJECTCLASS
  384.   IF FileType \= "PCX"
  385.   DO
  386.     IF Eattribute \= ""
  387.       LET FileType = Eattribute
  388.   END
  389.   SHUT attrib
  390.  
  391.   CASE FileType
  392.     ! Add the formats you are accepting and what you want to do with them
  393.     ! here.
  394.  
  395.     WHEN "IBMREPORT"
  396.     DO
  397.  
  398.       OutPutFile = String("_\REPORT.TXT",g_CurLoc)
  399.  
  400.       CALL Sys'INCLUDETEMP( OutPutFile )
  401.       FORGIVE
  402.         OPEN ?"IBMREPORT" ThisReport,             !Open IBMREPORT object using the current path
  403.          IDENTIFIER = FullFileName,
  404.          DIALOG = 0
  405.       IF A.System.ErrorNumber \= 0 | ThisReport'CODE
  406.       DO
  407.         CALL log_error
  408.         SHUT ThisReport
  409.         RETURN
  410.       END
  411.  
  412.       ! Remove the report's margins, eliminating some plain text problems.
  413.       CALL ThisReport'PAGESETUP("U",,,0,0,,,)
  414.  
  415.       CALL ThisReport'COPYTO(OutputFile,"TEXT")
  416.       FORGIVE
  417.         CALL Lotus'StoreInNotes(
  418.          FieldName,                               ! the name of the RichText field for the Report
  419.          NotesDocumentId,                         ! the Document to update (or empty to create a new one)
  420.          OutputFile,                              ! the Report output file (must have extension of TXT)
  421.          UpdateMode)                              ! the update mode used with the file (Append or Replace)
  422.  
  423.       IF Lotus'CODE \= 0
  424.       DO
  425.         ErrorFlag = "Notes"
  426.         CALL log_error
  427.         SHUT ThisReport
  428.       END
  429.  
  430.       SHUT ThisReport                             ! and then the Report
  431.  
  432.     END
  433.  
  434.  
  435.     WHEN "IBMCHART"
  436.     DO
  437.  
  438.       OutPutFile = String("_\CHART.PCX",g_CurLoc)
  439.       CALL Sys'INCLUDETEMP( OutPutFile )
  440.       FORGIVE
  441.         OPEN ?"IBMCHART" ThisChart,               ! Open the IBMCHART object using the current path
  442.          IDENTIFIER = FullFileName,
  443.          DIALOG = 0
  444.       IF A.System.ErrorNumber \= 0 | ThisChart'CODE
  445.       DO
  446.         LET ErrorFlag = "Path"
  447.         CALL log_error
  448.         SHUT ThisChart
  449.         RETURN
  450.       END
  451.       CALL ThisChart'COPYTO(OutputFile,"PCX")
  452.       FORGIVE
  453.         CALL Lotus'StoreInNotes(
  454.          FieldName,                               ! the name of the RichText field for the Report
  455.          NotesDocumentId,                         ! the Document to update (or empty to create a new one)
  456.          OutputFile,                              ! the Report output file (must have extension of TXT)
  457.          UpdateMode)                              ! the update mode used with the file (Append or Replace)
  458.  
  459.       IF Lotus'CODE > 0
  460.       DO
  461.         ErrorFlag = "Notes"
  462.         CALL log_error
  463.       END
  464.  
  465.  
  466.       SHUT ThisChart                              ! and then the Chart
  467.  
  468.       !
  469.     END
  470.  
  471.     WHEN "PCX"                                    ! Handles PCX file transfer
  472.     DO
  473.       IF DELWORD(NAME(FullFileName),1,1,".") = "PCX"! Check for .PCX file extension
  474.         OutputFile = FullFileName                 ! If it has one then use the file
  475.       ELSE
  476.       DO
  477.         OutPutFile = String("_\PCX.PCX",g_CurLoc)
  478.         CALL Sys'INCLUDETEMP( OutPutFile )
  479.         FORGIVE
  480.           CALL sys'COPY(FullFileName,OutPutFile)  ! If it doesn't have one then create a temporary
  481.         IF A.System.ErrorNumber \= 0
  482.         DO
  483.           LET ErrorFlag = "Path"                  ! Checks the non .PCX's file path
  484.           CALL log_error
  485.           RETURN
  486.         END
  487.       END
  488.  
  489.       FORGIVE
  490.         CALL Lotus'StoreInNotes(
  491.          FieldName,                               ! the name of the RichText field for the Report
  492.          NotesDocumentId,                         ! the Document to update (or empty to create a new one)
  493.          OutputFile,                              ! the Report output file (must have extension of TXT)
  494.          UpdateMode)                              ! the update mode used with the file (Append or Replace)
  495.  
  496.       IF Lotus'CODE > 0                           ! Send errors to the error handler
  497.       DO                                          ! N.B. this one now handles .PCX paths' errors
  498.         ErrorFlag = "Notes"
  499.         CALL log_error
  500.       END
  501.  
  502.       !
  503.     END
  504.  
  505.     WHEN "BITMAP"                                 ! Handles BMP file transfer
  506.     DO
  507.       IF DELWORD(NAME(FullFileName),1,1,".") = "BMP"! Check for .BMP file extension
  508.         OutputFile = FullFileName                 ! If it has one then use the file
  509.       ELSE
  510.       DO
  511.         OutPutFile = String("_\BMP.BMP",g_CurLoc)
  512.         CALL Sys'INCLUDETEMP( OutPutFile )
  513.  
  514.         FORGIVE
  515.           CALL sys'COPY(FullFileName,OutPutFile)  ! If it doesn't have one then create a temporary
  516.  
  517.         IF A.System.ErrorNumber \= 0
  518.         DO
  519.           LET ErrorFlag = "Path"                  ! Checks the non .BMP's file path
  520.           CALL log_error
  521.           RETURN
  522.         END
  523.       END
  524.  
  525.       FORGIVE
  526.         CALL Lotus'StoreInNotes(
  527.          FieldName,                               ! the name of the RichText field for the Report
  528.          NotesDocumentId,                         ! the Document to update (or empty to create a new one)
  529.          OutputFile,                              ! the Report output file (must have extension of TXT)
  530.          UpdateMode)                              ! the update mode used with the file (Append or Replace)
  531.  
  532.       IF Lotus'CODE > 0                           ! Send errors to the error handler
  533.       DO                                          ! N.B. this one now handles .BMP paths' errors
  534.         ErrorFlag = "Notes"
  535.         CALL log_error
  536.       END
  537.       !
  538.     END
  539.  
  540.     OTHERWISE
  541.     DO
  542.       LET ErrorFlag = "Parameters"
  543.       CALL Log_error
  544.     END
  545.  
  546.   END
  547.   RETURN
  548. END
  549. !
  550. ! User specified procedures may have up to 20 passed parameters.
  551. ! Procedures may be called as functions (using the RETURN
  552. ! facility to return a value) or may be called as normal
  553. ! procedures.
  554. !
  555. ! This procedure establishes a connection with all of the Notes
  556. ! Servers listed in the batch table, by calling the GetFileList
  557. ! function.  This ensures that the batch programme is logged
  558. ! onto all the servers which it will use (as if it is not logged
  559. ! on the user will be promted to enter the password).
  560. !
  561. PROCEDURE Connect
  562. DO
  563.  
  564.   DEFINE Dirs[0]
  565.   DEFINE DBList[0]
  566.   DEFINE DBInfo[0]
  567.  
  568.   DO row = 1 : BatchTab.NotesServer[0]'ENTRIES
  569.  
  570.     FORGIVE                                       ! If the server doesn't exist then don't crash
  571.       MODIFY Lotus,
  572.        SERVERNAME = BatchTab.NotesServer[row],    !Change server to that of the current row
  573.        DIRECTORY  = ""
  574.     IF A.System.ErrorNumber \= 0
  575.       ERROR 1,"The server in row _ of the transfer is not responding.  Unable to connect to this server"
  576.  
  577.     CALL Lotus'GetFileList( Pointer( Dirs[0] ), Pointer( DBList[0] ), Pointer( DBInfo[0] ) )!Establish a connection to it
  578.  
  579.   END
  580. END
  581. !
  582. ! User specified procedures may have up to 20 passed parameters.
  583. ! Procedures may be called as functions (using the RETURN
  584. ! facility to return a value) or may be called as normal
  585. ! procedures.
  586. ! This procedure processes all non-fatal errors
  587. !
  588. PROCEDURE Log_error
  589. DO
  590.  
  591.   CASE ErrorFlag                                  !Get the correct error message for the loggable errors
  592.     WHEN "Parameters"
  593.       LET ErrorMessage = STRING("Error in row _ of table (DocumentID is the only optional field); This file was not transferred",row)
  594.     WHEN "Path"
  595.       LET ErrorMessage = STRING("Error in row _ of table (The path does not exist); This file was not transferred",row)
  596.     WHEN "Notes"
  597.       LET ErrorMessage = STRING("Error in row _ of table (_ _); This file may not have been transferred.",
  598.        row,Lotus'CODE,Lotus'REASON)
  599.     WHEN "Break"
  600.       LET ErrorMessage = "Transfer aborted by 'Ctrl' + 'Break'"
  601.   END
  602.   ErrorCount = ErrorCount + 1                     !Update the count of the total number of loggable errors
  603.   IF ErrorNotify = 1
  604.     ERROR 1,ErrorMessage
  605.   INSERT errors[0] = ErrorMessage
  606.  
  607. END
  608. ! Add your code for this Event below.
  609.  
  610. ON TIMER
  611. DO
  612.  
  613.   ! Notify user of activity
  614.   LET MESSAGE = "A Batch has been started by the timer..."
  615.   CALL T.W_BATONOT.TEXT3'REFRESH
  616.  
  617.   !Reset timer for next execution - depending upon the user settings
  618.   CASE TimerFunction
  619.     WHEN "Daily"                                  !Daily timer
  620.     DO
  621.       ! Get tomorrow's date
  622.       LET date = DURATION(date,1)
  623.  
  624.       ! Activate next timer
  625.       CALL BatchTimer'AT(BatchTime,date)
  626.  
  627.     END
  628.     WHEN "Weekly"                                 !Weekly timer
  629.     DO
  630.       ! Get the date next week
  631.       LET date = DURATION(date,7)
  632.  
  633.       ! Activate next timer
  634.       CALL BatchTimer'AT(BatchTime,date)
  635.  
  636.     END
  637.     WHEN "Today"                                  !This day only timer
  638.     DO
  639.     END
  640.   END
  641.  
  642.   ! Call the batch job
  643.   CALL batch_proc
  644.  
  645.   ! Display the next date
  646.   CALL T.W_BATONOT.SLE3'REFRESH
  647.  
  648.   ! Save all the generated errors
  649.   CALL save_errors
  650.  
  651.   ! Display status
  652.   LET MESSAGE = STRING("Finished the batch '_' on _ at _. There were _ errors (see BATCHLOG).",BatchPath,DATE(),TIME(),ErrorCount)
  653.   CALL T.W_BATONOT.TEXT3'REFRESH
  654.  
  655. END
  656. !
  657. ! User specified procedures may have up to 20 passed parameters.
  658. ! Procedures may be called as functions (using the RETURN
  659. ! facility to return a value) or may be called as normal
  660. ! procedures.
  661. !
  662. ! This procedure saves batch execution details including all non-
  663. ! fatal errors to the log file: BATCHLOG
  664. !
  665. PROCEDURE save_errors
  666. DO
  667.  
  668.   ! Display status
  669.   LET MESSAGE = "Saving Batch details..."
  670.   CALL T.W_BATONOT.TEXT3'REFRESH
  671.  
  672.   ! Open the file object in append mode
  673.   OPEN FILE output,
  674.    NAME = "BATCHLOG",
  675.    LOCATION = LOCATION(BatchPath),
  676.    MODE = "APPEND"
  677.  
  678.   ! Generate the job details
  679.   LET details = STRING("Batch job using _ table on _. Started at _. Finished at _. Completed with _ errors.",BatchPath,DATE(),BatchTime,TIME(),ErrorCount)
  680.  
  681.   ! Output the batch job's details to the file
  682.   CALL output'PUT(details, LINE())
  683.  
  684.   !Error logging
  685.   IF ErrorCount \= 0
  686.   DO
  687.     CALL output'PUT("*****START OF LOGGED ERRORS*****", LINE())
  688.  
  689.     ! Output the errors to the file
  690.     DO i = 1 : errors[0]'ENTRIES
  691.       CALL output'PUT(errors[i], LINE())
  692.     END
  693.  
  694.     CALL output'PUT("*****END OF LOGGED ERRORS*****", LINE())
  695.   END
  696.  
  697.   ! Close the file
  698.   SHUT output
  699.  
  700. END
  701. !
  702. ! ON QUIT
  703. ! This block is executed when the user uses Close in the
  704. ! system menu.
  705. ! For a secondary window this would imply, 'shut the window'.
  706. ! For a primary window the implication is, 'close the
  707. ! Application'.
  708. !
  709. ON QUIT
  710. DO
  711.   CASE A.System.Object
  712.  
  713.     WHEN "T..W_BATONOT"                           ! primary window
  714.     DO
  715.       button = DIALOG("FTB0008",0,"Do you want to quit? All batch transfers will be cancelled.")
  716.       IF button = "Yes"
  717.         RUN PROGRAM ThisTask, STOP
  718.     END
  719.     OTHERWISE
  720.       SHUT ?A.System.Object
  721.   END
  722. END
  723. !
  724. ! ON SELECT
  725. ! This block is triggered whenever the user selects a control
  726. ! or menu entry.
  727. !
  728. ON SELECT
  729. DO
  730.   CASE A.System.Object
  731.     !
  732.     WHEN "T.W_BATONOT.STD_PUSH"                   ! Std cloned push buttons
  733.     CASE A.System.Boxnumber
  734.       WHEN "2"
  735.       DO
  736.         ! 'Push' button marked 'Modify'
  737.         SHUT BatchTimer
  738.         CALL controls(1)
  739.         LET T.W_BATONOT.STD_PUSH[2]'enabled = 0
  740.         !LET T.W_BATONOT.STD_PUSH[1]'enabled = 1
  741.  
  742.         ! Display status
  743.         LET MESSAGE = "Modify the settings and press 'Activate'"
  744.         CALL T.W_BATONOT.TEXT3'REFRESH
  745.  
  746.       END
  747.       !
  748.       WHEN "1"
  749.       DO
  750.         ! 'Push' button marked 'Activate'
  751.         CALL controls(0)
  752.         LET T.W_BATONOT.STD_PUSH[2]'enabled = 1
  753.         OPEN TIMER BatchTimer
  754.         LET BatchTime = TIME(hours||":"||minutes)
  755.         CALL BatchTimer'AT(BatchTime,date)
  756.  
  757.         ! Display status
  758.         LET MESSAGE = "Batch timer is set, press 'Modify' to change the settings"
  759.         CALL T.W_BATONOT.TEXT3'REFRESH
  760.  
  761.       END
  762.     END
  763.     !
  764.     WHEN "T.W_BATONOT.RADIO1"
  765.     DO
  766.       CASE A.System.Boxnumber
  767.         WHEN 1                                    ! button marked 'Continue'
  768.         DO
  769.           ! 'Radio' button marked 'Continue'
  770.           LET ErrorNotify = 0
  771.         END
  772.         !
  773.         WHEN 2                                    ! button marked 'Stop'
  774.         DO
  775.           ! 'Radio' button marked 'Stop'
  776.           LET ErrorNotify = 1
  777.         END
  778.         !
  779.       END
  780.     END
  781.     !
  782.     WHEN "T.W_BATONOT.RADIO2"
  783.     DO
  784.       CASE A.System.Boxnumber
  785.         WHEN 1                                    ! button marked 'No'
  786.         DO
  787.           ! 'Radio' button marked 'No'
  788.           TimerFunction = "Today"
  789.         END
  790.         !
  791.         WHEN 2                                    ! button marked 'Every Day'
  792.         DO
  793.           ! 'Radio' button marked 'Every Day'
  794.           TimerFunction = "Daily"
  795.         END
  796.         !
  797.         WHEN 3                                    ! button marked 'Every Week'
  798.         DO
  799.           ! 'Radio' button marked 'Every Week'
  800.           TimerFunction = "Weekly"
  801.         END
  802.         !
  803.       END
  804.     END
  805.   END
  806. END
  807. !
  808. ! User specified procedures may have up to 20 passed parameters.
  809. ! Procedures may be called as functions (using the RETURN
  810. ! facility to return a value) or may be called as normal
  811. ! procedures.
  812. !
  813. ! This procedure changes the 'enabled status of a large number of the buttons
  814. !
  815. PROCEDURE controls(status)
  816. DO
  817.  
  818. let T.W_BATONOT.RADIO1[0]'enabled = status
  819. let T.W_BATONOT.RADIO2[0]'enabled = status
  820. let T.W_BATONOT.SLE1'enabled = status
  821. let T.W_BATONOT.SLE2'enabled = status
  822. let T.W_BATONOT.SLE3'enabled = status
  823. let T.W_BATONOT.STD_PUSH[1]'enabled = status
  824.  
  825. END
  826.