ASP.NET
  Home arrow ASP.NET arrow Page 5 - Order-Related Modules for an ASP.NET AJAX ...
Click Here
IBM developerWorks
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-12-26

    Table of Contents:
  • Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website
  • Behind the Scenes
  • More Behind the Scenes Code
  • Web Handler
  • Buying Goods
  • Viewing the Shopping Cart
  • Page Initialization

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Buying Goods


    (Page 5 of 7 )

    After clicking the "Add to shopping cart" button, the related item can be put into the shopping cart, all of which is finished within the ProductView_RowCommand click event handler. In conclusion, the function will accomplish the following tasks:

    1. If there are no products inside the shopping cart, create an instance of the  OrderInfo(i.e. order) class which is used to save the cart related info;
    2. Obtain information about the product and create an instance of the OrderItemInfo(i.e. item) class to save this product-related info;
    3. Add the item objectinto the OrderItemList listof the order object;
    4. Update the info of the cart;
    5. If there are already products inside the shopping cart, get the order object used to save the cart-related info from the Session system variable;
    6. Obtain info of the product and create an instance of the OrderItemInfo(i.e. item) class to save this product-related info;
    7. Search from inside the order objectsub items that contain the same product as that inside the item project, and update the sub items info;
    8. Update the shopping cart.


    The following lists the complete code for the ProductView_RowCommand function:

    protected void ProductView_RowCommand(object
    sender,GridViewCommandEventArgs e){

    OrderItemInfo item = null;

    OrderInfo order = null;

    if(Session[Session.SessionID + OrderForm.Cart] == null) {

    item = GetOrderItemInformation(e);

    if(item == null) {

    ScriptManager.RegisterStartupScript(Page, GetType(), "script1",

    "alert('Data Error!');", true);

    return;

    }

    order = new OrderInfo();

    order.OrderItemList.Add(item);

    order.TotalMoney = item.Price;

    order.TotalNumber = item.Number;

    Session[Session.SessionID + OrderForm.Cart] = order;

    }

    else{

    order = (OrderInfo)Session[Session.SessionID + OrderForm.Cart];

    item = GetOrderItemInformation(e);

    if(item == null) {

    ScriptManager.RegisterStartupScript(Page, GetType(), "script2",

    "alert('Data Error!');", true);

    return;

    }

    int i = 0;

    for(i = 0; i < order.OrderItemList.Count; i++){

    if(item.ProductID == ((OrderItemInfo)order.OrderItemList[i]).ProductID) {

    ((OrderItemInfo)order.OrderItemList[i]).Number++;

    ((OrderItemInfo)order.OrderItemList[i]).ItemTotalMoney +=
    item.ItemTotalMoney;

    break;

    }

    }

    if(i == order.OrderItemList.Count) {

    order.OrderItemList.Add(item);

    }

    order.TotalNumber++;

    order.TotalMoney += item.Price;

    Session[Session.SessionID + OrderForm.Cart] = order;

    }

    ScriptManager.RegisterStartupScript(Page, GetType(), "script3",

    "alert('You have succeeded in adding the selected goods into the shopping
    cart!');", true);

    }

    For brevity, we omit the code listing for the GetOrderItemInformation helper function.

    In addition, there are several issues that deserve to be discussed. First, because when we get the product information, the row index of the ProductView controlhas to be used, at the earlier event (RowCreated) of the ProductView controlwe put the index number of the product into the CommandArgument propertyof the buyBtn button(which is the IDproperty of the "Add to shopping cart" button). Here's the related code:

    protected void ProductView_RowCreated(object sender,GridViewRowEventArgs
    e){

    if(e.Row.RowType == DataControlRowType.DataRow) {

    Button buyBtn = (Button)e.Row.FindControl("BuyBtn");

    if(buyBtn != null) {

    buyBtn.CommandArgument = e.Row.RowIndex.ToString();

    }

    }

    }

    Second, in traditional ASP.NET applications most of us like to use 'Response.Write("<script>window.alert('....')</script>");' to tell users the result of the current operation. However, due to leveraging the ASP.NET AJAX server control named UpdatePanelto enclose the GridView control we can not use that any more, or else we will meet some error like the one displayed in Figure 16.


    Figure 16-an error occurs when we use 'Response.Write(...);' inside UpdatePanel control to give some clue to the users

    Therefore, we have to resort to a static function named RegisterStartupScriptof the ScriptManager control. Here is an example of what happens when the "adding" operation is successful.

    ScriptManager.RegisterStartupScript(Page, GetType(), "script3",

    "alert('You have succeeded in adding the selected goods into the shopping
    cart!');", true);

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...
    - Order-Related Modules for an ASP.NET AJAX Se...
    - User and Role Management for an ASP.NET AJAX...
    - Programming an ASP.NET AJAX Server-Centric B...

    SunQuest




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway