- The TAU Business Model
- The Goals of TAU.NET System Design
- Architecture
- TAU.NET Node Adaptor
- Summary
11.4 TAU.NET Node Adaptor
Now let's consider the TAU.NET Node Adaptor in which the data is manipulated and the business rule realized.
11.4.1 TAU.NET Node Adaptor to Link Cell System Database
The following code segment is designed to implement the Web method in the Web Service GetServiceDataSetByLocation. We need to connect a database in the Cell System to retrieve the travel service records and detail line items according to the criteria on location.
[WebMethod] public TauServiceDataSet GetServiceDataSetByLocation(String locationCode) { TAU.TauServiceDataSet returnDataSet = new TAU.TauServiceDataSet(); try { sqlConnection1.Open(); sqlDATauServiceLocation.SelectCommand.Parameters ["@LocationCode"].Value = locationCode; sqlDATauServiceDetailLocation.SelectCommand.Parameters ["@LocationCode"].Value = locationCode; sqlDATauServiceLocation.Fill (returnDataSet, "TAU_SERVICE"); sqlDATauServiceDetailLocation.Fill(returnDataSet, "TAU_SERVICE_DETAIL"); } catch (Exception e) { returnDataSet.Reset(); throw e; } finally { sqlConnection1.Close(); } return returnDataSet; }
In this code segment, sqlConnection1, an instance of System. Data.SqlClient.SqlConnection, is used to support connection to the SQL database.
SqlDATauServiceLocation is an instance of SqlDataAdapter that is built on the following SQL statement:
SELECT TAU_MEMBER.NAME AS Name, TAU_MEMBER.SERVICEURL AS WebServiceUrl, TAU_MEMBER_LOCATION.LOCATIONCODE AS Location FROM TAU_MEMBER INNER JOIN TAU_MEMBER_LOCATION ON TAU_MEMBER.TAUMEMBERID
= TAU_MEMBER_LOCATION.TAUMEMBERID WHERE (TAU_MEMBER_LOCATION.LOCATIONCODE = @LocationCode)
sqlDATauServiceDetailLocation is an instance of SqlDataAdapter that is based on this SQL script:
SELECT TAU_SERVICE_DETAIL.SERVICEID AS SERVICEID, TAU_SERVICE_DETAIL.LineItemOrder AS LineItemOrder, TAU_SERVICE_DETAIL.ItemDesc AS ItemDesc, TAU_SERVICE_DETAIL.ItemUrl AS ItemUrl FROM TAU_SERVICE_DETAIL INNER JOIN TAU_SERVICE ON TAU_SERVICE_DETAIL.SERVICEID = TAU_SERVICE.SERVICEID WHERE (TAU_SERVICE.LOCATIONCODE = @LocationCode)
In this simple case, the implementation of the TAU.NET Node Adaptor components is embedded in the implementation of the Web method. Should applications become more complex, the TAU.NET Node Adaptor components should be implemented as separated classes and the Web method should access the data via its instances.
11.4.2 TAU.NET Node Adaptor to Serve a Web Page
In the previous section, we built a TAU.NET Node Adaptor to produce a DataSet containing records about travel service items by retrieving a relational database on a Cell System. Here, we implement another TAU.NET Node Adaptor as a client to request the Web method. This adapter is used from an ASP.NET page, which means the DataSet returning the Web Service would be served to a Web server page and Web browser eventually.
The ASP.NET page is designed as shown in Figure 11-11. We have a master DataGrid and a detail DataGrid. When the Search button is clicked, we load the DataSet for those DataGrid via the Web Service.F
Figure 11-11 Design of the ASP.NET page showing TAU.NET service item information.
The following code is for the button click:
private void buttonLoad_Click(object sender, System.EventArgs e) { objTauServiceDataSet = new TAU.TauServiceDataSet(); this.LoadDataSet(this.locationCode.Text); this.masterDataGrid.SelectedIndex = -1; this.masterDataGrid.DataBind(); this.detailDataGrid.Visible = false; Application["objTauServiceDataSet"] = this.objTauServiceDataSet; }
In this code, this.LoadDataSet(this.locationCode.Text) is designed to load the DataSet via the Web Service.
public void LoadDataSet(string locationCode) { TAU.Proxy.TauService objService; objService = new TAU.Proxy.TauService(); objService.Url="http://localhost/TAU/TauService.asmx"; TAU.Proxy.TauServiceDataSet objDataSetTemp; objDataSetTemp = new TAU.Proxy.TauServiceDataSet(); try { objDataSetTemp = objService.GetServiceDataSetByLocation( locationCode ); } catch (System.Exception eFillDataSet) { // Add exception handling code here. throw eFillDataSet; } try { // Merge the records that were just pulled from the data store into the main dataset objTauServiceDataSet.Merge(objDataSetTemp); } catch (System.Exception eLoadMerge) { // Add exception handling code here throw eLoadMerge; } }
Once the selection changes on the master DataGrid, we show the corresponding detail by following code logic:
private void masterDataGrid_SelectedIndexChanged( object sender, System.EventArgs e) { this.ShowDetailGrid(); } private void ShowDetailGrid() { if ((this.masterDataGrid.SelectedIndex != -1)) { System.Data.DataView parentRows; System.Data.DataView childRows; System.Data.DataRowView currentParentRow; this.objTauServiceDataSet = ((TAU.TauServiceDataSet) (Application["objTauServiceDataSet"])); parentRows = new DataView(); parentRows.Table = this.objTauServiceDataSet.Tables["TAU_SERVICE"]; currentParentRow=parentRows [this.masterDataGrid.SelectedIndex]; childRows = currentParentRow.CreateChildView( "TAU_SERVICE_TAU_SERVICE_DETAIL"); this.detailDataGrid.DataSource = childRows; this.detailDataGrid.DataBind(); this.detailDataGrid.Visible = true; } else { this.detailDataGrid.Visible = false; } }
Finally, we get the page shown in Figure 11-12.
Figure 11-12 ASP.NET Web page showing the result retrieved from the Web