コード例 #1
0
        public void ViewAllSelectedSites(Campground campground, string start, string end)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Dictionary <int, Site> Sites = _park.GetSelectedSiteDictionary(campground, start, end);
                if (Sites.Count > 0)
                {
                    Console.WriteLine($"| {"Site ID".PadRight(15)} | " +
                                      $"| {"Site Number".PadRight(15)} | " +
                                      $"| {"Max Occup.".PadRight(15)}" +
                                      $"| {"Accessible?".PadRight(15)} | " +
                                      $"| {"Max RVLength".PadRight(15)} | " +
                                      $"| {"Utility".PadRight(15)} |" +
                                      $"| {"Cost".PadRight(15)} ");
                    Console.WriteLine(new string('-', 120));

                    foreach (KeyValuePair <int, Site> item in Sites)
                    {
                        Console.WriteLine($"| {item.Key.ToString().PadRight(15)} | " +
                                          $"| {item.Value.SiteNumber.ToString().PadRight(15)} | " +
                                          $"| {item.Value.MaxOccupancy.ToString().PadRight(15)}" +
                                          $"| {item.Value.Accessible.ToString().PadRight(15)} | " +
                                          $"| {item.Value.MaxRVLength.ToString().PadRight(15)} | " +
                                          $"| {item.Value.Utilities.ToString().PadRight(15)} |" +
                                          $"| {item.Value.TotalFee.ToString("C")}".PadRight(15));
                    }
                    var selection = NationalPark.GetInteger("Which site would you like to reserve? Enter the site ID to select, or enter 0 to return");
                    if (selection == 0)
                    {
                        Console.Clear();
                        exit = true;
                    }
                    else if (Sites.ContainsKey(selection))
                    {
                        Console.WriteLine("What name should the reservation be made under?");
                        string reservationName = Console.ReadLine();
                        int    reservationID   = _park.AddReservation(Sites[selection], reservationName, start, end);
                        Console.WriteLine($"you're reservation number is {reservationID}. Thanks!");
                        Console.ReadKey();
                        exit = true;
                    }
                    else
                    {
                        Console.WriteLine("Please only enter a site number that exists");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("There are no available campsites for this date range. Please select another campground or date range.");
                    Console.ReadKey();
                    exit = true;
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Sample Code to get a connection string from the
            // App.Config file
            // Use this so that you don't need to copy your connection string all over your code!
            string          connectionString = ConfigurationManager.ConnectionStrings["CapstoneDatabase"].ConnectionString;
            NationalPark    park             = new NationalPark(connectionString);
            NationalParkCLI cli = new NationalParkCLI(park);

            cli.RunCLI();
        }
コード例 #3
0
 public NationalParkCLI(NationalPark park)
 {
     _park = park;
 }
コード例 #4
0
        public void SearchAllCamgrounds(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine($"Please enter the reservation date information to search for open campsites at {park.Name}.\n ");
                    Console.WriteLine("What is the arrival date? Enter date as: yyyy-mm-dd:");
                    string   arrival = Console.ReadLine().ToString();
                    DateTime arr     = DateTime.Parse(arrival);

                    Console.WriteLine("What is the departure date? Enter date as: yyyy-mm-dd:");
                    string   departure = Console.ReadLine().ToString();
                    DateTime dep       = DateTime.Parse(departure);
                    _park.ValidateReservationDates(dep, arr);
                    Console.Clear();

                    Console.WriteLine($"Here are available campsites at {park.Name} Park between {arrival} and {departure}\n");
                    List <Campground>      list          = _park.GetCampgroundList(park);
                    Dictionary <int, Site> selectedSites = new Dictionary <int, Site>();
                    foreach (Campground camp in list)
                    {
                        Console.WriteLine($"| Campground: {camp.CampgroundName.ToString().PadRight(15)}");
                        Console.WriteLine("| Campsites:".PadRight(15));
                        Dictionary <int, Site> Sites = _park.GetSelectedSiteDictionary(camp, arrival, departure);

                        Console.WriteLine($"| {"Site ID".PadRight(15)} | " +
                                          $"| {"Site Number".PadRight(15)} | " +
                                          $"| {"Max Occup.".PadRight(15)}" +
                                          $"| {"Accessible?".PadRight(15)} | " +
                                          $"| {"Max RVLength".PadRight(15)} | " +
                                          $"| {"Utility".PadRight(15)} |" +
                                          $"| {"Cost".PadRight(15)} ");
                        Console.WriteLine(new string('-', 120));

                        foreach (KeyValuePair <int, Site> item in Sites)
                        {
                            selectedSites.Add(item.Key, item.Value);
                            Console.WriteLine($"| {item.Key.ToString().PadRight(15)} | " +
                                              $"| {item.Value.SiteNumber.ToString().PadRight(15)} | " +
                                              $"| {item.Value.MaxOccupancy.ToString().PadRight(15)}" +
                                              $"| {item.Value.Accessible.ToString().PadRight(15)} | " +
                                              $"| {item.Value.MaxRVLength.ToString().PadRight(15)} | " +
                                              $"| {item.Value.Utilities.ToString().PadRight(15)} |" +
                                              $"| {item.Value.TotalFee.ToString("C")}".PadRight(15));
                        }
                        Console.WriteLine();
                    }
                    bool exit2 = false;
                    while (!exit2)
                    {
                        int selection = NationalPark.GetInteger("Which campsite would you like to make a reservation under? (enter 0 to cancel)?");
                        if (selection == 0)
                        {
                            Console.Clear();
                            exit = true; exit2 = true;
                        }
                        else if (selectedSites.ContainsKey(selection))
                        {
                            Console.WriteLine("What name should the reservation be made under?");
                            string reservationName = Console.ReadLine();
                            int    reservationID   = _park.AddReservation(selectedSites[selection], reservationName, arrival, departure);
                            Console.WriteLine($"you're reservation number is {reservationID}. Thanks!");
                            Console.ReadKey();
                            exit = true; exit2 = true;
                        }
                        else
                        {
                            Console.WriteLine("Please only enter a site number that exists");
                        }
                    }
                }
                catch (InvalidArrivalDateException)
                {
                    Console.WriteLine("Please only enter future dates.");
                    Console.ReadKey();
                }
                catch (InvalidDepartureDateException)
                {
                    Console.WriteLine("Please only enter and end date that is after your arrival date.");
                    Console.ReadKey();
                }
                catch
                {
                    Console.WriteLine("Please only enter the date in a valid format");
                    Console.ReadKey();
                    Console.Clear();
                }
            }
        }
コード例 #5
0
        public void ViewAllIndividualSites(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();

                Console.WriteLine($"{park.Name} National Park\n");
                Console.WriteLine($"| {"Campground ID".PadRight(15)} | " +
                                  $"| {"Campground Name".PadRight(35)} | " +
                                  $"| {"Month Open".PadRight(10)} | " +
                                  $"| {"Closing Month".PadRight(15)} | " +
                                  $"| {"Daily Fee".PadRight(10)} | ");
                Console.WriteLine(new string('-', 100));

                Dictionary <int, Campground> CampgroundDictionary = _park.GetCampgroundDictionary(park);
                foreach (KeyValuePair <int, Campground> item in CampgroundDictionary)
                {
                    Console.WriteLine($"| {item.Value.CampgroundID.ToString().PadRight(15)} | " +
                                      $"| {item.Value.CampgroundName.PadRight(35)} | " +
                                      $"| {item.Value.DisplayMonthOpen.ToString().PadRight(10)} | " +
                                      $"| {item.Value.DisplayMonthClose.ToString().PadRight(15)} | " +
                                      $"| {item.Value.DailyFee.ToString("C").PadRight(10)} |");
                }
                int selection = NationalPark.GetInteger("Enter a campground by ID to view details for all of its sites, or enter 0 to return.");
                if (selection == 0)
                {
                    exit = true;
                }
                else if (CampgroundDictionary.ContainsKey(selection))
                {
                    Campground             camp           = CampgroundDictionary[selection];
                    Dictionary <int, Site> SiteDictionary = _park.GetSiteDictionary(CampgroundDictionary[selection]);
                    Console.Clear();
                    Console.WriteLine($"| {"Site Number".PadRight(15)} | " +
                                      $"| {"Max Occup.".PadRight(15)}" +
                                      $"| {"Accessible?".PadRight(15)} | " +
                                      $"| {"Max RVLength".PadRight(15)} | " +
                                      $"| {"Utility".PadRight(15)} | " +
                                      $"| {"Cost".PadRight(15)} ");
                    Console.WriteLine(new string('-', 100));
                    foreach (KeyValuePair <int, Site> item in SiteDictionary)
                    {
                        Console.WriteLine($"| {item.Value.SiteNumber.ToString().PadRight(15)} | " +
                                          $"| {item.Value.MaxOccupancy.ToString().PadRight(15)}" +
                                          $"| {item.Value.Accessible.ToString().PadRight(15)} | " +
                                          $"| {item.Value.MaxRVLength.ToString().PadRight(15)} | " +
                                          $"| {item.Value.Utilities.ToString().PadRight(15)} | " +
                                          $"| {item.Value.TotalFee.ToString("C").PadRight(15)}");
                    }
                    Console.WriteLine("Press any key to return");
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("Please only enter a valid campgroundID number");
                    Console.ReadKey();
                }
            }
        }
コード例 #6
0
        public void SearchAvailableReservation(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine($"{park.Name} National Park");
                Console.WriteLine($"| {"Campground ID".PadRight(15)} | " +
                                  $"| {"Campground Name".PadRight(35)} | " +
                                  $"| {"Month Open".PadRight(10)} | " +
                                  $"| {"Closing Month".PadRight(15)} | " +
                                  $"| {"Daily Fee".PadRight(10)} | ");
                Console.WriteLine(new string('-', 100));

                Dictionary <int, Campground> CampgroundDictionary = _park.GetCampgroundDictionary(park);
                foreach (KeyValuePair <int, Campground> item in CampgroundDictionary)
                {
                    Console.WriteLine($"| {item.Value.CampgroundID.ToString().PadRight(15)} | " +
                                      $"| {item.Value.CampgroundName.PadRight(35)} | " +
                                      $"| {item.Value.DisplayMonthOpen.ToString().PadRight(10)} | " +
                                      $"| {item.Value.DisplayMonthClose.ToString().PadRight(15)} | " +
                                      $"| {item.Value.DailyFee.ToString("C").PadRight(10)} |");
                }
                int sel = NationalPark.GetInteger("Which campground would you like to search for an available reservation? (enter 0 to cancel)?");
                if (sel == 0)
                {
                    exit = true;
                }
                try
                {
                    if (CampgroundDictionary.ContainsKey(sel))
                    {
                        Console.WriteLine("What is the arrival date? Enter date as: yyyy-mm-dd:");
                        string   arrival = Console.ReadLine().ToString();
                        DateTime arr     = DateTime.Parse(arrival);

                        Console.WriteLine("What is the departure date? Enter date as: yyyy-mm-dd:");
                        string   departure = Console.ReadLine().ToString();
                        DateTime dep       = DateTime.Parse(departure);

                        _park.ValidateReservationDates(dep, arr);
                        ViewAllSelectedSites(CampgroundDictionary[sel], arrival, departure);
                    }
                    else
                    {
                        Console.WriteLine("Please only enter a valid campground number");
                        Console.ReadKey();
                    }
                }
                catch (InvalidArrivalDateException)
                {
                    Console.WriteLine("Please only enter future dates.");
                    Console.ReadKey();
                }
                catch (InvalidDepartureDateException)
                {
                    Console.WriteLine("Please only enter and end date that is after your arrival date.");
                    Console.ReadKey();
                }
                catch (Exception)
                {
                    Console.WriteLine(") Please only enter a valid campground number");
                    Console.ReadKey();
                }
            }
        }