Example #1
0
        /// <summary>
        ///  A function for creating an auction.
        /// </summary>
        ///  <remarks>
        ///  This function takes the user through the process of creating an auction.
        /// </remarks>
        ///
        public void createAuction()
        {
            // only display if user is a seller
            if (tcurrent.GetType() == typeof(Seller))
            {
                Console.WriteLine("Welcome to Auction screen!");
                Console.WriteLine("What are you selling?");
                string name = Console.ReadLine();

                Auction tauc;
                tauc = new Auction(name);

                Console.WriteLine("What would you like the starting price to be?");
                double start_price = double.Parse(Console.ReadLine());
                tauc.setStartPrice(start_price);
                tauc.setCurrentPrice(start_price);

                Console.WriteLine("Set a reserve price:");
                double reserve = double.Parse(Console.ReadLine());
                tauc.setReservePrice(reserve);

                Console.WriteLine("How long in minutes would you like the auction to last: ");
                int minutes = Int32.Parse(Console.ReadLine());

                Console.WriteLine("Press Y or N to confirm or cancel auction:");
                string startAuction = Console.ReadLine();

                tauc.setStatus('p'); // set status to p for pending

                if (startAuction == "y" || startAuction == "Y")
                {
                    tauc.setIsRunning(true);
                    Console.WriteLine("Success Auction Created! It will end at: ");
                    DateTime current = DateTime.Now;
                    tauc.setCloseDate(current.AddMinutes(minutes));
                    Console.WriteLine(tauc.getCloseDate().ToString("h:mm:ss tt"));
                    getCurrentUser().addAuction(tauc);
                    placeAuction(tauc);
                }
                else
                {
                    Console.WriteLine("Auction cancelled :(");
                }
            }
            else
            {
                Console.WriteLine("Account not a Seller.");
            }
        }
Example #2
0
        //-------PUBLIC METHODS---------------------

        /// <summary>
        ///  This function is used to run our auction.
        /// </summary>
        ///  <remarks>
        ///  Run the application loop
        /// </remarks>
        public void run()
        {
            //variables to hold our user menu choice
            string userInput;
            int    choice;
            int    exit = 5;
            // --------------- Sample Auctions ------------------------------------------
            Auction test;

            test = new Auction("Test");
            placeAuction(test);
            test.setCurrentPrice(99.99);
            test.setReservePrice(250);
            test.setCloseDate(DateTime.Now.AddSeconds(30));
            test.setIsRunning(true);

            Auction car;

            car = new Auction("car");
            car.setCurrentPrice(2000.99);
            car.setCloseDate(DateTime.Now.AddMinutes(7));
            car.setIsRunning(true);
            car.setReservePrice(3000);
            placeAuction(car);

            Auction laptop;

            laptop = new Auction("Laptop", 100, 300);
            laptop.setCloseDate(DateTime.Now.AddMinutes(2));
            laptop.setIsRunning(true);
            laptop.setCurrentPrice(laptop.getStartPrice());
            placeAuction(laptop);

            Auction ipad;

            ipad = new Auction("ipad", 150, 300, DateTime.Now.AddMinutes(3), true);
            ipad.setCurrentPrice(ipad.getStartPrice());
            placeAuction(ipad);

            //create a thread to automatically close auctions
            Thread checkAuctions = new Thread(threadedCheckAucClose);

            checkAuctions.Start();

            //------------------------------------------------------
            do
            {
                //load the menu and sample data and wait for user response
                Console.ResetColor();
                //Console.Clear();

                currentUser();
                createSampleUser();
                displayMenu();
                userInput = Console.ReadLine();

                //Handles format exception if user enters invalid characters
                if (!Int32.TryParse(userInput, out choice) || choice > 6)
                {
                    Console.WriteLine("Please enter valid input.");
                }
                else
                {
                    choice = Int32.Parse(userInput);
                }

                switch (choice)
                {
                case 1:
                    logIn();
                    break;

                case 2:
                    createUser();
                    break;

                case 3:
                    browseAuction();
                    break;

                case 4:
                    if (tcurrent == null)
                    {
                        break;
                    }
                    if (tcurrent.isLoggedIn() == true)     // only show this menu if user is logged in
                    {
                        createAuction();
                    }
                    break;

                case 5:
                    Environment.Exit(0);
                    break;

                case 6:
                    if (tcurrent.isLoggedIn() == true)     // log off user
                    {
                        tcurrent.setLoggedIn(false);
                    }
                    break;
                }
            } while (choice != exit);
        }