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

  1. !.HEADER
  2. ! ! Code generated  4-17-95 at 10:39 P.M.
  3. ! ! from WINDOW 'E:\visqdevt\LotNotes\visnote\ToNotes.wdw'
  4. !
  5. ! ! Windows referred:-
  6. ! ! 'E:\visqdevt\LotNotes\visnote\ToNotes.wdw' established as main window
  7. !.spec winsize MAX MAX
  8. !.spec textcol 0 17
  9. !.spec appdest 1 d:\visnotes\ToNotes.apl
  10. !.HEADER
  11. !
  12. ! DEFINITION
  13. ! Some ASL commands can be placed outside of the normal block
  14. ! structure. This block is provided to allow such commands to
  15. ! be accomodated
  16. !
  17. ! Assign boolean variables
  18. !
  19. DECLARE TASK NUMERIC yes = 1
  20. DECLARE TASK NUMERIC no  = 0
  21. !
  22. DECLARE TASK CHAR[4] ThisTask = A.System.ThisTask
  23. !
  24. ! Open the library and declare the required functions
  25. !
  26. LIBRARY ASL "MyLib..AppDevL",
  27.  App_Icon
  28.  
  29. !
  30. ! ON START
  31. ! This block is executed when the program is initially invoked.
  32. ! It is normally used to initialize variables needed during
  33. ! program execution and to open the main window of the
  34. ! application.
  35. !
  36. ON START(FileName, AppIdentifier, AppName)
  37. DO
  38.  
  39.  
  40.   ! Define Current Position
  41.   g_CurLoc = A.System.StartDs'Location
  42.   IF Split(g_CurLoc,Length(g_CurLoc),1) = "\"
  43.     g_CurLoc = Split(g_CurLoc,1,Length(g_CurLoc)-1)
  44.  
  45.  
  46.   !
  47.   ! Open the object store holding the user library
  48.   !
  49.   OPEN OBJECTSTORE MyLib,
  50.    NAME ="UserLib.A95",
  51.    LOCATION = S.Control.Path
  52.  
  53.   OPEN SYSTEM Sys                                 ! establish connection with OS/2
  54.  
  55.   FORGIVE
  56.   LET NotesPath = Sys'SEARCHPATH(                 ! locate the Notes directory
  57.    "NOTES.EXE",                                   ! by searching for the Notes program file
  58.    "PATH")                                        ! in the PATH setting of CONFIG.SYS
  59.   IF A.System.ErrorNumber
  60.   DO
  61.     ERROR 1,"Unable to open LotusNotes Object. Check that Lotus Notes is installed." ||
  62.             " correctly. The Lotus Notes directory must be in PATH and LIBPATH."
  63.     STOP
  64.   END
  65.  
  66.  
  67.   LET NotesServer=""                              ! Notes Server name
  68.   LET NotesDB=""                                  ! Notes databasename
  69.   LET NotesForm = ""                              ! Notes Form name
  70.   LET FieldName = ""                     ! Notes RichText field for Report/Chart output
  71.   LET NotesDocumentId = ""                        ! Notes document id to update
  72.  
  73.   DEFINE ServerList[0]
  74.   DEFINE DBList[0]
  75.   DEFINE FormList[0]
  76.   DEFINE FieldList[0]
  77.  
  78.   CALL Source_Define                              ! setup for drag/drop
  79.   CALL Target_Define                              ! setup for drag/drop
  80.   !
  81.   OPEN WINDOW W_ToNotes,, "I.Windows.ToNotes",
  82.    SOURCECTRL = POINTER(SourceCtrl[0]),
  83.    TARGETCTRL = POINTER(TargetCtrl[0])
  84.  
  85.   LET DILText = "Connecting to Lotus Notes..."
  86.  
  87.   FORGIVE
  88.     OPEN LOTUSNOTES Lotus
  89.  
  90.   IF Lotus'CODE > 0
  91.   DO
  92.     MESSAGE "FTB0003",0,Lotus'REASON
  93.     SHUT Lotus
  94.     STOP
  95.   END
  96.  
  97.   LET DILText = "Connected to Lotus Notes"
  98.  
  99.   !
  100.   CALL App_Icon(POINTER(W_ToNotes[0]))
  101.  
  102.   CALL Lotus'GetServerList( Pointer( ServerList[0] ) )
  103.  
  104. END
  105.  
  106. !
  107. ! ON SELECT
  108. ! This block is triggered whenever the user selects a control
  109. ! or menu entry.
  110. !
  111. ON SELECT
  112. DO
  113.   CASE A.System.Object
  114.     !
  115.     WHEN "T.W_ToNotes.DROPLIST1"
  116.     DO
  117.       MODIFY Lotus,
  118.         SERVERNAME = ServerList[A.System.BoxNumber],
  119.         DIRECTORY  = ""
  120.  
  121.       DEFINE Dirs[0]
  122.       DEFINE DBList[0]
  123.       DEFINE DBInfo[0]
  124.       CALL Lotus'GetFileList( Pointer( Dirs[0] ), Pointer( DBList[0] ), Pointer( DBInfo[0] ) )
  125.  
  126.     END
  127.     WHEN "T.W_ToNotes.DROPLIST2"
  128.     DO
  129.  
  130.       MODIFY Lotus,
  131.         DATABASE = DBList[A.System.BoxNumber]
  132.  
  133.       DEFINE FormList[0]
  134.       CALL Lotus'GetFormList( Pointer( FormList[0] ) )
  135.  
  136.     END
  137.  
  138.     WHEN "T.W_ToNotes.DROPLIST3"
  139.     DO
  140.  
  141.       MODIFY Lotus,
  142.         FORMNAME = FormList[A.System.BoxNumber]
  143.  
  144.       DEFINE FieldList[0]              ! List for target field droplist
  145.       DEFINE SFieldList[0]             ! List for Supplementary field droplists
  146.       DEFINE FieldInfo[0]
  147.       CALL Lotus'GetFormFieldList( Pointer( FieldList[0] ) , Pointer( FieldInfo[0]))
  148.       COPY FieldList,SFieldList
  149.       DO i = FieldList[0]'ENTRIES : 1,-1
  150.         CASE FieldInfo[i]
  151.           WHEN "RichText"              ! OK for main & supplementary targets
  152.             NOTHING
  153.           WHEN "Text"                  ! OK for supplementary field update,
  154.           DO                           ! but not for main target field.
  155.             DELETE FieldList[i]
  156.             DELETE FieldInfo[i]
  157.           END
  158.           OTHERWISE                    ! Cannot update this field.
  159.           DO
  160.             DELETE FieldList[i]
  161.             DELETE FieldInfo[i]
  162.             DELETE SFieldList[i]
  163.           END
  164.         END
  165.       END
  166.       INSERT FieldList[1] = ""
  167.       INSERT FieldInfo[1] = ""
  168.       INSERT SFieldList[1] = ""
  169.     END
  170.  
  171.   END
  172.  
  173. END
  174. !
  175. ! ON DATA
  176. ! This block responds to controls which can accept data entry.
  177. ! It is executed whenever the cursor leaves the control after
  178. ! data has been changed. This is normally used to provide input
  179. ! validation.
  180. !
  181. ON DATA
  182. DO
  183.   CASE A.System.Object
  184.     !
  185.   END
  186. END
  187. !
  188. ! ON QUIT
  189. ! This block is executed when the user uses Close in the
  190. ! system menu.
  191. ! For a secondary window this would imply, 'shut the window'.
  192. ! For a primary window the implication is, 'close the
  193. ! Application'.
  194. !
  195. ON QUIT
  196. DO
  197.   CASE A.System.Object
  198.  
  199.     WHEN "T..W_ToNotes"                           ! primary window
  200.       RUN PROGRAM ThisTask, STOP
  201.  
  202.     OTHERWISE
  203.       SHUT ?A.System.Object
  204.  
  205.   END
  206. END
  207. !
  208. ! ON DESKTOP
  209. ! This block is signaled if the user modifies the window in any
  210. ! way, for example, resizing or using the maximize or minimize
  211. ! icons. Code here will take account of any such actions, for
  212. ! example, by resizing controls to account for a new window
  213. ! size.
  214. !
  215. ON DESKTOP
  216. DO
  217.   CASE A.System.Object
  218.     WHEN "T..W_ToNotes"
  219.     DO
  220.       CASE A.System.Operation
  221.         WHEN "MIN"
  222.         DO
  223.           !
  224.         END
  225.         !
  226.         WHEN "NORM"
  227.         DO
  228.           !
  229.         END
  230.         !
  231.         WHEN "SIZE"
  232.         DO
  233.           ! Respond to window sizing ( for example by
  234.           ! repositioning or resizing controls )
  235.         END
  236.         !
  237.       END
  238.     END
  239.   END
  240. END
  241. !
  242. ! ON SOURCE
  243. ! This event is signalled when there has been Direct Manipulation
  244. ! between this application and some other application.
  245. ! This applications Source window has been dropped onto a target
  246. ! window. The owner of the target window is asking for data about
  247. ! this application.
  248. !
  249. ON SOURCE(pStream)
  250. DO
  251.   DECLARE POINTER pStream
  252.   !
  253.   CASE (?pStream)'FORMAT
  254.     !
  255.     WHEN "IBMAPPLICATN"
  256.     DO
  257.       IF (?pStream)'REFERENCE
  258.       DO
  259.         OPEN REFERENCE Reference,
  260.          SOURCETYPE = "FILE",
  261.          NAME       = NAME(AppIdentifier),
  262.          LOCATION   = LOCATION(AppIdentifier)
  263.  
  264.         CALL Reference'SAVE(pStream)
  265.         SHUT Reference
  266.       END
  267.     END
  268.     !
  269.     ! Add code for any other formats here
  270.     !
  271.   END
  272.   !
  273.   CALL (?pStream)'FINISHED()
  274.   SHUT(?pStream)
  275. END
  276. !
  277. ! This procedure sets up a SOURCECTRL object for direct manipulation and DDE
  278. ! actions.
  279. !
  280. PROCEDURE Source_Define
  281. DO
  282.   OPEN SOURCECTRL SourceCtrl,
  283.    OBJECTNAME  = AppIdentifier,
  284.    PRINTABLE   = 0,                               ! Can it be dragged to the printer?  If set the ON PRINT block is called
  285.    DISCARDABLE = 0,                               ! Can it be dragged to the shredder? If Set the ON DISCARD block is called
  286.    OPERATIONS  = "L"
  287.   !
  288.   CALL SourceCtrl'SETIMAGE("DLL", "FTBICONS<168>")
  289.   CALL SourceCtrl'AddFormat("IBMAPPLICATN", 1)
  290.   !
  291.   ! Any other formats you wish to render should be added here.
  292.   !
  293. END
  294. !
  295. ! Template for the ON TARGET block.
  296. ! This event is signalled when there has been Direct Manipulation
  297. ! between this application and some other application.
  298. ! This applications Source window has had an Icon dropped onto it
  299. ! from some other application. This application can now ask questions
  300. ! to find out what's been dropped, and take the appropriate action.
  301. !
  302. ON TARGET(pStream)
  303. DO
  304.   DECLARE POINTER pStream
  305.   DECLARE CHAR[8] AppendOrReplace
  306.  
  307.   CALL W_ToNotes'FLUSH()               ! Make sure all data entry is detected.
  308.  
  309.   !
  310.   IF T.W_ToNotes.REPLACE[0]'CHECKED = 1
  311.     AppendOrReplace = "REPLACE"
  312.   ELSE
  313.     AppendOrReplace = "APPEND"
  314.  
  315.   DEFINE SuppFields[0]                 ! Names of supplementary fields to update
  316.   DEFINE SuppValues[0]                 ! Values with which to update supplementary
  317.                                        ! fields.
  318.   IF \NOVALUE(SField1)                 ! If user specified a first supp. field
  319.   DO
  320.     INSERT SuppFields[0] = SField1
  321.     INSERT SuppValues[0] = VALUE(SVal1,"")
  322.   END
  323.   IF \NOVALUE(SField2)                 ! If user specified a first supp. field
  324.   DO
  325.     INSERT SuppFields[0] = SField2
  326.     INSERT SuppValues[0] = VALUE(SVal2,"")
  327.   END
  328.  
  329.   CASE
  330.     ! Add the formats you are accepting and what you want to do with them
  331.     ! here.
  332.  
  333.     WHEN (?pStream)'FORMAT = "IBMREPORT"
  334.     DO
  335.       IF Valid_Parms()=No              ! check to ensure that all necessary
  336.       DO                               ! parameters are entered
  337.         ERROR 10002,"Please supply all necessary details.  (Document ID is the only "||
  338.          "optional item.)"
  339.  
  340.         CALL (?pStream)'FINISHED()     ! shut the STREAM object
  341.         SHUT ?pStream                  ! if all parms were not supplied
  342.  
  343.         RETURN                         ! return to Wait state
  344.       END
  345.  
  346.       OutPutFile = String("_\REPORT.TXT",g_CurLoc)
  347.  
  348.       CALL Sys'INCLUDETEMP( OutPutFile )
  349.  
  350.       OPEN REFERENCE Reference         ! open a reference object and get the name
  351.       CALL Reference'LOAD(pStream)     ! of the report dropped and passed via the stream
  352.  
  353.       OPEN IBMREPORT ThisReport,
  354.        IDENTIFIER = FULLPATH(Reference'LOCATION,Reference'NAME)
  355.  
  356.       LET DILText = "Saving report to text file..."
  357.  
  358.       CALL ThisReport'COPYTO(OutputFile,"TEXT")
  359.  
  360.       CALL Lotus'StoreInNotes(
  361.            FieldName,                  ! the name of the RichText field for the Report
  362.            NotesDocumentId,            ! the Document to update (or empty to create a new one)
  363.            OutputFile,                 ! the Report output file (must have extension of TXT)
  364.            AppendOrReplace,
  365.            POINTER(SuppFields[0]),     ! pointer to list of fields to update
  366.            POINTER(SuppValues[0]) )    ! pointer to list of values to use
  367.  
  368.       IF Lotus'CODE = 0
  369.         LET DILText = "Report saved in Notes database..."
  370.       ELSE
  371.         LET DILText = STRING("Error _ _ saving report in Notes database...",
  372.          Lotus'CODE,Lotus'REASON)
  373.  
  374.       SHUT Reference                              ! shut the reference object
  375.  
  376.       SHUT ThisReport                             ! and then the Report
  377.  
  378.     END
  379.  
  380.     WHEN (?pStream)'FORMAT = "IBMCHART"
  381.     DO
  382.       IF Valid_Parms()=No                         ! check to ensure that all necessary
  383.       DO                                          ! parameters are entered
  384.         ERROR 10002,"Please supply all necessary details.  (Document ID is the only "||
  385.          "optional item.)"
  386.  
  387.         CALL (?pStream)'FINISHED()                ! shut the STREAM object
  388.         SHUT ?pStream                             ! if all parms were not supplied
  389.  
  390.         RETURN                                    ! return to Wait state
  391.       END
  392.  
  393.       OutPutFile = String("_\CHART.PCX",g_CurLoc)
  394.       CALL Sys'INCLUDETEMP( OutPutFile )
  395.  
  396.       OPEN REFERENCE Reference                    ! open a reference object and get the name
  397.       CALL Reference'LOAD(pStream)                ! of the chart dropped and passed via the stream
  398.  
  399.       OPEN ?"IBMCHART" ThisChart,
  400.        IDENTIFIER = FULLPATH(Reference'LOCATION,Reference'NAME)
  401.  
  402.       IF A.System.ErrorNumber
  403.       DO
  404.         ERROR 1,"The chart could not be opened, or Visualizer Charts has not "||
  405.          "been installed."
  406.         RETURN
  407.       END
  408.  
  409.       LET DILText = "Saving chart to a graphics file..."
  410.  
  411.       CALL ThisChart'COPYTO(OutputFile,"PCX")
  412.  
  413.       CALL Lotus'StoreInNotes(
  414.        FieldName,                        ! the name of the RichText field for the Chart
  415.        NotesDocumentId,                  ! the Document to update (or empty to create a new one)
  416.        OutputFile,                       ! the Chart output file (must have extension of PCX or BMP)
  417.        AppendOrReplace,
  418.        POINTER(SuppFields[0]),           ! pointer to list of fields to update
  419.        POINTER(SuppValues[0]) )          ! pointer to list of values to use
  420.  
  421.  
  422.       IF Lotus'CODE = 0
  423.         LET DILText = "Chart saved in Notes database..."
  424.       ELSE
  425.         LET DILText = STRING("Error _ _ saving chart in Notes database...",
  426.          Lotus'CODE,Lotus'REASON)
  427.  
  428.       SHUT Reference                              ! shut the reference object
  429.  
  430.       SHUT ThisChart                              ! and then the Chart
  431.  
  432.     END
  433.  
  434.     WHEN ( (?pStream)'FORMAT = "RTF" |
  435.            (?pStream)'FORMAT = "TXT" |
  436.            (?pStream)'FORMAT = "PCX"   )
  437.     DO
  438.       IF Valid_Parms()=No                         ! check to ensure that all necessary
  439.       DO                                          ! parameters are entered
  440.         ERROR 10002,"Please supply all necessary details.  (Document ID is the only "||
  441.          "optional item.)"
  442.  
  443.         CALL (?pStream)'FINISHED()                ! shut the STREAM object
  444.         SHUT ?pStream                             ! if all parms were not supplied
  445.  
  446.         RETURN                                    ! return to Wait state
  447.       END
  448.  
  449.       OPEN REFERENCE Reference                    ! open a reference object and get the name
  450.       CALL Reference'LOAD(pStream)                ! of the report dropped and passed via the stream
  451.  
  452.       InputFile = FULLPATH(Reference'LOCATION,Reference'NAME)
  453.  
  454.       CALL Lotus'StoreInNotes(
  455.        FieldName,                        ! the name of the RichText field for the Chart
  456.        NotesDocumentId,                  ! the Document to update (or empty to create a new one)
  457.        InputFile,                        ! the file whose contents are to be stored
  458.        AppendOrReplace,
  459.        POINTER(SuppFields[0]),           ! pointer to list of fields to update
  460.        POINTER(SuppValues[0]) )          ! pointer to list of values to use
  461.  
  462.  
  463.       IF Lotus'CODE = 0
  464.         LET DILText =
  465.           STRING("^ saved in Notes database...",InputFile)
  466.       ELSE
  467.         LET DILText = STRING("Error: _1 _2",
  468.          Lotus'CODE,Lotus'REASON)
  469.  
  470.       SHUT Reference
  471.     END
  472.   END
  473.  
  474.   CALL (?pStream)'FINISHED()                      ! shut the STREAM object
  475.   SHUT ?pStream                                   ! that was passed to this block
  476. END
  477.  
  478.  
  479. !
  480. ! This procedure sets up a TARGETCTRL object for use by DDE and
  481. ! Direct Manipulation.
  482. !
  483. PROCEDURE Target_Define
  484. DO
  485.   OPEN TARGETCTRL TargetCtrl
  486.   !
  487.   ! Add any formats you wish to accept here.
  488.   !
  489.  
  490.   CALL TargetCtrl'ADDFORMAT("IBMCHART","CML",1)   ! enable Charts to be dropped on our window
  491.   CALL TargetCtrl'ADDFORMAT("IBMREPORT","CML",1)  ! enable Reports to be dropped on our window
  492.   CALL TargetCtrl'ADDFORMAT("RTF","CML",1)        ! enable RTF files to be dropped on our window
  493.   CALL TargetCtrl'ADDFMTEXT("RTF","RTF")
  494.   CALL TargetCtrl'ADDFORMAT("PCX","CML",1)        ! enable PCX files to be dropped on our window
  495.   CALL TargetCtrl'ADDFMTEXT("PCX","PCX")
  496.   CALL TargetCtrl'ADDFORMAT("TXT","CML",1)        ! enable TXT files to be dropped on our window
  497.   CALL TargetCtrl'ADDFMTEXT("TXT","TXT")
  498. END
  499. !
  500. ! ERROR event
  501. ! This block is executed when there is a run-time error.
  502. ! You can trap errors here or allow the error message provided
  503. ! to identify the error and stop the program.
  504. !
  505.  
  506. ON ERROR
  507. DO
  508.   DECLARE CHAR[7] ans
  509.   DECLARE NUMERIC i
  510.   !
  511.   ! Message to identify failing module and line
  512.   !
  513.   LET ans = DIALOG("FTB7004", 0,
  514.    A.System.ErrorModule,
  515.    A.System.ErrorLine)
  516.  
  517.   DO i = 1 : A.System.ErrorNumber[0]'ENTRIES
  518.     IF ans = "CANCEL"
  519.       TERMINATE
  520.       !
  521.       ! Display system message corresponding to error
  522.       !
  523.     LET ans = DIALOG ("FTB" || A.System.Errornumber[i], 0,
  524.      A.System.ErrorInfo[i])
  525.   END
  526.  
  527.   STOP
  528. END
  529. !
  530. ! ON STOP
  531. ! This block is executed when the program is terminated.
  532. ! You should use the block to carry out any housekeeping
  533. ! required before closing
  534. !
  535. ON STOP
  536. DO
  537.   LET DILText = "Disconnecting from Lotus Notes..."
  538.   CALL W_ToNotes'REFRESH()
  539.  
  540.   SHUT Lotus
  541.   !
  542.   STOP
  543. END
  544. !
  545. ! User specified procedures may have up to 20 passed parameters.
  546. ! Procedures may be called as functions (using the RETURN
  547. ! facility to return a value) or may be called as normal
  548. ! procedures.
  549. !
  550. PROCEDURE Valid_Parms
  551. DO
  552.   IF NOVALUE(NotesDB)=Yes |                       ! is the database name empty?
  553.      NOVALUE(NotesForm)=Yes |                       ! is the Formname empty?
  554.      NOVALUE(FieldName)=Yes                         ! is the RichTextField name empy?
  555.     RETURN No                                     ! if so, then return a 0 (No)
  556.   ELSE
  557.     RETURN Yes                                    ! if not return a 1 (Yes)
  558. END
  559.