/// <summary>
        /// Loads in 10 random products into the product listbox
        /// </summary>
        private void LoadProducts()
        {
            IList <ProductViewModel> products = _productViewer.GetRandom10();

            //populate list
            foreach (ProductViewModel product in products)
            {
                lstBxProducts.Items.Add(product);
            }
        }
Exemple #2
0
        // view for creating new orders
        public ActionResult NewOrder()
        {
            // need to eventually query our business layers to retrieve information to pre-populates parts of the form
            // create bll viewer objects used for populating data
            int            StoreID        = 1; // Santa Cruz Store
            StaffViewer    staffViewer    = new StaffViewer();
            ProductViewer  productViewer  = new ProductViewer();
            CustomerViewer customerViewer = new CustomerViewer();
            StoreViewer    storeViewer    = new StoreViewer();

            NewOrderModel model = new NewOrderModel()
            {
                Staff     = staffViewer.GetAllEmployesByStore(StoreID),
                Products  = productViewer.GetRandom10(),
                Customers = customerViewer.GetRandom10(),
                Store     = storeViewer.GetStore(StoreID)
            };

            return(View(model));
        }
Exemple #3
0
        /// <summary>
        /// Runs the order form in the UI
        /// </summary>
        private static void CreateOrderForm()
        {
            int store_id, staff_id, product_id, customer_id, quantity;

            if (_storeViewer == null)
            {
                _storeViewer = new StoreViewer();
            }
            if (_staffViewer == null)
            {
                _staffViewer = new StaffViewer();
            }
            if (_productViewer == null)
            {
                _productViewer = new ProductViewer();
            }
            if (_customerViewer == null)
            {
                _customerViewer = new CustomerViewer();
            }
            if (_newOrderCreator == null)
            {
                _newOrderCreator = new NewOrderCreator();
            }

            IList <StaffViewModel>    staff;
            IList <StoreViewModel>    stores    = _storeViewer.GetAllStores();
            IList <CustomerViewModel> customers = _customerViewer.GetRandom10();
            IList <ProductViewModel>  products  = _productViewer.GetRandom10();

            WriteHeader();
            WriteOrderFormHeader();

            Console.WriteLine("Select store:");
            Console.WriteLine("---------------");
            for (var i = 0; i < stores.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, stores[i].Name);
            }

            CommandPrompt("Select store");
            string str_store_id = Console.ReadLine();

            //validate the incoming store_id
            if (!Int32.TryParse(str_store_id, out store_id) || store_id > stores.Count || store_id < 1)
            {
                Console.WriteLine("Invalid store entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //store_id is valid - grab employees
            staff = _staffViewer.GetAllEmployesByStore(store_id);

            //write the employee info onscreen
            WriteHeader();
            WriteOrderFormHeader();

            Console.WriteLine("Select salesperson:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < staff.Count; i++)
            {
                Console.WriteLine("{0}. {1} {2}", i + 1, staff[i].FirstName, staff[i].LastName);
            }
            CommandPrompt("Select salesperson");
            string str_staff_id = Console.ReadLine();

            //validate the incoming staff_id
            if (!Int32.TryParse(str_staff_id, out staff_id) || staff_id > staff.Count || staff_id < 1)
            {
                Console.WriteLine("Invalid salesperson entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //staff_id is valid - print out customers
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select customer:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < customers.Count; i++)
            {
                Console.WriteLine("{0}. {1} {2}", i + 1, customers[i].FirstName, customers[i].LastName);
            }
            CommandPrompt("Select customer");
            string str_customer_id = Console.ReadLine();

            //validate the incoming customer_id
            if (!Int32.TryParse(str_customer_id, out customer_id) || customer_id > customers.Count || customer_id < 1)
            {
                Console.WriteLine("Invalid customer entry.  Press any key...");
                Console.ReadKey();
                return;
            }


            //customer_id is valid - print out products
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select product:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < products.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, products[i].Name);
            }
            CommandPrompt("Select product");
            string str_product_id = Console.ReadLine();

            //validate the incoming product_id
            if (!Int32.TryParse(str_product_id, out product_id) || product_id > products.Count || product_id < 1)
            {
                Console.WriteLine("Invalid product entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //product_id is valid - print out quantity
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select quantity:");
            string str_quantity = Console.ReadLine();

            //validate the incoming product_id
            if (!Int32.TryParse(str_quantity, out quantity) || quantity < 1)
            {
                Console.WriteLine("Invalid quantity.  Press any key...");
                Console.ReadKey();
                return;
            }

            //all inputs valid - show an order summary screen
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Order Details:");
            Console.WriteLine("----------------");
            Console.WriteLine("Entered by {0} {1} at {2}", staff[staff_id - 1].FirstName, staff[staff_id - 1].LastName, stores[store_id - 1].Name);
            Console.WriteLine("Order for {0} {1}", customers[customer_id - 1].FirstName, customers[customer_id - 1].LastName);
            Console.WriteLine(products[product_id - 1].Name);
            Console.WriteLine("Qty: {0}", quantity);
            CommandPrompt("Is this correct? (Y/N)");
            string str_response = Console.ReadLine();

            if (str_response.ToLower() == "y")
            {
                NewOrderDTO newOrder = new NewOrderDTO()
                {
                    store_id    = store_id,
                    staff_id    = staff_id,
                    customer_id = customer_id,
                    order_date  = DateTime.Now,
                };

                NewOrderItemDTO newItem = new NewOrderItemDTO()
                {
                    product_id = product_id,
                    quantity   = quantity
                };

                newOrder.items.Add(newItem);

                _newOrderCreator = new NewOrderCreator();
                try
                {
                    int order_number = _newOrderCreator.CreateOrder(newOrder);
                    WriteHeader();
                    WriteOrderFormHeader();
                    Console.WriteLine("Order #{0} created successfully.", order_number);
                    Console.WriteLine("Press any key...");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return;
            }
        }