public int CompareTo(object obj)//compareTo方法 { myorder a = obj as myorder; return(this.ID.CompareTo(a.ID)); }
public override bool Equals(object obj) { myorder a = obj as myorder; return(this.ID == a.ID); }
public void addOrder() { try { Console.WriteLine("请输入订单号:"); int id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入客户名:"); string customer = Console.ReadLine(); Console.WriteLine("请输入日期:"); string date = Console.ReadLine(); myorder a = new myorder(id, customer, date); bool judge = true; bool same = false; foreach (myorder m in this.orders) { if (m.Equals(a)) { same = true; } } if (same) { Console.WriteLine("订单号重复"); } else { while (judge && !same) { Console.WriteLine("请输入订单项:"); string name = Console.ReadLine(); Console.WriteLine("请输入订单数量:"); int number = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入订单单价:"); double price = Convert.ToDouble(Console.ReadLine()); a.addOrderItem(name, number, price); Console.WriteLine("是否继续添加订单?请输入 是 或 否 "); string e = Console.ReadLine(); if (e == "否") { judge = false; } else if (e == "是") { continue; } else if (e != "是" && e != "否") { Exception x = new Exception(); throw x; } } } orders.Add(a); a.getAllPrice(); Console.WriteLine("输入成功!"); Console.WriteLine("----------------------"); } catch { Console.WriteLine("输入错误!"); } }