Esempio n. 1
0
 ////获得订单
 //public Order GetOrder(string orderId)
 //{
 //    using (var db = new OrderDB())
 //    {
 //        return db.Order.Include("Orderdetails").
 //          SingleOrDefault(o => o.CustomerNum == orderId);
 //    }
 //}
 //获得所有订单
 public List <Order> GetAllOrders()
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("orderDetails").ToList <Order>());
     }
 }
Esempio n. 2
0
 //通过客户名查询订单
 public List <Order> QueryByCustomer(string cusname)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("orderDetails")
                .Where(o => o.CustomerName.Equals(cusname)).ToList <Order>());
     }
 }
Esempio n. 3
0
 //通过商品名查询订单
 public List <Order> QueryByGoods(string comname)
 {
     using (var db = new OrderDB())
     {
         var query = db.Order.Include("orderDetails")
                     .Where(o => o.OrderDetails.Where(
                                orderdetail => orderdetail.CommodityName.Equals(comname)).Count() > 0);
         return(query.ToList <Order>());
     }
 }
Esempio n. 4
0
 //删除订单
 public void Remove(string orderId)
 {
     using (var db = new OrderDB())
     {
         var order = db.Order.Include("Orderdetails").SingleOrDefault(o => o.CustomerNum == orderId);
         db.OrderDetail.RemoveRange(order.OrderDetails);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
        //public List<Order> Orders = new List<Order>();

        //添加订单
        public void Add(Order order)
        {
            using (var db = new OrderDB())
            {
                db.Order.Add(order);
                //db.Order.Attach(order);
                //db.Entry(order).State = EntityState.Added;
                db.SaveChanges();
            }
        }
Esempio n. 6
0
 //更新订单
 public void Update(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.OrderDetails.ForEach(
             orderdetail => db.Entry(orderdetail).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 //查找订单
 public Order Find(OrderDB db, string s)
 {
     foreach (Order t in db.Order)
     {
         if (t.CustomerNum == s)
         {
             return(t);
         }
     }
     return(null);
 }
Esempio n. 8
0
        //删除订单
        private void button4_Click(object sender, EventArgs e)
        {
            using (var db = new OrderDB())
            {
                if (bindingSerives.Current != null)
                {
                    Orders order = (Orders)bindingSerives.Current;
                    service.DeleteOrder(order.orderNumber, order.theCustomer);
                }
            }
            BindingSource bs = new BindingSource();

            bs.DataSource             = service;
            bindingSerives.DataSource = bs;
        }