Listing H
Public Class SearchBooks
    Inherits System.Web.UI.Page
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
    Protected WithEvents cboAvailability As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtBookName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAuthor As System.Web.UI.WebControls.TextBox
    Protected WithEvents dgBooks As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Label5 As System.Web.UI.WebControls.Label
 
 
#Region " Web Form Designer Generated Code "
 
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
 
    End Sub
 
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
 
#End Region
 
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
 
 
        ' Initialize the availability drop down
        If Not Page.IsPostBack Then
            Dim ProxyObj As New BookProxy.BookWS()
            ProxyObj.BookSecurityContextValue = WSUtil.GetBookSecurityContext()
 
 
            Dim AvailabilityDs As DataSet = ProxyObj.GetAvailabilityDs()
            If Not AvailabilityDs Is Nothing Then
                Me.cboAvailability.DataSource = AvailabilityDs.Tables(0)
               Me.cboAvailability.DataTextField = JohnDb.AvailabilityDb.FIELD_AVAILABILITY_NAME
                Me.cboAvailability.DataValueField = JohnDb.AvailabilityDb.FIELD_AVAILABILITY_ID
                Me.DataBind()
 
 
                Me.cboAvailability.Items.Insert(0, "")
            End If
        End If
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' When the search button is clicked we invoke John's web service and search his books. The result is bound to our datagrid
    '#########################################################################################################################
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim ProxyObj As New BookProxy.BookWS()
        ProxyObj.BookSecurityContextValue = WSUtil.GetBookSecurityContext
 
 
        Dim AvailabilityId As Int32
        If Not Utils.IsNull(Me.cboAvailability.SelectedItem.Value) Then
            AvailabilityId = Convert.ToInt32(Me.cboAvailability.SelectedItem.Value)
        End If
        Dim BookDs As DataSet = ProxyObj.SearchBooks(Nothing, Me.txtAuthor.Text, Me.txtBookName.Text, AvailabilityId)
        If Not BookDs Is Nothing Then
            Me.dgBooks.DataSource = BookDs.Tables(0)
            Me.dgBooks.Visible = True
            Me.DataBind()
        End If
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' When an item in the datagrid is clicked, we add the book to the customers shopping cart
    '#########################################################################################################################
    Public Sub Place_Order(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        ' Add the book Id to the user's session
        Dim SessionObj As ClientSession = Session.Item(ClientSession.CLIENT_SESSION_REF)
        SessionObj.BookIds.Add(e.Item.Cells(0).Text)
 
 
        ' Increment the number of book in their order
        SessionObj.NumItems += 1
    End Sub
 
 
End Class