public void SearchForReservationTest()
        {
            string            park              = "Acadia";
            string            campground        = "Blackwoods";
            DateTime          arrivalDate       = DateTime.MinValue;
            DateTime          departureDate     = DateTime.MinValue;
            List <Campsite>   test              = new List <Campsite>();
            ReservationSqlDAL reservationSqlDAL = new ReservationSqlDAL();

            test = reservationSqlDAL.SearchForReservation(park, campground, arrivalDate, departureDate);
            Assert.IsNotNull(test);
        }
コード例 #2
0
        public void SearchCampgroundReservations(string park, string campground)
        {
            List <Campsite> avaiablereservations = new List <Campsite>();
            bool            validInput           = false;
            DateTime        arrivalDate          = DateTime.MinValue;
            DateTime        departureDate        = DateTime.MinValue;

            bool SearchReservations = true;

            do
            {
                do
                {
                    Console.Write("What is the arrival date? (mm/dd/yyyy): ");
                    string input = Console.ReadLine();
                    try
                    {
                        arrivalDate = DateTime.Parse(input);
                        validInput  = true;
                    }
                    catch
                    {
                        Console.WriteLine("Invalid Input (mm/dd/yyyy): ");
                    }
                } while (validInput == false);

                validInput = false;
                do
                {
                    Console.Write("What is the departure date? (mm/dd/yyyy): ");
                    string input = Console.ReadLine();
                    try
                    {
                        departureDate = DateTime.Parse(input);
                        validInput    = true;
                    }
                    catch
                    {
                        Console.WriteLine("Invalid Input (mm/dd/yyyy): ");
                    }
                } while (validInput == false);

                ReservationSqlDAL reservationSqlDAL = new ReservationSqlDAL();
                avaiablereservations = reservationSqlDAL.SearchForReservation(park, campground, arrivalDate, departureDate);
                if (avaiablereservations.Count == 0)
                {
                    Console.WriteLine("No available sites\n");
                    validInput = false;
                    do
                    {
                        try
                        {
                            Console.Write("Would you like to enter another date (Y/N): ");
                            char anotherSearch;
                            anotherSearch = Convert.ToChar(Console.ReadLine());
                            if (char.ToUpper(anotherSearch) == 'Y')
                            {
                                validInput         = true;
                                SearchReservations = true;
                            }
                            else if (char.ToUpper(anotherSearch) == 'N')
                            {
                                validInput         = true;
                                SearchReservations = false;
                                return;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("\nPlease Enter (Y/N)");
                        }
                    } while (validInput == false);
                }
                else
                {
                    SearchReservations = false;
                }
            } while (SearchReservations == true);


            Console.WriteLine("\nResults Matching Your Search Criteria");
            Console.WriteLine("Site No.".PadRight(11) + "Max Occup.".PadRight(11) + "Accessible".PadRight(13) + "Max RV Length".PadRight(15) + "Utility".PadRight(9) + "Cost");

            foreach (Campsite campsite in avaiablereservations)
            {
                TimeSpan difference = departureDate - arrivalDate;

                Console.WriteLine(
                    Convert.ToString(campsite.SiteNumber).PadRight(11) +
                    Convert.ToString(campsite.MaxOccupancy).PadRight(11) +
                    Convert.ToString(campsite.Accessible).PadRight(13) +
                    Convert.ToString(campsite.MaxRvLength).PadRight(15) +
                    Convert.ToString(campsite.Utilities).PadRight(9) +
                    (campsite.DailyFee * (difference.Days + 1)).ToString("C2")
                    );
            }

            validInput = false;
            Campsite selectedCampsite = new Campsite();

            Console.WriteLine("");
            do
            {
                int userinput = 0;
                try
                {
                    Console.Write("Which site should be reserved (enter 0 to cancel): ");
                    userinput = int.Parse(Console.ReadLine());
                    if (userinput == 0)
                    {
                        return;
                    }
                    foreach (Campsite campsite in avaiablereservations)
                    {
                        if (campsite.SiteNumber == userinput)
                        {
                            validInput       = true;
                            selectedCampsite = campsite;
                        }
                    }
                    if (validInput == false)
                    {
                        Console.WriteLine("Invalid Site Number\n");
                    }
                }
                catch (FormatException e)
                {
                    Console.WriteLine("Invalid Input\n");
                }
            } while (validInput == false);
            Console.Write("What name should the reservation be made under): ");
            string name = Console.ReadLine();

            MakeNewReservation(name, selectedCampsite.SiteId, arrivalDate, departureDate);
            Console.WriteLine("");
        }