Пример #1
0
        //搜索操作
        static public void SearchOrder(OrderService myOrder)
        {
            List <Order> SearchResult = new List <Order>();

            Console.WriteLine
                ("选择您要进行的服务: 1.根据客户查找; 2.根据订单号查找;3.根据产品种类查找;4.返回主菜单");
            int whichFun = 0;

            while (whichFun == 0)
            {
                try
                {
                    whichFun = int.Parse(Console.ReadLine());
                    if (whichFun < 1 || whichFun > 4)
                    {
                        throw new System.FormatException();
                    }
                }
                catch (System.FormatException e)
                {
                    whichFun = 0;
                    Console.Write(e.Message);
                    Console.WriteLine("请重新输入");
                }
            }
            switch (whichFun)
            {
            case 1:
                Console.WriteLine("输入客户名: ");
                String CustomerName = Console.ReadLine();
                SearchResult = myOrder.SearchByCustomer(CustomerName);
                break;

            case 2:
                Console.WriteLine("输入订单号: ");
                String OrderNum = Console.ReadLine();
                SearchResult = myOrder.SearchByNum(OrderNum);
                break;

            case 3:
                Console.WriteLine("输入产品名: ");
                String ProductName = Console.ReadLine();
                SearchResult = myOrder.SearchByPro(ProductName);
                break;

            case 4:
                return;
            }
            try
            {
                myOrder.WriteResult(SearchResult);
            }
            catch (NoSearchResult e)
            {
                Console.WriteLine(e.NoResult);
            }
        }
Пример #2
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);
        }