Esempio n. 1
0
 /// <summary>
 /// query all orders
 /// </summary>
 /// <returns>List<Order>:all the orders</returns>
 public List <Order> QueryAll()
 {
     using (var odb = new OrderDB())
     {
         return(odb.Order.Include("Details").ToList());
     }
 }
Esempio n. 2
0
        /// <summary>
        /// import from an xml file
        /// </summary>
        public List <Order> Import(string path)
        {
            if (Path.GetExtension(path) != ".xml")
            {
                throw new ArgumentException($"{path} isn't a xml file!");
            }
            XmlSerializer xs     = new XmlSerializer(typeof(List <Order>));
            List <Order>  result = new List <Order>();

            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    using (var odb = new OrderDB())
                    {
                        odb.Order.AddRange((List <Order>)xs.Deserialize(fs));
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw new ApplicationException("import error:" + e.Message);
            }
        }
Esempio n. 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     /*string result = "";
      * var query = PublicValue.os.QueryOrderbyGoods(textBox1.Text);
      * if (query == null)
      *  MessageBox.Show("不存在符合要求的订单");
      * else
      * {
      *  foreach (Order.Order o in query)
      *      result += o.ToString();
      *  textBox2.Text = result;
      * }*/
     using (var db = new OrderDB())
     {
         var query = db.Order.Include("items")
                     .Where(o => o.GoodsList.Where(
                                item => item.GoodsName.Equals(textBox1.Text)).Count() > 0);
         string result = "";
         foreach (Order.Order o in query)
         {
             result += o.ToString();
         }
         textBox2.Text = result;
     }
 }
Esempio n. 4
0
 public List<Order> GetAllOrders()
 {
     using (var db = new OrderDB())
     {
         return db.Order.Include("details").ToList<Order>();
     }
 }
Esempio n. 5
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.OrderMoney >= 10000).ToList<Order>();
     }
 }
Esempio n. 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.Id == id);
     }
 }
Esempio n. 7
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.details.Where(d => d.Goods.Name == name).Count() > 0).ToList<Order>();
     }
 }
Esempio n. 8
0
 /// <summary>
 /// query by orderId
 /// </summary>
 /// <param name="orderId">id of the order to find</param>
 /// <returns>List<Order></returns>
 public Order GetById(int orderId)
 {
     using (var odb = new OrderDB())
     {
         return(odb.Order.FirstOrDefault(o => o.Id == orderId));
     }
     //return orderList.FirstOrDefault(o => o.Id == orderId);
 }
Esempio n. 9
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.Name == name).ToList<Order>();
     }
 }
Esempio n. 10
0
 /// <summary>
 /// query orders whose totalAmount >= totalAmount
 /// </summary>
 /// <param name="totalAmount">the minimum totalAmount</param>
 /// <returns></returns>
 public List <Order> QueryByTotalAmount(float totalAmount)
 {
     using (var odb = new OrderDB())
     {
         return(odb.Order.Where(o => o.TotalAmount >= totalAmount).ToList());
     }
     //          var query = orderList.Where(o => o.TotalAmount >= totalAmount);
     //return query.ToList();
 }
Esempio n. 11
0
 /// <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();
     }
 }
Esempio n. 12
0
 /// <summary>
 /// query by customerName
 /// </summary>
 /// <param name="customerName">customer name</param>
 /// <returns></returns>
 public List <Order> QueryByCustomerName(string customerName)
 {
     using (var odb = new OrderDB())
     {
         return(odb.Order.Where(o => o.Customer.Equals(customerName)).ToList());
     }
     //      var query = orderList
     //    .Where(o => o.Customer.Name == customerName);
     //return query.ToList();
 }
Esempio n. 13
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.Id == order_id);
         db.OrderDetail.RemoveRange(order.details);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Esempio n. 14
0
 /// <summary>
 /// query by goodsName
 /// </summary>
 /// <param name="goodsName">the name of goods in order's orderDetail</param>
 /// <returns></returns>
 public List <Order> QueryByGoodsName(string goodsName)
 {
     using (var odb = new OrderDB())
     {
         return(odb.Order.Include("Details").Where(o => o.Details.Where(d => d.Goods.Name.Equals(goodsName)).ToList().Count > 0).ToList());
     }
     //var query = orderList.Where(
     //  o => o.Details.Exists(
     //    d => d.Goods.Name == goodsName));
     //return query.ToList();
 }
Esempio n. 15
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();
     }
 }
Esempio n. 16
0
 //private List<Order> orderList;
 /// <summary>
 /// constructor
 /// </summary>
 public OrderService()
 {
     //orderList = new List<Order>();
     using (var odb = new OrderDB())
     {
         odb.Database.ExecuteSqlCommand("truncate table orderdetails");
         odb.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS = 0");
         odb.Database.ExecuteSqlCommand("truncate table orders");
         odb.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS = 1");
     }
 }
Esempio n. 17
0
 /// <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();
         }
     }
 }
Esempio n. 18
0
        //public void Sort(Comparison<Order> comparison) {
        //  orderList.Sort(comparison);
        //}

        /// <summary>
        /// Exprot the orders to an xml file.
        /// </summary>
        public void Export(String fileName)
        {
            if (Path.GetExtension(fileName) != ".xml")
            {
                throw new ArgumentException("the exported file must be a xml file!");
            }
            XmlSerializer xs = new XmlSerializer(typeof(List <Order>));

            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                using (var odb = new OrderDB())
                {
                    xs.Serialize(fs, odb.Order.ToList());
                }
            }
        }
Esempio n. 19
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();
        }
Esempio n. 20
0
        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();
            }
        }
Esempio n. 21
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(); }
 }
Esempio n. 22
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*string result = "";
             * var query = PublicValue.os.QueryOrderbyId(textBox1.Text);
             * if (query == null)
             *  MessageBox.Show("不存在符合要求的订单");
             * else
             * {
             *  foreach (Order.Order o in query)
             *      result += o.ToString();
             *  textBox2.Text = result;
             * }*/
            string Id = textBox1.Text;

            using (var db = new OrderDB())
            {
                Order.Order order = db.Order.Include("Items").
                                    SingleOrDefault(o => o.OrderId == Id);
                textBox2.Text = order.ToString();
            }
        }
Esempio n. 23
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);
        }