docs.intersystems.com
Caché Web Applications Tutorial
Using Dot Syntax
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Search:    

We also need to set the Total property of the TicketOrder object, which stores the total cost of the tickets we have ordered. This illustrates how easy it is to follow a reference from one object to another by using “dot” syntax. For instance,

itm.Show.Theater.AdultPrice
starts with the TicketItem object, follows a reference to the Show and from there to the Theater object to obtain the price of an adult ticket.
We use dot syntax to calculate the cost of this new order item—the number of adult tickets times the adult price plus the number of child tickets times the child price—and add it to the total. (You may be wondering where the values for AdultTickets and ChildTickets come from. The way our application is designed, they are not specified by the user. Instead, we use defaults specified in the TicketItem class definition, which the user can change if necessary.)
We exit our method with a Quit statement.
—Utils.AddShow—
ClassMethod AddShow(ShowID As %String)
{
    // Use an existing Order object or create a new one
    If ($data(%session.Data("Order"))) {
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))
    }
    Else {
        Set ord = ##class(Cinema.TicketOrder).%New()
    }
    // Create a new TicketItem object
    Set itm = ##class(Cinema.TicketItem).%New()

    // Connect to a Show object
    Set shw = ##class(Cinema.Show).%OpenId(ShowID)
    Set itm.Show = shw
    // Connect to the Order object
    Set itm.TicketOrder = ord

    // Add the cost of this new item to the total
    Set ord.Total = ord.Total
        + (itm.AdultTickets * itm.Show.Theater.AdultPrice)
        + (itm.ChildTickets * itm.Show.Theater.ChildPrice)


    // Save incomplete order and remember its Id in %session.
    Do ord.%Save()
    Set %session.Data("Order") = ord.%Id()

    Quit
}


Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA