<%@ Language=VBScript %> <% '***** Server-side script starts here. ***** '***** Declarations of variables known to all server subs and functions 'reference to the Company class used to retrieve and store persistent data. dim myCompany 'reference to MessageQueue object. It holds messages created by the business object. dim myMessageQueue 'mstrMode holds the name of the operation being performed. 'Valid values are: "NEW", "OPEN", "ADD", "UPDATE", "DELETE" and "CLOSE" 'The default mode is "OPEN", the actual mode will be determined in the 'GetParameters' sub dim mstrMode mstrMode= "OPEN" 'The list page provides a reference to the Company's ObjectID dim mstrCompanyObjID 'the Company detail XML dim myCompanyXML 'reference to the CompanyDetail view dim myView 'the threshold for messages dim mlngMessageThreshold mlngMessageThreshold = 3 'reference to the DOM object used for parsing business object XML dim myXMLDOMObject 'reference to the DOM object used for parsing XSL dim myXSLDOMObject ' 'Insert module level declarations here '********************************************************* '***** Subs and functions evaluated at the server. ***** '********************************************************* function GetParameters() 'GetParameters is the first sub called when page is executed. GetParameters = True 'get the mode of operation mstrMode = Request("mode") 'get the object ID passed in mstrCompanyObjID = Request("ID") end function sub Connect() 'create the DOM object used for parsing XML set myXMLDOMObject = Server.CreateObject("MSXML2.DOMDocument") 'create the DOM object used for parsing XSL set myXSLDOMObject = Server.CreateObject("MSXML2.DOMDocument") 'create the Company object. set myCompany = Server.CreateObject("Project_Layer2.Company") 'create a MessageQueue that contains the Company messages set myMessageQueue = Server.CreateObject("mtrCommonRT25.mtrMessageQueue") 'start the Business Object myCompany.StartUp myMessageQueue myCompany.ReportMessages = false myCompany.ReportErrors = false 'set the reference to the CompanyDetail view set myView = myCompany.GetView("CompanyDetail") end sub sub ReadItem() 'Read the requested Company myCompany.Read(mstrCompanyObjID) end sub sub Add() 'add a Company myCompany.Add 'check for any messages if myMessageQueue.HighestSeverityLevel >= mlngMessageThreshold then 'retrieve messages and store them in the session variable RetrieveMessages Response.Redirect "CompanyDetail.asp?mode=NEW" end if end sub sub Update() 'update Company myCompany.Update 'check for any messages if myMessageQueue.HighestSeverityLevel >= mlngMessageThreshold then 'retrieve messages and store them in the session variable RetrieveMessages Response.Redirect "CompanyDetail.asp?ID=" + mstrCompanyObjID end if end sub sub Delete() 'Delete Company myCompany.Delete 'check for any messages if myMessageQueue.HighestSeverityLevel >= mlngMessageThreshold then 'retrieve messages and store them in the session variable RetrieveMessages end if end sub sub DisplayMessages() 'show any messages generated by the business object dim strMessages strMessages = Session("Messages") if Len(strMessages) > 0 then Response.Write strMessages Session("Messages") = "" end if end sub sub RetrieveMessages() 'retrieve messages generated by the business object dim strXslFilepath dim objXslDocElement dim strMsgHTML dim strMsgXML 'build the XML for the messages strMsgXML = "" strMsgXML = strMsgXML & myMessageQueue.XML() 'use messagelist XSL template to format messages strXslFilePath = Server.MapPath("messagelist.xsl") if myXMLDOMObject.LoadXML(strMsgXML) then 'message XML loaded successfully if myXSLDOMObject.Load(strXslFilePath) then set objXslDocElement = myXSLDOMObject.documentElement if not (objXslDocElement Is Nothing) then strMsgHTML = myXMLDOMObject.transformNode(objXslDocElement) 'store message HTML in session variable Session("Messages") = strMsgHTML end if end if end if end sub function CheckFlowControl() 'this function determines if we need to go back CheckFlowControl = true if mstrMode = "CLOSE" then CheckFlowControl = false Response.Redirect "CompanyList.asp" end if end function sub SaveProperties() 'start an editing session myCompany.StartEdit 'save the properties if operation is 'UPDATE' or 'ADD' '(system generated properties are not saved) 'if the control is a 'checkbox', look for the value 'on' to determine if the checkbox was checked 'Read Only properties are NOT updated myCompany.Number = Request("Number") myCompany.Name = Request("Name") myCompany.CompanyType = Request("CompanyType") myCompany.Category = Request("Category") myCompany.BusinessCode = Request("BusinessCode") myCompany.Credit_Rating = Request("Credit_Rating") if request("Tax_Exempt") = "on" then myCompany.Tax_Exempt = "True" else myCompany.Tax_Exempt = "False" end if 'test all permitted values for Status select case Request("Status") case "Prospect" myCompany.Status = "Prospect" case "Active" myCompany.Status = "Active" case "Inactive" myCompany.Status = "Inactive" end select myCompany.ParentCompany = Request("ParentCompany") myCompany.StateOfIncorporationCode = Request("StateOfIncorporationCode") myCompany.Memo = Request("Memo") 'end the current editing session myCompany.SaveEdits end sub 'Additional subs and functions 'Insert additional functions and subs here ' '***** Server subs that create a Company detail ASP page ***** sub BuildDisplayFields() dim strXslFilepath dim objXslDocElement dim strHTML 'build the XML for Company detail view myCompanyXML = "" myCompanyXML = myCompanyXML & "" myCompanyXML = myCompanyXML & myCompany.GetXML(myView) myCompanyXML = myCompanyXML & "" 'use the detail XSL template to format Company detail properties strXslFilePath = Server.MapPath("detailfrm.xsl") if myXMLDOMObject.LoadXML(myCompanyXML) then 'XML loaded successfully if myXSLDOMObject.Load(strXslFilePath) then set objXslDocElement = myXSLDOMObject.documentElement if not (objXslDocElement Is Nothing) then strHTML = myXMLDOMObject.transformNode(objXslDocElement) 'send HTML to browser Response.Write strHTML end if end if end if end sub %> <% '***** Execute the server-side subs and functions. ***** if GetParameters() then if CheckFlowControl() then Connect end if end if 'if business object has an ID, then use it to read a Company if mstrCompanyObjID <> "" then ReadItem if mstrMode = "ADD" or mstrMode = "UPDATE" then 'call subroutine to save Company properties SaveProperties if mstrMode = "ADD" then 'add a new record Add else 'update the current record Update end if 'redirect to the CompanyList ASP page Response.Redirect "CompanyList.asp" elseif mstrMode = "DELETE" then 'delete the current record Delete 'redirect to the CompanyList ASP page Response.Redirect "CompanyList.asp" end if %>
<% if mstrMode = "NEW" then %> <% else %> <% end if %> File <% if mstrMode <> "NEW" then %> <% end if %> Edit Help


<% DisplayMessages %>
<% 'Create detail fields for Company properties BuildDisplayFields 'array of fields 'clean up objects to avoid memory leaks myCompany.Shutdown set myCompany = nothing %>

* are required fields.