Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Order Management System!");
            OrderService service = new OrderService();
            string       path    = @"orders.xml";

            service.Import(path);
            while (true)
            {
                try
                {
                    String orderID;
                    String customerName;
                    Console.WriteLine("\n");
                    String action = GetInput("1.add an order\t2.delete an order\t3.alter your order\t4.sort your orders\nPlease select an action: ");
                    switch (action)
                    {
                    case "1":
                        customerName = GetInput("Customer name:");
                        service.AddOrder(customerName, Int32.Parse(DateTime.Now.ToString("HHmmss")));
                        Console.WriteLine("Add an order successful!");
                        service.PrintOrders(service.orderList);
                        //Console.WriteLine("Your order ID is:" );
                        break;

                    case "2":
                        orderID = GetInput("Order ID:");
                        service.DeleteOrder(Int32.Parse(orderID));
                        Console.WriteLine("Delete the order successful!");
                        service.PrintOrders(service.orderList);

                        break;

                    case "3":
                        orderID = GetInput("Order ID:");
                        String operation = GetInput("add item\t" + "delete item\nPlease select an operation:");

                        switch (operation)
                        {
                        case "add item":
                            Console.WriteLine("Please enter item,amount and unitprice ,Separated by space");
                            string[] string1 = System.Text.RegularExpressions.Regex.Split(Console.ReadLine(), @"[ ]+");
                            string[] par3    = new string[3];
                            for (int i = 0; i < 3; i++)
                            {
                                par3[i] = string1[i];
                            }
                            service.AlterOrder(Int32.Parse(orderID), operation, par3);

                            service.PrintOrders(service.orderList);
                            break;

                        case "delete item":
                            Console.WriteLine("Please enter item and amount ,Separated by space");
                            string[] string2 = System.Text.RegularExpressions.Regex.Split(Console.ReadLine(), @"[ ]+");
                            string[] par2    = new string[2];
                            for (int i = 0; i < 2; i++)
                            {
                                par2[i] = (string2[i]);
                            }
                            service.AlterOrder(Int32.Parse(orderID), operation, par2);
                            service.PrintOrders(service.orderList);
                            break;

                        default:
                            throw new ArgumentException("Invalid input!");
                        }
                        break;

                    case "4":
                        Console.WriteLine("Please enter search conditions:");
                        customerName = GetInput("Customer name:");
                        orderID      = GetInput("Order ID:");
                        String goodsName = GetInput("Goods name:");
                        customerName = customerName == "" ? null : customerName;
                        orderID      = orderID == "" ? null : orderID;
                        goodsName    = goodsName == "" ? null : goodsName;
                        List <Order> results = service.SearchOrder(customerName, orderID, goodsName);
                        service.PrintOrders(results);
                        break;

                    default:
                        throw new ArgumentException("No such operation!");
                    }
                    service.Export(path);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid input!");
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Order Management System!");
            OrderService service = new OrderService();

            service.Import("orders.xml");
            service.OrderIDCounter = service.Orders != null && service.Orders.Count > 0
                ? service.Orders[service.Orders.Count - 1].OrderID : 0;
            while (true)
            {
                try
                {
                    String orderID;
                    String customerName;
                    String customerAddress;
                    String action = GetInput("1.add an order\t2.delete an order\t3.modify an order\t4.select the orders\nPlease select an action: ");
                    switch (action)
                    {
                    case "1":
                        customerName    = GetInput("Customer name:");
                        customerAddress = GetInput("Customer address:");
                        Console.WriteLine("Add an order successful!");
                        Console.WriteLine("Your order ID is:" + service.AddOrder(new Order(0,
                                                                                           new Customer(customerName, customerAddress), DateTime.Now, new List <OrderItem>())));
                        break;

                    case "2":
                        orderID = GetInput("Order ID:");
                        service.DeleteOrder(Int32.Parse(orderID));
                        Console.WriteLine("Delete the order successful!");
                        break;

                    case "3":
                        orderID = GetInput("Order ID:");
                        String operation = GetInput(
                            "customer name\tcustomer address\torder time\tadd item\n" +
                            "delete item\tquantity\nPlease select an operation:"
                            );
                        String modifyData = "";
                        if (operation != "add item")
                        {
                            modifyData = GetInput("The data After modify:");
                        }
                        object data    = null;
                        int    goodsID = 0;
                        switch (operation)
                        {
                        case "customer name":
                        case "customer address":
                            data = modifyData;
                            break;

                        case "order time":
                            data = DateTime.Parse(modifyData);
                            break;

                        case "add item":
                            goodsID = Int32.Parse(GetInput("Goods ID:"));
                            int quantity = Int32.Parse(GetInput("Quantity:"));
                            data = new OrderItem(new Goods(goodsID), quantity);
                            break;

                        case "delete item":
                            goodsID = Int32.Parse(GetInput("Goods ID:"));
                            break;

                        case "quantity":
                            goodsID = Int32.Parse(GetInput("Quantity:"));
                            data    = Int32.Parse(modifyData);
                            break;

                        default:
                            throw new ArgumentException("Invalid argument!");
                        }
                        service.AlterOrder(Int32.Parse(orderID), operation, data, goodsID);
                        Console.WriteLine("Modify successful!");
                        Console.Write(service.FindOrder(int.Parse(orderID), null, null)[0]);
                        break;

                    case "4":
                        Console.WriteLine("Please enter search conditions:");
                        orderID = GetInput("Order ID:");
                        String goodsName = GetInput("Goods name:");
                        customerName = GetInput("Customer name:");
                        int orderId = orderID == "" ? int.MinValue : int.Parse(orderID);
                        goodsName    = goodsName == "" ? null : goodsName;
                        customerName = customerName == "" ? null : customerName;
                        List <Order> results = service.FindOrder(orderId, goodsName, customerName);
                        Console.WriteLine("Result:");
                        foreach (Order order in results)
                        {
                            Console.WriteLine(order);
                        }
                        break;

                    default:
                        throw new ArgumentException("No such operation!");
                    }
                    service.Export("orders.xml");
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid input!");
                }
            }
        }