Step 5: Implement the OrderConfirmation.aspx Page

The OrderConfirmation.aspx page provides order confirmation. After a user confirms an order, this page submits the order information for post-processing by Commerce Server 2002.

In this step you will build and implement the order confirmation page by doing the folloiwng:

  1. Create the OrderConfirmation.aspx page and insert the header.
  2. Add a table to the page to organize the data displayed to the user.
  3. Insert a Repeater control onto the form and create an item template for it.
  4. Insert controls on the OrderConfirmation.aspx page.
  5. Insert Commerce Server classes.
  6. Insert class-wide variables.
  7. Add code to the Page_Load event handler.
  8. Add code to the confirmOrderBtn_click() event handler.

To create the OrderConfirmation.aspx page and insert the header

To add a table to the OrderConfirmation.aspx page

To insert the repeater control

To insert controls on the OrderConfirmation.aspx page

To insert Commerce Server classes

To insert class-wide variables

To add code to the Page_Load() event handler

To add code to the confirmOrderBtn_Click() event handler

To create the OrderConfirmation.aspx page and insert the header

  1. Click Start, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.

  2. In the Microsoft Development Environment [design] – Start Page screen, click Open Project.

  3. In the Open Project dialog box, select the NorthwindTraders project, and then click Open.

  4. In the NorthwindTraders – Microsoft Visual C# .NET [design] – Default.aspx window, in the Solution Explorer window, right-click NorthwindTraders, point to Add, and then click Add Web Form.

  5. In the Add new Item - NorthwindTraders dialog box, in the Name box, type OrderConfirmation.aspx, and then click Open.

  6. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, in the lower-left corner, click HTML, and then add the following code at the very top of the page, below the <%@ Page> but before the <!DOCTYPE> tags:

    <%@ Import Namespace="Microsoft.CommerceServer.Runtime" %>
    <%@ Import Namespace="Microsoft.CommerceServer.Runtime.Orders" %>
    

To add a table to the OrderConfirmation.aspx page

  • Add the following HTML code in to the page:

    <asp:Label id="PageSubTitle" />
       <table width="80%" cellpadding="1" cellspacing="0" border="0">
          <tr valign="top" bgcolor="#000000">
             <td align="center" id="Quantity" width="10%" 
                style="COLOR: #ffffff"></td>
             <td align="center" id="Name" width="60%"  
                style="COLOR: #ffffff"></td>
             <td align="center" id="Price" width="10%"  
                style="COLOR: #ffffff"></td>
             <td align="center" id="DiscountedPrice" width="10%"   
                style="COLOR: #ffffff"></td>                  
             <td >&nbsp;<br></td>
          </tr>
       </table>
    

To insert the Repeater control

  1. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, in the lower-left corner, click Design.

  2. Click View on the toolbar, and then click Toolbox.

  3. In the Toolbox window, in the Web Forms box, drag and drop a Repeater control onto the form.

  4. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type OrderListing.

  5. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, in the lower-left corner, click HTML.

  6. Move the <asp:Repeater> and </asp:Repeater> tags between the </tr> and </table> tags.

  7. Insert the following code (as a sub-element) between the <asp:Repeater> and </asp:Repeater> tags:

    <ItemTemplate>
       <tr>
       <td colspan=5>
          <%# DataBinder.Eval(Container.DataItem, "Name") %>
       </td>
       </tr>                  
       <asp:Repeater id="BasketListing" DataSource='<%#DataBinder.Eval(Container.DataItem, "LineItems")%>' >
          <ItemTemplate>
          <tr>
                <td align="left" width="10%"  ID="Td1">
                   <asp:Label ID="QuantityContent" Runat="server">
                      <%# ((LineItem)Container.DataItem)["Quantity"] %>
                   </asp:Label>
                </td>
                <td align="left" width="60%"  ID="Td2">
                   <asp:Label ID="ProductName" Runat="server">
                      <%# ((LineItem)Container.DataItem)["_product_Name"] %>
                   </asp:Label>
                   <br />
                   <asp:Label ID="Description" Runat="server">
                      <%# ((LineItem)Container.DataItem)["_product_Description"] %>
                   </asp:Label>
                </td>
                <td valign="right" width="10%"  ID="Td3">
                   <asp:Label ID="PriceContent" Font-Name="verdana" Runat="server">
                      <%# Decimal.Parse(((LineItem)Container.DataItem)["_product_cy_list_price"].ToString()).ToString("c") %>
                   </asp:Label>
                </td>
                <td valign="right" width="10%"  ID="Td4">
                   <asp:Label ID="DiscountedPriceContent" Font-Name="verdana" Runat="server">
                      <%# Decimal.Parse(((LineItem)Container.DataItem)["_cy_oadjust_adjustedprice"].ToString()).ToString("c") %>
                   </asp:Label>
                </td>
                </tr>
             </ItemTemplate>
             <SeparatorTemplate>
                <tr>
                <td colspan="5">
                   <hr noshade  ID="Hr1"/>
                </td>
                </tr>
             </SeparatorTemplate>
          </asp:Repeater>
       </ItemTemplate>
       <FooterTemplate>
       </FooterTemplate>
    

Ee810306.note(en-US,CS.20).gifNote

  • All fields beginning with “_” are temporary and only exist until the current basket instance is shut down. They are regenerated each time the pipeline components are run.

To insert controls on the OrderConfirmation.aspx page

Ee810306.note(en-US,CS.20).gifNote

  • Add the following controls above the basket listing code that was added in the procedure, "To insert the Repeater control."
  1. In the Solution Explorer window, click View Designer.
  2. Click View on the toolbar, and then click Toolbox.
  3. In the Toolbox window, in the Web Forms, drag and drop a Label control onto the form.
  4. In the Properties window, make sure the control that you just created is selected, and then do the following:
    Use this To do this
    ID Type AddressTitleLabel.
    Text Type Address:.
  5. In the Toolbox window, in the Web Forms, drag and drop another Label control onto the form.
  6. In the Properties window, make sure you the control that you just created is selected, and then in the ID box, type firstNameLabel.
  7. In the Toolbox window, in the Web Forms, drag and drop a Label control onto the form.
  8. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type lastNameLabel.
  9. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  10. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type addressLine1Label.
  11. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  12. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type addressLine2Label.
  13. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  14. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type cityLabel.
  15. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  16. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type stateLabel.
  17. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  18. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type zipLabel.
  19. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, in the lower-left corner, click HTML.
  20. Add the <br><br> tags after zipLabel.
  21. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, in the lower-left corner, click Design.
  22. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  23. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type subTotalLabel.
  24. In the Toolbox window, in the Web Forms, drag and drop a Label control onto the form.
  25. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type shippingTotalLabel.
  26. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  27. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type taxTotalLabel.
  28. In the Toolbox window, in the Web Forms section, drag and drop a Label control onto the form.
  29. In the Properties window, make sure the control that you just created is selected, and then in the ID box, type totalLabel.
  30. In the Toolbox window, in the Web Forms section, drag and drop a Button control onto the form.
  31. In the Properties window, make sure the control that you just created is selected, and then do the following:
    Use this To do this
    ID Type confirmOrderBtn.
    Text Type Confirm Order >>.

To insert Commerce Server classes

  1. In the Solution Explorer window, click View Code.

  2. Add the following references in the using section:

    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Runtime.Profiles;
    using Microsoft.CommerceServer.Runtime.Orders;
    using Microsoft.CommerceServer.Runtime.Pipelines;
    using Microsoft.CommerceServer.Runtime.Catalog;
    using Microsoft.CommerceServer.Runtime.Diagnostics;
    using Microsoft.CommerceServer.Runtime.Caching;
    

To insert class-wide variables

  • In the public class section, add the following code:

    protected System.Web.UI.WebControls.Repeater BasketListing;
    
    OrderContext    ordersys = CommerceContext.Current.OrderSystem;
     Microsoft.CommerceServer.Runtime.Orders.Basket basket = null;
    

To add code to the Page_Load() event handler

  • In the Page_Load() event handler, add the following code:

       // Render the basket 
       // Validate login and redirect if user is not logged in
    
       if(!IsPostBack) 
       {
    
          CommerceContext ctx = CommerceContext.Current;
          Profile userProfile = null;
          bool isLoggedOn = ctx.AuthenticationInfo.IsAuthenticated();
    
          // This simple process does not carry the product that the
          // user was attempting to enter.  This would be good to do 
          // in a real site...
    
          if(!isLoggedOn) 
          {
             Response.Redirect("login.aspx");
          }
    
          // Extract the userID to get the basket
          ProfileContext profContext = ctx.ProfileSystem;
          string userId = ctx.UserID;
    
          basket = ordersys.GetBasket(new Guid(userId));
    
    
    
          //If there isn't anything in the basket, then redirect to the default.aspx page.
          if(!(basket.OrderForms.Count > 0)) 
          {
             Response.Redirect("default.aspx");
          }
    
          //Get the user profile
          userProfile = profContext.GetProfile(ctx.UserID,"UserObject");
    
          PipelineInfo info = new PipelineInfo("basket");
    
          info["CacheName"] = "discounts";
          info.Profiles.Add("User", CommerceContext.Current.UserProfile);
          basket.RunPipeline(info);   
          // Run the total pipeline...
          info = new PipelineInfo("Total");
          basket.RunPipeline(info);
    
          // Now, populate the controls with the data from the user's order.
          totalLabel.Text = basket.Total.ToString("C");
          shippingTotalLabel.Text = basket.ShippingTotal.ToString("C");
          subTotalLabel.Text = basket.SubTotal.ToString("C");
          taxTotalLabel.Text = basket.TaxTotal.ToString("C");
    
          // Assume the billing address is our only address in the OrderGroup.
          // Also, assume a US format address.
    
          // First, get the address object.
          OrderAddress address = basket.Addresses[basket.OrderForms["default"].BillingAddress];
          addressLine1Label.Text = address.Line1;
          addressLine2Label.Text = address.Line2;
          firstNameLabel.Text = address.FirstName;
          lastNameLabel.Text = address.LastName;
          cityLabel.Text = address.City;
          stateLabel.Text = address.State;
          zipLabel.Text = address.PostalCode;
    
          string orderFormName = "default";
          if(null != basket.OrderForms[orderFormName] && 0 < basket.OrderForms[orderFormName].LineItems.Count) 
          {
             OrderListing.DataSource = basket.OrderForms;
             OrderListing.DataBind();
          }
          basket.Save();
       }
    

To add code to the confirmOrderBtn_Click() event handler

  1. In the Solution Explorer window, click View Code.

  2. In the NorthwindTraders – Microsoft Visual C# .NET [design] – OrderConfirmation.aspx window, double-click the Confirm Order >> button.

  3. In the confirmOrderBtn_Click() button handler, add the following code:

       CommerceContext ctx = CommerceContext.Current;
       // Extract the userID to get the basket
       ProfileContext profContext = ctx.ProfileSystem;
       string userId = ctx.UserID;
    
       basket = ordersys.GetBasket(new Guid(userId));
    
       // This next command converts our basket into an order and initiates
       // post-processing inside of CS2002.
       basket.SaveAsOrder();
    
       // Bounce the user to the start page.  We would also include a
       // page that displays an order number/receipt for purchase in a
       // live production site.
       Response.Redirect("default.aspx");
    

Copyright © 2005 Microsoft Corporation.
All rights reserved.