Esempio n. 1
0
 public void addOrder(Order b)
 {
     orderList.Add(b);
     count++;
     using (var db = new OrderDB())
     {
         db.OrderList.Add(b);
         db.SaveChanges();
     }
 }
Esempio n. 2
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. 3
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);
     }
 }