The Home Page - Default.aspx
The default page is the entry point into the application. This page is meant as a home base and starting point for users.
From a development point of view this page performs only a couple of relatively simple tasks:
- Display a welcome message
Obviously, being the home page it's important to greet the user and let them know what they've reached and what they can do here. This is static content. - It tries to 'remember' the user
The page tries to read a WebStore cookie that reassociates the user with a user profile and then reads some basic information and shipping preferences. - Display the current specials
Depending on how you like to run a list of specials is displayed. You can either use the SpecialsListing user control to do this automatically assuming you've configured some or all of your items to display as Specials, or you can manually add these items along with links on the page. On my Web site I actually use a static list, because for me it's actually easier to to edit the HTML content than set up items with the content.
Remembering the user
The Web Store uses a single permanently cookie to try and track the user and remember him when he returns. To manage this cookie the store actually provides a WebStoreCookie class, which has a GetUserId() method that can be used to retrieve that UserId. This method essentially either returns an existing id or generates a new one. This info is then used to load up a CustomerRecord through the busCustomer bus object, which is then used to assign a few session variables that identify the user and some of his preferences (namely the shipping settings). The code for all this is straight forward and very short in fact:private void Page_Load(object sender, System.EventArgs e)
{
/// *** Try to get persistent cookie and load user
this.UserId = WebStoreCookie.GetUserId();
this.Customer = WebStoreFactory.GetbusCustomer();
if (this.Customer.LoadByUserId(this.UserId))
{
DataRowContainers.wws_customersRow CustRow = this.Customer.GetTypedDataRow(false);
this.lblWelcome.Text = "Welcome back, " + CustRow.Firstname + ".";
ShippingInfo ShipInfo= (ShippingInfo) Session["ShippingInfo"];
if (ShipInfo == null)
{
ShipInfo = new ShippingInfo();
ShipInfo.CountryId = CustRow.Countryid;
ShipInfo.State = CustRow.State;
ShipInfo.Zip = CustRow.Zip;
Session["ShippingInfo"] = ShipInfo;
}
}
}
You can see here that all data and logic access occurs through business object methods. Note also that the business object reference is retrieved through the WebStoreFactory class rather than directly instantiating the busCustomer class. This is done so that subclasses can be specified in a single location in the factory class which simply performs the instantiation and hands back a reference.
The WebStore uses a DataRowContainer class wrapper for most record level access which is handled by this code:
DataRowContainers.wws_customersRow CustRow = this.Customer.GetTypedDataRow(false);
Each of the business objects has a method that returns a typed DataRow instance that has members that parallel the fields of the table with full .Net type safety. This behavior is optional in the store and you can always access fields directly standard ADO.Net untyped behavior:
string Name = (string) Customer.DataRow["FirstName"] + " " + Customer.DataRow["LastName"];
The typed DataRows are obviously much nicer to use, but the classes that provide this are generated. To find out more how these generated classes are created and work check out Using Typed DataRows.
You can also get familiar with the ShipInfo class which is used to store all Shipping related options for the user. This object contains information like the shipping state, zip and country, the shipping method etc. - everything needed in order to calculate shipping and tax values. These values are entered through the run of the application before the order is placed and is retrieved at the end of the process to create the final order and calculate all totals. The object is light weight and is stored in whole in the Session object. The code above demonstrates the safe way to retrieve the value by checking for non-existance (null).
The Specials Listing
The list of specials is simply list of Urls that point directly at item pages for the specific item. Links point at Item.aspx?sku=WEBSTORE for example where sku is the stock id for the item.You can also use a data driven approach by using the SpecialsListing control. This control lists all items out of inventory that are configured as Specials. This list is autogenerated for you and include all items that have the Specials Field to a non-zero value and the SpecialHd and SpecialTxt fields filled. The Specials field is used as the sorting mechanism with higher numbers showing first.
You can embed the Specials control with this simple code:
Control registration:
<%@Register TagPrefix="ww" TagName="SpecialsListing" src="SpecialsListing.ascx"%>
Embedded control:
<ww:SpecialsListing id="Specials" runat="server"></ww:SpecialsListing>
© West Wind Technologies, 1996-2018 • Updated: 12/12/03
Comment or report problem with topic