Пример #1
0
        public void reviseOrder()
        {
            Console.WriteLine("请输入要修改的订单的订单号:");
            string orderID = Console.ReadLine();

            try
            {
                Order m = checkOrderIDUnique(orderID);
                if (m == null)
                {
                    throw new OrderException("错误!不存在该订单号的订单");
                }
                Console.WriteLine("请输入新的订单号:");
                string s = Console.ReadLine();
                Order  i = checkOrderIDUnique(s);
                if (i != null)
                {
                    throw new OrderException("错误!已存在该订单号的订单");
                }
                m.OrderID = s;
                Console.WriteLine("请输入新的客户名:");
                m.Customer = Console.ReadLine();
                Console.WriteLine("请输入新的客户电话:");
                m.Customerphone = Console.ReadLine();
                if (checkOrderNum(m) == false)
                {
                    throw new OrderException("错误!输入的订单号不符合规则!");
                }
                if (checkOrderPhone(m) == false)
                {
                    throw new OrderException("错误!输入的订单号不符合规则!");
                }
                List <Orderdetails> orderdetailsList = new List <Orderdetails>();
                Console.WriteLine("请输入新的订单商品种类数目:");
                int a = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请依次输入每一种商品名称,数量,价格。");
                for (int b = 1; b <= a; b++)
                {
                    Console.WriteLine("请输入第" + b + "种商品名称。");
                    string productname = Console.ReadLine();
                    Console.WriteLine("请输入第" + b + "种商品数量。");
                    int productnum = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("请输入第" + b + "种商品价格。");
                    int          productprice        = Convert.ToInt32(Console.ReadLine());
                    Orderdetails productorderdetails = new Orderdetails(productname, productnum, productprice);
                    orderdetailsList.Add(productorderdetails);
                }
                m.orderdetailsList = orderdetailsList;
            }
            catch (OrderException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            OrderService orderService = new OrderService();

            Console.WriteLine("请选择希望订单进行的操作(只需输入相应操作前面数字即可):");
            Console.WriteLine("1.添加新订单");
            Console.WriteLine("2.删除订单");
            Console.WriteLine("3.查询订单");
            Console.WriteLine("4.修改订单");
            Console.WriteLine("5.打印订单列表");
            Console.WriteLine("6.打印出订单总金额高于或等于1万元的订单");
            Console.WriteLine("7.退出");
            Console.WriteLine("8.序列化");
            try
            {
                bool exit = false;
                while (exit == false)
                {
                    int choice = Convert.ToInt32(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        Order neworder = new Order();
                        List <Orderdetails> orderdetailsList = new List <Orderdetails>();
                        Console.WriteLine("请输入订单号:");
                        neworder.OrderID = Console.ReadLine();
                        Console.WriteLine("请输入客户名称:");
                        neworder.Customer = Console.ReadLine();
                        Console.WriteLine("请输入客户电话:");
                        neworder.Customerphone = Console.ReadLine();
                        Console.WriteLine("请输入该订单商品种类数目:");
                        int m = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("请依次输入每一种商品名称,数量,价格。");
                        for (int i = 1; i <= m; i++)
                        {
                            Console.WriteLine("请输入第" + i + "种商品名称。");
                            string productname = Console.ReadLine();
                            Console.WriteLine("请输入第" + i + "种商品数量。");
                            int productnum = Convert.ToInt32(Console.ReadLine());
                            Console.WriteLine("请输入第" + i + "种商品价格。");
                            Double       productprice        = Convert.ToDouble(Console.ReadLine());
                            Orderdetails productorderdetails = new Orderdetails(productname, productnum, productprice);
                            orderdetailsList.Add(productorderdetails);
                        }
                        neworder.orderdetailsList = orderdetailsList;
                        orderService.addOrder(neworder);
                        break;

                    case 2:
                        Console.WriteLine("请输入订单号:");
                        string deleteorderID = Console.ReadLine();
                        orderService.deleteOrder(deleteorderID);
                        break;

                    case 3:
                        orderService.search();
                        break;

                    case 4:
                        orderService.search();
                        break;

                    case 5:
                        orderService.PrintOrderList(orderService.orderList);
                        break;

                    case 6:
                        orderService.searchover(orderService.orderList);
                        break;

                    case 7:
                        exit = true;
                        break;

                    case 8:
                        orderService.export();
                        break;

                    default:
                        throw new Exception("错误!没有这个选项");
                    }
                }
            }
            catch (OrderException e)
            {
                Console.WriteLine(e.Message);
            }
        }