Change the Web UI Component to use the DHO Component
By moving all the business and data handling logic to the DHO, the Web UI code becomes much simplerno more ADO database, recordset objects, and SQL statements to mess with! For example, the Web UI component contains a procedure named DetailProc, which needs to get the Publisher indicated by the PubID value on the querystring. To get a single Publisher using the new DHO, DetailProc now needs only four lines of code.
Dim lPubList As clsPublisherList Dim lPub As clsPublisher Set lPubList = New clsPublisherList Set lPub = lPubList.Fetch(gAspReq.QueryString.Item("PubID"))
And the code in the SearchProc procedure can get a Collection of all Publishers that match the search string by calling the clsPublisherList.Search method:
Dim lPubList As clsPublisherList Dim lPubCol As Collection ' Get the Filter value from the form. mUserState.Filter = gAspReq.Item("txtFilter") ' Instantiate the clsPublisherList object and ask it for a list ' of Publishers with a name that matches the search filter. Set lPubList = New clsPublisherList Set lPubCol = lPubList.Search(mUserState.Filter)
Of course, there are now more total lines of code that get executed if you count the code in both the PublishersWebUI and PublishersDHO components, but the hope is that the advantages listed at the beginning of this article outweigh any performance hit this technique creates.
I've also enhanced the sample application by changing the detail form to allow Publisher data to be updated. This basically involves changing the Detail.htm file to use a form and adding a new UpdateProc action to the Select Case statement in the clsWebApp.WebMain method. Again, for brevity's sake, the entire UpdateProc procedure is not listed in this article, but the code that uses the DHO component to do the update is now pretty trivial:
' Create a new Publisher object. Set lPub = New clsPublisher ' Get the new values from the form. Example: lPub.PubID = gAspReq.QueryString("PubID") lPub.Name = gAspReq.Form("txtName") ... ' Ask the clsPublisherList object to update this Publisher. Set lPubList = New clsPublisherList Call lPubList.Update(lPub)