예제 #1
0
        protected void OnSubmitButton(Object s, EventArgs e)
        {
            // Create the XML document
            XDocument xml = new XDocument(
                new XElement("order",
                             new XElement("reference_number", order.GetReferenceNumber().ToString()),
                             new XElement("pizzas",
                                          order.pizzas.Select(pizza => new XElement("pizza",
                                                                                    new XElement("name", pizza.name),
                                                                                    new XElement("base_toppings", pizza.base_toppings),
                                                                                    pizza.toppings.Select(topping =>
                                                                                                          new XElement("extra_topping", topping.name)),
                                                                                    new XElement("cost", pizza.Cost().ToString("c"))))),
                             new XElement("total_price", order.Cost().ToString("c")),
                             new XElement("order_time", DateTime.Now.ToString())));

            // Write the XML to file
            // TODO(topher): where should this file be saved?
            string output_filename = @"C:\Users\topher\Documents\order_" +
                                     order.GetReferenceNumber() + ".xml";

            using (System.IO.FileStream fs =
                       System.IO.File.Create(output_filename))
            {
                xml.Save(fs);
            }

            Response.Redirect("OrderComplete.aspx");
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Order order = (Order)Session["order"];

            if (order == null)
            {
                // How did we manage that?
                Response.Redirect("Default.aspx");
            }

            ReferenceNumberLabel.Text = "Reference number: #" +
                                        order.GetReferenceNumber().ToString();
            TotalLabel.Text = "Total cost (including sales tax): " +
                              order.Cost().ToString("c");
        }