'--- open Logon table ----------------------------------------
TBStart
TRStart STYLE_T_HEADING
TD STYLE_T_RIGHT, STYLE_F_LABEL_INFO & "User ID"
TDText STYLE_T_CELL_ACCENT, USER_ID, 10, 10, Request(USER_ID), BLANK
TREnd
TRStart STYLE_T_HEADING
TD STYLE_T_RIGHT, STYLE_F_LABEL_INFO & "Password"
TDText STYLE_T_CELL_ACCENT, USER_ USER_PASSWORD, 10, 10,
Request(USER_PASSWORD), BLANK
TREnd
TRStart STYLE_T_HEADING
TDSubmit STYLE_T_CENTER & STYLE_T_COLSPAN_2, "Enter Project Manager", BLANK
TREnd
'--- close Logon table --------------------------------------
TBEnd
Public Sub TBStart()
gintIndent = gintIndent + 1
Dim color
Dim width
If TableWidth <> "0" Then width = " width=" & TableWidth
If TableColor <> BLANK Then color = " bgcolor=" & TableColor
If TableColor = "X" Then color = BLANK
Text "<table" & _
width & _
color & _
" cellpadding=" & TableCellPadding & _
" cellspacing=" & TableCellSpacing & _
" border=" & TableBorder & _
">"
End Sub
Public Sub TBEnd()
Text "</table>"
gintIndent = gintIndent - 1
End Sub
Figure 2 Encapsulating Code
This Visual Basic Code | Equates to this HTML |
TRStart STYLE_T_HEADING | <tr bgcolor=888888> |
TD STYLE_T_RIGHT, STYLE_F_LABEL_INFO & "User ID" | <td align=right> <font color=4444FF face=Arial>User ID</td> |
TDText STYLE_T_CELL_ACCENT, USER_ID, 10, 10, Request(USER_ID), BLANK |
<td bgcolor=EEEEEE> <input type=text name="User_ID" size=10 maxsize=10 value=""> </td> |
TREnd | </tr> |
TDSubmit STYLE_T_CENTER & STYLE_T_COLSPAN_2, "Enter Project Manager", BLANK |
<td align=center colspan=2> <input type=submit value="Enter Project Manager"> </td> |
Figure 4 Driving ADO with ASP
Dim strSQL, rs, mConn
Set mConn = Server.CreateObject("ADODB.Connection")
mConn.Open A_DATABASE_DSN, A_DATABASE_USER, A_DATABASE_PASSWORD
strSQL = "SELECT * FROM Project WHERE ProjectID = " & Request(PROJECT_ID)
Set rs = mConn.Execute(strSQL, lngRecordsAffected, DB_OPTION_TEXT)
'--- is recordset empty -------------------------------------------------
If rs.EOF Then
Session(ERROR_MESSAGE) = MOD_ERROR_PROJECT_LOAD_EMPTY
Log LOG_TYPE_APPLICATION, MOD_ERROR_PROJECT_LOAD_EMPTY
Paint
Exit Sub
End If
'--- Load current Project in to session variables ----------------------
Session(PROJECT_ID) = rs(PROJECT_ID)
Session(PROJECT_DESCRIPTION) = rs(PROJECT_DESCRIPTION)
Session(PROJECT_OWNER) = rs(PROJECT_OWNER)
Session(PROJECT_CREATED) = rs(PROJECT_CREATED)
'--- clean up the objects used -----------------------------------------
Set rs = Nothing
Set mConn = Nothing
'--- go on to next page ---------------------------------
AppRedirect PATH_APP & MODULE_B01 & SUFFIX_ASP
Figure 5 X_Server.CLS Methods
Function CreateObject(ByVal strObject As String) As Object
CreateObject = CreateObject(strObject)
End Function
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function MapPath(ByVal strRelativeFile) As String
End Function
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function URLEncode(ByVal strIn) As String
End Function
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function HTMLEncode(ByVal strIn) As String
End Function
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Property Get ScriptTimeout() As Long
End Property
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Property Let ScriptTimeout(ByVal lngTimeOut as long)
End Property
Figure 6 X_Support.bas and X_Support.cls
X_Support.bas declaration section
Option Explicit
Public Application As New Application
Public Session As New Session
Public Response As New Response
Public Request As New Request
Public Server As New Server
X_Support.cls Application Property Let and Get
Private colApplication As New Collection
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Property Let Application(ByVal strPropertyName As String,
ByVal strPropertyValue As String)
On Error GoTo ApplicationLetErr
colApplication.Add strPropertyValue, strPropertyName
ApplicationLetExit:
Exit Property
ApplicationLetErr:
If Err = 457 Then 'item in collection
colApplication.Remove strPropertyName
Resume
End If
Resume
End Property
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Property Get Application(ByVal strPropertyName As String) As String
On Error GoTo ApplicationGetErr
Application = colApplication.Item(strPropertyName)
ApplicationGetExit:
Exit Property
ApplicationGetErr:
Application = BLANK
Resume ApplicationGetExit
End Property
Figure 7 Server Side Includes
'asp <!--#include virtual="/ASP/Admin.inc" -->
'asp <!--#include virtual="/ASP/App.inc" -->
'asp <!--#include virtual="/ASP/Utility.inc" -->
'asp <%
Option Explicit 'vb
Const PAGE_HEADING = "Project Manager"
Const PAGE_NAME = "Logon"
Const THIS_MODULE = "A01"
Const FIELD_USERID = "UserID"
Const FIELD_PASSWORD_ = "Password"
Const MOD_ERROR_STR_LOGON_FAIL = _
"Your logon ID or password were not found."
Const MOD_ERROR_RS_LOAD_EMPTY = "ERROR:A01:RS empty"
Dim mConn 'modular level connection variable
'asp Route
Figure 8 Sub Route
Public Sub Route()
'--- set the connection to the database --------------------------------
AppConnectionOpen
Set mConn = Session(SESSION_CONNECTION)
If Request(RETURN_FROM_FORM) Then
Process
Else
Paint
End If
AppConnectionClose mConn
End Sub
Figure 9 Sub Paint
Sub Paint()
'--- open HTML document ----------------------------------
HTMLOpen
HeadingOpen PAGE_HEADING & SSPACE & PAGE_NAME
HeadingClose
BodyOpen A_STYLE_BODY_PARMS
AppPageOpen PAGE_HEADING, PAGE_NAME, THIS_MODULE
'--- open the form -----------------------------------------
FStart THIS_MODULE, PATH_APP & THIS_MODULE & SUFFIX_ASP, BLANK
FHidden RETURN_FROM_FORM, True
'--- open shell 2 table -------------------------------------
TBStart
AppDisplayAlertMessage
TRStart BLANK
TDStart BLANK
'--- open Logon table ----------------------------------------
TBStart
TRStart STYLE_T_HEADING
TD STYLE_T_RIGHT, STYLE_F_LABEL_INFO & "User ID"
TDText STYLE_T_CELL_ACCENT, USER_ID, 10, 10, Request(USER_ID), BLANK
TREnd
TRStart STYLE_T_HEADING
TD STYLE_T_RIGHT, STYLE_F_LABEL_INFO & "Password"
TDText STYLE_T_CELL_ACCENT, USER_ USER_PASSWORD, 10, 10, Request(USER_PASSWORD), BLANK
TREnd
TRStart STYLE_T_HEADING
TDSubmit STYLE_T_CENTER & STYLE_T_COLSPAN_2, "Enter Project Manager", BLANK
TREnd
'--- close Logon table --------------------------------------
TBEnd
TDEnd
TREnd
'--- close shell 2 table ------------------------------------
TBEnd
'--- close the form -----------------------------------------
FEnd
'--- Close Page ---------------------------------------------------
AppPageClose THIS_MODULE
'--- close application footer --------------------------
AppFooterBody
BodyClose
'--- close HTML document ------------------------------------
HTMLClose
End Sub
Figure 10 Sub Process
Private Sub Process()
If A_PRODUCTION_MODE_ON Then
On Error Resume Next
End If
Dim strUserID, strPassword, UserType
Dim rs, strSQL
Const PROJECT_ID = 1
Const PROJECT_DESCRIPTION = 2
Const PROJECT_OWNER = 3
Const PROJECT_CREATED = 4
'--- test for maximum logons -------------------------------------------
Session(MAX_LOGON_ATTEMPTS_STRING) = Session(MAX_LOGON_ATTEMPTS_STRING) + 1
If Session(MAX_LOGON_ATTEMPTS_STRING) > MAX_LOGON_ATTEMPTS Then
Session(MAX_LOGON_ATTEMPTS_STRING) = 0
AppRedirect A_MAX_SECURITY_ATTEMPTS_PATH
End If
'--- get the userid and password from the request object ---------------
strUserID = Request(USER_ID)
strPassword = Request(USER_PASSWORD)
'--- confirm id and password entry -------------------------------------
If Len(Trim(strUserID)) = 0 Or Len(Trim(strPassword)) = 0 Then
Session(ERROR_MESSAGE) = "Please enter BOTH an ID and a Password"
Paint
Exit Sub
End If
'--- Retrieve User record for validation -------------------------------
Set mConn = Server.CreateObject("ADODB.Connection")
mConn.open A_DATABASE_DSN, A_DATABASE_USERNAME, A_DATABASE_PASSWORD
strSQL = "SELECT * FROM Project WHERE UserID='" & strUserID "' AND _
Password='" & strPassword & "'"
Set rs = mConn.execute(strSQL, lngRecordsAffected, DB_OPTION_UNKNOWN)
'--- is rs EOF? -------------------------------------------------------
If rs.EOF Then
Session(ERROR_MESSAGE) = "Your userid or password failed validation. _
Please retry."
Log LOG_TYPE_APPLICATION, MOD_ERROR_USER_LOGON_FAIL
Paint
Exit Sub
End If
'--- Load current Project into session variables -----------------------
Session(PROJECT_ID) = rs(PROJECT_ID)
Session(PROJECT_DESCRIPTION) = rs(PROJECT_DESCRIPTION)
Session(PROJECT_OWNER) = rs(PROJECT_OWNER)
Session(PROJECT_CREATED) = rs(PROJECT_CREATED)
'--- clean up the objects used -----------------------------------------
Set rs = Nothing
'--- Loaded project go on to next page ---------------------------------
AppRedirect PATH_APP & MODULE_B01 & SUFFIX_ASP
End Sub