コード例 #1
0
        /// <summary>
        /// The override of ExecuteSelection handles whatever selection was made by the user.
        /// This is where any business logic is executed.
        /// </summary>
        /// <param name="choice">"Key" of the user's menu selection</param>
        /// <returns></returns>
        protected override bool ExecuteSelection(string choice)
        {
            switch (choice)
            {
            case "1":     // Do whatever option 1 is
                Console.WriteLine($"{ null,-3}Name{ null,-16} Open{ null,-6} Close{ null,-5} Daily Fee{ null,-6}");
                ListAllCampgrounds();
                ListSites();
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                this.siteId = GetInteger("Which site should be reserved (Enter 0 to cancel): ");
                Site site = siteDAO.GetSiteById(siteId);

                if (siteId == 0)
                {
                    Console.Clear();
                }
                else if (siteId == site.Campground_ID)
                {
                    Console.WriteLine($"Please enter the name for your reservation: ");
                    string name = Console.ReadLine();
                    reservationDAO.CreateReservation(site.Site_ID, name, arrivalDate, departureDate, createdDate);
                }

                return(true);

            case "2":     // Do whatever option 2 is
                break;
            }
            return(true);
        }
コード例 #2
0
        //creates a reservation based on the user's chosen dates and siteId
        private void CreateReservation(DateTime arriveDate, DateTime departDate)
        {
            Console.ForegroundColor = (ConsoleColor.Magenta);
            int siteIdSelection = CliHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?: ");

            //if user chooses 0 then return to original menu
            if (siteIdSelection == 0)
            {
                Console.Clear();
                return;
            }
            //else statement proceeds with good reservation
            else
            {
                Console.ForegroundColor = (ConsoleColor.Magenta);
                string reservedName = CliHelper.GetString("What name should the reservation be made under?: ");

                Reservation reservation = new Reservation
                {
                    siteID   = siteIdSelection,
                    name     = reservedName,
                    fromDate = arriveDate,
                    toDate   = departDate
                };

                int reservationId = reservationDAO.CreateReservation(reservation);

                if (reservationId > 0)
                {
                    Console.ForegroundColor = (ConsoleColor.Magenta);
                    Console.WriteLine("Your reservation has been added");
                    Console.WriteLine();
                }
                else
                {
                    Console.ForegroundColor = (ConsoleColor.Red);
                    Console.WriteLine("Error, try again");
                    Console.WriteLine();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates reservation based on availability of dates.
        /// </summary>
        /// <param name="arrivalDate"></param>
        /// <param name="departureDate"></param>
        private void CreateReservation(DateTime arrivalDate, DateTime departureDate)
        {
            int siteIdChoice = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?:");

            if (siteIdChoice == 0)
            {
                Console.Clear();
                return;
            }
            else
            {
                string reservationName = CLIHelper.GetString("What name should the reservation be made under?:");

                Reservation newReservation = new Reservation
                {
                    SiteId   = siteIdChoice,
                    Name     = reservationName,
                    FromDate = arrivalDate,
                    ToDate   = departureDate
                };

                int reservationId = reservationDAO.CreateReservation(newReservation);

                if (reservationId > 0)
                {
                    Console.WriteLine("====================Successfully added your reservation===================");
                    Console.WriteLine("");
                }

                else
                {
                    Console.WriteLine("==================== ERROR occurred in creating your Reservation =================== ");
                    Console.WriteLine("PLEASE TRY AGAIN");
                    Console.WriteLine("");
                }
            }
        }
コード例 #4
0
        // this method RARSM uses the ilist cg cg aka the campground table
        private void RunAvailableReservationSearchMenu(IList <Campground> campgrounds)
        {   // clears the console
            Console.Clear();
            // uses the WCL function with the cg list to print out the cg list (cg table from sql db)
            WriteCampgroundsList(campgrounds);
            // asks the user to select a campground to make a rezz or 0 to return to prev menu
            Console.Write("\nSelect a Campground to make a reservation or 0 to go back: ");
            // list of sites from the site table n sql
            IList <Site> sites;
            // cg list from cg class
            Campground campground;
            // the date of arrival
            DateTime userArrival;
            // date of departure
            DateTime userDeparture;
            // number of days they are staying
            int numberOfDaysToStay;
            // assigns GVS method with he number of cg's given to it to uSelection
            int userSelection = GetValidSelection(campgrounds.Count);

            // if users selects 0, return to prev menu
            if (userSelection == 0)
            {
                return;
            }
            // subtracts 1 from user selection bc the index starts at 0 while the options start at 1
            userSelection--;
            //this is the assigns the cg selection to cg
            campground = campgrounds[userSelection];
            // execute this loop while true
            while (true)
            {
                // asks user for arrival date
                Console.Write("What is the arrival date (MM/DD/YYYY)? ");
                // this assigns the GVD method to uArrival
                userArrival = GetValidDate();
                // asks user for departure date
                Console.Write("What is the departure date (MM/DD/YYYY)? ");
                //this assigns the GCD method to uDeparture
                userDeparture = GetValidDate();
                // while loop in while loop that compares the uD to uA making sure that the reserve at least a day
                while (userDeparture.CompareTo(userArrival) <= 0)//you have reserve at least one day
                {
                    // returns ths if they don't reserve atleast 1 day
                    Console.Write("No, really.... What is the departure date (MM/DD/YYYY)? ");
                    userDeparture = GetValidDate();
                }

                //DONE do logic to search for available campsites during their dates
                //we did the logic in a SQL statement in the SiteDAO
                Console.Clear();


                sites = siteDAO.GetAvailableSites(userArrival, userDeparture, campground);
                //DONE figure out how to figure out if their dates occur in the campground's offseason and if so, remove all the sites

                /*
                 *  If their start month is less than their end month, things are normal so we.......
                 *  If their start year is not the same as their end year, then they're camping over the new year and it's kinda odd how we figure out if they're okay to camp
                 *      -if the campground is not open in december and january..... then they can't stay there
                 *      -if their start month is less than their end month, then they're trying to camp for over a full year so the park needs to be open year round if they want that reservation
                 *
                 */
                // if the user arrival year is the same as departure year, move on to next if statement
                if (userArrival.Year == userDeparture.Year)
                {
                    // if this statement is NOT(!) - userArrmonth is greater than/equal to the cg's open from month AND uArrM is less than/equal to cg open to month AND uDepM is greater than/equal to cg open from month AND uDepM is less than/equal to cg open to mm
                    if (!(userArrival.Month >= campground.OpenFrom && userArrival.Month <= campground.OpenTo && userDeparture.Month >= campground.OpenFrom && userDeparture.Month <= campground.OpenTo))
                    {
                        // clear the sites because they can't stay then
                        //in this case, they're NOT safe to keep going
                        sites.Clear();
                    }
                }
                else
                {    // if the cg open from month is NOT 1 AND cg open to month is NOT 12, then clear the sites
                    //in this case, they're camping over the new year and things get weiiiiird
                    if (campground.OpenFrom != 1 && campground.OpenTo != 12)
                    {
                        sites.Clear();
                    }
                }
                // if the count of the list is 0, tell the user there are no sites available at that time, asks if they want to try again
                if (sites.Count == 0)
                {
                    Console.WriteLine("There were no available campsites for the given time frame. \nWould you like to enter a different set of dates(Y/N)?");
                    // this takes the user input, makes it ower case and trim off extra spaces
                    string userYorN = Console.ReadLine().ToLower().Trim();
                    // if the user's input starts w/ y or is y then continuie with the rez loop again
                    if (userYorN.StartsWith("y"))
                    {
                        continue;//continue with the loop, which is to say, go back and ask for dates again
                    }
                    // this is if they don't respond y, yes, or anything starting with a letter other than y
                    Console.WriteLine("Returning to Campground Menu...");
                    Thread.Sleep(3000); // waits 3 seconds
                    return;             // returns to previous menu
                }
                else
                {
                    break;//if we get here, then they gave us dates with available campsites and we're breaking the loop to continue with reserving
                    //this should happen MOST of the time
                }
            }
            // this gives the number of days they stay to nODTS to use to give the total cost
            numberOfDaysToStay = ((TimeSpan)(userDeparture - userArrival)).Days;
            // prints the message
            Console.WriteLine("Results Matching Your Search Criteria");
            // prints the sites
            WriteSiteList(sites);
            // prints the cost
            Console.WriteLine($"\tThe cost will be {campground.DailyFee * numberOfDaysToStay:c}");
            // asks for user input
            Console.Write($"\nWhich site would you like to reserve (enter 0 to cancel)? ");
            // assigns GVS(sites) to uSTR
            int userSiteToReserve = GetValidSiteSelection(sites);

            // if uSTO is 0, return to menu
            if (userSiteToReserve == 0)
            {
                return;
            }
            // DONE make sure they enter a valid name for the reservation
            // asks for a name that the reservation will be made under
            Console.Write("What name should the reservation be made under? ");
            //assigns GVN to uName
            string userName = GetValidName();
            //DONE do logic to find the site ID
            //starts siteI at -1
            int siteID = -1;

            // for each site in the list of sites (site table)
            foreach (Site site in sites)
            {
                // if the uSTR is the site number
                if (userSiteToReserve == site.SiteNumber)
                { // the siteID is now the site id
                    siteID = site.SiteID;
                }
            }
            //Console.WriteLine(siteID);
            // assings the current time when called
            DateTime currentTime = DateTime.Now;
            // this is assigns the create rez method to the reservationID int
            int reservationID = reservationDAO.CreateReservation(new Reservation()
            {
                SiteID = siteID, Name = userName, FromDate = userArrival, ToDate = userDeparture, CreateDate = currentTime
            });

            //DONE write out their reservation info here
            // this is the confirmation info printed to the user
            Console.WriteLine("Final Reservation Info:\n");
            Console.WriteLine($"\tThe site ID is {siteID}");
            Console.WriteLine($"\tThe reservation is under {userName}");
            Console.WriteLine($"\tYou are staying from {userArrival:d} to {userDeparture:d}");
            Console.WriteLine($"\tThe reservation creation time is {currentTime}");
            Console.WriteLine($"\tThe reservation has been made and the confirmation ID is {reservationID}");
            // prints it all out to the console
            Console.ReadLine();
        }