Listing F
Public Class SearchOrders
    Inherits System.Web.UI.Page
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEventscboStatus As System.Web.UI.WebControls.DropDownList
    Protected WithEventscboClients As System.Web.UI.WebControls.DropDownList
    Protected WithEventsbtnSearch As System.Web.UI.WebControls.Button
    Protected WithEventslblMsg As System.Web.UI.WebControls.Label
    Protected WithEventsdgResults As System.Web.UI.WebControls.DataGrid
 
 
#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
 
 
        If Not Page.IsPostBack Then
            Dim ClientObj As New ClientServices()
            Dim ClientDs As DataSet = ClientObj.GetAllClients()
 
 
           Me.cboClients.DataSource = ClientDs.Tables(0)
           Me.cboClients.DataTextField = ClientDb.FIELD_CLIENT_NAME
           Me.cboClients.DataValueField = ClientDb.FIELD_CLIENT_ID
 
 
           Me.cboStatus.Items.Add("") 'blank entry
           Me.cboStatus.Items.Add(OrderDb.ORDER_STATUS_PENDING)
           Me.cboStatus.Items.Add(OrderDb.ORDER_STATUS_COMPLETE)
 
 
           Me.DataBind()
 
 
           Me.cboClients.Items.Insert(0, "")
 
 
           Me.lblMsg.Visible = False
           Me.dgResults.Visible = True
        End If
    End Sub
 
 
    '#########################################################################################################################
   ' This method searches the database for orders that have been placed. If filtered by status=Pending, we provide a button
    ' allowing the user to confirm and complete the order
    '#########################################################################################################################
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim OrderObj As New OrderServices()
        Dim ClientId As Int32 = Nothing
        If Not Utils.IsNull(Me.cboClients.SelectedItem.Value) Then
           ClientId = Convert.ToInt32(Me.cboClients.SelectedItem.Value)
        End If
        Dim OrderDs As DataSet = OrderObj.GetOrders(Nothing, Me.cboStatus.SelectedItem.Value, ClientId)
 
 
        If Not OrderDs Is Nothing Then
            If Me.cboStatus.SelectedItem.Text = OrderDb.ORDER_STATUS_PENDING Then
               Me.dgResults.Columns.Item(5).Visible = True
            Else
               Me.dgResults.Columns.Item(5).Visible = False
            End If
           Me.dgResults.DataSource = OrderDs.Tables(0)
           Me.dgResults.Visible = True
           Me.DataBind()
 
 
           Me.lblMsg.Visible = False
           Me.dgResults.Visible = True
        End If
 
 
    End Sub
 
 
 
 
    '#########################################################################################################################
   ' Confirms a pending order by invoking Tom's web service and updating the order in his application first.
    ' The call is made asynchronously to allow for fast user response
    '#########################################################################################################################
    Public Sub Confirm_Order(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        ' Grab the Id of the order being confirmed
        Dim OrderId As Int32 = Convert.ToInt32(e.Item.Cells(0).Text)
        Dim OrderObj As New OrderServices()
 
 
        'Get the information regarding the order
        Dim OrderDs As DataSet = OrderObj.GetOrders(OrderId, Nothing, Nothing)
 
 
        '## NOTE ##
        ' If we add additional clients, we need to check the client Id and invoke
       ' the correct web service method for that particular client. Since
        ' Tom is the only client in our example, we invoke his web service directly
 
 
        Dim OrderProxy As New OrderProxy.OrderWS()
       OrderProxy.OrderSecurityContextValue = WSUtil.GetOrderSecurityContext()
       OrderProxy.BeginConfirmOrder(OrderId, OrderDs, New AsyncCallback(AddressOfCompleteOrder), OrderProxy)
 
 
       Me.lblMsg.Text = "The order has been sent for completion processing"
       Me.lblMsg.Visible = True
       Me.dgResults.Visible = False
 
 
    End Sub
 
 
 
 
    '#########################################################################################################################
   ' Callback function for when Tom's application completes the confirm order method. At this point everything is ok
    ' and we can update our own database's reference of the order to completed
    '#########################################################################################################################
    Private Sub CompleteOrder(ByValAsyncResult As IAsyncResult)
        Dim ProxyObj As OrderProxy.OrderWS = CType(AsyncResult.AsyncState, OrderProxy.OrderWS)
        Dim OrderId As Int32 = ProxyObj.EndConfirmOrder(AsyncResult)
 
 
        ' We can be guaranteed that Tom's app has completed the order, so update the order in John's app also
        Dim OrderObj As New OrderServices()
       OrderObj.ConfirmOrder(OrderId)
 
 
    End Sub
End Class