home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ddewsql.zip / DDEAPP.VRX < prev    next >
Text File  |  1995-07-31  |  16KB  |  531 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end; else do
  20.         call VROptions 'ImplicitNames'
  21.     end
  22.     InitArgs.0 = argCount
  23.     if( argCount > 0 )then do i = 1 to argCount
  24.         InitArgs.i = arg( i + argOff )
  25.     end
  26.     drop calledAs argCount argOff
  27.  
  28. /*  Load the windows
  29. */
  30.     call VRInit
  31.     parse source . . spec
  32.     _VREPrimaryWindowPath = ,
  33.         VRParseFileName( spec, "dpn" ) || ".VRW"
  34.     _VREPrimaryWindow = ,
  35.         VRLoad( parent, _VREPrimaryWindowPath )
  36.     drop parent spec
  37.     if( _VREPrimaryWindow == "" )then do
  38.         call VRMessage "", "Cannot load window:" VRError(), ,
  39.             "Error!"
  40.         _VREReturnValue = 32000
  41.         signal _VRELeaveMain
  42.     end
  43.  
  44. /*  Process events
  45. */
  46.     call Init
  47.     signal on halt
  48.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  49.         _VREEvent = VREvent()
  50.         interpret _VREEvent
  51.     end
  52. _VREHalt:
  53.     _VREReturnValue = Fini()
  54.     call VRDestroy _VREPrimaryWindow
  55. _VRELeaveMain:
  56.     call VRFini
  57. exit _VREReturnValue
  58.  
  59. VRLoadSecondary:
  60.     __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
  61.     if __vrlsWait then do
  62.         call VRFlush
  63.     end
  64.     __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
  65.     if __vrlsHWnd = '' then signal __vrlsDone
  66.     if __vrlsWait \= 1 then signal __vrlsDone
  67.     call VRSet __vrlsHWnd, 'WindowMode', 'Modal' 
  68.     __vrlsTmp = __vrlsWindows.0
  69.     if( DataType(__vrlsTmp) \= 'NUM' ) then do
  70.         __vrlsTmp = 1
  71.     end
  72.     else do
  73.         __vrlsTmp = __vrlsTmp + 1
  74.     end
  75.     __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
  76.     __vrlsWindows.0 = __vrlsTmp
  77.     do while( VRIsValidObject( VRWindow() ) = 1 )
  78.         __vrlsEvent = VREvent()
  79.         interpret __vrlsEvent
  80.     end
  81.     __vrlsTmp = __vrlsWindows.0
  82.     __vrlsWindows.0 = __vrlsTmp - 1
  83.     call VRWindow __vrlsWindows.__vrlsTmp 
  84.     __vrlsHWnd = ''
  85. __vrlsDone:
  86. return __vrlsHWnd
  87.  
  88. /*:VRX         Fini
  89. */
  90. Fini:
  91.     window = VRWindow()
  92.     call VRSet window, "Visible", 0
  93.     drop window
  94. return 0
  95.  
  96. /*:VRX         Halt
  97. */
  98. Halt:
  99.     signal _VREHalt
  100. return
  101.  
  102. /*:VRX         Init
  103. */
  104. Init:
  105.     windowmain = VRWindow()
  106.  
  107.     /* display the DDE Server Object Window */
  108.     call VRLoadSecondary "sw_2"
  109.  
  110.     call VRMethod windowmain, "Activate"
  111.     call VRSet "Window1", "StatusText", "Press 'Connect' To Start"
  112. return    
  113.  
  114. /*:VRX         PB_10_Click
  115. */
  116. PB_10_Click: 
  117.  call quit
  118. return
  119.  
  120. /*:VRX         PB_1_Click
  121. */
  122. PB_1_Click: 
  123.   /* Display Message that we are trying to find all avaiable DDE Servers */
  124.   call VRSet "Window1", "StatusText", "Getting Available DDE Servers"
  125.  
  126.   /* Pause for status text to be read on bottom of window */
  127.   do i=1 to 10000
  128.   end
  129.  
  130.   /* Find all available DDE Servers and topics currently available and 
  131.      store them in a stem variable called convs
  132.   */
  133.   call VRMethod "DDEC_1", "Initiate", "convs." 
  134.  
  135.   /* a secondary window to display the contents of the stem variable convs */ 
  136.   window = VRLoadSecondary( "sw_1", "W" )
  137.  
  138.   /* display a message on for the Accept command on attempting to converse
  139.      with WSQL DDE Server
  140.   */
  141.   call VRSet "Window1", "StatusText", "Attempting to converse with WSQL DDE Server"
  142.   
  143.   /* Accept the the only conversation */
  144.   ok = VRMethod( "DDEC_1", "Accept", )
  145.  
  146.   /* check return code of Accept method */
  147.   if ok = 1 then /* Accept operation is successful */
  148.     call VRSet "Window1", "StatusText", "Conversation is established"
  149.   else do /* Accept method failed must try again */
  150.     call VRSet "Window1", "StatusText", "No Conversation established check connections then press Connect again."
  151.     call DDEAPP7 VRWindow()
  152.     return 
  153.   end
  154.  
  155.   call VRSet "Window1", "StatusText", "Poking the CONNECT Command to WSQL DDE Server" 
  156.   
  157.   /* Dialog file to remind user that the connect
  158.      command must done before you connect to the database
  159.   */
  160.   call VRSet "Window1", "Visible", 0
  161.   call DDEAPP4 VRWindow()
  162.   call VRSet "Window1", "Visible", 1
  163.  
  164.   /* connecting to database */ 
  165.   status = VRMethod( "DDEC_1", "Poke", "CONNECT", ""   )
  166.   if status = "error" then do
  167.      call VRSet "Window1", "StatusText", "Error on trying to connect to database, resolve problem and press Link."
  168.      call DDEAPP7 VRWindow()
  169.      return 
  170.   end 
  171.  
  172.   call VRSet "Window1", "Pointer", "Wait"
  173.   do i = 1 to 50000
  174.   end
  175.   call VRSet "Window1", "Pointer", "<Default>"
  176.  
  177.   /* reset the text in the status area to null */
  178.   call VRSet "Window1", "StatusText", ""
  179.  
  180.   /* enable poke, terminate, request, execute and 
  181.      execute sample buttons
  182.   */
  183.   call VRSet "PB_2", "Enabled", 1 
  184.   call VRSet "PB_3", "Enabled", 1
  185.   call VRSet "PB_4", "Enabled", 1
  186.   call VRSet "PB_5", "Enabled", 1
  187.   call VRSet "PB_6", "Enabled", 1
  188.   
  189.   /* File Dialog to remind user of commands to can execute
  190.      with DDE Server
  191.   */
  192.   call VRSet "Window1", "Visible", 0
  193.   call DDEAPP5 VRWindow()
  194.   call VRSet "Window1", "Visible", 1
  195.  
  196. return
  197.  
  198. /*:VRX         PB_2_Click
  199. */
  200. PB_2_Click: 
  201.     /* display file dialog about the poke command */
  202.     call DDEAPP6 VRWindow()
  203. return
  204.  
  205. /*:VRX         PB_3_Click
  206. */
  207. PB_3_Click: 
  208.     /* display file dialog on request command */
  209.     call DDEAPP10 VRWindow()
  210. return
  211.  
  212. /*:VRX         PB_4_Click
  213. */
  214. PB_4_Click: 
  215.     /* display file dialog on request execute command */
  216.     call DDEAPP9 VRWindow()
  217. return
  218.  
  219. /*:VRX         PB_5_Click
  220. */
  221. PB_5_Click: 
  222.     /* Do not allow the poke connect command to execute
  223.        because connection with WSQLDDE is terminated
  224.     */
  225.     call VRSet "PB_9", "Enabled", 0
  226.  
  227.     /* Terminate the connection with the database*/
  228.     call VRMethod "DDEC_1", "Terminate"
  229.     call VRSet "Window1", "StatusText", "Terminating WSQL DDE Connection"
  230. return
  231.  
  232. /*:VRX         PB_6_Click
  233. */
  234. PB_6_Click: 
  235.     /* Execute an automated example */
  236.     call VRLoadSecondary "SW_3", "W"
  237. return
  238.  
  239. /*:VRX         PB_7_Click
  240. */
  241. PB_7_Click: 
  242.   call VRSet "SW_3", "StatusText", "See Multi-Line Entry Field on Commands Executed and Output from 'Run'"
  243.  
  244.   /* pause */
  245.   do i=1 to 10000
  246.   end
  247.   
  248.   /* set the mouse arrow to a the clock */
  249.   call VRSet "SW_3", "Pointer", "Wait"
  250.  
  251.   /* Clear the query buffer and add the SELECT statement to it */
  252.   call VRMethod "DDEC_1", "Poke", "Clear", "SELECT * FROM Lab"
  253.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Clear','SELECT * FROM Lab'"||"0d"x 
  254.  
  255.   call VRMethod "MLE_1", "Insert", "Notes: "
  256.   call VRMethod "MLE_1", "Insert", "The query buffer is cleared and the SELECT statement is added to it"||"0d"x||"0d"x
  257.   
  258.   /* Get the column names and data and store them in a stem variable 
  259.      Had the item been Column_Names then only the column names would
  260.      have been stored in the stem variable. Similarily if the item 
  261.      had been Data then just the data rows would have appeared
  262.   */
  263.   call VRMethod "DDEC_1", "RequestList", "Column_Names_And_Data", "column_and_data."
  264.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','RequestList','Column_Names_And_Data','column_and_data.'"
  265.   
  266.   /* Output the contents of the columns and data into a MLE */
  267.   call VRMethod "MLE_1", "Insert", "0d"x
  268.   call VRMethod "MLE_1", "Insert", "Output:"||"0d"x
  269.   do i = 1 to column_and_data.0
  270.       call VRMethod "MLE_1", "Insert", column_and_data.i 
  271.   end
  272.  
  273.   call VRMethod "MLE_1", "Insert", "Notes: "
  274.   call VRMethod "MLE_1", "Insert", "Had the Item in the RequestList method been 'Column_Names' then only the column names would have appeared in the above output. Similarly, if the item had been 'Data' then just the data rows would have appeared"||"0d"x 
  275.  
  276.   /* Clear the query buffer and add the SELECT statement to it */
  277.   call VRMethod "DDEC_1", "Poke", "Clear", "SELECT Surname, Studnum FROM Student"
  278.   call VRMethod "MLE_1", "Insert", "0d"x
  279.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Clear','SELECT Surname,Studnum FROM Student'"||"0d"x 
  280.  
  281.   call VRMethod "MLE_1", "Insert", "Notes: "
  282.   call VRMethod "MLE_1", "Insert", "The query buffer is cleared and the SELECT statement is added"||"0d"x||"0d"x
  283.  
  284.   /* The query buffer will contain: 
  285.      SELECT Surname, Studnum FROM Student WHERE Studnum < 86009
  286.   */
  287.   call VRMethod "DDEC_1", "Poke", "Add", "where Studnum < 86009"
  288.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Add','where Studnum < 86009'"||"0d"x
  289.   
  290.   call VRMethod "MLE_1", "Insert", "Notes: "
  291.   call VRMethod "MLE_1", "Insert", "The query buffer now contains:SELECT Surname, Studnum FROM Student WHERE Studnum < 86009 "||"0d"x||"0d"x 
  292.  
  293.   /* The ORDER BY clause is appended to the query buffer, and the data 
  294.      from the query is placed on the clipboard. The Item could have been
  295.      Clip_Column_Names or Clip_Column_Names_And_Data
  296.   */
  297.   call VRMethod "DDEC_1", "Poke", "Clip_Data", "ORDER BY Surname"
  298.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Clip_Data','ORDER BY Surname'"||"0d"x
  299.  
  300.   call VRMethod "MLE_1", "Insert", "Notes:"
  301.   call VRMethod "MLE_1", "Insert", "The ORDER BY clause is appended to the query buffer, and the data form the query is placed on the clipboard.  The item could also have been 'Clip_Column_Names' or 'Clip_Column_Names_And_Data' "||"0d"x
  302.  
  303.   /* paste the contents of the clipboard onto the MLE */
  304.   
  305.   call VRMethod "MLE_1", "Insert", "0d"x||"Output:"||"0d"x
  306.   text = VRMethod( "Application", "GetClipboard" )
  307.   call VRMethod "MLE_1", "Insert", text
  308.  
  309.   /* Executing a command */
  310.   call VRMethod "DDEC_1", "Poke", "Clear", "UPDATE Student SET Surname='BRIGGS-SMITH'"
  311.   call VRMethod "MLE_1", "Insert", "0d"x
  312.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Clear','UPDATE Student SET Surname='BRIGGS-SMITH''"||"0d"x||"0d"x 
  313.  
  314.   /* The WHERE clause is appended to the query buffer and the command 
  315.      UPDATE Student SET Surname="BRIGGS-SMITH' WHERE surname='BRIGGS'
  316.      is sent to the database engine
  317.   */
  318.   call VRMethod "DDEC_1", "Execute", "WHERE surname='BRIGGS'"
  319.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Execute','WHERE surname='BRIGGS''"||"0d"x
  320.  
  321.   call VRMethod "MLE_1", "Insert", "Notes: "
  322.   call VRMethod "MLE_1", "Insert", "The WHERE clause is appended to the query buffer and the command above is sent to the database engine"||"0d"x||"0d"x 
  323.  
  324.   /* Terminating the connection to the database engine
  325.      DDE conversation still exists
  326.   */
  327.   call VRMethod "DDEC_1", "Poke", "Disconnect", ""
  328.   call VRMethod "MLE_1", "Insert", "call VRMethod 'DDEC_1','Poke','Disconnect'"||"0d"x
  329.  
  330.   call VRMethod "MLE_1", "Insert", "Notes: "
  331.   call VRMethod "MLE_1", "Insert", "The connection to the database engine is terminated. The DDE conversation still exists, so another POKE Connect could be done" 
  332.  
  333.   /* Allow to Poke the Connect Command to do the example again */
  334.   call VRSet "PB_9", "Enabled", 1 
  335.     
  336.   /* set mouse pointer back to the arrow which is default */
  337.   call VRSet "SW_3", "Pointer", "<Default>"
  338.  
  339.   call VRSet "PB_6", "Enabled", 0 
  340.    
  341. return
  342.  
  343. /*:VRX         PB_8_Click
  344. */
  345. PB_8_Click: 
  346.      call sw_3_close
  347. return
  348.  
  349. /*:VRX         PB_9_Click
  350. */
  351. PB_9_Click: 
  352.     call VRMethod "DDEC_1", "Poke", "CONNECT", "" 
  353.  
  354.     /* Do not allow the command to be executed again 
  355.        until the sample has been run again
  356.     */
  357.     call VRSet "PB_9", "Enabled", 0 
  358.  
  359.     /* Enable the sample to be executed again */
  360.     call VRSet "PB_6", "Enabled", 1 
  361. return
  362.  
  363. /*:VRX         Quit
  364. */
  365. Quit:
  366.     window = VRWindow()
  367.     call VRSet window, "Shutdown", 1
  368.     drop window
  369. return
  370.  
  371. /*:VRX         SW_1_Close
  372. */
  373. SW_1_Close: 
  374.    call SW_1_Fini
  375. return
  376.  
  377. /*:VRX         SW_1_Create
  378. */
  379. SW_1_Create: 
  380.     call SW_1_Init
  381. return
  382.  
  383. /*:VRX         SW_1_Fini
  384. */
  385. SW_1_Fini: 
  386.     window = VRInfo( "Window" )
  387.     call VRDestroy window
  388.     drop window
  389.  
  390.     /* set the primary window visible */
  391.     call VRSet "Window1", "Visible", 1
  392. return
  393. /*:VRX         SW_1_Init
  394. */
  395. SW_1_Init: 
  396.     ok = VRSet( "Window1", "Visible", 0 )
  397.     window = VRInfo( "Object" )
  398.     if( \VRIsChildOf( window, "Notebook" ) ) then do
  399.         call VRSet window, "Visible", 1
  400.         call VRMethod window, "Activate"
  401.     end
  402.     drop window
  403.  
  404.     /* create field for container: Service Name and Topic 
  405.        populate container with possible conversations
  406.     */
  407.     fieldHandle1 = VRMethod( "CN_1", "AddField", "String", "Service Name" )
  408.     fieldHandle2 = VRMethod( "CN_1", "AddField", "String", "Topic" )
  409.      if (convs.0 > 0) then do
  410.        records.0 = convs.0
  411.        do i = 1 to convs.0
  412.           parse var convs.i server "," topic
  413.           records.i = ";;;;;"||fieldHandle1||";"||server||";"||fieldHandle2||";"||topic
  414.        end
  415.        call VRMethod "CN_1", "AddRecordList", , "", records.
  416.    end
  417.  
  418.    /* display dialog file with some notes about the information in the */
  419.    /* container in SW_1 */
  420.    call DDEAPP2 VRWindow()
  421.  
  422.    /* set the secondary window invisible */
  423.    call VRSet "SW_1", "Visible", 0
  424.    
  425.    /* Get information about the topic */
  426.    call DDEAPP3 VRWindow()
  427.   
  428.    /* Retrieve information handled in DDEAPP3 window file */
  429.    call VRMethod "Application", "GetVar", "database", "database" 
  430.    call VRMethod "Application", "GetVar", "password", "password"
  431.    call VRMethod "Application", "GetVar", "userid", "userid"
  432.    
  433.    /* check for valid database name and path */
  434.    if ( database \= "" ) then do
  435.       parse arg database name'.'ext
  436.       if ( (ext \= "db") | \VRFileExists(database) ) then do
  437.          Do while ( \VRFileExists(database))
  438.            Buttons.1 = "Ok"
  439.            Buttons.0 = 1
  440.            id = VRMessage( VRWindow(), "Invalid Database Name or Path", "Warning", "None", "Buttons.", ,  )
  441.            Types.1 = "*.db"
  442.            Types.0 = 1
  443.            database = VRFileDialog( VRWindow(), "Choose WSQL Database", "Save", "c:\wsql40\*.db", , , "Types." )
  444.          end
  445.       end
  446.    end   
  447.  
  448.    /* check whether a database was given or not */
  449.    if database ="" then
  450.       call VRMethod "DDEC_1", "Initiate", "wsql.", "WSQLDDE", userid||","||password 
  451.    else
  452.       call VRMethod "DDEC_1", "Initiate", "wsql.", "WSQLDDE", userid||","||password||","||database
  453.      
  454.    /* close the window */
  455.    call SW_1_Fini 
  456. return   
  457.  
  458. /*:VRX         SW_2_Close
  459. */
  460. SW_2_Close: 
  461.     call SW_2_Fini
  462. return
  463.  
  464. /*:VRX         SW_2_Create
  465. */
  466. SW_2_Create: 
  467.     call SW_2_Init
  468. return
  469.  
  470. /*:VRX         SW_2_Fini
  471. */
  472. SW_2_Fini: 
  473.     window = VRInfo( "Window" )
  474.     call VRDestroy window
  475.     drop window
  476. return
  477. /*:VRX         SW_2_Init
  478. */
  479. SW_2_Init: 
  480.     window = VRInfo( "Object" )
  481.     if( \VRIsChildOf( window, "Notebook" ) ) then do
  482.         /* sets to align main window with SW_2 */
  483.         ok = VRSet( "SW_2", "Top", 0 )
  484.         call VRSet window, "Visible", 1
  485.         height = VRGet( "SW_2", "Height" )
  486.         ok = VRSet( "Window1", "Top", Height )
  487.         call VRSet windowmain, "Visible", 1
  488.     end
  489.     drop window
  490. return
  491.  
  492. /*:VRX         SW_3_Close
  493. */
  494. SW_3_Close: 
  495.     call SW_3_Fini
  496. return
  497.  
  498. /*:VRX         SW_3_Create
  499. */
  500. SW_3_Create: 
  501.     call SW_3_Init
  502. return
  503.  
  504. /*:VRX         SW_3_Fini
  505. */
  506. SW_3_Fini: 
  507.     window = VRInfo( "Window" )
  508.     call VRDestroy window
  509.     drop window
  510. return
  511. /*:VRX         SW_3_Init
  512. */
  513. SW_3_Init: 
  514.     window = VRInfo( "Object" )
  515.     if( \VRIsChildOf( window, "Notebook" ) ) then do
  516.         call VRMethod window, "CenterWindow"
  517.         call VRSet window, "Visible", 1
  518.         call VRMethod window, "Activate"
  519.     end
  520.     drop window
  521.     column_and_data.0=0
  522. return
  523.  
  524. /*:VRX         Window1_Close
  525. */
  526. Window1_Close:
  527.     call VRMethod "DDEC_1", "Terminate" 
  528.     call Quit
  529. return
  530.  
  531.