Lecture 03 - Shopping Cart V3
Lecture 03 - Shopping Cart V3
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:
• 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
• 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