Esempio n. 1
0
        private CustomerProducts GetCustomerProducts(Customer customer)
        { // The method to get the products from the customer
            CustomerProducts customerProducts = null;

            // Loop through all the products assigned to the customer
            foreach (CustomerProducts cProds in _customerProducts)
            {
                // Match the current customer in the list of customers
                if (cProds.TheCustomer.FirstName == customer.FirstName &&
                    cProds.TheCustomer.LastName == customer.LastName)
                {
                    customerProducts = cProds;

                    if (customerProducts.Payment == null)
                    {
                        // Call the method to get the payment option
                        customerProducts.Payment = _sqlData.GetPaymentOptionForCustomer(customer);
                    }
                }
            }

            if (customerProducts == null)
            {
                customerProducts             = new CustomerProducts();
                customerProducts.TheCustomer = customer;
                _customerProducts.Add(customerProducts);
            }

            return(customerProducts);
        }
        public void OrderProduct()
        {
            Console.WriteLine("Which customer?");
            Customer customer = ChooseCustomer();
            //CustomerProducts customerProducts = GetCustomerProducts(customer);
            CustomerProducts customerProducts = new CustomerProducts();

            Product nextProduct = null;

            do
            {
                nextProduct = ChooseProduct();
                if (nextProduct != null)
                {
                    customerProducts.ProductsList.Add(nextProduct);
                }
            }while (nextProduct != null);
        }
        public void CompleteOrder()
        {
            Console.WriteLine("Which customer?");
            Customer         customer         = ChooseCustomer();
            CustomerProducts customerProducts = GetCustomerProducts(customer);

            if (customerProducts == null)
            {
                Console.WriteLine("Please add some products to your order first." +
                                  "\nPress any key to return to main menu.");
                return;
            }
            else
            {
                //foreach (CustomerProducts cProds in _customerProducts)
                //{
                //    if (cProds.TheCustomer.FirstName == customer.FirstName &&
                //        cProds.TheCustomer.LastName == customer.LastName)
                //{
                //    Console.WriteLine((i + 1) + ". " + productsToOrder[i].Name);
                //}
                //}
                Console.Clear();
                Console.WriteLine(string.Format("The total is ${0}.", customerProducts.ProductsList.Sum(x => x.Price)));
                //decimal finalPrice = 0;
                //foreach (Product product in customerProducts.Products)
                //{
                //    finalPrice += product.Price;
                //}
                Console.WriteLine("Is this total correct?");
                Console.Write("Y/N>");
                string answer = Console.ReadLine();

                if (answer == "Y" || answer == "y")
                {
                    _sqlData.CreateCustomerOrder(customerProducts);
                    Console.WriteLine("Your order is complete");
                }
                else if (answer != "Y" || answer != "y")
                {
                    return;
                }
            }
        }
Esempio n. 4
0
        public void OrderProducts()
        {
            Console.WriteLine("Which customer?");
            // This calls the method to choose the customer
            Customer customer = ChooseCustomer();
            // Pass in the current customer to get their current products
            CustomerProducts customerProducts = GetCustomerProducts(customer);

            Product nextProduct = null;

            do
            {
                nextProduct = ChooseProduct();
                if (nextProduct != null)
                {
                    customerProducts.Products.Add(nextProduct);
                }
            }while (nextProduct != null);
        }
        public void CreateCustomerOrder(CustomerProducts customerProducts)
        {
            DateTime now         = DateTime.Now;
            int      orderNumber = (new Random()).Next(int.MaxValue);
            //1. Add row to CustomerOrder table
            string command = string.Format("INSERT INTO CustomerOrder (OrderNumber, DateCreated, IdCustomer, IdPaymentOption, Shipping) " +
                                           "VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')", orderNumber, now.ToString(), customerProducts.TheCustomer.IdCustomer, customerProducts.Payment.IdPaymentOption, "UPS");

            UpdateDataBase(command);

            //2. Get IdOrder from CustomerOrder table
            command = string.Format("SELECT IdCustomerOrder FROM CustomerOrder WHERE IdCustomer='{0}' AND OrderNumber='{1}'", customerProducts.TheCustomer.IdCustomer, orderNumber);
            int idOrder = GetIdFromTable(command);

            //3. Ad row to OrderProducts table
            foreach (var product in customerProducts.Products)
            {
                command = string.Format("INSERT INTO OrderProducts (IdProduct, IdOrder)" +
                                        "VALUES ('{0}', '{1}')", product.IdProduct, idOrder);
                UpdateDataBase(command);
            }
        }
        public void CreatePaymentOption()
        {
            Console.WriteLine("Which customer would you like to create a payment option for?");
            Customer         customer         = ChooseCustomer();
            CustomerProducts customerProducts = GetCustomerProducts(customer);
            PaymentOption    paymentOption    = new PaymentOption();

            //get the IdCustomer from the Customer table
            paymentOption.IdCustomer = customer.IdCustomer;

            Console.WriteLine("Enter payment type (e.g. AmEx, Visa, Checking");
            paymentOption.Name = Console.ReadLine();

            Console.WriteLine("Enter account/C.C number");
            paymentOption.AccountNumber = Console.ReadLine();

            customerProducts.Payment = paymentOption;

            //call to update database
            _sqlData.CreatePaymentOption(paymentOption);

            Console.Clear();
        }
Esempio n. 7
0
        public void CompleteOrder()
        {
            Console.WriteLine("Which customer?");
            Customer         customer         = ChooseCustomer();
            CustomerProducts customerProducts = GetCustomerProducts(customer);

            //foreach(CustomerProducts cProds in _customerProducts)
            //{
            //    if (cProds.TheCustomer.FirstName == customer.FirstName &&
            //        cProds.TheCustomer.LastName == customer.LastName)
            //    {
            //    }
            //}

            Console.WriteLine(string.Format("The total is ${0}.", customerProducts.Products.Sum(x => x.Price)));
            //decimal finalPrice = 0;
            //foreach(Product product in customerProducts.Products)
            //{
            //    finalPrice += product.Price;
            //}
            //Console.WriteLine(finalPrice);

            _sqlData.CreateCustomerOrder(customerProducts);
        }
        public CustomerProducts GetCustomerProducts(Customer customer)
        {
            CustomerProducts customerProducts = new CustomerProducts();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = string.Format(@"
            SELECT
            p.Name Product,
            p.Price Price,
            c.FirstName + ' ' + c.LastName AS FullName
            FROM Product p 
            INNER JOIN OrderProducts op 
              ON p.IdProduct = op.IdProduct 
            INNER JOIN CustomerOrder co
              ON op.IdOrder = co.IdOrder 
            INNER JOIN Customer c
              ON co.IdCustomer = c.IdCustomer
            WHERE c.IdCustomer = '{0}'", customer.IdCustomer);
            cmd.Connection  = _sqlConnection;

            _sqlConnection.Open();

            //using will clean up everything... open and close connections
            using (SqlDataReader dataReader = cmd.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    Product product = new Product();
                    product.Name  = dataReader.GetString(0);
                    product.Price = dataReader.GetDecimal(1);

                    customerProducts.ProductsList.Add(product);
                }
            }

            _sqlConnection.Close();

            return(customerProducts);



            //foreach (CustomerProducts cProds in _customerProducts)
            //{
            //    if (cProds.TheCustomer.FirstName == customer.FirstName &&
            //        cProds.TheCustomer.LastName == customer.LastName)
            //    {
            //        customerProducts = cProds;
            //    }
            //    if (customerProducts.Payment == null)
            //    {
            //        customerProducts.Payment = _sqlData.GetPaymentOptionForCustomer(customer);
            //    }
            //}
            //if (customerProducts == null)
            //{
            //    customerProducts = new CustomerProducts();
            //    customerProducts.TheCustomer = customer;
            //    _customerProducts.Add(customerProducts);
            //}
        }