public Order FindOrder(string onum) { using (var db = new OrderDB()) { return(db.Order.Include("oDlist").SingleOrDefault(o => o.ONum == onum)); } }
public List <Order> GetAllOrders() { using (var db = new OrderDB()) { return(db.Order.Include("oDlist").ToList()); } }
public void AddOrder(Order order) { using (var db = new OrderDB()) { db.Order.Add(order); db.SaveChanges(); } }
public List <Order> GetAllOrders() { using (var db = new OrderDB()) { orders = db.Order.Include("items").ToList(); return(db.Order.Include("items").ToList()); } }
//按订单号删除 public void RemoveOrder(string onum) { using (var db = new OrderDB()) { var order = db.Order.Include("oDlist").SingleOrDefault(o => o.ONum == onum); db.Order.Remove(order); db.OrderDetails.RemoveRange(order.oDlist); db.SaveChanges(); } }
public void DeleteOrderById(string id) { using (var db = new OrderDB()) { var order = db.Order.Include("Items").SingleOrDefault(o => o.ID == id); db.OrderItem.RemoveRange(order.items); db.Order.Remove(order); db.SaveChanges(); } }
public List <Order> QueryByGoods(string stuff) { using (var db = new OrderDB()) { var query = db.Order.Include("items") .Where(o => o.items.Where( item => item.stuff.Equals(stuff)).Count() > 0); return(query.ToList()); } }
public void ReviseOrder(Order order) { using (var db = new OrderDB()) { db.Order.Attach(order); db.Entry(order).State = EntityState.Modified; order.oDlist.ForEach( item => db.Entry(item).State = EntityState.Modified); db.SaveChanges(); } }
public void AddOrder(Order order) { using (var db = new OrderDB()) { db.Order.Add(order); db.Order.Attach(order); db.Entry(order).State = EntityState.Added; db.SaveChanges(); } Console.WriteLine("添加成功"); }
public Order FindOrderById(string id) { using (var db = new OrderDB()) { return(db.Order.Include("Items"). SingleOrDefault(o => o.ID == id)); } //var result = from item in orders // where item.Myid == id // select item; //if (result.ToList().Count == 0) //{ // Console.WriteLine("查无此单"); // return; //} //foreach (Order order in result.ToList()) //{ // Console.WriteLine(order); //} }
//public void FindOrderByStuff(string stuff) //{ // var result = from item in orders // where (item.Getlist().Where(a => a.stuff == stuff)).ToList().Count!=0 // select item; // if (result.ToList().Count == 0) // { // Console.WriteLine("查无此单"); // return ; // } // foreach (Order order in result.ToList()) // { // Console.WriteLine(order); // } //} public List <Order> FindByClientName(string name) { using (var db = new OrderDB()) { return(db.Order.Include("items") .Where(o => o.ClientName.Equals(name)).ToList()); } //var result = from item in orders // where item.ClientName == name // select item; //if (result.ToList().Count == 0) //{ // Console.WriteLine("查无此单"); // return; //} //foreach (Order order in result.ToList()) //{ // Console.WriteLine(order); //} }
static void Main(string[] args) { OrderDB dbcontext = new OrderDB(); //创建数据库如果不存在的话 if (dbcontext.Database.CreateIfNotExists()) { Console.WriteLine("数据库已创建成功!"); //Console.Read(); } else { Console.WriteLine("数据库已经存在,无需创建!"); } Order order1 = new Order(3, "王林", "+86 13333333333"); Order order2 = new Order(2, "苏铭", "+86 12345678901"); OrderService orderService = new OrderService(); OrderDetails Orderdetail = new OrderDetails("下品灵石", 1, 1); OrderDetails Orderdetai2 = new OrderDetails("极品灵石", 10, 10000); order1.AddOrderDetails(Orderdetail); order2.AddOrderDetails(Orderdetai2); try { orderService.AddOrder(order1); orderService.AddOrder(order2); } catch { Console.WriteLine("订单已存在"); } Console.WriteLine("欢迎来到订单管理系统\n"); while (true) { Console.WriteLine("您有五个选择:\n"); Console.WriteLine("1、添加订单\n" + "2、通过订单号删除订单\n" + "3、通过订单号查询订单\n" + "4、通过订单号更改订单\n" + "5、通过商品名查询订单\n" + "6、通过客户名查询订单\n" + "7、查询总金额超过一万的订单\n" + "8、保存所有数据到本地\n" + "9、导入所有数据到系统\n" + "10、退出系统\n" + "请输入您的选择:"); string str = Console.ReadLine(); int choice; if (!int.TryParse(str, out choice)) { Console.WriteLine("输入格式错误请重新输入"); } if (choice == 1) { Order order = CreateOrder(); orderService.AddOrder(order); } else if (choice == 2) { //int id = StringToIntId(); Console.WriteLine("请输入订单号"); string ID = Console.ReadLine(); orderService.DeleteOrderById(ID); } else if (choice == 4) { //int id = StringToIntId(); Order order = CreateOrder(); orderService.updateOrder(order); } else if (choice == 3) { //int id = StringToIntId(); Console.WriteLine("请输入订单号:"); string id = Console.ReadLine(); //orderService.FindOrderById(id); Console.WriteLine(orderService.FindOrderById(id)); } else if (choice == 5) { Console.WriteLine("请输入商品名称:"); str = Console.ReadLine(); orderService.QueryByGoods(str); } else if (choice == 6) { Console.WriteLine("请输入客户名:"); str = Console.ReadLine(); orderService.FindByClientName(str); } else if (choice == 7) { orderService.FindBigTrade(); } else if (choice == 8) { orderService.Export(); } else if (choice == 9) { orderService.Import(); } else { break; } } }