Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //deletelist List = new deletelist();
            //List.ShowDialog();
            using (var db = new OrderDB())
            {
                if (bindingSource1.Current != null)
                {
                    OrderDetail order  = (OrderDetail)bindingSource1.Current;
                    var         order1 = db.Order.SingleOrDefault(o => o.Id == order.Id);
                    db.Order.Remove(order1);
                    db.SaveChanges();
                    button5.PerformClick();
                }
                else
                {
                    MessageBox.Show("没有选中订单");
                }

                //using (FileStream fs = new FileStream("people.xml", FileMode.Create))
                //{
                //    xs.Serialize(fs, testList);
                //}
            }
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     //using (FileStream fs = new FileStream("people.xml", FileMode.Open))
     //{
     //    testList = (List<OrderDetail>)xs.Deserialize(fs);
     //}
     //int n = 0;
     //foreach (OrderDetail s in testList)
     //{
     //    n += 1;
     //    if (n == Convert.ToInt32(newa))
     //    {
     //        s.Id = newb;
     //        s.Name = newc;
     //        s.Customer = newd;
     //        s.Money = Convert.ToInt32(newe);
     //        s.Ordernumber= Convert.ToInt64(newf);
     //        s.Phonenumber= Convert.ToInt64(newg);
     //    }
     //};
     using (var db = new OrderDB())
     {
         db.Order.Remove(order);
         order.Id          = newb;
         order.Name        = newc;
         order.Customer    = newd;
         order.Money       = Convert.ToInt32(newe);
         order.Ordernumber = Convert.ToInt64(newf);
         order.Phonenumber = Convert.ToInt64(newg);
         db.Order.Add(order);
         db.SaveChanges();
     }
 }
Example #3
0
 public void AddOrder(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Add(order);
         db.SaveChanges();
     }
 }
Example #4
0
 public void Delete(int orderId)
 {
     using (var db = new OrderDB())
     {
         var order = db.Order.Include("OrderDetails").SingleOrDefault(o => o.OrderNu == orderId);
         db.OrderDetail.RemoveRange(order.OrderDetails);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Example #5
0
 public void Update(Order order)
 {
     using (var db = new OrderDB())
     {
         db.tb_Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.Items.ForEach(item => db.Entry(item).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Example #6
0
 public void DeleteByID(String id)
 {
     using (var db = new OrderDB())
     {
         var order = db.tb_Order.Include("Items").SingleOrDefault(m => m.ID == id);
         db.tb_OrderDetails.RemoveRange(order.Items);   //还需要删除 items 的内容
         db.tb_Order.Remove(order);
         db.SaveChanges();
     }
 }
Example #7
0
 public void DeleteByName(string name)
 {
     using (var db = new OrderDB())
     {
         var orders = db.Order.Include("OrderDetails").TakeWhile(o => o.Name == name);
         foreach (Order order in orders)
         {
             db.OrderDetail.RemoveRange(order.OrderDetails);
         }
         db.Order.RemoveRange(orders);
         db.SaveChanges();
     }
 }
Example #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //using (FileStream fs = new FileStream("people.xml", FileMode.Open))
            //{
            //    testList = (List<OrderDetail>)xs.Deserialize(fs);
            //}
            OrderDetail a = new OrderDetail();

            a.Id          = x;
            a.Name        = b;
            a.Customer    = c;
            a.Money       = Convert.ToInt32(d);
            a.Ordernumber = Convert.ToInt64(number);
            a.Phonenumber = Convert.ToInt64(phone);
            //bool repeatnumber = false;
            //foreach (OrderDetail s in testList)
            //{
            //    if (a.Ordernumber == s.Ordernumber)
            //    {
            //        MessageBox.Show("重复账单号", "提示", MessageBoxButtons.OK);
            //        repeatnumber = true;
            //    }
            //}
            //testList.Add(a);
            //if (repeatnumber)
            //{
            //    testList.Remove(a);
            //}
            //if (a.Phonenumber < 10000000000 || a.Phonenumber > 16000000000)
            //{
            //    MessageBox.Show("请输入正确的电话号码", "提示", MessageBoxButtons.OK);
            //    testList.Remove(a);
            //}


            //try
            //{
            //    string year = number.Substring(0, 4);
            //    string month = number.Substring(4, 2);
            //    string day = number.Substring(6, 2);
            //    if (a.Ordernumber > 20000000000 && a.Ordernumber < 26000000000)
            //    {
            //        if (Convert.ToInt32(year) > 2000 && Convert.ToInt32(year) < 2999 && Convert.ToInt32(month) < 13
            //          && Convert.ToInt32(month) > 0 && Convert.ToInt32(day) < 32
            //          && Convert.ToInt32(year) > 0) { }
            //        else
            //        {
            //            MessageBox.Show("请按照 年月日+三位流水号输入订单号", "提示", MessageBoxButtons.OK);
            //            testList.Remove(a);
            //        }
            //    }
            //    else
            //    {
            //        MessageBox.Show("请按照 年月日+三位流水号输入订单号", "提示", MessageBoxButtons.OK);
            //        testList.Remove(a);
            //    }
            //}
            //catch
            //{
            //    MessageBox.Show("请按照 年月日+三位流水号输入订单号", "提示", MessageBoxButtons.OK);
            //    testList.Remove(a);
            //}
            using (var db = new OrderDB())
            {
                try
                {
                    db.Order.Add(a);
                    //db.Order.Attach(order);
                    //db.Entry(order).State = EntityState.Added;
                    db.SaveChanges();
                    MessageBox.Show("创建成功", "提示", MessageBoxButtons.OK);
                }
                catch { MessageBox.Show("ID不可以重复", "提示", MessageBoxButtons.OK); }
            }
            //using (FileStream fs = new FileStream("people.xml", FileMode.Create))
            //{
            //    xs.Serialize(fs, testList);
            //}
        }