Esempio n. 1
0
 public OrderService()
 {
     using (var db = new OrderDB())
     {
         var orderList1 = from o in db.OrderList select o;
         orderList = orderList1.ToList();
     }
 }
Esempio n. 2
0
 public void addOrder(Order b)
 {
     orderList.Add(b);
     count++;
     using (var db = new OrderDB())
     {
         db.OrderList.Add(b);
         db.SaveChanges();
     }
 }
Esempio n. 3
0
        //更改List第num个成员;flag为0,更改订单号,flag为1,更改订单商品名称,flag为2,更改订单客户名称
        public bool changeOrder(int num, string s, int flag)
        {
            try
            {
                switch (flag)
                {
                case 0:
                    orderList[num - 1].orderNum = s;
                    using (var db = new OrderDB())
                    {
                        db.OrderList.Attach(orderList[num - 1]);
                        db.Entry(orderList[num - 1]).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    break;

                case 1:
                    orderList[num - 1].orderName = s;
                    using (var db = new OrderDB())
                    {
                        db.OrderList.Attach(orderList[num - 1]);
                        db.Entry(orderList[num - 1]).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    break;

                default:
                    orderList[num - 1].orderClient = s;
                    using (var db = new OrderDB())
                    {
                        db.OrderList.Attach(orderList[num - 1]);
                        db.Entry(orderList[num - 1]).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    break;
                }
                return(true);
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("需要修改的订单不存在");
                return(false);
            }
        }
Esempio n. 4
0
 public bool deleteOrder(long i)
 {
     try
     {
         var result = orderList.SingleOrDefault(a => a.orderNum == i.ToString());
         orderList.Remove(result);
         count--;
         using (var db = new OrderDB())
         {
             var order = db.OrderList.SingleOrDefault(o => o.orderNum == i.ToString());
             db.OrderList.Remove(order);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine("该订单不存在");
         return(false);
     }
 }
Esempio n. 5
0
        //通过Linq查询订单 flag为0按订单号查找,flag为1按订单客人名称,flag为2查询总价超过10000的订单
        public IEnumerable <Order> searchOrderbyLinq(string s, int flag)
        {
            switch (flag)
            {
            case 0:
                using (var db = new OrderDB())
                {
                    return(db.OrderList.Where(o => o.orderNum == s).ToList());
                }

            case 1:
                using (var db = new OrderDB())
                {
                    return(db.OrderList.Where(o => o.orderClient == s).ToList());
                }

            default:
                using (var db = new OrderDB())
                {
                    return(db.OrderList.Where(o => o.tot > 10000).ToList());
                }
            }
        }