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

  1. !.HEADER
  2. !.SPEC APPDEST 0 D:\DESKTOP\VIS2LONO\LNQ.APL
  3. !.HEADER
  4. !
  5. !
  6. ! Program Name     - LNQMAIN.PRG
  7. !
  8. ! Program Function - Key Task for the Sample Lotus Notes Query application
  9. !                    This program controls the major portion of the user-interface
  10. !                    and collects information from each of the programs listed below
  11. !                    in order to query the Lotus Notes database and retrieve the
  12. !                    selected documents and fields.
  13. !
  14. ! Called by        - <none>
  15. !
  16. ! Calls            - FILES.PRG     Selection of the Notes Database & Form
  17. !                    RENFLD.PRG    Renaming of Notes fieldnames
  18. !                    SELFLD.PRG    Selection of Notes fields
  19. !                    SELDOC.PRG    Selection of Notes documents
  20. !                    MSG.PRG       Display of error messages
  21. !
  22. !                    LOTUSNOTES    Object provided by ASL Wrapper to PAS2LONO.DLL
  23. !
  24. !
  25. ! The LOTUSNOTES object provides all of the! function necessary to get data from Lotus
  26. ! Notes databases.  An overview of the function capabilities follows:
  27. !
  28. !
  29. !   Initiate conversation with Notes         "OPEN"
  30. !   Request a list of servers from Notes     "GetServerList"
  31. !   Request a list of files on a server      "GetFileList"
  32. !   Request a list of forms in a database    "GetFormList"
  33. !   Request a list of fields on a form       "GetFormFieldList"
  34. !   Create an ASL table with query results   "CreateProductTable"
  35. !   Terminate the conversation with Notes    "CLOSE"
  36. !.spec winsize 420 118
  37. !.spec textcol 0 17
  38. !.spec appdest 1 d:\desktop\vis2lono\LNQ.apl
  39. !.HEADER
  40. !
  41. ! DEFINITION
  42. ! Some ASL commands can be placed outside of the normal block
  43. ! structure. This block is provided to allow such commands to
  44. ! be accomodated
  45. !
  46. ! Assign boolean variables
  47. !
  48. DECLARE TASK NUMERIC yes = 1
  49. DECLARE TASK NUMERIC no  = 0
  50. !
  51. DECLARE TASK CHAR[4] ThisTask = A.System.ThisTask
  52. DECLARE POINTER perror
  53.  
  54. !
  55. ! Open the library and declare the required functions
  56. !
  57. LIBRARY ASL "MyLib..AppDevL",
  58.  Files,
  59.  SaveAs,
  60.  File_Put,
  61.  File_Get,
  62.  Print,
  63.  Help_SetUp,
  64.  App_Help,
  65.  App_Icon
  66. !
  67. ! ON SELECT
  68. ! This block is triggered whenever the user selects a control
  69. ! or menu entry.
  70. !
  71. ON SELECT
  72. DO
  73.   LET A.System.Object = Toolbar'FILTER(           ! Call the Toolbar object to handle SELECTs
  74.    A.System.Event,                                ! on the toolbar and set the standard variables
  75.    A.System.Object,                               ! A.System.Object, etc. to the appropriate objectnames
  76.    A.System.BoxNumber)                            ! set in the TOOLDATA vector
  77.   !
  78.   ! Filter selections on the help menu
  79.   IF App_Help()
  80.     RETURN
  81.     !
  82.  
  83.   CASE A.System.Object
  84.     !
  85.     WHEN "T.W_lnqmain.HelpButton"
  86.     DO
  87.       ! list box set for single select mode
  88.       LET Rc =  Sys'COMMANDCODE("VIEW " ||        ! view the online help file
  89.        FULLPATH(A.System.StartDS'LOCATION,        ! in INF format
  90.        "LNQ.INF"))
  91.     END
  92.     !
  93.     !
  94.     WHEN "T.W_lnqmain.Save"                       ! currently unavailable
  95.     DO
  96.       ! Respond to Menu entry marked '"Save"'
  97.     END
  98.     !
  99.     WHEN "T.W_lnqmain.CopyTo"                     ! currently unavailable
  100.     DO
  101.       ! Respond to Menu entry marked '"Copy To..."'
  102.     END
  103.     !
  104.     WHEN "T.W_lnqmain.SelectDocuments"
  105.     DO
  106.       ! Respond to Menu entry marked '"Select Documents"'
  107.       IF UNKNOWN(p_SelDoc)
  108.         START PROGRAM p_SelDoc,"I.modules.SelDoc",
  109.          START(
  110.          POINTER(W_lnqmain[0]),                   ! ownerwindow alias
  111.          POINTER(Selection[0]))                   ! pointer to selection vector
  112.       ELSE
  113.         RUN PROGRAM p_SelDoc
  114.  
  115.     END
  116.     !
  117.     WHEN "T.W_lnqmain.RenameFields"
  118.     DO
  119.       ! Respond to Menu entry marked '"Rename Fields"'
  120.  
  121.       IF UNKNOWN(p_RenFld)
  122.         START PROGRAM p_RenFld,"I.modules.RenFld",! display dialog to change names
  123.          START(POINTER(ColumnDerivation[0]),      ! original names
  124.          POINTER(ColumnName[0]),                  ! new names
  125.          POINTER(ColumnSelectFlag[0]),            ! selected columns
  126.          POINTER(W_lnqmain[0]))                   ! Ownerwindow alias
  127.       ELSE
  128.         RUN PROGRAM p_RenFld
  129.     END
  130.     !
  131.     WHEN "T.W_lnqmain.SelectFields"
  132.     DO
  133.       ! Respond to Menu entry marked '"Select Fields"'
  134.  
  135.       IF UNKNOWN(p_SelFld)
  136.         START PROGRAM p_SelFld,"I.modules.SelFld",
  137.          START(POINTER(ColumnSelectFlag[0]),      ! vector of selected columns
  138.          POINTER(ColumnName[0]),                  ! column names
  139.          POINTER(W_lnqmain[0]))                   ! ownerwindow alias
  140.       ELSE
  141.         RUN PROGRAM p_SelFld
  142.  
  143.       WAIT PROGRAM p_SelFld
  144.  
  145.       LET T.W_lnqmain.LIST1[0]'ORDERDATA = ColumnSelectFlag[0]
  146.     END
  147.     !
  148.     WHEN "T.W_lnqmain.Run"
  149.     DO
  150.       ! Respond to Menu entry marked '"Run"'
  151.       LET ResultsName = Run_Query()               ! run the query
  152.       CALL Open_Table(ResultsName)          ! and display the results in Table Editor
  153.  
  154.     END
  155.     WHEN "T.W_lnqmain.Messages"                   ! display the error messages
  156.     DO
  157.       DEFINE A.Lotus.ErrorInfo[0]                      ! Get Error Info from Lotus Object
  158.       pERROR=POINTER(A.Lotus.ErrorInfo[0])      ! Into A.Lotus.ErrorInfo
  159.       FORGIVE                                                !  which will be referenced by the
  160.            CALL LOTUS'GetErrorInfo(pError)         ! Message Program
  161.       IF UNKNOWN(p_Messages)
  162.       ! Respond to Menu entry marked '"Messages"'
  163.         START PROGRAM p_Messages,"I.Modules.Msg",
  164.          START(
  165.          POINTER(W_lnqmain[0]))                   ! ownerwindow alias
  166.       ELSE
  167.         RUN PROGRAM p_Messages
  168.     END
  169.  
  170.     !
  171.     WHEN "T.W_lnqmain.Print"                      ! currently unavailable
  172.     DO
  173.       ! Respond to Menu entry marked '"Print..."'
  174.     END
  175.     !
  176.     !
  177.     !
  178.     WHEN "T.W_lnqmain.Toolbar"                    ! currently unavailable
  179.     DO
  180.       ! Respond to Menu entry marked '"Toolbar"'
  181.     END
  182.     !
  183.     WHEN "T.W_lnqmain.SelectForm"
  184.     DO
  185.       ! Respond to Menu entry marked '"Select Form..."'
  186.       !
  187.  
  188.       IF UNKNOWN(p_Files)                         ! if not started
  189.         START PROGRAM p_files,"I.Modules.Files",  ! then start the program
  190.          START(POINTER(W_lnqmain[0]),             ! ownerwindow alias
  191.          POINTER(Lotus[0]))                       ! Lotus Notes Object
  192.       ELSE                                        ! otherwise
  193.         RUN PROGRAM p_Files,QUEUE()               ! just pass control to it
  194.  
  195.       WAIT PROGRAM p_files                        ! wait for its signal
  196.  
  197.       IF NOVALUE(Form)                            ! if no form selected
  198.         RETURN                                    ! then go no farther
  199.  
  200.       LET DataSource = "Data Source - "||Server|| ! update on-screen scalar
  201.        IF(SPLIT(Directory,1,1)\="\","\","")||     ! that displays where data
  202.       Directory||"\"||Form                        ! comes from
  203.  
  204.       ! check for new form name here
  205.  
  206.       CALL Get_Field_Info()                       ! get details on Fields from the Form
  207.  
  208.       CALL Set_Toolbar_State("UP")                ! enable Toolbar
  209.  
  210.     END
  211.   END
  212. END
  213. !
  214. ! ON START
  215. ! This block is executed when the program is initially invoked.
  216. ! It is normally used to initialize variables needed during
  217. ! program execution and to open the main window of the
  218. ! application.
  219. !
  220. ON START(FileName, AppIdentifier, AppName)
  221. DO
  222.   !
  223.   ! Open the object store holding the user library
  224.   !
  225.   OPEN OBJECTSTORE MyLib,
  226.    NAME ="UserLib.A95",
  227.    LOCATION = S.Control.Path
  228.  
  229.   FORGIVE
  230.     OPEN LOTUSNOTES Lotus                         ! Open the Lotus Notes Object
  231.   IF A.System.ErrorNumber
  232.   DO
  233.     ERROR 1,"Unable to open LotusNotes Object. Check that Lotus Notes is installed" ||
  234.             " correctly. The Lotus Notes directory must be in PATH and LIBPATH."
  235.     STOP
  236.   END
  237.  
  238.  
  239.   OPEN SYSTEM Sys                                 ! access OS/2 facilities
  240.  
  241.   OPEN PROFILE Prof
  242.   !
  243.   ! Assign all variables referred by the windows
  244.   !
  245.   LET DataSource = "Data Source - (none)"         ! used by Text control named 'T.W_lnqmain.TEXT3'
  246.   LET Server     = ""
  247.   LET Directory  = ""
  248.   LET Form       = ""
  249.   ! valid characters for ASL column names
  250.   LET ValidCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
  251.  
  252.   ! Obtain Current Directory
  253.   g_CurLoc = A.System.StartDs'Location
  254.   IF Split(g_CurLoc,Length(g_CurLoc),1) = "\"
  255.     g_CurLoc = Split(g_CurLoc,1,Length(g_CurLoc)-1)
  256.  
  257.  
  258.   DEFINE Selection[1]
  259.   !
  260.   ! Open an instance of the clipboard
  261.   OPEN CLIPBOARD clip
  262.   !
  263.   ! Open the help object and identify (dummy) file holding compiled text
  264.   !
  265.   OPEN HELP Help
  266.   CALL Help_SetUp("SampHelp.Hlp", "Help")
  267.   !
  268.   ! Call procedure to define data for list control(s)
  269.   !
  270.   CALL List_Define
  271.  
  272.   !
  273.   OPEN WINDOW W_lnqmain,, "I.Windows.lnqmain",
  274.    VISIBLE=No
  275.  
  276.   LET MarginRight = W_lnqmain'SIZEX -             ! get margins for use
  277.    T.W_lnqmain.LIST1'SIZEX -                      ! when window is resized
  278.    T.W_lnqmain.LIST1'X                            ! and DESKTOP event is triggered
  279.  
  280.   LET MarginTop = W_lnqmain'SIZEY -
  281.    T.W_lnqmain.LIST1'SIZEY -
  282.    T.W_lnqmain.LIST1'Y
  283.  
  284.   CALL Open_Toolbar                               ! add a toolbar to the window
  285.   !
  286.   CALL App_Icon(POINTER(W_lnqmain[0]))
  287.   !
  288.   ! assign the column titles for list controlLIST1
  289.   LET T.W_lnqmain.LIST1'COLTITLE1="Title_1"
  290.  
  291.   CALL Set_Toolbar_State("DISABLED")              ! disable toolbar (except Table & Help)
  292.  
  293.   MODIFY W_LnqMain,                               ! prohibit window from being
  294.    MINX = W_LnqMain'SIZEX,                        ! sized smaller than when it
  295.    MINY = W_LnqMain'SIZEY,                        ! was opened
  296.    VISIBLE=Yes                                    ! show the window
  297.  
  298.  
  299. END
  300. !
  301. ! Construct the arrays needed to support list controls
  302. !
  303. PROCEDURE List_Define
  304. DO
  305.   !
  306.   ! Define data to handle list 'T.W_lnqmain.LIST1'
  307.   !
  308.   DEFINE ColumnsC[0]                              ! REFERENCE vector
  309.   DEFINE LayoutC[0]                               ! EXPRESSION vector
  310.   !
  311.   ! fill the EXPRESSION vector
  312.   !
  313.   INSERT LayoutC[0]="WIDTH=100 SEPARATOR=YES JUST=LEFT READONLY=YES"
  314.   INSERT LayoutC[0]="WIDTH=100 SEPARATOR=YES JUST=LEFT READONLY=YES"
  315.   INSERT LayoutC[0]="WIDTH=85 SEPARATOR=YES JUST=LEFT READONLY=YES"
  316.   INSERT LayoutC[0]="WIDTH=200 SEPARATOR=YES JUST=LEFT READONLY=YES"
  317.   !
  318.   ! Initialise the referred vectors. These are the vectors
  319.   ! which will contain the data to be displayed
  320.   !
  321.   DEFINE ColumnName[0]
  322.   DEFINE ColumnDerivation[0]
  323.   DEFINE ColumnType[0]
  324.   DEFINE ColumnComment[0]
  325.   !
  326.   ! fill the REFERENCE vector to point to these vectors
  327.   !
  328.   INSERT ColumnsC[0] = "ColumnName"
  329.   INSERT ColumnsC[0] = "ColumnDerivation"
  330.   INSERT ColumnsC[0] = "ColumnType"
  331.   INSERT ColumnsC[0] = "ColumnComment"
  332.   !
  333.   ! create and fill the titles vector
  334.   !
  335.   DEFINE Title_1[0]
  336.   INSERT Title_1[0] = "Name"
  337.   INSERT Title_1[0] = "Notes Fieldname"
  338.   INSERT Title_1[0] = "Type"
  339.   INSERT Title_1[0] = "Comment"
  340. END
  341. !
  342. ! ON QUIT
  343. ! This block is executed when the user uses Close in the
  344. ! system menu.
  345. ! For a secondary window this would imply, 'shut the window'.
  346. ! For a primary window the implication is, 'close the
  347. ! Application'.
  348. !
  349. ON QUIT
  350. DO
  351.   CASE A.System.Object
  352.  
  353.     WHEN "T..W_lnqmain"                           ! primary window
  354.       RUN PROGRAM ThisTask, STOP
  355.  
  356.     OTHERWISE
  357.       SHUT ?A.System.Object
  358.  
  359.   END
  360. END
  361. !
  362. ! ON DESKTOP
  363. ! This block is signaled if the user modifies the window in any
  364. ! way, for example, resizing or using the maximize or minimize
  365. ! icons. Code here will take account of any such actions, for
  366. ! example, by resizing controls to account for a new window
  367. ! size.
  368. !
  369. ON DESKTOP
  370. DO
  371.   CASE A.System.Object
  372.     WHEN "T..W_lnqmain"
  373.     DO
  374.       CASE A.System.Operation
  375.         WHEN "MAX"
  376.         DO
  377.           ! change the list box dimensions based upon window changes
  378.  
  379.           MODIFY T.W_lnqmain.LIST1,
  380.            SIZEX = T..W_lnqmain'SIZEX - MarginRight -
  381.            T.W_lnqmain.LIST1'X,
  382.            SIZEY = T..W_lnqmain'SIZEY - MarginTop -
  383.            T.W_lnqmain.LIST1'Y
  384.  
  385.         END
  386.         !
  387.         WHEN "NORM"
  388.         DO
  389.           ! change the list box dimensions based upon window changes
  390.  
  391.           MODIFY T.W_lnqmain.LIST1,
  392.            SIZEX = T..W_lnqmain'SIZEX - MarginRight -
  393.            T.W_lnqmain.LIST1'X,
  394.            SIZEY = T..W_lnqmain'SIZEY - MarginTop -
  395.            T.W_lnqmain.LIST1'Y
  396.         END
  397.         !
  398.         WHEN "SIZE"
  399.         DO
  400.           ! change the list box dimensions based upon window changes
  401.  
  402.           MODIFY T.W_lnqmain.LIST1,
  403.            SIZEX = T..W_lnqmain'SIZEX - MarginRight -
  404.            T.W_lnqmain.LIST1'X,
  405.            SIZEY = T..W_lnqmain'SIZEY - MarginTop -
  406.            T.W_lnqmain.LIST1'Y
  407.         END
  408.         !
  409.       END
  410.     END
  411.   END
  412. END
  413. !
  414. ! ERROR event
  415. ! This block is executed when there is a run-time error.
  416. ! You can trap errors here or allow the error message provided
  417. ! to identify the error and stop the program.
  418. !
  419.  
  420. ON ERROR
  421. DO
  422.   DECLARE CHAR[7] ans
  423.   DECLARE NUMERIC i
  424.   !
  425.   ! Message to identify failing module and line
  426.   !
  427.   LET ans = DIALOG("FTB7004", 0,
  428.    A.System.ErrorModule,
  429.    A.System.ErrorLine)
  430.  
  431.   DO i = 1 : A.System.ErrorNumber[0]'ENTRIES
  432.     IF ans = "CANCEL"
  433.       TERMINATE
  434.       !
  435.       ! Display system message corresponding to error
  436.       !
  437.     LET ans = DIALOG ("FTB" || A.System.Errornumber[i], 0,
  438.      A.System.ErrorInfo[i])
  439.   END
  440.  
  441.   RUN PROGRAM ThisTask,STOP
  442. END
  443. !
  444. ! ON STOP
  445. ! This block is executed when the program is terminated.
  446. ! You should use the block to carry out any housekeeping
  447. ! required before closing
  448. !
  449. ON STOP
  450. DO
  451.       SHUT Lotus                           ! Close the Lotus Notes Object
  452.  
  453.   STOP
  454. END
  455. !
  456. ! User specified procedures may have up to 20 passed parameters.
  457. ! Procedures may be called as functions (using the RETURN
  458. ! facility to return a value) or may be called as normal
  459. ! procedures.
  460. !
  461. PROCEDURE Open_Toolbar
  462. DO
  463.   ! Now we prepare the toolbar information arrays
  464.  
  465.   DEFINE tbarUp[0]                                /* array of UP bitmaps          */
  466.   DEFINE tbarDown[0]                              /* array of DOWN bitmaps        */
  467.   DEFINE tbarDis[0]                               /* array of DISABLED bitmaps    */
  468.  
  469.   DEFINE tbarLatch[0]                             /* array of latchable values    */
  470.   DEFINE tbarGroup[0]                             /* array of button groupings    */
  471.   DEFINE tbarToggle[0]                            /* array of toggle groupings    */
  472.   DEFINE tbarInit[0]                              /* array of initial states      */
  473.  
  474.   DEFINE tbarNames[0]                             /* array of button object names */
  475.   DEFINE tbarDesc[0]                              /* array of description texts   */
  476.   DEFINE tbarHelp[0]                              /* array of help text res IDs   */
  477.  
  478.   ! The UP bitmaps. Notice that bitmaps can be identified by
  479.   ! fully-qualified file name, or by DLL name and resource ID
  480.   INSERT tbarUp[0]     = "FTBBMPS<1070>"          ! save
  481.   INSERT tbarUp[0]     = "FTBBMPS<1075>"          ! copy to
  482.   INSERT tbarUp[0]     = "FTBBMPS<1080>"          ! print
  483.   INSERT tbarUp[0]     = "FTBBMPS<1000>"          ! select table
  484.   INSERT tbarUp[0]     = "FTBBMPS<1010>"          ! select rows
  485.   INSERT tbarUp[0]     = "FTBBMPS<1500>"          ! rename columns
  486.   INSERT tbarUp[0]     = "FTBBMPS<1005>"          ! select columns
  487.   INSERT tbarUp[0]     = "FTBBMPS<1030>"          ! run
  488.   INSERT tbarUp[0]     = "FTBBMPS<1105>"          ! help
  489.   ! The DOWN bitmaps.
  490.   INSERT tbarDown[0]     = "FTBBMPS<1071>"        ! save
  491.   INSERT tbarDown[0]     = "FTBBMPS<1076>"        ! copy to
  492.   INSERT tbarDown[0]     = "FTBBMPS<1081>"        ! print
  493.   INSERT tbarDown[0]     = "FTBBMPS<1001>"        ! select table
  494.   INSERT tbarDown[0]     = "FTBBMPS<1011>"        ! select rows
  495.   INSERT tbarDown[0]     = "FTBBMPS<1501>"        ! rename columns
  496.   INSERT tbarDown[0]     = "FTBBMPS<1006>"        ! select columns
  497.   INSERT tbarDown[0]     = "FTBBMPS<1031>"        ! run
  498.   INSERT tbarDown[0]     = "FTBBMPS<1106>"        ! help
  499.  
  500.   ! The DISABLED bitmaps.
  501.  
  502.   INSERT tbarDis[0]     = "FTBBMPS<1072>"         ! save
  503.   INSERT tbarDis[0]     = "FTBBMPS<1077>"         ! copy to
  504.   INSERT tbarDis[0]     = "FTBBMPS<1082>"         ! print
  505.   INSERT tbarDis[0]     = "FTBBMPS<1002>"         ! select table
  506.   INSERT tbarDis[0]     = "FTBBMPS<1012>"         ! select rows
  507.   INSERT tbarDis[0]     = "FTBBMPS<1502>"         ! rename columns
  508.   INSERT tbarDis[0]     = "FTBBMPS<1007>"         ! select columns
  509.   INSERT tbarDis[0]     = "FTBBMPS<1032>"         ! run
  510.   INSERT tbarDis[0]     = "FTBBMPS<1107>"         ! help
  511.  
  512.   ! Our third and fourth buttons are to be latchable
  513.   INSERT tbarLatch[0]  = 0
  514.   INSERT tbarLatch[0]  = 0
  515.   INSERT tbarLatch[0]  = 0
  516.   INSERT tbarLatch[0]  = 0
  517.   INSERT tbarLatch[0]  = 0
  518.   INSERT tbarLatch[0]  = 0
  519.   INSERT tbarLatch[0]  = 0
  520.  
  521.   INSERT tbarLatch[0]  = 0
  522.   INSERT tbarLatch[0]  = 0
  523.  
  524.   ! Keep the first one separate, and group the other three together
  525.   INSERT tbarGroup[0]  = 0
  526.   INSERT tbarGroup[0]  = 0                        /* large gap between first and second
  527.   INSERT tbarGroup[0]  = 0                        /* small gap between second and third
  528.   INSERT tbarGroup[0]  = 2                        /* no gap between the two that toggle
  529.   INSERT tbarGroup[0]  = 0                        /* no gap between the two that toggle
  530.   INSERT tbarGroup[0]  = 0
  531.   INSERT tbarGroup[0]  = 0
  532.   INSERT tbarGroup[0]  = 2
  533.   INSERT tbarGroup[0]  = 2
  534.  
  535.   ! Our second two buttons will toggle each other on and off
  536.   ! All the '1's form a toggle group, and the '2's, and so on
  537.   ! This only makes sense for latchable buttons
  538.   INSERT tbarToggle[0] = 0                        /* 0 = no toggling */
  539.   INSERT tbarToggle[0] = 0
  540.   INSERT tbarToggle[0] = 0
  541.   INSERT tbarToggle[0] = 0
  542.   INSERT tbarToggle[0] = 0
  543.   INSERT tbarToggle[0] = 0
  544.   INSERT tbarToggle[0] = 0
  545.  
  546.   INSERT tbarToggle[0] = 0
  547.   INSERT tbarToggle[0] = 0
  548.  
  549.   ! Initial states - all up, except button four which will be down
  550.   INSERT tbarInit[0]   = "UP"
  551.   INSERT tbarInit[0]   = "UP"
  552.   INSERT tbarInit[0]   = "UP"
  553.   INSERT tbarInit[0]   = "UP"
  554.   INSERT tbarInit[0]   = "UP"
  555.   INSERT tbarInit[0]   = "UP"
  556.   INSERT tbarInit[0]   = "UP"
  557.  
  558.   INSERT tbarInit[0]   = "UP"
  559.   INSERT tbarInit[0]   = "UP"
  560.  
  561.   ! Object names - we can choose these as we like
  562.   INSERT tbarNames[0]  = "T.w_lnqmain.Save"
  563.   INSERT tbarNames[0]  = "T.w_lnqmain.CopyTo"
  564.   INSERT tbarNames[0]  = "T.w_lnqmain.Print"
  565.   INSERT tbarNames[0]  = "T.W_lnqmain.SelectForm"
  566.   INSERT tbarNames[0]  = "T.w_lnqmain.SelectDocuments"
  567.   INSERT tbarNames[0]  = "T.w_lnqmain.RenameFields"
  568.   INSERT tbarNames[0]  = "T.w_lnqmain.SelectFields"
  569.   INSERT tbarNames[0]  = "T.w_lnqmain.Run"
  570.   INSERT tbarNames[0]  = "T.w_lnqmain.HelpButton"
  571.  
  572.  
  573.   ! Button description texts
  574.   INSERT tbarDesc[0]   = "Save"
  575.   INSERT tbarDesc[0]   = "Copy to..."
  576.   INSERT tbarDesc[0]   = "Print"
  577.   INSERT tbarDesc[0]   = "Select Form"
  578.   INSERT tbarDesc[0]   = "Select Documents"
  579.   INSERT tbarDesc[0]   = "Rename Fields"
  580.   INSERT tbarDesc[0]   = "Select Fields"
  581.   INSERT tbarDesc[0]   = "Run"
  582.   INSERT tbarDesc[0]   = "Help"
  583.  
  584.   ! Button help text res IDs
  585.   INSERT tbarHelp[0]   = 10192
  586.   INSERT tbarHelp[0]   = 10193
  587.   INSERT tbarHelp[0]   = 10194
  588.   INSERT tbarHelp[0]   = 10195
  589.   INSERT tbarHelp[0]   = 10195
  590.   INSERT tbarHelp[0]   = 10195
  591.   INSERT tbarHelp[0]   = 10195
  592.   INSERT tbarHelp[0]   = 10195
  593.   INSERT tbarHelp[0]   = 10195
  594.  
  595.   ! Now open the tool bar
  596.  
  597.   OPEN TBAR ToolBar, w_lnqmain,                   /* open tool bar on my window */
  598.    UP         = POINTER(tbarUp[0]),
  599.    DOWN       = POINTER(tbarDown[0]),
  600.    DISABLED   = POINTER(tbarDis[0]),
  601.    LATCH      = POINTER(tbarLatch[0]),
  602.    GROUP      = POINTER(tbarGroup[0]),
  603.    TOGGLE     = POINTER(tbarToggle[0]),
  604.    INISTATE   = POINTER(tbarInit[0]),
  605.    TOOLDATA   = POINTER(tbarNames[0]),
  606.    TOOLTEXT   = POINTER(tbarDesc[0]),
  607.    HELPIDS    = POINTER(tbarHelp[0]),
  608.    HELP       = POINTER(MyHelp[0]),
  609.    HELPGLOBAL = 10191,
  610.    VISIBLE    = 1
  611.  
  612.  
  613. END
  614. !
  615. ! User specified procedures may have up to 20 passed parameters.
  616. ! Procedures may be called as functions (using the RETURN
  617. ! facility to return a value) or may be called as normal
  618. ! procedures.
  619. !
  620. PROCEDURE Get_Field_Info
  621. DO
  622.   DEFINE FieldList[0]
  623.   DEFINE FieldType[0]
  624.   DEFINE ColumnList[0]
  625.  
  626.   ! 'push' button marked 'GetFieldList'
  627.   LET Lotus'Servername = Server                   ! Set Attributes
  628.   LET Lotus'Database = Database
  629.   LET Lotus'Formname = Form
  630.  
  631.   FORGIVE
  632.       CALL Lotus'GetFormFieldList( POINTER(FieldList[0]),  ! pointer to list of fields
  633.                           POINTER(FieldType[0]))  ! pointer to list of fieldtypes
  634.  
  635.   If LOTUS'CODE > 0
  636.      DO
  637.      MESSAGE "FTB0003",0,LOTUS'REASON
  638.      RETURN
  639.      END
  640.  
  641.  
  642.  
  643.   DEFINE ColumnTypeASL[0]
  644.   DEFINE ColumnName[0]
  645.   DEFINE ColumnDerivation[0]                      ! Notes fieldname (unedited)
  646.   DEFINE ColumnDerivationASL[0]                   ! Notes fieldname (ASL-valid)
  647.   DEFINE ColumnType[0]
  648.   DEFINE ColumnComment[0]
  649.   DEFINE ColumnSelectFlag[0]
  650.  
  651.  
  652.   DO cc=1:FieldList[0]'ENTRIES
  653.  
  654.     IF FieldList[cc]\=""                          ! ensure that no blanks exist
  655.     DO
  656.       LET ColRef = Valid_Name(                    ! test for a valid ASL column name
  657.        FieldList[cc],                             ! passing this current fieldname
  658.        POINTER(ColumnName[0]))                    ! and list of valid names so far
  659.  
  660.       CASE FieldType[cc]                          ! equate the Notes fieldtype to an ASL type
  661.         WHEN "Text"
  662.           LET ColType = "Character"
  663.  
  664.         WHEN "Number"
  665.           LET ColType = "Numeric"
  666.  
  667.         WHEN "Time/Date"
  668.           LET ColType = "Character"
  669.  
  670.         WHEN "RichText"
  671.           LET ColType="Character"
  672.  
  673.         WHEN "Multi-Value List"
  674.           LET ColType = "Character"
  675.  
  676.         OTHERWISE                                 ! default to Character data
  677.           LET ColType = "Character"
  678.  
  679.       END
  680.  
  681.       !
  682.       ! then assign values to ASL vectors for use later
  683.       !
  684.       INSERT ColumnName[0]       = ColRef         ! the valid ASL column name
  685.       INSERT ColumnDerivation[0] = FieldList[cc]  ! the fieldname it came from
  686.       INSERT ColumnDerivationASL[0] = ColRef      ! valid ASL name for backup (in case of user rename)
  687.       INSERT ColumnComment[0]    = ""             ! comment for later support
  688.       INSERT ColumnSelectFlag[0] = cc             ! indicates selection of column (default all)
  689.       INSERT ColumnType[0]       = FieldType[cc]  ! Notes fieldtype
  690.       INSERT ColumnTypeASL[0]    = ColType        ! equivalent ASL type
  691.     END
  692.   END
  693. END
  694. !
  695. ! User specified procedures may have up to 20 passed parameters.
  696. ! Procedures may be called as functions (using the RETURN
  697. ! facility to return a value) or may be called as normal
  698. ! procedures.
  699. !
  700. PROCEDURE Valid_Name(pOriginalName,pAlreadyExists)
  701. DO
  702.   DECLARE LOCAL NUMERIC InvalidChars=Yes
  703.   !
  704.   ! step one is to get rid of invalid characters for an ASL column
  705.   ! name ($,etc)
  706.   !
  707.   WHILE InvalidChars
  708.   DO
  709.     LET InvalidChars=SCAN(
  710.      pOriginalName,
  711.      ValidCharacters,,,"\=",1)
  712.  
  713.     IF InvalidChars                               ! if an invalid character
  714.       LET pOriginalName =                         ! is found in the Notes fieldname
  715.        OVERLAY(pOriginalName,"_",InvalidChars)    ! then it should be replaced with an underscore
  716.   END
  717.   !
  718.   ! next step is to truncate the column name to the ASL
  719.   ! limit and see if this new name already exists
  720.   ! if it does exist then begin changing the name starting at
  721.   ! the end using numerics 0-9
  722.   !
  723.   LET CharToChange=20
  724.   LET NextChar=1
  725.  
  726.   LET NewName=SPLIT(pOriginalName,1,20)           ! get first 20 chars since ASL limit is 20
  727.  
  728.   LET AlreadyThere=FIND(                          ! look for this column name
  729.    (?pAlreadyExists),                             ! in the vector passed into procedure
  730.    NewName)                                       ! this is the column to look for
  731.  
  732.   WHILE AlreadyThere                              ! if a column already exists
  733.   DO                                              ! by this same column name
  734.     LET NewName=SPLIT(                            ! generate a new name
  735.      NewName,1,CharToChange-1) || NextChar
  736.  
  737.     LET AlreadyThere=FIND(                        ! and then look for it
  738.      (?pAlreadyExists),                           ! in the same vector
  739.      NewName)
  740.  
  741.     LET NextChar+=1                               ! increase counter for trailing character
  742.  
  743.     IF NextChar=10                                ! if we just bumped up to our limit
  744.     DO                                            ! for a single character
  745.       LET NextChar=1                              ! then reset char to 0
  746.       LET CharToChange-=1                         ! and move to the left to change
  747.     END
  748.  
  749.   END
  750.  
  751.   RETURN NewName                                  ! return the new name back to the caller
  752.  
  753. END
  754. !
  755. ! User specified procedures may have up to 20 passed parameters.
  756. ! Procedures may be called as functions (using the RETURN
  757. ! facility to return a value) or may be called as normal
  758. ! procedures.
  759. !
  760. PROCEDURE Run_Query
  761. DO
  762.   DECLARE LOCAL CHARACTER[*] TempTableName = ""   ! define local variables
  763.   DECLARE LOCAL CHARACTER[*] CreateTableRc = ""
  764.  
  765.  
  766.   DEFINE A.System.LNErrorInfo[0]                  ! reset error message vector
  767.  
  768.   DEFINE ColumnsToSelect[0]                       ! create list of columns selected
  769.  
  770.   DO cc=1:ColumnSelectFlag[0]'ENTRIES             ! and populate it
  771.     INSERT ColumnsToSelect[0] =                   ! for the query
  772.      ColumnDerivation[ColumnSelectFlag[cc]]
  773.   END
  774.  
  775.   IF \NOVALUE(Selection[1])
  776.     LET SelectionCriteria =                       ! set default selection criteria
  777.      "SELECT Form="""||Form||""" & " ||           ! by inserting the Formname as part of the selection
  778.      Selection[1]                                 ! and then adding the user portion
  779.   ELSE
  780.     LET SelectionCriteria =
  781.      "SELECT Form="""||Form||""""
  782.  
  783.   LET Lotus'Servername = Server                   ! Set Server Name
  784.   LET Lotus'Database = Database                   ! Set Database
  785.   LET Lotus'Expression = SelectionCriteria        ! Set selection expression
  786.   LET TempTableName = String("_\Result.TAB",g_Curloc)
  787.   ! CALL Sys'INCLUDETEMP( TempTableName )           ! Delete file at application close
  788.   FORGIVE
  789.      CALL Lotus'CreateProductTable(
  790.                       TempTableName,                 ! Table to create
  791.                       POINTER(ColumnsToSelect[0]))   ! pointer to vector of columns to create
  792.  
  793.   If LOTUS'CODE > 0
  794.      DO
  795.      MESSAGE "FTB0003",0,LOTUS'REASON,LOTUS'CODE
  796.      RETURN
  797.      END
  798.  
  799.  
  800.   OPEN TABLE ResultsTable,                        ! open a table over the OS/2 file
  801.    NAME     = NAME(TempTableName),                ! to hold the query results obtained
  802.    LOCATION = LOCATION(TempTableName),            ! via the Lotus Notes interface
  803.    MODE     = "WRITE"                             ! table opened in Write mode
  804.  
  805.  
  806.   INSERT A.System.LNErrorInfo[0]=Lotus'Code
  807.  
  808.   DO cc=1:ColumnSelectFlag[0]'ENTRIES             ! rename the columns on the results
  809.     IF ColumnSelectFlag[cc]\=""
  810.     DO
  811.       LET OldName = "ResultsTable." ||            ! table to those specified by the user
  812.        ColumnDerivationASL[ColumnSelectFlag[cc]]
  813.  
  814.       LET NewName = "ResultsTable." ||            ! to rename
  815.        ColumnName[ColumnSelectFlag[cc]]
  816.  
  817.       RENAME ?OldName,?NewName
  818.  
  819.       IF ColumnTypeASL[cc] = "Numeric"
  820.         FORGIVE LET (?NewName)[0]'TYPE = "Numeric"
  821.     END
  822.   END
  823.  
  824.   SHUT ResultsTable                               ! shut the Visualizer table
  825.  
  826.   RETURN TempTableName                            ! return the physical tablename
  827.  
  828. END
  829. !
  830. ! User specified procedures may have up to 20 passed parameters.
  831. ! Procedures may be called as functions (using the RETURN
  832. ! facility to return a value) or may be called as normal
  833. ! procedures.
  834. !
  835. PROCEDURE Open_Table(pIdentifier)
  836. DO
  837.   SHUT Resultsview                                ! shut existing view
  838.  
  839.   FORGIVE
  840.     OPEN IBMTABLE ResultsView,                    ! use the Table Editor to view
  841.      NAME       = "Query Results",                ! results of Query
  842.      IDENTIFIER = pIdentifier
  843.  
  844.   IF A.System.ErrorNumber                         ! an error occurred
  845.   DO
  846.     ERROR 10001,"A problem was encountered displaying the query results"
  847.     RETURN
  848.   END
  849.  
  850.   CALL ResultsView'OPEN()                         ! surface the view
  851. END
  852. !
  853. ! User specified procedures may have up to 20 passed parameters.
  854. ! Procedures may be called as functions (using the RETURN
  855. ! facility to return a value) or may be called as normal
  856. ! procedures.
  857. !
  858. PROCEDURE Set_Toolbar_State(pState)
  859. DO
  860.   ! pState is set on call to "UP", "DOWN", or "DISABLED"
  861.  
  862.   DECLARE LOCAL CHARACTER[10] pState
  863.  
  864.   LET Grayed = IF(                                ! Gray-out menuitems if
  865.    pState="DISABLED",                             ! buttons are to be disabled
  866.    Yes,
  867.    No,
  868.    No)
  869.  
  870.   !
  871.   ! set toolbar items
  872.   !
  873.   CALL Toolbar'STATE("T.w_lnqmain.Save","DISABLED")! temporarily disabled
  874.   CALL Toolbar'STATE("T.w_lnqmain.CopyTo","DISABLED")
  875.   CALL Toolbar'STATE("T.w_lnqmain.Print","DISABLED")
  876.   CALL Toolbar'STATE("T.w_lnqmain.SelectDocuments",pState)
  877.   CALL Toolbar'STATE("T.w_lnqmain.RenameFields",pState)
  878.   CALL Toolbar'STATE("T.w_lnqmain.SelectFields",pState)
  879.   CALL Toolbar'STATE("T.w_lnqmain.Run",pState)
  880.   !
  881.   ! set menubar items
  882.   !
  883.   LET T.w_lnqmain.Save[0]'GRAYED = Yes            ! next 4 temporarily disabled
  884.   LET T.w_lnqmain.CopyTo[0]'GRAYED = Yes
  885.   LET T.w_lnqmain.Print[0]'GRAYED = Yes
  886.   LET T.w_lnqmain.Toolbar[0]'GRAYED = Yes
  887.   LET T.w_lnqmain.SelectDocuments[0]'GRAYED = Grayed
  888.   LET T.w_lnqmain.RenameFields[0]'GRAYED = Grayed
  889.   LET T.w_lnqmain.SelectFields[0]'GRAYED = Grayed
  890.   LET T.w_lnqmain.Run[0]'GRAYED = Grayed
  891.  
  892. END
  893. !
  894. ! PROPERTIES event
  895. ! This block is executed when there the user presses Mouse Button 2
  896. !
  897. ON PROPERTIES
  898. DO
  899.   LET A.System.Object = Toolbar'FILTER(           ! Call the Toolbar object to handle
  900.    A.System.Event,                                ! this Event for the toolbar buttons
  901.    A.System.Object,                               ! Mouse Button 2 on a toolbar button displays a pulldown menu
  902.    A.System.BoxNumber)                            ! displaying text from the TOOLTEXT attribute
  903.  
  904. END
  905.