[ Pobierz całość w formacie PDF ]
.Recordset.MovePrevious44: IF ERR.Number 0 THEN45: ERR.Clear46: END IF47: END SUB48:49: SUB MoveNext_onClick50: On Error Resume Next51: ADC.Recordset.MoveNext52: IF ERR.Number 0 THEN52: ERR.Clear53: END IF54: END SUB55:56: SUB MoveLast_onClick57: ADC.Recordset.MoveLast58: END SUB59:60: SUB Update_onClick61: ADC.SubmitChanges62: ADC.Refresh63: Grid.Rebind64: END SUB65:66: SUB Cancel_onClick67: ADC.CancelUpdate68: ADC.Refresh69: Grid.Rebind70: END SUB71:72: SUB Execute_onClick73: ADC.Server ="http://"74: ADC.Connect = "DSN=OrdersDb"75: ADC.SQL = "Select * from Products"76: ADC.Refresh77: Grid.Rebind78: END SUB79:80:81:82:Lines 1-7 in Listing 11.3 put up the title for the window and a heading.Lines 9-17 place the SheridanActiveX grid control in the page.Lines 19-21 place the Microsoft RDS DataControl (also called theAdvanced Data Control or ADC) into the page.Lines 26-32 place several buttons on the page toenable the user to interact with the UI.Lines 35 to 80 contain VBScript code for handling buttonpresses by the user.Lines 80-82 end the tags to indicate the end of the page.The Microsoft RDS DataControl (ADC) is an ActiveX control that is instantiated on the clientmachine in the browser's process.When the user presses the execute button, lines 73-75 set the Server,Connect, and SQL properties in the ADC.Line 76 calls the ADC Refresh method.This methoduses the Server, Connect, and SQL properties to tell the middle tier to connect to the database andissue the SQL query.The ADC then retrieves the records and caches them on the client machine.Line 77 tells the grid control to rebind to the records.The grid actually does more than just displaythem.The grid enables the user to navigate through the records, using the code in lines 37 through 58.The user can edit the records' contents in the grid.The user can cancel those changes by clicking theCancel button, which executes the code in lines 66-70.The user can commit the changes by clickingthe Update button, which executes the code in lines 60-64.The output of Listing 11.3 is shown inFigure 11.9.Figure 11.9 : The client tier page in IE4.What happens behind the scenes with Remote Data Services is quite amazing.Figure 11.10 shows thearchitecture of RDS.Figure 11.10: The RDS architecture.Following is an explanation of the sequence in a typical RDS operation:1.A thin client, such as a browser, running on a client tier machine creates a local instance of theRDS.DataControl (perhaps it is bound to a grid control running in the browser).2.When the user makes a request for the data, RDS.DataControl creates a remote instance ofRDSServer.DataFactory on the middle-tier machine and issues a query to theDataFactory object.3.The DataFactory object on the middle-tier machine uses OLE DB or ODBC to query thedatabase on the data-tier machine.4.The database processes the query and sends all the records to the DataFactory object on themiddle-tier machine.5.The DataFactory object stores all the records from the query in an OLE DB row set, calledthe server-side cache, which resides on the middle-tier machine.6.The DataFactory places an ADO Recordset interface on the row set and sends it to theclient machine as the RDS.DataControl requests it.7.If configured to do so, with large amounts of data the RDS.DataControl can cause the gridcontrol to become interactive very soon after the DataFactory begins sending data to theclient machine.Step 7 mentions a capability that RDS provides that could be crucial for applications that process largeamounts of data.RDS enables the results of queries to be sent asynchronously.The RDS.DataControl can be configured to retrieve data in the background or asynchronously.Ifthe RDS.DataControl is retrieving the data in the background and the user tells it to MoveLast(move to the last record), user interactivity will cease until all the data is retrieved.If theRDS.DataControl is retrieving the data asynchronously and the user tells it to MoveLast, userinteractivity will continue.The RDS.DataControl will move to the most recent record receivedand will continue to retrieve data asynchronously.You can enable the asynchronous capabilities of RDS by using the code shown in Listing 11.4.Createa new ASP page for this code.Call it something like ClientTierAsync.ASP.Listing 11.4 RDS Asynchronous Operations1:2:3: Client Tier4: 5:6: Remote Data Service and Sheridan Grid Control7:8:9:13:14:15:16:17:18:19:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39: Const adcExecSync = 140: Const adcExecAsync = 241:42: Const adcFetchUpFront = 143: Const adcFetchBackground = 244: Const adcFetchAsync = 345:46: Const adcReadyStateLoaded = 247: Const adcReadyStateInteractive = 348: Const adcReadyStateComplete = 449:50: SUB ADC_OnReadyStateChange51: Select case ADC.ReadyState52: case adcReadyStateLoaded: RsState.Value = "Loaded"53: case adcReadyStateInteractive: RsState.Value = "Interactive"54: case adcReadyStateComplete: RsState.Value = "Complete"55: END Select56: END SUB57:58: SUB MoveFirst_onClick 59: ADC.Recordset.MoveFirst60: END SUB61:62: SUB MovePrevious_onClick63: On Error Resume Next64: ADC.Recordset.MovePrevious65: IF ERR.Number 0 THEN66: ERR [ Pobierz całość w formacie PDF ]