예제 #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     using (var db = new OrderDB())
     {
         bindingSource1.DataSource = db.Order.ToList();
     }
 }
예제 #2
0
        /// <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();
        }
예제 #3
0
 /// <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>());
     }
 }
예제 #4
0
 /// <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>());
     }
 }
예제 #5
0
 public List <Order> GetAllOrders()
 {
     using (var db = new OrderDB())
     {
         var x = db.Order.Include("details").ToList <Order>();
         return(x);
     }
 }
예제 #6
0
 /// <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));
     }
 }
예제 #7
0
 /// <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>());
     }
 }
예제 #8
0
 /// <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();
     }
 }
예제 #9
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.orderDetailList.ForEach(
             detail => db.Entry(detail).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
예제 #10
0
 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();
     }
 }
예제 #11
0
 /// <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();
         }
     }
 }
예제 #12
0
 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 ");
         }
     }
 }
예제 #13
0
        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); }
            }
        }