Example #1
0
 /// <summary>
 /// OrderDetail constructor
 /// </summary>
 /// <param name="Num">orderDetail's num</param>
 /// <param name="goods">orderDetail's goods</param>
 /// <param name="quantity">goods' quantity</param>
 public OrderDetail(Goods goods, int quantity)
 {
     this.Goods    = goods;
     this.Quantity = quantity;
 }
Example #2
0
        static void Main(string[] args)
        {
            using (var db = new Db())
            {
                try
                {
                    Customer customer1 = new Customer(1, "Customer1");
                    Customer customer2 = new Customer(2, "Customer2");

                    Goods milk  = new Goods(1, "Milk", 69.9f);
                    Goods eggs  = new Goods(2, "eggs", 4.99f);
                    Goods apple = new Goods(3, "apple", 5.59f);

                    Order order1 = new Order(1, customer1);
                    order1.AddDetails(new OrderDetail(apple, 8));
                    order1.AddDetails(new OrderDetail(eggs, 10));
                    // order1.AddDetails(new OrderDetail(eggs, 8));
                    order1.AddDetails(new OrderDetail(milk, 10));

                    Order order2 = new Order(2, customer2);
                    order2.AddDetails(new OrderDetail(eggs, 10));
                    order2.AddDetails(new OrderDetail(milk, 10));

                    Order order3 = new Order(3, customer2);
                    order3.AddDetails(new OrderDetail(milk, 100));

                    OrderService orderService = new OrderService();
                    orderService.AddOrder(order1);
                    orderService.AddOrder(order2);
                    orderService.AddOrder(order3);

                    Console.WriteLine("\n GetById");
                    Console.WriteLine(orderService.GetById(1));
                    Console.WriteLine(orderService.GetById(5) == null);

                    Console.WriteLine("\nGetAllOrders");
                    List <Order> orders = orderService.QueryAll();
                    orders.ForEach(o => Console.WriteLine(o));

                    Console.WriteLine("\nGetOrdersByCustomerName:'Customer2'");
                    orders = orderService.QueryByCustomerName("Customer2");
                    orders.ForEach(o => Console.WriteLine(o));

                    Console.WriteLine("\nGetOrdersByGoodsName:'eggs'");
                    orders = orderService.QueryByGoodsName("eggs");
                    orders.ForEach(o => Console.WriteLine(o));

                    Console.WriteLine("\nGetOrdersTotalAmount:1000");
                    orders = orderService.QueryByTotalAmount(1000);
                    orders.ForEach(o => Console.WriteLine(o));

                    Console.WriteLine("\nRemove order(id=2) and qurey all");
                    orderService.RemoveOrder(2);
                    orderService.QueryAll().ForEach(
                        o => Console.WriteLine(o));

                    Console.WriteLine("\n order by Amount");
                    orderService.Sort(
                        (o1, o2) => o2.TotalAmount.CompareTo(o1.TotalAmount));
                    orderService.QueryAll().ForEach(
                        o => Console.WriteLine(o));



                    Console.WriteLine("\n export and import orders");
                    orderService.Export(@".\order.xml");
                    List <Order> importedOrders = orderService.Import(@".\order.xml");
                    importedOrders.ForEach(o => Console.WriteLine(o));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                /*
                 * db.goods.Add(milk);
                 * db.goods.Add(eggs);
                 * db.goods.Add(apple);
                 *
                 * db.customer.Add(customer1);
                 * db.customer.Add(customer2);
                 *
                 * db.order.Add(order1);
                 * db.order.Add(order2);
                 * db.order.Add(order3);
                 *
                 * db.SaveChanges();*/
            }
        }