0% found this document useful (0 votes)
41 views

Lecture 03 - Shopping Cart V3

Asp introduction
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Lecture 03 - Shopping Cart V3

Asp introduction
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

The shopping cart

application
ISTN3SI C# Lecture 3
Create the business tables
• Customer – Order – OrderDetails – Products
• Update button → Update Database when the button is available
Create the business tables
• Customer – Order – OrderDetails – Books
Populate some data
Designing the Sales Page
• Logically, this should be a private page…
• Should not be on the home page as user should log in first…
• So create a new web form page called OnlineShop
• NB: Use Add New Item → Web Form with Master Page → Select Site.Master
• If you use Add → Web Form, you have to do this manually…
Designing the Sales Page
• The products that are on sale should be visible…
• Drag and drop the table into the design view of the intended page
Extending the Gridview
• Add an ImageField
Allocating Images
• Why we named the images 0, 1,
2 etc.
• DataImageUrlField –
ProductID
• DataImageUrlFormat –
Location of image relative to
Solution Explorer
The result
• Note the headers not
based on DB fields
• Adjust/crop images as
needed
• Use the ControlStyle
properties
• Set formatting of text as
needed
Viewing to Carting
• Add a template field and a button
• The template field should have a dropdown box
• The template field must be edited (Edit Template), drag a Dropbox onto the area and add
items
• The button should be labelled “Add to Cart”
• Add a label for the date
• Display the date when the page loads
The result
Initializing the cart
• In the global.asax.cs file, create a session_start method
as follows:

void Session_Start(object sender, EventArgs e)


{
Session.Add("Cart", null);
}
Creating the Cart Item class
• Create a class
• The C# OO lectures should have
given you an understanding of
the code’s meaning…
Useful Info
• Add a DetailsView data object
• Add a SqlDataSource object – Configure to link to the Customer table
• Select * from Customer Where ([eMail] = @email)
• Link the DetailsView object to DSCustomer

• The idea here is to show the details of the customer that is making
the purchase
• Remember that this page will be behind a security wall… Only
registered users can access the Online Shop
Developing the shopping cart
Used to link the logged in individual
to the Customer account

Covered later…
The viewable Shopping Cart
• Add a GridView and setup as
follows:
• Add a button to remove from cart
• Later… the cartList will be bound to
this GridView (UpdateCart)
Setting up Command Names
• Allocate a CommandName
to the Add to Cart button…
• Why?
• See next slide
CommandName and button click
• The user clicks on Add to Cart, but which one?
• Give the button click a command name (btnClick)
• When the button is clicked, check whether this was a CommandName that
triggered the button click
• The Event handler GridViewProduct_RowCommand deals with what happens
when any Add to Cart is clicked
Sending the item to the cart object

Covered later…
Cart Items → GridView
• Binds the cartList to the GridView
• Sets all the values to display as currency

Used for counting and displaying in


Site.Master
Getting the total due
• One of the more straightforward jobs to do…
App runthrough…
• Log in and go to Store… Cart not visible as no items selected
App runthrough… add items
• Customer wants 5 marvel bags, 5 cookies and 3 X 2 bouncy ball sets
Deleting rows from the cart
• How to tell which row was deleted?
• Similar to Add to cart…
• Use a commandbutton (delete) rather than a normal button
• Will leave to you to work out
Preparing for Sale Confirmation
• Add a button for Finalizing the Sale
• The following tasks MUST be accomplished
• Current date (of sale) – already displayed (Label1)
• CustomerID – Get the username/email address of the corresponding user
from the Customer table
• Sale total amount – Displayed (TotalDue)
• The ID of the newly recorded sale must be generated
• Not possible to record the sale without it
• Record the Order and the OrderDetails
Getting the customerID
• The user needs to log in
• Once this happens, User.Identity.Name gets you the customer
username; use this username as a parameter to find the Customer in
the Customer table and then display all customer details in a
Gridview/Detailsview; now extract the CustomerID and use this for
the recording of the sale
Generating the ID of the newly recorded sale
• A SqlDataSource is required to record the
Order
• Insert Into Order
Generating the ID of the newly recorded sale
• Configure the InsertQuery
property
• Remove the OrderID from the
INSERT SQL statement and
Parameters list
• Set the default values for the
OrderDate and AmountDue
parameters
• Scope_Identity()
• Refresh Parameters to see OrderID
• Change advanced properties
Generating the ID of the newly recorded sale

• Now the overall Sale has been recorded in the Order Table…the next
challenge is to get back the OrderID so that it can be used to record
the details of the Individual items that have been ordered – this has
not been captured as yet and is the most challenging part….coming
up next!!
Adding the Order Details to the OrderDetails
table
• Creating the order necessitates the creation of the orderdetails
• Thus, use the same dataset that recorded the sale (DSInsertOrder)
• Created an Inserted event handler – This controls what happens when a
record is inserted into the DB
Adding the Order Details to the OrderDetails
table
• Add a new SQLDataSource and take note of the required parameters
Adding the Order Details to the OrderDetails
table
Adding the Order Details to the OrderDetails
table
Confirmation to Process Sale

• Javascript-based confirmation
• Optional but good to ask a final time…
Final View
Basic Shopping Cart done
• Improvements left for you
• After item is added, reset dropdown to 0
• Better presentation of logged in user
• Better presentation in general
• Use of currency symbols where appropriate

You might also like