COMP 3241 ECommerce Technologies Richard Henson University of

  • Slides: 36
Download presentation
COMP 3241 E-Commerce Technologies Richard Henson University of Worcester October 2014

COMP 3241 E-Commerce Technologies Richard Henson University of Worcester October 2014

Week 5: Server Scripting, and Shopping Cart Systems n Objectives: Ø Relate data modelling

Week 5: Server Scripting, and Shopping Cart Systems n Objectives: Ø Relate data modelling to server-side development Ø Create product pages that can pass on data Ø Explain the use of asp. net web controls with HTML to allow parameter passing between pages

Resolving the Products. Customers relationship n Many databases have failed through lack of knowledge

Resolving the Products. Customers relationship n Many databases have failed through lack of knowledge of entity modelling… Product Customer many: many relationship…!!!

Link Entity… n “Many: many” relationship ØOption 1: “programme” as OO database from scratch

Link Entity… n “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 Product XYZ (order? ) Customer

Is one more entity enough? n One customer makes the order ØCan make multiple

Is one more entity enough? n One customer makes the order ØCan make multiple orders Ø 1: many relationship n One or more products make up the order Øproduct and order still many: many n Product & Order need a further entity between them…

Shopping Cart Entities n All of this needs to be reflected in shopping cart

Shopping Cart Entities n All of this needs to be reflected in shopping cart database design… n Why? (discuss…)

Possible basic data (entity) model for a Shopping System order product No entity relationships

Possible basic data (entity) model for a Shopping System order product No entity relationships shown! Order line Where does Shopping Cart fit? customer

Possible Data Model with entities/attributes added n Field names may vary but the principle

Possible Data Model with entities/attributes added n Field names may vary but the principle is the same… n Field names must match with server script variables

Testing the Logical Design with Physical Data… n ERM may work on paper… ØBut

Testing the Logical Design with Physical Data… n ERM may work on paper… ØBut easy to get the logic wrong… n 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 n Popular options for small(ish) databases:

Creating the Physical Database from a Logical Design n Popular options for small(ish) databases: ØMicrosoft Access » only Access 2000 onwards properly SQL compliant ØMy. SQL (open source) » originally shareware for Unix » also for Windows n Popular options for larger databases: ØSQLServer ØORACLE

Essential attributes for Orders Entity n All entities in an entity model… Øneed a

Essential attributes for Orders Entity n 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? n Foreign key to link to

Essential attributes for Orderline Entity Primary key attribute? n Foreign key to link to another entity… n Øagain… which one? n Each orderline contains other data that needs to be recorded to complete the order. Which other attributes are needed?

Completing the Data model n Server scripts will use data from one/more entities Ø

Completing the Data model n Server scripts will use data from one/more entities Ø essential that attributes for entities correctly identified n How can any gaps in the data model be filled in? Ø important that this is completed before programming the scripts begins…

Role of Server Scripting in creating Product Pages n Server scripts with appropriate embedded

Role of Server Scripting in creating Product Pages n Server scripts with appropriate embedded SQL required for: Øpicking the right data out of the remote database Ø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 n Asp. net supports local storage of data through

Local storage of “remote” data n Asp. net supports local storage of data through datasets (arrays) in protected memory Ø 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 n 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) n As you have seen, Visual Studio

The Dataset Display (one record from database) n As you have seen, Visual Studio facilitates selection of controls creating local datasets associated with a server-based database n Also helps 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 & HTML tag nesting n HTML forms work at the client end…

HTML forms & HTML tag nesting n HTML forms work at the client end… Øcollect data in a structured way Ølocal storage through form fields: » pre-defined data type (parameter) » specific field name (parameter) n Note syntax (within <body>): » <div><form><repeater><itemtemplate><table> » </table></itemtemplate></repeater></form></div>

Mapping of data within a HTML form n HTML form structure: Ø text boxes/fieldnames

Mapping of data within a HTML form n HTML form structure: Ø text boxes/fieldnames for adding data Ø Get/Post tells page where to send the data Ø button(s) to trigger the sending of data to the location specified by get or post… n Data added to the form can be sent to: Ø email address Ø URL of a web server

HTML forms Input-Output syntax n Basic structure: <form> … </form> n ACTION parameter points

HTML forms Input-Output syntax n Basic structure: <form> … </form> n ACTION parameter 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 n METHOD parameter tells the form how to send its

HTML forms Input-Output syntax n METHOD parameter 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 characters)

Modular Development association of “code” files with HTML n Existing good code recycled whenever

Modular Development association of “code” files with HTML n Existing good code recycled whenever possible… Ø useful for portability (no point in rewriting…) Ø used in conventional HTML e. g. css n Several additional ways to use text files/source code with. aspx pages: Ø SSI Include global. asax Ø “code behind” n aspx also allows “ready to run” compiled code Ø “toolbox” controls & “assemblies”

The Server-Side #Include (SSI) Directive n Saved as a. inc file Øused with multiple

The Server-Side #Include (SSI) Directive n Saved as a. inc file Øused with multiple asp(x) pages n Syntax: » #INCLUDE directive and either “VIRTUAL” or “FILE” keyword placed inside what would normally be HTML comment tags, with file=“filename” » e. g. : <!--#include file="common/copyright. inc"-->

Using Server Scripting to Create online Shopping System n “Click to buy” Ø product

Using Server Scripting to Create online Shopping System n “Click to buy” Ø product Information stored on database Ø script connects to database Ø products can be displayed on a page or as aeries of categories n Recording/monitoring of clicking behaviour to simulate buying… Ø coded into the product page & shopping cart Ø shopping system “logic” needs to be right…

Web. Xel “Shopping Cart” control n “ready assembled” web control… Øsets up the fields

Web. Xel “Shopping Cart” control n “ready assembled” web control… Øsets up the fields that will be used to store the shopping data n Could have been set up as a series of code behind files Ølot of coding as source code… Øwhy bother anyway if already perfected? Øcode needs to be used by many. aspx pages

“Shopping Cart” assembly n More secure than source code Øaccessed by multiple. aspx pages…

“Shopping Cart” assembly n More secure than source code Øaccessed by multiple. aspx pages… Øneeds to be as fast as possible! n 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 libraries

Preparation: pre-compiled n Not only has someone written the C# code for the shopping

Preparation: pre-compiled n Not only has someone written the C# code for the shopping cart… Øit has already been compiled as well! Øresulting assembly found on RH’s website as Web. Xel. Cart. dll n 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 and HTML code n Product page(s) usually need to be

“Click to buy” Scripting and HTML code n Product page(s) usually need to be capable of displaying multiple records Ø associated Product. ID value for a row relates to the database record displayed n Of all available web controls… Ø “Repeater” achieves this display most effectively

Effect of “Click to Buy” n The “add” function is built into a pre-written

Effect of “Click to Buy” n The “add” function is built into a pre-written page called Addfrom. Database. aspx n Page has no HTML (and therefore no display…) but it triggers an SQL query to: Ø pick up a variable value chosen by the “click” Ø send the value to the server as Product. ID Ø collect the product description and price fields Ø save all three values to the dataset

Passing the Product ID Parameter Product Page “click” Product ID value sent as e.

Passing the Product ID Parameter Product Page “click” Product ID value sent as e. g. “Prod. ID” Remote DB Add from DB scripts Shopping Cart fields extracted from remote database

Parameter Passing between Pages (1) n How can a click on a hyperlink… Øsend

Parameter Passing between Pages (1) n How can a click on a hyperlink… Øsend a parameter to a server database Øadd a series of correct values to the shopping cart? ? ?

Parameter Passing (2) n Simple (!) Øthe page uses HTML “get” logic based on

Parameter Passing (2) n 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” n 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. Prod. ID

“Add to Cart” control n Cart logic to make “click to cart” actually happen…

“Add to Cart” control n Cart logic to make “click to cart” actually happen… Ø other values such as quantity added to the dataset (default setting normally 1) Ø 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 n In any case, the result should be a display of the shopping cart contents

Displaying the Cart Contents cart. aspx n Another carefully designed web page that displays

Displaying the Cart Contents cart. aspx n Another carefully designed web page that displays the cart contents and does some simple calculations Ø uses a repeater and an HTML table to display products data (like “products” page) Ø differences from “products”… » data 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 development “errors”… n MUCH can go wrong…!!! n Before embarking on shopping cart

Typical development “errors”… n MUCH can go wrong…!!! n Before embarking on shopping cart development, make sure… Ø all local/remote web server settings are correct Ø screen fields and db fields use the same format » mustn’t use “reserved words” or punctuation, inc spaces Ø users have sufficient access rights to write to the database » this especially includes the “IIS process” user n Major adjustments may be needed in response to a minor change in design… Ø all the more reason to get the design right…

Anything else? n One other thing that still need to be covered theoretically is

Anything else? n One other thing that still need to be covered theoretically is the asp. net environment and how “controls” are created, and assembled… n Next week… (!)

Thanks for listening… n Over the next few weeks, we’ll work on the coding

Thanks for listening… n Over the next few weeks, we’ll work on the coding to put this into practice…