Download ITY276 presentation 4

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Versant Object Database wikipedia , lookup

Operational transformation wikipedia , lookup

Data center wikipedia , lookup

Semantic Web wikipedia , lookup

Data analysis wikipedia , lookup

Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Data model wikipedia , lookup

Forecasting wikipedia , lookup

Information privacy law wikipedia , lookup

Business intelligence wikipedia , lookup

Web analytics wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Data vault modeling wikipedia , lookup

Database model wikipedia , lookup

E-Commerce Technologies
Richard Henson
University of Worcester
October 2013
Week 5: Database Design, Server
Scripting and Forms Design for
Shopping Cart Systems
 Ensure that a consistent data model has been
designed as an essential first stage in development
 Explain the .net coding required to trap data from
HTML forms and write data to specified data fields
 Explain the use of web controls with HTML to
allow parameter passing between pages
 Create product pages that can pass on data
Resolving the ProductsCustomers relationship
Many databases have failed through
lack of knowledge of entity modelling…
many:many relationship…!!!
Link Entity…
“Many:many” relationship
Option 1: “programme” as OO database from
scratch to allow repeats (!)
Option 2: use Relational Database…
» not allowed: use “link” entities until no many:many left
XYZ (order?)
Is one more entity enough?
One customer makes the order
Can make multiple orders
1:many relationship
One or more products make up the
product and order still many:many
Product & Order need a further entity
between them…
Shopping Cart Entities
All of this needs to be reflected in
shopping cart database design…
Why? (discuss…)
Possible basic data (entity)
model for a Shopping System
No entity
Order line
Where does
Shopping Cart fit?
Possible Data Model with
entities/attributes added
Field names may
be different but
the principle is the
Testing the Logical Design
with Physical Data…
ERM may work on paper…
But easy to get the logic wrong…
Test with practical working model
create database tables
link, according to your ERM
populate the tables with trial data of an
appropriate format
make sure all is still consistent…
Creating the Physical Database
from a Logical Design
Popular options for small(ish) databases:
Microsoft Access
» only Access 2000 onwards properly SQL compliant
MySQL (open source)
» originally shareware for Unix
» also for Windows
Popular options for larger databases:
Essential attributes
for Orders Entity
All entities in an entity model…
need a primary key
need a foreign key to link with an attribute
in another entity
» which attributes in orders?
Essential attributes for
Orderline Entity
Primary key attribute?
 Foreign key to link to another entity…
again… which one?
Each orderline contains other data that
needs to be recorded to complete the
order. Which other attributes are needed?
Completing the Data model
Server scripts will use data from one/more
 essential that attributes for entities correctly
How can any gaps in the data model be filled
 important that this is completed before
programming the scripts begins…
Role of Server Scripting in
creating Product Pages
Server behaviours with appropriate
embedded SQL required for:
picking the right data out of the remote
writing data to the appropriate locations in
HTML pages on the local client browser
Managing a temporary store in memory on
the local machine
Local storage of “remote” data
 supports local storage of data through
datasets (arrays)
 simply a local copy of various data fields held on
one or more data tables on the remote database
 each field becomes a variable in local memory
The dataset fields map directly onto the fields
in the remote database
 new data can therefore always be stored locally until
the appropriate server command is made that writes
it to the remote database
The Dataset Display
(one record from database)
As you have seen, VWD facilitates the setting
up of datasets (& datagrids)
VWD also used to help generate scripts for
display of dataset data on a HTML page…
 further control(s) can be used to create a HTML
table for displaying a single record
 a navigation bar object can then be added and
used to navigate to other records
HTML forms and Web forms
HTML forms work at the client end…
collect data in a structured way
store it as pre-defined data type with
specific field name, initially on the local
Web forms are constructs
 easily created in Visual Studio using .net toolbox
 don’t use HTML… in this module we’ll be
sticking with HTML forms
Care with mapping of data
within a HTML form
Structure of a HTML form:
 Get/Post tell page where to send the data
 text boxes/fieldnames for adding data
 button(s) to trigger the sending of data to the
location specified by get or post…
Data added to the form can be sent to:
 email address
 URL of a web server
HTML forms Input-Output syntax
Basic structure: <form> … </form>
Within the form definition, ACTION points to a
URL that will accept the supplied information
and do something with it
 it is up to the web server at that website to deduce
the type of script from its suffix
 the web server then needs to use appropriate
software to process it
HTML forms Input-Output syntax
Also within the form definition,
METHOD tells the form how to send its
data fields back to the script:
POST sends all the information from the
form separately from the URL string
» could be used with mailto
GET attaches the information from the form
to the end of the URL string (max 255
Modular Development of
Applications: “code” files in HTML
Existing good code recycled whenever
 useful for portability (no point in rewriting…)
Several ways to use settings/code text file
called within first .aspx page:
 SSI Include
 “code behind” css
Also possible to associate “ready to run”
compiled code
 “toolbox” controls & “assemblies”
The Server-Side #Include
(SSI) Directive
Saved as a .inc file
used with multiple asp(x) pages
» #INCLUDE directive and either “VIRTUAL” or
“FILE” keyword placed inside what would normally
be HTML comment tags, with file=“filename”
» e.g: <!--#include
Using Server Scripting to
Create the Shopping System
Product Information stored on database
Script connects to database
Products can all be displayed on a page
Very useful for users to “click to buy”?
How can clicking behaviour be recorded?
 coded into the product page & shopping cart
 where shopping cart logic comes in very handy…
“Shopping Cart” control
A “ready assembled” web control…
sets up the fields that will be used to store
the shopping data
Could have been set up as a code
behind file
lot of coding…
why bother if someone has perfected it
also, needs to be used by many .aspx pages
“Shopping Cart” control
Better off as an assembly
apart from accessed by multiple .aspx
» needs to be as fast as possible!
Structure: assemblies added to the
App_Data folder
need to be formally included with a page
using <#include…. >
.dll suffix standard for “C” dynamic linked
A pre-compiled
cart control
Not only has someone written the C#
code for a shopping cart for you…
it has already been compiled as well!
found on RH’s website as part of
Contains dataset fields used with
specific field and parameter names
need to mesh with corresponding fields on:
» product pages…
» cart display page
“Click to buy” Scripting
Product page itself needs to be capable of
displaying multiple records
 associated ProductID value for a row relates to the
record displayed
Of all available web controls…
 “Repeater” control achieves this display most
Effect of “Click to Buy”
The “add” function is built into a pre-written
page called AddfromDatabase.aspx
This page has no HTML (and therefore no
display… but it triggers an SQL query to:
 pick up this variable value
 send the value to the server as ProductID
 collect the product description and price fields
 save all three values to the dataset
Passing the Product ID
Product ID value
sent as e.g. “ProdID”
Add from DB
Shopping Cart
fields extracted
from remote
Parameter Passing
between Pages (1)
“Click to buy” is one of the more effective
tricks of server scripting pages with multiple
records (!)
How can a click on a hyperlink send a
parameter that adds a series of correct values
to the cart? ? ?
Parameter Passing (2)
Simple (!) The page uses HTML “get” logic based on
a hyperlink used with “?”
Variable name defined in “get” part
 corresponds to the primary key in “products”
Role of hyperlink:
 picks up the primary key value
 allocates this value to the variable used to get the data from
the database e.g. ProdID
“Add to Cart” control
This contains the logic to make “click to cart”
actually happen
 other values such as quantity can then be added
to the dataset
 dataset record will be equivalent to an “orderline”
 values for other products can then be stored in the
same dataset but with different orderline values
In any case, the result should be a display of
the shopping cart contents
Displaying the Cart Contents
Another carefully designed web page that
displays the cart contents and does some
simple calculations
 download as cart.aspx
 not too different from the product page
 uses a repeater and an HTML table to display
products data
 differences:
» the data is displayed from the cart not the products table
» line total and grand total fields used to display each item total,
and sum total of all line totals
Typical RAD tool “errors”…
MUCH can go wrong…!!!
Before embarking on shopping cart
 need to make sure all local/remote web server settings
are correct
 screen fields and db fields must use the same format
» mustn’t use “reserved words” or punctuation, inc spaces
 users must have sufficient access rights to write to the
» this especially includes the “IIS process” user
 major adjustments may be needed in response to a
minor change in design…
» all the more reason to get the design right…
Anything else?
One other thing that still need to be
covered theoretically is the “C#” code
behind model…
 Next week… (!)
Thanks for listening…
Over the next few weeks, we’ll
work on the coding to put this
into practice…