public static void Main() { try { Customer customer1 = new Customer(1, "Customer1"); Customer customer2 = new Customer(2, "Customer2"); Goods milk = new Goods(1, "Milk", 69.9); Goods eggs = new Goods(2, "eggs", 4.99); Goods apple = new Goods(3, "apple", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2); OrderDetail orderDetails3 = new OrderDetail(3, milk, 1); Order order1 = new Order(1, customer1, "15622586649"); Order order2 = new Order(2, customer2, "15622586649"); Order order3 = new Order(3, customer2, "15622586649"); order1.AddDetails(orderDetails1); order1.AddDetails(orderDetails2); order1.AddDetails(orderDetails3); //order1.AddOrderDetails(orderDetails3); order2.AddDetails(orderDetails2); order2.AddDetails(orderDetails3); order3.AddDetails(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order1); os.AddOrder(order2); os.AddOrder(order3); Console.WriteLine("GetAllOrders"); List <Order> orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine("GetOrdersByCustomerName:'Customer2'"); orders = os.QueryByCustomerName("Customer2"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine("GetOrdersByGoodsName:'apple'"); orders = os.QueryByGoodsName("apple"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine("GetOrdersByPrice:1000"); orders = os.QueryByPrice(1000); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine("Remove order(id=2) and qurey all"); os.RemoveOrder(2); os.QueryAllOrders().ForEach( od => Console.WriteLine(od)); } catch (Exception e) { Console.WriteLine(e.Message); } }
private void button1_Click(object sender, EventArgs e) { Form form1 = new Form(); Button Mybutton1 = new Button(); TextBox t1 = new TextBox(); TextBox t2 = new TextBox(); TextBox t3 = new TextBox(); TextBox t4 = new TextBox(); TextBox t5 = new TextBox(); TextBox t6 = new TextBox(); TextBox t7 = new TextBox(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); Label l4 = new Label(); Label l5 = new Label(); Label l6 = new Label(); Label l7 = new Label(); Mybutton1.Text = "确认添加"; l1.Text = "请输入订单号"; l1.Location = new Point(10, 10); t1.Location = new Point(l1.Left, l1.Height + l1.Top + 10); l2.Text = "请输入顾客名称"; l2.Location = new Point(l1.Left, t1.Height + t1.Top + 10); t2.Location = new Point(l1.Left, l2.Height + l2.Top + 10); l3.Text = "请输入商品数量"; l3.Location = new Point(l1.Left, t2.Height + t2.Top + 10); t3.Location = new Point(l1.Left, l3.Height + l3.Top + 10); l4.Text = "请输入商品名称"; l4.Location = new Point(l1.Left, t3.Height + t3.Top + 10); t4.Location = new Point(l1.Left, l4.Height + l4.Top + 10); l5.Text = "请输入商品单价"; l5.Location = new Point(l1.Left, t4.Height + t4.Top + 10); t5.Location = new Point(l1.Left, l5.Height + l5.Top + 10); l6.Text = "请输入商品序号"; l6.Location = new Point(l1.Left, t5.Height + t5.Top + 10); t6.Location = new Point(l1.Left, l6.Height + l6.Top + 10); l7.Text = "请输入顾客序号"; l7.Location = new Point(l1.Left, t6.Height + t6.Top + 10); t7.Location = new Point(l1.Left, l7.Height + l7.Top + 10); Mybutton1.Location = new Point(l1.Left, t7.Height + t7.Top + 10); form1.Text = "订单添加"; form1.FormBorderStyle = FormBorderStyle.FixedDialog; form1.Size = new Size(500, 600); form1.StartPosition = FormStartPosition.CenterScreen; form1.Controls.Add(l1); form1.Controls.Add(l2); form1.Controls.Add(l3); form1.Controls.Add(l4); form1.Controls.Add(l5); form1.Controls.Add(t1); form1.Controls.Add(t2); form1.Controls.Add(t3); form1.Controls.Add(t4); form1.Controls.Add(t5); form1.Controls.Add(t6); form1.Controls.Add(t7); form1.Controls.Add(l6); form1.Controls.Add(l7); form1.Controls.Add(Mybutton1); Mybutton1.DialogResult = DialogResult.OK; form1.AcceptButton = Mybutton1; form1.ShowDialog(); string s1 = t1.Text; string s2 = t2.Text; string s3 = t3.Text; string s4 = t4.Text; string s5 = t5.Text; string s6 = t6.Text; string s7 = t7.Text; uint num1 = 0; double num2 = 0; num1 = UInt32.Parse(s6); num2 = Double.Parse(s5); ordertest.Goods good = new ordertest.Goods(num1, s4, num2); num1 = UInt32.Parse(s7); ordertest.Customer cu = new ordertest.Customer(num1, s2); num1 = UInt32.Parse(s3); ordertest.OrderDetail od = new ordertest.OrderDetail(1, good, num1); num1 = UInt32.Parse(s1); ordertest.Order or = new ordertest.Order(num1, cu); or.AddDetails(od); if (form1.DialogResult == DialogResult.OK) { orders.Add(or); form1.Dispose(); bindingSource1.DataSource = null; bindingSource1.DataSource = orders; } }
public static void Main() { try { Customer customer1 = new Customer(1, "Customer1"); Customer customer2 = new Customer(2, "Customer2"); Goods milk = new Goods(1, "Milk", 69.9); Goods eggs = new Goods(2, "eggs", 4.99); Goods apple = new Goods(3, "apple", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2); OrderDetail orderDetails3 = new OrderDetail(3, milk, 1); Order order1 = new Order(1, customer1); Order order2 = new Order(2, customer2); Order order3 = new Order(3, customer2); order1.AddOrderDetail(orderDetails1); order1.AddOrderDetail(orderDetails2); order1.AddOrderDetail(orderDetails3); //order1.AddOrderDetails(orderDetails3); order2.AddOrderDetail(orderDetails2); order2.AddOrderDetail(orderDetails3); order3.AddOrderDetail(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order1); os.AddOrder(order2); os.AddOrder(order3); Order[] Myorders = { order1, order2, order3 }; var query = from BigOrder in Myorders where BigOrder.OrderId > 10000 select BigOrder; foreach (var m in query) { Console.WriteLine(m); } Console.WriteLine("GetAllOrders"); List <Order> orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("GetOrdersByCustomerName:'Customer2'"); orders = os.GetOrdersByCustomerName("Customer2"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("GetOrdersByGoodsName:'apple'"); orders = os.QueryOrdersByGoodsName("apple"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("Remove order(id=2) and qurey all"); os.RemoveOrder(2); orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Main() { try { Customer customer1 = new Customer(1, "Customer1"); Customer customer2 = new Customer(2, "Customer2"); Goods milk = new Goods(1, "Milk", 69.9); Goods eggs = new Goods(2, "eggs", 4.99); Goods apple = new Goods(3, "apple", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2); OrderDetail orderDetails3 = new OrderDetail(3, milk, 1); Order order1 = new Order(1, customer1); Order order2 = new Order(2, customer2); Order order3 = new Order(3, customer2); order1.AddDetails(orderDetails1); order1.AddDetails(orderDetails2); //order1.AddDetails(orderDetails3); //order1.AddOrderDetails(orderDetails3); order3.AddDetails(orderDetails2); //order3.AddDetails(orderDetails3); order2.AddDetails(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order1); os.AddOrder(order2); os.AddOrder(order3); OrderExport2Xml(os); OrderService osnew = XmlImport2Order(); //Read data of order system from existing Xml configuration file //OrderService osnew = os; //Use the data created manually Console.WriteLine("GetAllOrdersInIDAscendingOrder"); List <Order> orders = osnew.QueryAllOrders(); orders.Sort(); foreach (Order order in orders) { Console.WriteLine(order.ToString()); } Console.WriteLine("GetAllOrdersInSumDecendingOrder"); foreach (Order order in orders) { order.CalculateSum(); } foreach (Order order in orders.OrderByDescending(i => i.sum)) { Console.WriteLine(order.ToString()); Console.WriteLine("\tsum = " + order.sum.ToString()); } Console.WriteLine("GetOrdersByCustomerName:'Customer2'"); orders = osnew.QueryByCustomerName("Customer2"); foreach (Order order in orders) { Console.WriteLine(order.ToString()); } Console.WriteLine("GetOrdersByGoodsName:'apple'"); orders = osnew.QueryByGoodsName("apple"); foreach (Order order in orders) { Console.WriteLine(order); } Console.WriteLine("Remove order(id=2) and qurey all"); osnew.RemoveOrder(2); osnew.QueryAllOrders().ForEach( od => Console.WriteLine(od)); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Main() { try { Customer customer1 = new Customer(1, "宝多六花"); Customer customer2 = new Customer(2, "新条茜"); Goods milk = new Goods(1, "牛奶", 69.9); Goods eggs = new Goods(2, "鸡蛋", 4.99); Goods apple = new Goods(3, "苹果", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, milk, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2333); OrderDetail orderDetails3 = new OrderDetail(3, apple, 1); Order order1 = new Order(1, customer1); Order order2 = new Order(2, customer2); Order order3 = new Order(3, customer2); order1.AddDetails(orderDetails1); order1.AddDetails(orderDetails2); order1.AddDetails(orderDetails3); //order1.AddOrderDetails(orderDetails3); order2.AddDetails(orderDetails2); order2.AddDetails(orderDetails3); order3.AddDetails(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order1); os.AddOrder(order2); os.AddOrder(order3); Console.WriteLine("获取所有订单:" + "\n"); List <Order> orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString() + "\n"); } string name1 = "宝多六花"; Console.WriteLine("通过客户姓名查询订单:'宝多六花'"); //orders = os.QueryByCustomerName("宝多六花"); var m = from n1 in orders where n1.Customer.Name == name1 select n1; foreach (var od in m) { Console.WriteLine(od.ToString() + "\n"); } List <OrderDetail> detail = new List <OrderDetail> { orderDetails1, orderDetails2, orderDetails3 }; string good1 = "牛奶"; Console.WriteLine("通过商品查询订单:'牛奶'"); //orders = os.QueryByGoodsName("牛奶"); var n = from n2 in detail where n2.Goods.Name == good1 select n2; foreach (var od in n) { Console.WriteLine(od.ToString() + "\n"); } Console.WriteLine("查询订单金额大于1w元的订单:"); var w = from x in detail where x.Goods.Price * x.Quantity > 10000 select x; foreach (var od in w) { Console.WriteLine(od.ToString() + "\n"); } Console.WriteLine("删除订单(ID=2)和Query全部:"); os.RemoveOrder(2); os.QueryAllOrders().ForEach( od => Console.WriteLine(od)); Console.WriteLine(); bool b1 = os.Export(orders); bool b2 = os.Import("serialiable.xml"); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { try { Customer customer1 = new Customer(1, "张三"); Customer customer2 = new Customer(2, "赵四"); Goods milk = new Goods(1, "牛奶", 6.9); Goods eggs = new Goods(2, "鸡蛋", 4.99); Goods apple = new Goods(3, "苹果", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2); OrderDetail orderDetails3 = new OrderDetail(3, milk, 1); Order order1 = new Order(1, customer1); Order order2 = new Order(2, customer2); Order order3 = new Order(3, customer2); order1.AddOrderDetail(orderDetails1); order1.AddOrderDetail(orderDetails2); order1.AddOrderDetail(orderDetails3); order2.AddOrderDetail(orderDetails2); order2.AddOrderDetail(orderDetails3); order3.AddOrderDetail(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order1); os.AddOrder(order2); os.AddOrder(order3); Console.WriteLine("得到所有订单"); List <Order> orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("按照顾客姓名查询:赵四"); orders = os.GetOrdersByCustomerName("赵四"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("按照商品查询:'苹果'"); orders = os.QueryOrdersByGoodsName("苹果"); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); Console.WriteLine("移除订单(2号)并查询订单"); os.RemoveOrder(2); orders = os.QueryAllOrders(); foreach (Order od in orders) { Console.WriteLine(od.ToString()); } Console.WriteLine(""); //os.Export(); //os.Import(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Main() { try { Customer customer1 = new Customer(1, "Customer1"); Customer customer2 = new Customer(2, "Customer2"); Goods milk = new Goods(1, "Milk", 69.9); Goods eggs = new Goods(2, "eggs", 4.99); Goods apple = new Goods(3, "apple", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 8); OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2); OrderDetail orderDetails3 = new OrderDetail(3, milk, 1); Order order1 = new Order(1, customer1); Order order2 = new Order(2, customer2); Order order3 = new Order(3, customer2); order1.AddDetails(orderDetails1);//add details for order1 order1.AddDetails(orderDetails2); order1.AddDetails(orderDetails3); order2.AddDetails(orderDetails2); //add details for order2 order2.AddDetails(orderDetails3); //add details for order3 order3.AddDetails(orderDetails3); OrderService os = new OrderService(); os.AddOrder(order2); os.AddOrder(order1); os.AddOrder(order3); Console.WriteLine("GetAllOrders"); List <Order> orders = os.QueryAllOrders(); foreach (Order order in orders) { Console.WriteLine(order.ToString()); } Console.WriteLine("\nSort orders by Id"); orders.Sort(); foreach (Order order in orders) { Console.WriteLine(order.ToString()); } Console.WriteLine("\nSort orders by Price"); List <Order> sortorders = orders.OrderByDescending(s => s.money).ToList <Order>(); foreach (Order order in sortorders) { Console.WriteLine(order.ToString()); } Console.WriteLine("\nGetOrdersByCustomerName:'Customer2'"); orders = os.QueryByCustomerName("Customer2"); foreach (Order order in orders) { Console.WriteLine(order.ToString()); } Console.WriteLine("\nGetOrdersByGoodsName:'eggs'"); orders = os.QueryByGoodsName("eggs"); foreach (Order order in orders) { Console.WriteLine(order); } Console.WriteLine("\nRemove order(id=2) and qurey all"); os.RemoveOrder(2); os.QueryAllOrders().ForEach( od => Console.WriteLine(od)); } catch (Exception e) { Console.WriteLine(e.Message); } }