home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxdemo.zip / SAMPLEDB.$$$ / WINDOW1.VRX < prev    next >
Text File  |  1993-06-18  |  5KB  |  181 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
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         Fini
  67. */
  68. Fini:
  69.     window = VRWindow()
  70.     call VRSet window, 'visible', 'false'
  71.     drop window
  72.     call sqldbs 'STOP USING DATABASE'
  73.     call sqldbs 'STOP DATABASE MANAGER'
  74. return '0'
  75.  
  76. /*:VRX         Halt
  77. */
  78. Halt:
  79.     signal _VREHalt
  80. return
  81.  
  82. /*:VRX         Init
  83. */
  84. Init:
  85.     window = VRWindow()
  86.     call VRMethod window, "CenterWindow"
  87.     call VRSet window, "Visible", 1
  88.     call VRMethod window, "Activate"
  89.     drop window
  90.  
  91.     call VRSet "pb_next", "Enabled", 0
  92.     if Rxfuncquery('SQLDBS') <> 0 then
  93.         rcy = rxfuncadd( 'SQLDBS', 'SQLAR', 'SQLDBS' )
  94.     if rXFUNCQUERY('SQLEXEC') <> 0 then
  95.         rcy = rxfuncadd( 'SQLEXEC', 'SQLAR', 'SQLEXEC' )
  96.  
  97.     dbname = "sample"
  98.     call sqldbs 'START DATABASE MANAGER'
  99.     if ( SQLCA.SQLCODE <> 0 & SQLCA.SQLCODE \= -1026) then do
  100.         call VRMessage VRWindow(), "Database Manager could not be started: SQLCODE = " SQLCA.SQLCODE, 'Error'
  101.         return
  102.     end
  103.  
  104.     call sqldbs 'START USING DATABASE' dbname
  105.     if (SQLCA.SQLCODE <> 0  & SQLCA.SQLCODE \= -1098) then do
  106.         call VRMessage VRWindow(), "Start DB error: SQLCODE = " SQLCA.SQLCODE, 'Error'
  107.         return
  108.     end
  109.  
  110.     call sqlexec "DECLARE c1 cursor for s1"
  111. return
  112. /*:VRX         pb_clear_Click
  113. */
  114. pb_clear_Click:
  115.         call VRSet 'EF_id', 'value', ''
  116.         call VRSet 'EF_name', 'value', ''
  117.         call VRSet 'EF_job', 'value', ''
  118.         call VRSet 'EF_years', 'value', ''
  119.         call VRSet 'EF_department_name', 'value', ''
  120.  
  121.         call VRSet 'pb_search', 'enabled', 'true'
  122.         call VRSet 'pb_next', 'enabled', 'false'
  123.  
  124.         call sqlexec 'CLOSE c1'
  125. return
  126. /*:VRX         pb_exit_Click
  127. */
  128. pb_exit_Click:
  129.         call sqlexec 'CLOSE c1'
  130.         call Quit
  131. return
  132. /*:VRX         pb_next_Click
  133. */
  134. pb_next_Click:
  135.  
  136.         call VRSet 'EF_id', 'value', idnum
  137.         call VRSet 'EF_name', 'value', staff_name
  138.         call VRSet 'EF_job', 'value', job_name
  139.         call VRSet 'EF_years', 'value', year_num
  140.         call VRSet 'EF_department_name', 'value', location
  141.  
  142.         call sqlexec 'FETCH c1 INTO :idnum, :staff_name, :job_name, :year_num, :location'
  143.         if( SQLCA.SQLCODE <> 0)then do
  144.                 call VRSet 'pb_next', 'enabled', 'false'
  145.           end
  146.  
  147. return
  148. /*:VRX         pb_search_Click
  149. */
  150. pb_search_Click:
  151.         prep_string = "SELECT id, name, job, years, deptname from staff, org where staff.dept=org.deptnumb"
  152.  
  153.         call sqlexec 'PREPARE s1 FROM :prep_string'
  154.         if( SQLCA.SQLCODE <> 0 ) then do
  155.                 call VRMessage VRWindow(), "Error preparing statement: SQLCODE = " sqlca.sqlcode
  156.                 return
  157.         end
  158.  
  159.         call sqlexec 'OPEN c1'
  160.         call sqlexec 'FETCH c1 INTO :idnum, :staff_name, :job_name, :year_num, :location'
  161.         if( SQLCA.SQLCODE = 0) then do
  162.                 call VRSet 'pb_search', 'enabled', 'false'
  163.                 call VRSet 'pb_next', 'enabled', 'true'
  164.                 call pb_next_Click
  165.         end
  166.         else call VRMessage VRWindow(), "No records found in the database." SQLCA.SQLCODE
  167. return
  168. /*:VRX         Quit
  169. */
  170. Quit:
  171.     window = VRWindow()
  172.     call VRSet window, 'shutdown', 'true'
  173.     drop window
  174. return
  175.  
  176. /*:VRX         Window1_Close
  177. */
  178. Window1_Close:
  179.     call Quit
  180. return
  181.