private void button4_Click(object sender, EventArgs e) { using (var db = new OrderDB()) { bindingSource1.DataSource = db.Order.ToList(); } }
/// <summary> /// 确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string s = textBox1.Text.ToString(); Regex regex = new Regex(@"\d{11}"); if (!regex.IsMatch(textBox3.Text)) { throw new Exception("电话格式不正确"); } string i = textBox2.Text.ToString(); long cusid = long.Parse(textBox3.Text.ToString()); Customer customer = new Customer(cusid, s); Order order = new Order(i, customer); foreach (OrderDetail item in orderDetails) { using (var db = new OrderDB()) { db.OrderDetail.Add(item); db.SaveChanges(); } } Form1.os.AddOrder(order); Form1.bindingSource1.DataSource = null; Form1.bindingSource1.DataSource = Form1.os.GetAllOrders(); Close(); }
/// <summary> /// get the order in the dic by it's name (using Linq language) /// </summary> /// <param name="name"></param> /// <returns></returns> public List <Order> GetOrderByName(string name) { using (var db = new OrderDB()) { return(db.Order.Include("details") .Where(od => od.orderDetailList.Where(d => d.Goods.GoodsName == name).Count() > 0).ToList <Order>()); } }
/// <summary> /// get the order by it's Customer's name (using Linq language) /// </summary> /// <param name="name"></param> /// <returns></returns> public List <Order> GetOrderByCustomer(string name) { using (var db = new OrderDB()) { return(db.Order.Include("details") .Where(o => o.Customer.CustomerName == name).ToList <Order>()); } }
public List <Order> GetAllOrders() { using (var db = new OrderDB()) { var x = db.Order.Include("details").ToList <Order>(); return(x); } }
/// <summary> /// get the order by it's id /// </summary> /// <param name="id"></param> /// <returns></returns> public Order GetOrderById(string id) { using (var db = new OrderDB()) { return(db.Order.Include("details"). SingleOrDefault(o => o.OrderId == id)); } }
/// <summary> /// get the order whose money >= 10000 /// </summary> /// <returns></returns> public List <Order> GetBigOrder() { using (var db = new OrderDB()) { return(db.Order.Include("details") .Where(o => o.Money >= 10000).ToList <Order>()); } }
/// <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.OrderId == order_id); db.OrderDetail.RemoveRange(order.orderDetailList); 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.orderDetailList.ForEach( detail => db.Entry(detail).State = EntityState.Modified); db.SaveChanges(); } }
private void button1_Click(object sender, EventArgs e) { using (var db = new OrderDB()) { db.Order.Remove(order); order.num = newb; order.name = newc; order.customer = newd; order.price = Convert.ToInt32(newe); order.phone = Convert.ToInt64(newf); order.order = Convert.ToInt64(newg); db.Order.Add(order); db.SaveChanges(); } }
/// <summary> /// add order to the dic /// </summary> /// <param name="order"></param> public void AddOrder(Order order) { if (!CheckId(order.OrderId)) { throw new Exception($"订单 {order.OrderId} 不合法!"); } else { using (var db = new OrderDB()) { db.Order.Add(order); db.SaveChanges(); } } }
private void button2_Click(object sender, EventArgs e) { using (var db = new OrderDB()) { if (bindingSource1.Current != null) { OrderDetails order = (OrderDetails)bindingSource1.Current; var order1 = db.Order.SingleOrDefault(o => o.num == order.num); db.Order.Remove(order1); db.SaveChanges(); button4.PerformClick(); } else { MessageBox.Show("have not chosen order "); } } }
private void button1_Click(object sender, EventArgs e) { OrderDetails order = new OrderDetails(); order.num = x; order.name = b; order.customer = c; order.price = Convert.ToInt32(d); order.phone = Convert.ToInt64(p); order.order = Convert.ToInt64(o); using (var db = new OrderDB()) { try { db.Order.Add(order); db.SaveChanges(); MessageBox.Show("success", "remind:", MessageBoxButtons.OK); } catch { MessageBox.Show("error,number repeat! ", "remind:", MessageBoxButtons.OK); } } }