Company List
<%
'***** Server-side script starts here. *****************
'***** Declarations of variables known to all server subs and functions
'reference to the 'CompanyList' class used to retrieve lists of Company values.
dim myCompanyList
'reference to the MessageQueue object. It holds messages created by the business object.
dim myMessageQueue
'reference to the View object
dim myView
'mstrMode holds the name of the operation being performed.
'valid values are: "OPEN" and "SEARCH"
'default mode is OPEN
'the variable will be set in the 'GetParameters' sub
dim mstrMode
mstrMode= "OPEN"
'Company search page stored as HTML
'(value will be set in the GetParameters sub)
dim mstrCompanySearchHTML
'number of records returned
dim mlngRecordCount
'starting record number
dim mlngStart
'maximum number of records to be displayed on a page
dim mlngMaxRecords
mlngMaxRecords = 20
'*** Additional module level declarations ***
'Insert module level declarations here
'*********************************************************
'***** Subs and functions evaluated at the server. *****
'*********************************************************
sub Connect()
'attach to the CompanyList object and retrieve a list of property values
set myCompanyList = Server.CreateObject("Project_Layer2.CompanyList")
'create the MessageQueue
set myMessageQueue = Server.CreateObject("mtrCommonRT25.mtrMessageQueue")
'start CompanyList
myCompanyList.StartUp myMessageQueue
'create a mtrBusObjView object. It holds search criteria and display information
set myView = myCompanyList.GetView("CompanyList")
end sub
sub RecordCount()
'subroutine to determine the record count after a search
mlngRecordCount = myCompanyList.RecordCount
end sub
'search for Company that match
sub Search(strCriteria)
dim varItem
dim criteria
if mstrMode = "SEARCH" then
for each varItem in myView.SearchProperties
criteria = varItem & "criteria"
select case varItem
case "Tax_Exempt"
'checkbox uses special checks (test 'Yes' and 'No')
if Request(varItem) = "Yes" then
myView.AddSearchCriteria varItem, "=", "True"
elseif Request(varItem) = "No" then
myView.AddSearchCriteria varItem, "=", "False"
end if
case else
if len(Request(varItem)) then
if len(Request(criteria)) then
'property has criteria (<, >, <=, >=, <> etc.)
myView.AddSearchCriteria varItem, Request(criteria), Request(varItem)
else
myView.AddSearchCriteria varItem, "like", Request(varItem)
end if
else
if Request(criteria) = "Is Null" or Request(criteria) = "Is Not Null" then
myView.AddSearchCriteria varItem, Request(criteria), ""
end if
end if
end select
next
'search using above criteria
myCompanyList.Search(myView)
'store the XML definition of the View in a session variable
'it will also contain any search criteria
session("CompanyViewXML") = myView.GetXMLDefinition()
else
'mode is OPEN
if len(strCriteria) then
'search criteria is available, do a search
myCompanyList.Search strCriteria
else
'no search criteria
myCompanyList.Search myView.GetXMLDefinition()
end if
end if
'now that search is over, get a recordcount
mlngRecordCount = myCompanyList.RecordCount
end sub
sub GetParameters()
'first sub called when Companylist page is loaded
'get the mode of operation
mstrMode = Request("mode")
'store the Company search HTML in the module variable
mstrCompanySearchHTML = session("CompanySearch")
if Request("start") <> "" then
mlngStart = CLng(Request("start"))
else
mlngStart = 1
end if
end sub
sub BuildList()
dim strCompanyListXML
dim strViewXML
dim objXML
dim objXSL
dim strXslFilepath
dim objXslDocElement
dim strHTML
dim strViewSearchXML
dim intNumPages
dim strPaginationHTML
'provide page navigation
if mlngRecordCount > 0 then
intNumPages = mlngRecordcount/mlngMaxRecords
'if there are records that don't fill a page, add one more page
if (mlngRecordCount mod mlngMaxRecords) > 1 and (intNumPages > 1) then
intNumPages = intNumPages + 1
end if
'page navigation is provided only if we have more than one page
for i = 1 to intNumPages
if i = 1 then
if mlngStart <> 1 then
strPaginationHTML = "
Result pages: " & i & " "
else
strPaginationHTML = "
Result pages: 1 "
end if
else
if mlngStart <> (i-1) * mlngMaxRecords + 1 then
strPaginationHTML = strPaginationHTML & "" & i & " "
else
strPaginationHTML = strPaginationHTML & "" & i & " "
end if
end if
next
if len(strPaginationHTML) then strPaginationHTML = strPaginationHTML & "
"
end if
'get XML for the view
strViewXML = myCompanyList.GetXML(myView, mlngStart, mlngMaxRecords)
'build XML for CompanyList view
strCompanyListXML = ""
strCompanyListXML = strCompanyListXML & ""
strCompanyListXML = strCompanyListXML & strViewXML
strCompanyListXML = strCompanyListXML & ""
set objXML = Server.CreateObject("MSXML2.DOMDocument")
objXML.async = false
set objXSL = Server.CreateObject("MSXML2.DOMDocument")
objXSL.async = false
'use XSL to format Company's display properties
strXslFilePath = Server.MapPath("businessobjectlist.xsl")
if objXML.LoadXML(strCompanyListXML) then
'list XML loaded successfully
if objXSL.Load(strXslFilePath) then
set objXslDocElement = objXSL.documentElement
if not (objXslDocElement Is Nothing) then
strHTML = objXML.transformNode(objXslDocElement)
'write pagination on top
Response.Write strPaginationHTML
'write Company list HTML to browser
Response.Write strHTML
'write pagination on bottom
Response.Write strPaginationHTML
end if
end if
else
Response.Write "
Company XML error
"
end if
'if CompanyList page is being loaded for the first time
'generate HTML for Company search and store as a session variable
if len(strCompanySearchHTML) = 0 then
strSearchXML = myCompanyList.GetSearchXML(myView)
strViewSearchXML = ""
strViewSearchXML = strViewSearchXML & ""
strViewSearchXML = strViewSearchXML & strSearchXML
strViewSearchXML = strViewSearchXML & ""
'use XSL to format strViewSearchXML
strXslFilePath = Server.MapPath("search.xsl")
if objXML.LoadXML(strViewSearchXML) then
'XML loaded successfully, load XSL
if objXSL.Load(strXslFilePath) then
'XSL loaded successfully
set objXslDocElement = objXSL.documentElement
if not (objXslDocElement Is Nothing) then
strHTML = objXML.transformNode(objXslDocElement)
'store the Company search HTML in a session variable
session("CompanySearch") = strHTML
end if
end if
else
Response.Write "
Company search XML error
"
end if
end if
end sub
'Additional subs and functions
'Insert additional functions and procedures here
%>
<%
'***** Execute the server-side subs and functions. *****************
GetParameters
Connect
Search(session("CompanyViewXML"))
%>