Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

ChangeQuantity メソッド 2

次に、大人用と子供用のどちらのチケットの枚数の変更かを、TicketType 引数を調べることで決定します。その後、TicketOrder オブジェクトに保存されている合計金額を修正し、新しい枚数を TicketItem オブジェクトの AdultTickets プロパティまたは ChildTickets プロパティに格納します。

—Utils.ChangeQuantity—
Utils.ChangeQuantity
ClassMethod ChangeQuantity(
        ItemNum As %Integer, 
        TicketType As %Integer, 
        NewQuantity As %Integer)
{
    If $data(%session.Data("Order")) {
        // Open the current order object
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))

        // Update quantity
        Set itm=ord.Items.GetAt(ItemNum)

        // Determine if we are changing
        // adult or child tickets
        If ( TicketType = 1) {
            // Adjust the total price
            Set ord.Total = ord.Total +
                ((NewQuantity - itm.AdultTickets) * itm.Show.Theater.AdultPrice)
            // Update the number of tickets
            Set itm.AdultTickets = NewQuantity
        }
        Else {
            Set ord.Total = ord.Total +
                ((NewQuantity - itm.ChildTickets) * itm.Show.Theater.ChildPrice)
            Set itm.ChildTickets = NewQuantity
        }
        // ...
    }
}
FeedbackOpens in a new tab