Пример #1
0
        //主操作函数
        static public void mainService(OrderService myOrder)
        {
            Console.WriteLine("选择您要进行的服务: 1.添加订单; 2.查询订单;" +
                              "3.打印全部订单; 4.打印金额大于10000的订单; 5.输出xml; 6.退出");
            int whichFunction = 0;

            while (whichFunction == 0)
            {
                try
                {
                    whichFunction = int.Parse(Console.ReadLine());
                    if (whichFunction < 1 || whichFunction > 6)
                    {
                        throw new System.FormatException();
                    }
                }
                catch (System.FormatException e)
                {
                    whichFunction = 0;
                    Console.Write(e.Message);
                    Console.WriteLine("请重新输入");
                }
            }
            switch (whichFunction)
            {
            case 1:
                myOrder.NewOrder();
                break;

            case 2:
                SearchOrder(myOrder);
                break;

            case 3:
                try
                {
                    myOrder.WriteResult(myOrder.ListOfOrder);
                }
                catch (NoSearchResult e)
                {
                    Console.WriteLine(e.NoResult);
                }
                break;

            case 4:
                List <Order> Morethanres = myOrder.SearchMoreThan(myOrder.ListOfOrder, 10000);
                myOrder.WriteResult(Morethanres);
                break;

            case 5:
                myOrder.Export(myOrder.ListOfOrder, @"AllOrder.txt");
                break;

            case 6:
                return;

            default:
                break;
            }
            mainService(myOrder);
        }