Пример #1
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            int currentIndex = 0;

            if (this.orderList.SelectedItems.Count > 0)               //判断listview有被选中项
            {
                currentIndex = this.orderList.SelectedItems[0].Index; //取当前选中项的index

                string odId = orderList.Items[currentIndex].SubItems[0].Text;

                os.Delete(odId);
                orderList.Items[currentIndex].Remove();
            }
        }
Пример #2
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (orderBindingSource.Current != null)
     {
         OrderService orderService = new OrderService();
         Order        order        = (Order)orderBindingSource.Current;
         orderService.Delete(order.Id);
         orderBindingSource.DataSource = orderService.GetAllOrders();
     }
     else
     {
         MessageBox.Show("No Order is selected!");
     }
 }
Пример #3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            OrderService orderService = new OrderService();

            List <OrderItem> items1 = new List <OrderItem>()
            {
                new OrderItem("1", "iPhone XR", 6499, 1),
                new OrderItem("2", "iPhone XS", 8699, 1),
                new OrderItem("3", "Airpords", 1199, 2)
            };

            List <OrderItem> items2 = new List <OrderItem>()
            {
                new OrderItem("4", "iPad Pro", 6499, 1),
                new OrderItem("5", "Airpords", 1199, 1)
            };

            //添加订单
            Order order1 = new Order("20181124001", "Alan", "18788888888", items1);

            orderService.Add(order1);

            Order order2 = new Order("20181124002", "Bob", "18777777777", items2);

            orderService.Add(order2);

            //修改订单
            Order order3 = new Order("20181124001", "Iggie", "18766666666", items1);

            orderService.Update(order3);

            //得到所有订单
            List <Order> orders = orderService.GetAllOrders();

            Console.WriteLine("所有订单:");
            orders.ForEach(o => Console.WriteLine(o.OrderNumber + " " + o.Client + " " + o.PhoneNumber + " " + o.TotalPrice));

            //Id查询
            Order order = orderService.QueryById("20181124002");

            Console.WriteLine("ID查询:");
            orders.ForEach(o => Console.WriteLine(o.OrderNumber + " " + o.Client + " " + o.PhoneNumber + " " + o.TotalPrice));

            //客户名查询
            orders = orderService.QueryByClient("Iggie");
            Console.WriteLine("客户名查询:");
            orders.ForEach(o => Console.WriteLine(o.OrderNumber + " " + o.Client + " " + o.PhoneNumber + " " + o.TotalPrice));

            //商品名查询
            orders = orderService.QueryByGoods("Airpords");
            Console.WriteLine("商品名查询:");
            orders.ForEach(o => Console.WriteLine(o.OrderNumber + " " + o.Client + " " + o.PhoneNumber + " " + o.TotalPrice));

            //总价大于10000元查询
            orders = orderService.QueryBigOrder();
            Console.WriteLine("总价大于10000元查询:");
            orders.ForEach(o => Console.WriteLine(o.OrderNumber + " " + o.Client + " " + o.PhoneNumber + " " + o.TotalPrice));

            //序列化
            string path = @"../../MyOrderList.xml";

            orderService.Export(path);

            //删除订单
            orderService.Delete("20181124002");
        }