예제 #1
0
 public Customer customerSearchID(string id) => SearchCustomers.customerSearchID(_customers, id);
예제 #2
0
        public static void makeOrder()
        {
            // get all of the customers
            List <Customer> customers = SqlDb.GetAllCustomers();

            Library.DataBase db = new Library.DataBase(customers);

            // Print a list of the customers
            db.printCustomers();
            Console.WriteLine("Enter a Customer ID");
            string customerId = Console.ReadLine();

            // select your customer
            Customer customer = SearchCustomers.customerSearchID(customers, customerId);

            // don'd continue unless the person actually put in a correct customer id.
            if (customer.isValid())
            {
                // get the store information
                uiPrintAllStores();
                Console.WriteLine("Choose a Store: ");

                int    StoreChoiceCheck = 0;
                string StoreChoice      = Console.ReadLine();
                Int32.TryParse(StoreChoice, out StoreChoiceCheck);
                Store store = SqlDb.GetInventory(StoreChoiceCheck);
                if (store.hasInventory())
                {
                    // add store to our database
                    db.AddStore(store);

                    // making order
                    Order newOrder = new Order(StoreChoiceCheck, customer.CustomerId);
                    store.printInventory();

                    Console.WriteLine("Starting order press (q) to quit");
                    string choice = "";
                    while (choice.ToLower() != "q")
                    {
                        Console.WriteLine("Choose a Product");
                        choice = Console.ReadLine();
                        if (choice != "q" && choice != "q")
                        {
                            int choiceCheck = 0;
                            int.TryParse(choice, out choiceCheck);
                            // if user actually inserts a number
                            if (choiceCheck != 0)
                            {
                                // using the only store in the database grab the product from the inventory
                                var item = db[0].getInventory(choiceCheck);


                                //give user a chance to escape one more time
                                string quantity = "";
                                if (quantity != "q" && choice != "q" && item.ProductID != 0)
                                {
                                    Console.WriteLine("Choose a quantity: ");
                                    quantity = Console.ReadLine();
                                    int quantityCheck = 0;
                                    int.TryParse(quantity, out quantityCheck);
                                    if (quantityCheck != 0)
                                    {
                                        newOrder.addItem(item, quantityCheck);
                                        Console.WriteLine("Your Total So Far is " + newOrder.Cost);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Quanity Must be greater than 0");
                                    }
                                }
                            }
                        }

                        db.Stores[0].AddOrder(newOrder);
                    }
                    // if we have items in our order submit to database
                    if (newOrder.hasItems())
                    {
                        int TransactionNumber = SqlDb.AddCustomerOrder(db);
                        Console.WriteLine(newOrder.newOrderString(TransactionNumber));
                    }
                }
            }
        }