Beispiel #1
0
 /// <summary>
 /// change the order's Customer
 /// </summary>
 /// <param name="orderId"></param>
 /// <param name="newCustomer"></param>
 public void Update(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.details.ForEach(
             detail => db.Entry(detail).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Beispiel #2
0
        /// <summary>
        /// update the order
        /// </summary>
        /// <param name="order">the order to be updated</param>
        public void Update(Order order)
        {
            using (var db = new OrderDB())
            {
                Order oldOrder = db.Order.Include("Details").SingleOrDefault(o => o.Id == order.Id);
                db.OrderItem.RemoveRange(oldOrder.Details);
                db.SaveChanges();
            }

            using (var db = new OrderDB())
            {
                foreach (OrderDetail detail in order.Details)
                {
                    db.Entry(detail).State = EntityState.Added;
                }

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
            }


            //RemoveOrder(order.Id);
            //orderList.Add(order);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            string cname, id;

            id    = System.Guid.NewGuid().ToString("N");
            cname = textBox1.Text;
            List <Goods> glist = new List <Goods>();

            if (int.Parse(textBox2.Text) != 0 && textBox2.Text != null)
            {
                glist.Add(new Goods("木材", int.Parse(textBox2.Text), 18));
            }
            if (int.Parse(textBox3.Text) != 0 && textBox3.Text != null)
            {
                glist.Add(new Goods("玻璃", int.Parse(textBox3.Text), 15));
            }
            if (int.Parse(textBox4.Text) != 0 && textBox4.Text != null)
            {
                glist.Add(new Goods("圆石", int.Parse(textBox4.Text), 20));
            }
            if (int.Parse(textBox5.Text) != 0 && textBox5.Text != null)
            {
                glist.Add(new Goods("水泥", int.Parse(textBox5.Text), 10));
            }

            Order.Order order = new Order.Order(id, cname, glist);
            foreach (Order.Order o in PublicValue.os.orderlist)
            {
                if (o.Equals(order))
                {
                    MessageBox.Show("添加失败!原因:订单明细与已有订单相同");
                    return;
                }
            }
            PublicValue.os.orderlist.Add(order);

            using (var db = new OrderDB())
            {
                db.Order.Add(order);
                //db.Order.Attach(order);
                db.Entry(order).State = EntityState.Added;
                db.SaveChanges();
            }

            MessageBox.Show("创建成功!订单号为" + id);
            this.Close();
        }
Beispiel #4
0
 /// <summary>
 /// add new order
 /// </summary>
 /// <param name="order">the order to be added</param>
 public void AddOrder(Order order)
 {
     using (var odb = new OrderDB())
     {
         try
         {
             odb.Entry(order).State = EntityState.Added;
             odb.SaveChanges();
         }
         catch
         {
             ;
         }
     }
     //if (orderList.Contains(order)) {
     //  throw new ApplicationException($"the orderList contains an order with ID {order.Id} !");
     //}
     //orderList.Add(order);
     // using (var db = new OrderDB()) { db.Order.Add(order); db.SaveChanges(); }
 }