Esempio n. 1
0
        private static void HandleOptions()
        {
            OrderService orderService = new OrderService();

            while (true)
            {
                Console.WriteLine("  菜  单");
                Console.WriteLine("1、添加订单");
                Console.WriteLine("2、删除订单");
                Console.WriteLine("3、修改订单");
                Console.WriteLine("4、查询订单");
                Console.WriteLine("5、显示所有订单");
                Console.WriteLine("6、退出系统");
                Console.Write("请选择需要进行的操作:");
                try
                {
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        orderService.Add();
                        break;

                    case 2:
                        orderService.Remove();
                        break;

                    case 3:
                        orderService.Modify();
                        break;

                    case 4:
                        orderService.Query();
                        break;

                    case 5:
                        orderService.Show();
                        break;

                    case 6:
                        return;

                    default:
                        Console.WriteLine("请输入1到6之间的数字!任意键继续");
                        Console.ReadKey();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 2
0
        static void RemoveOrder()
        {
            Console.Write("当前订单表详情:");
            orderservice.ShowOrder();
            Console.Write("请输入要删除的订单序号(如果要删除序列表的第一个订单即订单1就输入1:");
            int  A;
            bool valid = int.TryParse(Console.ReadLine(), out A);

            while (!valid || A > orderservice.numOfOrder || A <= 0)
            {
                Console.Write($"输入错误,请输入小于等于{orderservice.numOfOrder}的正整数:");
                valid = int.TryParse(Console.ReadLine(), out A);
            }
            orderservice.Remove(A);
        }
Esempio n. 3
0
        public void RemoveTest()
        {
            OrderService orderService = new OrderService();

            OrderService orderService2 = new OrderService();

            orderService2.Add();
            orderService2.Remove();

            XmlSerializer xmlSer = new XmlSerializer(typeof(List <Order>));

            orderService.Export(xmlSer, "1.xml");
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("1.xml");

            orderService2.Export(xmlSer, "2.xml");
            XmlDocument xmlDocument2 = new XmlDocument();

            xmlDocument2.Load("2.xml");

            Assert.AreEqual(xmlDocument.InnerXml, xmlDocument2.InnerXml);
        }
Esempio n. 4
0
        private static void HandleOptions()
        {
            OrderService orderService = new OrderService();

            while (true)
            {
                Console.WriteLine("  菜  单");
                Console.WriteLine("1、添加订单");
                Console.WriteLine("2、删除订单");
                Console.WriteLine("3、修改订单");
                Console.WriteLine("4、查询订单");
                Console.WriteLine("5、显示所有订单");
                Console.WriteLine("6、序列化为xml文件");
                Console.WriteLine("7、从xml文件载入订单");
                Console.WriteLine("8、退出系统");
                Console.Write("请选择需要进行的操作:");
                try
                {
                    int           option      = int.Parse(Console.ReadLine());
                    XmlSerializer xmlSer      = new XmlSerializer(typeof(List <Order>));
                    string        xmlFileName = "orders.xml";
                    switch (option)
                    {
                    case 1:
                        orderService.Add();
                        break;

                    case 2:
                        orderService.Remove();
                        break;

                    case 3:
                        orderService.Modify();
                        break;

                    case 4:
                        orderService.Query();
                        break;

                    case 5:
                        orderService.Show();
                        break;

                    case 6:
                        orderService.Export(xmlSer, xmlFileName);
                        break;

                    case 7:
                        orderService.Import(xmlSer, xmlFileName);
                        break;

                    case 8:
                        return;

                    default:
                        Console.WriteLine("请输入1到8之间的数字!任意键继续");
                        Console.ReadKey();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }