/// <summary> /// remove order /// </summary> /// <param name="orderId">id of the order which will be removed</param> public void RemoveOrder(int orderId) { using (var db = new OrderDB()) { Order oldOrder = db.Order.Include("Details").SingleOrDefault(o => o.Id == orderId); db.OrderItem.RemoveRange(oldOrder.Details); db.SaveChanges(); } }
/// <summary> /// remove the order in the dic /// </summary> /// <param name="order_id"></param> public void RemoveOrder(string order_id) { using (var db = new OrderDB()) { var order = db.Order.Include("details").SingleOrDefault(o => o.Id == order_id); db.OrderDetail.RemoveRange(order.details); db.Order.Remove(order); db.SaveChanges(); } }
/// <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(); } }
/// <summary> /// add order to the dic /// </summary> /// <param name="order"></param> public void AddOrder(Order order) { if (!CheckId(order.Id)) throw new Exception($"订单 {order.Id} 不合法!"); else { using (var db = new OrderDB()) { db.Order.Add(order); db.SaveChanges(); } } }
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(); }
private void button1_Click(object sender, EventArgs e) { string Id = textBox1.Text; /*bool flag = PublicValue.os.CancelOrder(textBox1.Text); * if (flag) * MessageBox.Show("删除成功"); * else * MessageBox.Show("删除失败,订单不存在");*/ using (var db = new OrderDB()) { var order = db.Order.Include("Items").SingleOrDefault(o => o.OrderId == Id); db.Goods.RemoveRange(order.GoodsList); db.Order.Remove(order); db.SaveChanges(); } }
/// <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(); } }
/// <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); }