Beispiel #1
0
        void SetOrderDetails(Order o)
        {
            txtNotes.Text = o.Notes;

            foreach (var lineItem in o.OrderItems)
            {
                var ucLi = ObjectFactory.GetInstance<ucLineItem>();
                ucLi.LoadOrderItems(_orderItems);
                flpMain.Controls.Add(ucLi);
            }
        }
        XElement OrderToXml(Order o)
        {
            XElement xOrder = new XElement("Order",
                new XAttribute("GrandTotal", o.GrandTotal.ToString()),
                new XAttribute("OrderDate", o.OrderDate.ToShortDateString()),
                new XAttribute("PaymentMethod", o.PaymentMethod.ToString()),
                new XAttribute("SubTotal", o.SubTotal.ToString()),
                new XAttribute("Taxes", o.Taxes),
                new XAttribute("Notes", o.Notes)
                );

            foreach (var lineItem in o.OrderItems)
            {
                xOrder.Add(
                    new XElement("OrderItem",
                        new XElement("Account", lineItem.Account),
                        new XElement("Description", lineItem.Description),
                        new XElement("IsTaxed", lineItem.IsTaxed),
                        new XElement("ItemName", lineItem.ItemName),
                        new XElement("Price", lineItem.Price),
                        new XElement("Quantity", lineItem.Quantity),
                        new XElement("ItemID", lineItem.ItemID),
                        new XElement("Total", lineItem.Total)
                    ));
            }
            return xOrder;
        }
        Order XmlToOrder(XElement xOrder)
        {
            Order o = new Order();

            double grandTotal;
            double subTotal;
            double taxes;
            DateTime orderDate;

            if (xOrder.Attribute("Notes") != null)
                o.Notes = xOrder.Attribute("Notes").Value;

            if (double.TryParse(xOrder.Attribute("GrandTotal").Value, out grandTotal))
                o.GrandTotal = grandTotal;

            if (double.TryParse(xOrder.Attribute("SubTotal").Value, out subTotal))
                o.SubTotal = subTotal;

            if (double.TryParse(xOrder.Attribute("Taxes").Value, out taxes))
                o.Taxes = taxes;

            if (DateTime.TryParse(xOrder.Attribute("OrderDate").Value, out orderDate))
                o.OrderDate = orderDate;

            try
            {
                o.PaymentMethod = _util.ParseEnum<Enums.PaymentMethod>(xOrder.Attribute("PaymentMethod").Value);
            }
            catch (Exception)
            {
                o.PaymentMethod = Enums.PaymentMethod.NotSelected;
            }

            var xOrderItems = xOrder.Elements("OrderItem");

            foreach (var xOrderItem in xOrderItems)
            {

                OrderItem oi = new OrderItem();
                oi.Account = xOrderItem.Element("Account").Value;
                oi.Description = xOrderItem.Element("Description").Value;
                oi.ItemName = xOrderItem.Element("ItemName").Value;
                oi.ItemID = xOrderItem.Element("ItemID").Value;

                double price;
                if (double.TryParse(xOrderItem.Element("Price").Value, out price))
                    oi.Price = price;

                double quantity;
                if (double.TryParse(xOrderItem.Element("Quantity").Value, out quantity))
                    oi.Quantity = quantity;

                double total;
                if (double.TryParse(xOrderItem.Element("Total").Value, out total))
                    oi.Total = total;

                bool taxed = false;
                if (bool.TryParse(xOrderItem.Element("IsTaxed").Value, out taxed))
                    oi.IsTaxed = taxed;

                o.OrderItems.Add(oi);
            }
            return o;
        }
 public CustomerOrderObject()
 {
     _vehicle = new Vehicle();
     _customer = new Customer();
     _order = new Order();
 }