home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / rds.cab / adctest.asp1 < prev    next >
Text File  |  1997-10-28  |  7KB  |  248 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE>RDS 1.5 Query Page</TITLE>
  4. </HEAD>
  5. <BODY BACKGROUND="AddressBook/Arcadia.gif">
  6. <CENTER>
  7. <H1>Remote Data Service 1.5 Query Page</H1>
  8.  
  9. <BR>
  10. <OBJECT ID="GRID" WIDTH=600 HEIGHT=200 Datasrc="#ADC"
  11.  CODEBASE="http://<%=Request.ServerVariables("SERVER_NAME")%>/MSADC/Samples/ssdatb32.cab"
  12.  CLASSID="CLSID:AC05DC80-7DF1-11d0-839E-00A024A94B3A">
  13.   <PARAM NAME="_Version"        VALUE="131072">
  14.   <PARAM NAME="BackColor"     VALUE="-2147483643">
  15.   <PARAM NAME="BackColorOdd"  VALUE="-2147483643">
  16.   <PARAM NAME="ForeColorEven" VALUE="0">    
  17. </OBJECT>
  18. <BR>
  19.  
  20. <BR>
  21. <table>
  22.   <tr><td>ADC Server:<td><INPUT NAME=Server SIZE=70>
  23.   <tr><td>Connection:<td><INPUT NAME=Connect SIZE=70>
  24.   <tr><td>Query:<td><INPUT NAME=SQL SIZE=70>
  25.   <tr><td>Recordset Status:<td><INPUT TYPE=TEXT Name=RecordSetStat SIZE =30>
  26.   <tr><td>Execute Option:<td><INPUT TYPE=TEXT Name=ExecOpt SIZE =30>
  27.   </table>
  28.  
  29. <BR>
  30. <INPUT TYPE=BUTTON NAME="Requery" VALUE="Run!">
  31. <INPUT TYPE=BUTTON NAME="MoveFirst" VALUE="First">
  32. <INPUT TYPE=BUTTON NAME="MovePrev" VALUE="Prev">
  33. <INPUT TYPE=BUTTON NAME="MoveNext" VALUE="Next">
  34. <INPUT TYPE=BUTTON NAME="MoveLast" VALUE="Last"> <BR><BR>
  35. <INPUT TYPE=BUTTON NAME="Update" VALUE="Save Changes">
  36. <INPUT TYPE=BUTTON NAME="Cancel" VALUE="Cancel Changes">
  37. <BR><BR>
  38. <INPUT TYPE=BUTTON NAME="Stop" VALUE="Cancel Query">
  39. <INPUT TYPE=BUTTON NAME="Asynchoff" VALUE="Turn Asynch off">
  40. <INPUT TYPE=BUTTON NAME="Asynchon" VALUE="Turn Asynch on">
  41. </CENTER>
  42.  
  43. <OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
  44.     ID=ADC HEIGHT=1 WIDTH = 1>
  45. </OBJECT>
  46.  
  47. <SCRIPT LANGUAGE="VBScript">
  48. '---- enum Values ----
  49. Const adcExecSync = 1
  50. Const adcExecAsync = 2
  51.  
  52. '---- enum Values ----
  53. Const adcFetchUpFront = 1
  54. Const adcFetchBackground = 2
  55. Const adcFetchAsync = 3
  56.  
  57. '---- enum Values ----
  58. Const adcStateClosed = &H00000000
  59. Const adcStateOpen = &H00000001
  60. Const adcStateConnecting = &H00000002
  61. Const adcStateExecuting = &H00000004
  62. Const adcStateFetching = &H00000008
  63.  
  64. '---- enum Values ----
  65. Const adcReadyStateLoaded = 2
  66. Const adcReadyStateInteractive = 3
  67. Const adcReadyStateComplete = 4
  68.  
  69.  
  70. SUB Window_OnLoad
  71.   Server.Value = "http://<%=Request.ServerVariables("SERVER_NAME")%>"
  72.   Connect.Value = "DSN=AdvWorks"
  73.   SQL.Value = "Select * from Products"
  74.  
  75.   Select case ADC.ExecuteOptions
  76.     case adcExecSync: ExecOpt.Value = "Synchronous"
  77.     case adcExecAsync: ExecOpt.Value = "Asynchronous"
  78.   END Select
  79.  
  80.   Select case ADC.ReadyState
  81.     case adcReadyStateLoaded: RecordSetStat.Value = "Loaded"
  82.     case adcReadyStateInteractive: RecordSetStat.Value = "Interactive"
  83.     case adcReadyStateComplete: RecordSetStat.Value = "Complete"
  84.   END Select
  85.  
  86. END SUB
  87.  
  88. SUB ADC_OnReadyStateChange
  89.   'Fires every time that ADC.ReadyState changes
  90.   Select case ADC.ReadyState
  91.     case adcReadyStateLoaded: RecordSetStat.Value = "Loaded"
  92.     case adcReadyStateInteractive: RecordSetStat.Value = "Interactive"
  93.     case adcReadyStateComplete: RecordSetStat.Value = "Complete"
  94.   END Select
  95. END SUB
  96.  
  97. SUB ADC_OnDataSetChanged
  98.   'Fires after execution is done
  99.  
  100. END SUB
  101.  
  102. SUB ADC_OnDataSetComplete
  103.  'Fires after fetching is complete
  104.  
  105. END SUB
  106.  
  107. sub Move (strDirection)
  108.   'Custom sub to handle Asyncronous fetching
  109.   'Asynchronous fetching allows you to cancel in the middle of fetching a large
  110.   'recordset
  111.   if ADC.Recordset.State = adcStateClosed then
  112.     if ADC.ReadyState = adcReadyStateComplete then
  113.       msgbox "Query results failed to arrive, please rerun query synchronously and check for errors."
  114.     end if
  115.     if ADC.ReadyState = adcReadyStateLoaded then
  116.       msgbox "Query results have not yet arrived"    
  117.     end if
  118.   else
  119.     if ADC.Recordset.State = adcStateOpen Then    
  120.       on error resume next
  121.       select case strDirection
  122.         Case "First"
  123.           ADC.Recordset.MoveFirst
  124.         Case "Next"
  125.           ADC.Recordset.MoveNext
  126.         Case "Last"
  127.           ADC.Recordset.MoveLast
  128.         Case "Prev"
  129.           ADC.Recordset.MovePrevious
  130.        end select
  131.       IF ERR.Number <> 0 then
  132.         if Err.Number = 3021 THEN
  133.           if ADC.Recordset.BOF then
  134.             ADC.Recordset.MoveFirst  'If already at start of recordset stay at top.
  135.           else 
  136.             ADC.Recordset.MoveLast   'If already at end of recordset stay at bottom.
  137.           END IF
  138.         else 
  139.           msgbox "Unexpected error in Move actions. " & Err.Description
  140.         END IF
  141.       end if
  142.     else
  143.       msgbox "The state is unexpected, an error has occurred"   'Very General error msg. 
  144.     end if
  145.   end if
  146. End Sub
  147.  
  148. SUB MoveFirst_OnClick
  149.   'Call to Custom Sub, Move, to handle attempts to move the record pointer during asynch fetches
  150.   move "First"
  151. END SUB
  152.  
  153. SUB MoveNext_OnClick
  154.   'Call to Custom Sub, Move, to handle attempts to move the record pointer during asynch fetches
  155.   Move "Next"
  156. END SUB
  157.  
  158. SUB MovePrev_OnClick
  159.   'Call to Custom Sub, Move, to handle attempts to move the record pointer during asynch fetches
  160.   Move "Prev"
  161. END SUB
  162.  
  163. SUB MoveLast_OnClick
  164.   'Call to Custom Sub, Move, to handle attempts to move the record pointer during asynch fetches
  165.   Move "Last"
  166. END SUB
  167.  
  168. 'Submits edits made and pulls a clean copy of the new data.
  169. SUB Update_OnClick
  170.   If ADC.ReadyState <> adcReadyStateLoaded then
  171.     ADC.SubmitChanges
  172.     ADC.Refresh
  173.         
  174.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  175.     Grid.Rebind
  176.  
  177.   Else
  178.     MsgBox "Query results still arriving, Please wait"
  179.   End if
  180.     
  181. END SUB
  182.  
  183. 'Cancel edits and restores original values.
  184. SUB Cancel_OnClick
  185.   if ADC.ReadyState <> adcReadyStateLoaded then
  186.      ADC.CancelUpdate
  187.     
  188.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  189.     Grid.Rebind
  190.  
  191.   Else
  192.     MsgBox "Query results still arriving, Please wait"
  193.   End if
  194.  
  195. END SUB
  196.  
  197. SUB Requery_OnClick
  198.   If ADC.ReadyState <> adcReadyStateComplete then
  199.     MsgBox "Query results still arriving, Please wait"
  200.   Else
  201.     ADC.Server = Server.Value
  202.      ADC.Connect = Connect.Value
  203.     ADC.SQL = SQL.Value
  204.  
  205.     ADC.Refresh
  206.     
  207.     'Optional command specific to the Sheridan Grid to ensure display of the correct data
  208.     Grid.Rebind
  209.  
  210.   End if
  211.  
  212. END SUB
  213.  
  214. SUB Stop_OnClick
  215.   'If an asychronous query is taking too long to execute you can use this to cancel the query
  216.   ADC.Cancel
  217.  
  218. END SUB
  219.  
  220. SUB Asynchoff_OnClick
  221.   'In cases where there are problems querying the database you may need to switch to synchronous mode
  222.   'in order to get the error
  223.   ADC.ExecuteOptions = adcExecSync
  224.   ADC.FetchOptions = adcFetchBackground
  225.   Select case ADC.ExecuteOptions
  226.     case adcExecSync: ExecOpt.Value = "Synchronous"
  227.     case adcExecAsync: ExecOpt.Value = "Asynchronous"
  228.   END Select
  229.  
  230.  
  231. END SUB
  232.  
  233. SUB Asynchon_OnClick
  234.   'In cases where there are problems querying the database you may need to switch to synchronous mode
  235.   'in order to get the error
  236.   ADC.ExecuteOptions = adcExecAsync
  237.   ADC.FetchOptions = adcFetchAsync
  238.   Select case ADC.ExecuteOptions
  239.     case adcExecSync: ExecOpt.Value = "Synchronous"
  240.     case adcExecAsync: ExecOpt.Value = "Asynchronous"
  241.   END Select
  242.  
  243. END SUB
  244.  
  245. </SCRIPT>
  246. </BODY>
  247. </HTML>
  248.