Figure 12   New MSCS ASP Components

SimpleList A collection of variant type variables.
Dictionary A dynamic array of variables. Each variable is identified by a name/value pair.
Content Manages database connection and query storage.
DataFunctions Provides several data manipulation functions for locale conversion.
DataSource Used to access databases.
DBStorage Handles common store tasks, such as retrieving and updating order and customer data.
MessageManager Contains language-specific messages to be used in the OPP.
OrderForm A set of SimpleList and Dictionary objects, used as a storage facility for order-related information.
OrderPipeline Used to process orders.
Page Provides an interface that simplifies the creation of HTML code.
StandardSManager TrafficLogFile Handles shopper information. Logs user information and store events to a text file.
TrafficTable Records store events and user information to a database table.


Figure 13 The Content Component

AddDatasource (Alias, ConnectionString) Adds a new datasource to the Content object.
AddQuery (QueryName, QueryText, CursorType, CursorSize, RetrievalMethod) Adds a new query to the Content object.
DataSource (DSN) Returns the datasource whose alias is DSN (if present).


Figure 14 The Datasource Component

CreateADOConnection Returns a read-only ADO connection object that can be used as a parameter for ExecuteADO.
Execute (SQL, [Parameters]) Executes the query whose alias is SQL. Alternatively, SQL can also specify SQL query text directly.
ExecuteADO (Connection, SQL, Parameters) Executes a query through an open ADO connection created with CreateADOConnection. As in Execute, SQL can either specify an alias or a SQL query.


Figure 15 ODBC Connection String

An ODBC connection string has the following format:

Str = "ODBC; [ParamName1=Value1;] [ParamName2=Value2;] [...][ParamNameN=ValueN;]"

The "ODBC;" preamble does not have to be specified when initializing ADO connections. Following is a list of valid parameters for SQL servers.

DRIVER The name of the ODBC driver.
DSN The name of the datasource.
SERVER The name/address of the server.
UID The user ID used when accessing the database.
PWD The password used when accessing the database.
APP The name of the application (optional).
WSID The Workstation ID of the machine where the connection is initiated from (optional).
DATABASE The name of the database. Optional if it has been specified during the datasource setup in the ODBC Manager.


Figure 16 Content/Datasource Sample


 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 
 <!--
     This HTML page generates a list of all the products included
     in the Marco Tabini Store's database
     
     Written by Marco Tabini, 11/18/97
     marcot@ifront.com
     v. 1.0
 -->
 
 <HTML>
 <HEAD>
     <TITLE>Content/Datasource Sample</TITLE>
 </HEAD>
 
 <%
     REM The following is borrowed from MSCS
 
     REM -- ADO command types:
     adCmdText       = 1 
     adCmdTable      = 2 
     adCmdStoredProc = 4
     adCmdUnknown    = 8
 
     REM -- ADO cursor types:
     adOpenForwardOnly = 0
     adOpenKeyset      = 1
     adOpenDynamic     = 2
     adOpenStatic      = 3
 
     REM End of borrow!
 
     set MTContent = Server.CreateObject("Commerce.Content")
     MTContent.AddDataSource "MT", 
         "DSN=commerce;UID=userID;PWD=XXXXX;DATABASE=commerce"
     
     call MTContent.AddQuery("get_depts", "select * from mt_dept", 0, adCmdText, 
                              0, adOpenForwardOnly, 0)
     call MTContent.AddQuery("get_products", "select * from mt_product", 0, 
                              adCmdText, 0, adOpenForwardOnly, 0)
     
     set DS = MTContent("MT")
     
     set Products = DS.Execute ("get_products")
 %>
 
 
 
 <BODY>
 
 <CENTER>
     <H1>
         The Marco Tabini Store
     </H1>
 
     <P>
 
     <H2>
         List of products
     </H2>
 </CENTER>
 
 <!-- Display all the products! -->
 
 <TABLE>
     <% For Each Product in Products %>
     <TR>
     <TD>
     <% = Product.Name %>
     </TD>
     <TD>
     <% = Product.List_Price %>
     </TD>
     </TR>
     <% Next %>
 </TABLE>
 
 </BODY>
 </HTML>


Figure 18 The StandardSManager

CreateShopperID Creates a new unique shopper ID.
DeleteShopperID(ShopperID) Deletes the ShopperID shopper ID from the database.
GetShopperID Retrieves the shopper ID stored on the client system. If no shopper ID is available, the function returns null.
InitManager (StoreKey, Mode) Intializes the object and determines whether the shopper ID will be stored in a cookie on the client system or in a URL.
PutShopperID (Null, ShopperID) Stores the cookie on the client system or in a URL.


Figure 19 The OrderForm Component

AddItem (SKU, Quantity, Price) Adds a new item to the OrderForm.
ClearOrderForm Completely clears the OrderForm object storage.
ClearItems Only removes all the order's items from the OrderForm. Other information, such as order total, any errors, and so on remains intact


Figure 20 The DataFunctions Component

Property Locale Establishes the default locale settings to be used in the Page component's conversion functions.
CleanString
(String, MinLength, MaxLength StripWhiteSpaces, StripReturn, Case, Locale)
Strips white spaces from a string. Optionally, converts it to lower or upper-case and verifies that its length falls within a given range.
ConvertDateString
(String, Locale)
Converts a string into a date variant according to the locale specified.
ConvertDateTimeString
(DateTime, DateLocale, TimeLocale)
Converts the DateTime value specified in DateTime to a DateTime variant based on the locale specified in Locale.
ConvertFloatString
(Float, Locale)
Converts the string expression specified in Float to a double variant according to the specified locale.
ConvertMoneyStringToNumber
(Money, Locale)
Converts the currency value specified in Money to the lowest monetary unit of the locale specified. For example, for a value in dollars, the amount will be returned in cents.
ConvertNumberString
(Number, Locale)
Converts the value specified in Number to an integer variant according to the specified locale.
ConvertTimeString (Time, Locale) Converts a time expression to a date variant according to the specified locale.
Date (Date, Locale) Converts a date variant into a string based on the specified locale.
DateTime (DateTime, Locale) Same as Date, but applies to DateTime variants.
Float (Float, Locale) Converts a floating-point number to a string based on the specified locale.
Money (Money, Locale) Converts a numeric value to a currency string expression based on the current locale. This function assumes that the integer part of Money contains the amount to be converted in the lowest monetary unit of the locale specified. For example, a value of 1234 will be converted to $12.34, and so on.
Number (Number, Locale) Converts an integer value to a string based on the locale specified.
Time (Time, Locale) Converts a Time value to a string based on the specified locale.
ValidateDateTime (DateTime, LowDateTime, HighDateTime) Verifies that the date expressed by DateTime falls between LowDateTime and HighDateTime.
ValidateFloat (Value, MinimumValue, MaximumValue) Verifies that the floating-point value expressed by Value falls between MinimumValue and MaximumValue.
ValidateNumber (Value, MinimumValue, MaximumValue) Same as ValidateFloat, but applies to integer values.


Figure 21 The Page Component

Property Context Contains the ASP Scripting Context.
Property Messages Identifies the language to use for errors.
Check (Value) Generates the word "CHECKED" if value is different from zero. Used to automatically generate self-centering dropdown or list boxes.
Encode (Expression) Converts Expression to HTML-encoded text. Substitutes dangerous character with percent expressions.
GetShopperID Returns the current shopper's ID (if any).
IncrShopperPerfCtrs Increments the Total New Shoppers value in the performance monitor.
Option (Value, State) Generates an <OPTION> tag and adds the SELECTED if State is nonzero.
ProcessVerifyWith (OrderForm) Stores the content of hidden fields created with the VerifyWith method in the OrderForm. These values are used by the OPP to ensure that the OrderForm has not been modified between its presentation in the basket and the final purchase.
PutShopperID (ShopperID) Same as StandardSManager.PutShopperID.
RequestDate
(Name, Default, LowDate, HighDate, Locale)
Retrieves a URL argument from the page's GET or POST parameters and attempts to convert it to a date variant based on the specified locale. Optionally, RequestDate also checks that the value retrieved falls within the range specified by LowDate and HighDate. If Name does not identify any available parameter, the function returns the value specified in Default.
RequestDateTime (Name, Default, LowDateTime, HighDateTime, Locale) Same as RequestDate, but works with DateTime variants.
RequestDefault (Name, Default) Attempts to retrieve a URL parameter. If Name does not identify any available parameter, the function returns the value specified in Default.
RequestFloat (Name, Default, LowFloat, HighFloat, Locale) Same as RequestDate, but works with double variants.
RequestMoneyAsNumber
(Name, Default, LowMoney, HighMoney, Locale)
Attempts to convert the currency value specified in the Name URL parameter to a number based on the specified locale. Optionally, checks that the value retrieved falls within the range specified by LowMoney and HighMoney.
RequestNumber (Name, Default, LowNumber, HighNumber, Locale) Same as RequestDate, but works with integer variants.
RequestString (Name, Default, MinStrLen, MaxStrLen, StripWhite, StripReturn, Case, Locale) Same as RequestDate, but works with string variants. Optionally, it also strips white spaces and the string case uniform.
RequestTime (Name, Default, LowTime, HighTime, Locale) Same as RequestDate, but returns a date variant in which the time has been zeroed out.
RunPlan (OrderForm) Invokes the OPP to perform preliminary processing of an order.
RunProduct (OrderForm) Invokes the OPP to process the product information of an order only.
RunPurchase (OrderForm) Invokes the OPP to complete a purchase.
SURL (Filename, Arguments) Creates a secure URL based on the file name specified in FileName and the argument list specified in Arguments. Assumes that the store is one level deep into the site's directory structure.
URL (Filename, Arguments)
VerifyWith (OrderForm, Arguments)
Same as SURL, but creates a nonsecure URL. Outputs a set of hidden parameters containing the value of the OrderForm variables identified by Arguments. These will be used by the OPP to verify that the contents of the OrderForm have not been changed between the presentation of the order and the completion of the purchase.


Figure 24 Changing Text and Face Color


 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 <!-- This program generates a page that displays Microsoft Wallet
 ActiveX Objects and lets the user randomly change text
 & button face colours by clicking on a button. 
 Written by Marco Tabini, 11/17/1997
     marcot@ifront.com
     v. 1.0
 -->
 
 <HTML>
 <HEAD>
     <TITLE>Microsoft Psycho-Wallet Test</TITLE>
 </HEAD>
 
 <SCRIPT LANGUAGE="VBSCRIPT">
 
     Rem -- General declaration & calls
 
     randomize 'Starts up VBS's random numbers generator
 
     dim Colors (5)
 
     Colors (1) = "#FF00FF"
     Colors (2) = "#FF0000"
     Colors (3) = "#008080"
     Colors (4) = "#0000FF"
     Colors (5) = "#000000"
 
     Rem -- Sub ChangeTextColor
     Rem -- Changes the text colour for the specified
     Rem -- Object
 
     Sub ChangeTextColor (WhichControl)
         Color = int (rnd() * 5 + 1)
         
         if WhichControl = "Address" then
             addrSelector.TextColor = Colors (Color)
         else
             paySelector.TextColor = Colors (Color)
         end if
     End Sub
 
     Rem -- Sub ChangeFaceColor
     Rem -- Changes the button face colour for the specified
     Rem -- Object
 
     Sub ChangeFaceColor (WhichControl)
     Color = int (rnd() * 5 + 1)
     
     if WhichControl = "Address" then
         addrSelector.Face3D = Colors (Color)
     else
         paySelector.Face3D = Colors (Color)
         end if
     End Sub
 
 </SCRIPT
 
 <BODY>
 
     <CENTER>
     <TABLE>
     <TR>
     <TD>
     <!-- Display Address Selector -->
     <TABLE>
     <TR ALIGN=CENTER>
     <TD>
     <OBJECT
     ID="addrSelector"
     CLASSID="clsid:87D3CB63-BA2E-11cf-B9D6-00A0C9083362"
     CODEBASE="mswallet.cab#Version=2,0,0,1307"
     HEIGHT="123"
     WIDTH="154"
     >
     </OBJECT>
     </TD>
     </TR>
     <TR ALIGN=CENTER>
     <TD>
     <INPUT TYPE="BUTTON" VALUE="Change Text Colour" 
        OnClick=ChangeTextColor("Address")>
     </TD>
     </TR>
     <TR ALIGN=CENTER>
     <TD>
     <INPUT TYPE="BUTTON" VALUE="Change Face Colour" 
        OnClick=ChangeFaceColor("Address")>
     </TD>
     </TR>
     </TABLE>
  
     </TD>  <TD>  <!-- Display Payment Selector -->    <TABLE>  <TR ALIGN=CENTER>  
          <TD>    <OBJECT    ID="paySelector"
     CLASSID="clsid:87D3CB66-BA2E-11cf-B9D6-00A0C9083362"
     CODEBASE="mswallet.cab#Version=2,0,0,1307"
     HEIGHT="123"
     WIDTH="154"
     >
     </OBJECT>
     </TD>
     </TR>
     <TR ALIGN=CENTER>
     <TD>
     <INPUT TYPE="BUTTON" VALUE="Change Text Colour" 
        OnClick=ChangeTextColor("Payment")>
     </TD>
     </TR>
     <TR ALIGN=CENTER>
     <TD>
     <INPUT TYPE="BUTTON" VALUE="Change Face Colour" 
        OnClick=ChangeFaceColor("Payment")>
     </TD>
     </TR>
     </TABLE>
     </TD>
     </TR>
     </TABLE>
 
     </CENTER>
 
 </BODY>
 </HTML>


Figure 31 OrderMagnitude Categories

Category Name Lower Boundary Upper Boundary
Small Packet 0 2
Packet 2 5
Box 5 10
Large Box 10 20
Huge Box 20 50
Truckload! 50 1000


Figure 32 OrderCategories Table


 Create Table OrderCategories 
     (
     CategoryID    Integer Primary Key Identity (1,1),
     CategoryName  VarChar (70) Not NULL,
     LowBoundary   Integer Not NULL,
     HighBoundary  Integer Not NULL
     )


Figure 33 MSCSExecute Config Values

Engine_prog_id The ProgID of the scripting engine (for example VBScript ).
Script_type The type of script that the component is running. Can be INTERNAL or EXTERNAL.
Script_name If Script_type is EXTERNAL, this parameter hold the full path to the include file that contains the script.
Script_text If Script_type is INTERNAL, then this parameter contains the text of the script.


Figure 34 OPP Scripting Context Objects

ShopperObject The Shopper ID for the current shopper.
DataSource The store's DataSource object.
Page The Page component.
Content The store's Content object.
ReceiptStorage The receipt storage object for the store. Used to access previously saved orders.
DataFunctions An instance of the DataFunction component.
MessageManager Contains all the store's OPP message errors.


Figure 35 OrderMagnitude Component


 Function MSCSExecute(config, orderform, context, flags)
    
     'Compute the total number of items in the order
     
     OrderItemsNumber = 0
     
     For Each Item In orderform.Items
         OrderItemsNumber = OrderItemsNumber + Item.Quantity
     Next
     
     Set DS = context.DataSource
     Set OrderCategories = DS.Execute("select * from ordercategories")
 
     For Each OrderCategory In OrderCategories
         If CInt(OrderItemsNumber) >= CInt(OrderCategory.LowBoundary) And
             CInt(OrderItemsNumber) < CInt(OrderCategory.HighBoundary) Then
             orderform.OrderCategory = OrderCategory.CategoryName
         End If
     Next
     
     If IsNull(orderform.OrderCategory) Then
         orderform.OrderCategory = "Unknown Category"
     End If
 
     MSCSExecute = 1   'set function return value to 1 for success
 
 End Function


Figure 36 MSCSExecute return values

1 No error.
2 Warning. Indicates that an error has occurred within the component, but that the OPP execution flow should not be stopped.
3 Error. Indicates that an unrecoverable error has occurred within the component. The OPP execution flow will be halted immediately.