예제 #1
0
        /// <summary>
        /// Returns a list of all of the campgrounds.
        /// </summary>
        /// <returns></returns>
        ///
        public IList <CampGround> GetCampGrounds(int parkId)
        {
            List <CampGround> campGrounds = new List <CampGround>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    //sql statement that returns the campgrounds that are within the park selected by the user
                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE park_id = @park_id", connection);
                    cmd.Parameters.AddWithValue("@park_id", parkId);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        CampGround campGround = ConvertReaderToCampGrouds(reader);
                        campGrounds.Add(campGround);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred");
                Console.WriteLine(e.Message);
                throw;
            }
            return(campGrounds);
        }
예제 #2
0
        public CampGround GetSingleCampGround(int campGroundId)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    //sql statement that references an individual campgroundId so that the cost can be calculated
                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE campground_id = @campground_id;", connection);
                    cmd.Parameters.AddWithValue("@campground_id", campGroundId);
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        CampGround campGround = ConvertReaderToCampGrouds(reader);
                        return(campGround);
                    }
                    else
                    {
                        return(null);
                    }
                }
            } catch (Exception e)
            {
                Console.WriteLine("Could not find campground");
                Console.WriteLine(e.Message);
            }
            return(null);
        }
        public void TestMethodTentPlaces()
        {
            CampGround campingPlace = new CampGround(10, 0, 0, 0);

            Assert.AreEqual(10, campingPlace.pitch.nofUnitsLeft);
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(1), "Add tent place no.1");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(2), "Add tent place no.2");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(3), "Add tent place no.3");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(4), "Add tent place no.4");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(5), "Add tent place no.5");

            Assert.IsFalse(campingPlace.pitch.RemoveItemsFromUnitList(5), "Add tent place no.5 again");

            Assert.AreEqual(5, campingPlace.pitch.nofUnitsLeft);

            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(6), "Add tent place no.6");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(7), "Add tent place no.7");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(8), "Add tent place no.8");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(9), "Add tent place no.9");
            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(10), "Add tent place no.10");

            Assert.AreEqual(0, campingPlace.pitch.nofUnitsLeft);

            campingPlace.pitch.AddItemsToUnitList(5);

            Assert.AreEqual(1, campingPlace.pitch.nofUnitsLeft);

            Assert.IsTrue(campingPlace.pitch.RemoveItemsFromUnitList(5), "Add tent place 5 after free it");

            Assert.AreEqual(0, campingPlace.pitch.nofUnitsLeft);
        }
        /// <summary>
        /// Views a single campground to get the daily fee.
        /// </summary>
        /// <param name="campGroundId"></param>
        /// <returns></returns>
        public CampGround ViewCampground(int campGroundId)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(SQL_ViewCampground, conn);
                    cmd.Parameters.AddWithValue("@campground_id", campGroundId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        CampGround camp = ConvertReaderToCampground(reader);
                        return(camp);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Could not load campground.");
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        public void TestMethodSmallCabin()
        {
            CampGround campingPlace = new CampGround(0, 8, 0, 0);

            Assert.AreEqual(8, campingPlace.smallBungalow.nofUnitsLeft);

            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(1), "Add small cabin no.1");
            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(2), "Add small cabin no.2");
            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(3), "Add small cabin no.3");
            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(4), "Add small cabin no.4");
            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(5), "Add small cabin no.5");

            Assert.AreEqual(3, campingPlace.smallBungalow.nofUnitsLeft, "expect 3 left");

            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(6), "Add small cabin no.6");
            Assert.IsFalse(campingPlace.smallBungalow.RemoveItemsFromUnitList(6), "Add small cabin no.6 again");

            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(7), "Add small cabin no.7");
            Assert.IsTrue(campingPlace.smallBungalow.RemoveItemsFromUnitList(8), "Add small cabin no.8");

            Assert.IsFalse(campingPlace.smallBungalow.RemoveItemsFromUnitList(9), "Add small cabin no.9");

            Assert.AreEqual(0, campingPlace.smallBungalow.nofUnitsLeft, "expect 0 left");

            campingPlace.smallBungalow.AddItemsToUnitList(5);

            Assert.AreEqual(1, campingPlace.smallBungalow.nofUnitsLeft, "expect 0 left");
        }
        public List <CampGround> GetCampGrounds(int parkId)
        {
            //GetCampGrounds will retrieve all campgrounds within the selected park.
            List <CampGround> output = new List <CampGround>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(@"SELECT * FROM campground WHERE park_id = @parkId", conn);
                    cmd.Parameters.AddWithValue("@parkId", parkId);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        CampGround c = new CampGround();
                        c.ParkId       = parkId;
                        c.Name         = Convert.ToString(reader["name"]);
                        c.OpenFrom     = Convert.ToInt32(reader["open_from_mm"]);
                        c.OpenTo       = Convert.ToInt32(reader["open_to_mm"]);
                        c.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);
                        c.CampgroundId = Convert.ToInt32(reader["campground_id"]);

                        output.Add(c);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Something went wrong with the campground data, please try again later");
            }

            return(output);
        }
        public IList <CampGround> GetCampGround()
        {
            List <CampGround> output = new List <CampGround>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("Select * From campGround", conn);


                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        CampGround campGround = new CampGround();
                        campGround.CampGroundId = Convert.ToInt32(reader["campground_id"]);
                        campGround.Name         = Convert.ToString(reader["name"]);
                        campGround.OpenFrom     = Convert.ToInt32(reader["open_from_mm"]);
                        campGround.OpenTo       = Convert.ToInt32(reader["open_to_mm"]);
                        campGround.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);
                        output.Add(campGround);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("There was a problem accessing the database.");
                throw;
            }
            return(output);
        }
예제 #8
0
        public IList <CampGround> GetCampGroundByParkId(int ParkId)
        {
            List <CampGround> campgrounds = new List <CampGround>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    // column    // param name
                    SqlCommand cmd = new SqlCommand("SELECT * FROM campground WHERE park_id = @ParkId;", conn);
                    // param name    // param value
                    cmd.Parameters.AddWithValue("@ParkId", ParkId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        CampGround campground = ConvertReaderToCampGround(reader);
                        campgrounds.Add(campground);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("An error occurred reading campsites by park.");
                Console.WriteLine(ex.Message);
                throw;
            }
            return(campgrounds);
        }
        /// <summary>
        /// Views all campgrounds.
        /// </summary>
        /// <param name="parkId"></param>
        /// <returns></returns>
        public IList <CampGround> ViewCampgrounds(int parkId)
        {
            List <CampGround> campGrounds = new List <CampGround>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(SQL_ViewCampgrounds, conn);
                    cmd.Parameters.AddWithValue("@park_id", parkId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        CampGround camp = ConvertReaderToCampground(reader);
                        campGrounds.Add(camp);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Could not load campgrounds.");
                Console.WriteLine(ex.Message);
                throw;
            }

            return(campGrounds);
        }
        public void TestMethodLuxuryCabin()
        {
            CampGround campingPlace = new CampGround(0, 0, 0, 2);

            Assert.AreEqual(2, campingPlace.luxuryBungalow.nofUnitsLeft);
            Assert.IsTrue(campingPlace.luxuryBungalow.RemoveItemsFromUnitList(1), "Add big cabin no.1");
            Assert.IsTrue(campingPlace.luxuryBungalow.RemoveItemsFromUnitList(2), "Add big cabin no.2");
            Assert.AreEqual(0, campingPlace.luxuryBungalow.nofUnitsLeft);
            Assert.IsFalse(campingPlace.luxuryBungalow.RemoveItemsFromUnitList(2), "Add big cabin no.2 again");
            campingPlace.luxuryBungalow.AddItemsToUnitList(2);
            Assert.AreEqual(1, campingPlace.luxuryBungalow.nofUnitsLeft);
        }
        public void TestAddItemToUnitList()
        {
            CampGround campingPlace = new CampGround(5, 0, 0, 0);

            campingPlace.pitch.AddItemsToUnitList(1);
            Assert.AreEqual(5, campingPlace.pitch.nofUnitsLeft);
            campingPlace.pitch.RemoveItemsFromUnitList(1);
            Assert.AreEqual(4, campingPlace.pitch.nofUnitsLeft);
            campingPlace.pitch.AddItemsToUnitList(1);
            campingPlace.pitch.AddItemsToUnitList(1);
            campingPlace.pitch.AddItemsToUnitList(2);
            Assert.AreEqual(5, campingPlace.pitch.nofUnitsLeft);
        }
예제 #12
0
        private CampGround ConvertReaderToCampGround(SqlDataReader reader)
        {
            CampGround campground = new CampGround();

            campground.CampGroundId   = Convert.ToInt32(reader["campground_id"]);
            campground.ParkId         = Convert.ToInt32(reader["park_id"]);
            campground.CampgroundName = Convert.ToString(reader["name"]);
            campground.OpenMonth      = Convert.ToInt32(reader["open_from_mm"]);
            campground.ClosingMonth   = Convert.ToInt32(reader["open_to_mm"]);
            campground.DailyFee       = Convert.ToInt32(reader["daily_fee"]);

            return(campground);
        }
        private CampGround ConvertReaderToCampground(SqlDataReader reader)
        {
            CampGround camp = new CampGround();

            camp.CampgroundId = Convert.ToInt32(reader["campground_id"]);
            camp.ParkId       = Convert.ToInt32(reader["park_id"]);
            camp.Name         = Convert.ToString(reader["name"]);
            camp.OpenFrom     = Convert.ToInt32(reader["open_from_mm"]);
            camp.OpenTo       = Convert.ToInt32(reader["open_to_mm"]);
            camp.DailyFee     = Convert.ToDecimal(reader["daily_fee"]);

            return(camp);
        }
예제 #14
0
        private CampGround ConvertReaderToCampGrouds(SqlDataReader reader)
        {
            CampGround campGround = new CampGround();

            campGround.name          = Convert.ToString(reader["name"]);
            campGround.campground_id = Convert.ToInt32(reader["campground_id"]);
            campGround.park_id       = Convert.ToInt32(reader["park_id"]);
            campGround.open_from_mm  = Convert.ToInt32(reader["open_from_mm"]);
            campGround.open_to_mm    = Convert.ToInt32(reader["open_to_mm"]);
            campGround.daily_fee     = Convert.ToDecimal(reader["daily_fee"]);

            return(campGround);
        }
예제 #15
0
        public List <Site> GetSites(CampGround camp)
        {
            List <Site> output = new List <Site>();

            //Always wrap connection to a database in a try-catch block

            //Create a SqlConnection to our database
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                const string sqlSites = "SELECT site_id, campground_id, site_number, max_occupancy, accessible, max_rv_length, utilities " +
                                        "FROM site " +
                                        "WHERE campground_id = @campgroundId " +
                                        "Order By campground_id;";

                SqlCommand cmd  = new SqlCommand();
                Site       site = new Site();
                cmd.CommandText = sqlSites;
                cmd.Connection  = connection;
                cmd.Parameters.AddWithValue("@campgroundId", camp.CampgroundId);

                // Execute the query to the database
                SqlDataReader reader = cmd.ExecuteReader();

                // The results come back as a SqlDataReader. Loop through each of the rows
                // and add to the output list
                while (reader.Read())
                {
                    CampGround campground = new CampGround();
                    site = new Site();
                    // Read in the value from the reader
                    // Reference by index or by column_name
                    site.SiteId       = Convert.ToInt32(reader["site_id"]);
                    site.CampgroundId = Convert.ToInt32(reader["campground_id"]);
                    site.SiteNumber   = Convert.ToInt32(reader["site_number"]);
                    site.MaxOccupancy = Convert.ToInt32(reader["max_occupancy"]);
                    site.Accessible   = Convert.ToBoolean(reader["accessible"]);
                    site.MaxRvLength  = Convert.ToInt32(reader["max_rv_length"]);
                    site.Utilities    = Convert.ToBoolean(reader["utilities"]);


                    // Add the continent to the output list
                    output.Add(site);
                }
            }


            // Return the list of continents
            return(output);
        }
        public List <Reservation> GetTopFiveReservations(string campgroundName, DateTime startDate, DateTime endDate)
        {
            List <Reservation> output = new List <Reservation>();

            //Create a SqlConnection to our database
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                const string sqlReservation = "SELECT TOP (5) campground_id, name, open_from_mm, open_to_mm, daily_fee " +
                                              "FROM campground;";

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sqlReservation;
                cmd.Connection  = connection;
                //cmd.Parameters.AddWithValue("@firstName", firstname);
                //cmd.Parameters.AddWithValue("@lastName", lastname);


                // Execute the query to the database
                SqlDataReader reader = cmd.ExecuteReader();

                // The results come back as a SqlDataReader. Loop through each of the rows
                // and add to the output list
                // select * from reservation
                // where(from_date > '01-06-2017' and from_date > '02-06-2017')
                // and(to_date < '01-06-2017' and to_date > '01-06-2017');

                while (reader.Read())
                {
                    CampGround campground = new CampGround();

                    // Read in the value from the reader
                    // Reference by index or by column_name
                    campground.CampgroundId = Convert.ToInt32(reader["campground_id"]);
                    campground.Name         = Convert.ToString(reader["name"]);
                    campground.OpenFromMm   = Convert.ToInt32(reader["open_from_mm"]);
                    campground.OpenToMm     = Convert.ToInt32(reader["open_to_mm"]);
                    campground.DailyFee     = Convert.ToDouble(reader["daily_fee"]);

                    // Add the continent to the output list
                    //output.Add(campground);
                }
            }


            // Return the list of continents
            return(output);
        }
        public void TestMethodBigCabin()
        {
            CampGround campingPlace = new CampGround(0, 0, 5, 0);

            Assert.AreEqual(5, campingPlace.bigBungalow.nofUnitsLeft);
            Assert.IsTrue(campingPlace.bigBungalow.RemoveItemsFromUnitList(1), "Add big cabin no.1");
            Assert.IsTrue(campingPlace.bigBungalow.RemoveItemsFromUnitList(2), "Add big cabin no.2");
            Assert.IsTrue(campingPlace.bigBungalow.RemoveItemsFromUnitList(3), "Add big cabin no.3");
            Assert.AreEqual(2, campingPlace.bigBungalow.nofUnitsLeft);
            Assert.IsTrue(campingPlace.bigBungalow.RemoveItemsFromUnitList(4), "Add big cabin no.4");
            Assert.IsTrue(campingPlace.bigBungalow.RemoveItemsFromUnitList(5), "Add big cabin no.5");
            Assert.IsFalse(campingPlace.bigBungalow.RemoveItemsFromUnitList(5), "Add big cabin no.5 again");
            campingPlace.bigBungalow.AddItemsToUnitList(3);
            Assert.AreEqual(1, campingPlace.bigBungalow.nofUnitsLeft);
        }
        public List <CampGround> GetCampGrounds(Park park)
        {
            List <CampGround> output = new List <CampGround>();

            //Always wrap connection to a database in a try-catch block

            //Create a SqlConnection to our database
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                const string sqlCampgrounds = "SELECT campground_id, park_id, name, open_from_mm, open_to_mm, daily_fee " +
                                              "FROM campground " +
                                              "WHERE park_id = @parkId " +
                                              "Order By name;";

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sqlCampgrounds;
                cmd.Connection  = connection;
                cmd.Parameters.AddWithValue("@parkId", park.ParkId);

                // Execute the query to the database
                SqlDataReader reader = cmd.ExecuteReader();

                // The results come back as a SqlDataReader. Loop through each of the rows
                // and add to the output list
                while (reader.Read())
                {
                    CampGround campground = new CampGround();

                    // Read in the value from the reader
                    // Reference by index or by column_name
                    campground.CampgroundId = Convert.ToInt32(reader["campground_id"]);
                    campground.ParkId       = Convert.ToInt32(reader["park_id"]);
                    campground.Name         = Convert.ToString(reader["name"]);
                    campground.OpenFromMm   = Convert.ToInt32(reader["open_from_mm"]);
                    campground.OpenToMm     = Convert.ToInt32(reader["open_to_mm"]);
                    campground.DailyFee     = Convert.ToDouble(reader["daily_fee"]);

                    // Add the continent to the output list
                    output.Add(campground);
                }
            }


            // Return the list of continents
            return(output);
        }
        public void CampgroundDisplay(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                CampgroundsDAL    campgrounds = new CampgroundsDAL(_connectionString);
                List <CampGround> cgList      = new List <CampGround>();
                cgList = campgrounds.GetCampGrounds(park);
                Dictionary <int, CampGround> cgDictionary = new Dictionary <int, CampGround>();

                Console.WriteLine("--------------------------------------------------------------------------------------");
                Console.WriteLine("                                Park Campgrounds                                ");
                Console.WriteLine($"                                 {park.Name}                                   ");
                Console.WriteLine("--------------------------------------------------------------------------------------");
                Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", " ", "Name", "Open", "Close", "Daily Fee"));

                for (int i = 1; i <= cgList.Count; i++)
                {
                    CampGround campground = cgList[i - 1];
                    Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", $"#{i}", campground.Name, campground.OpenMonth, campground.CloseMonth, campground.DailyFee.ToString("c")));
                    cgDictionary.Add(i, campground);


                    //Console.ReadKey();
                }


                Console.WriteLine();
                Console.WriteLine("Select a Command");
                Console.WriteLine("(1) Search for Available Reservation");
                Console.WriteLine("(2) Return to Previous Screen");

                char selCampground = Console.ReadKey().KeyChar;

                if (selCampground == '2')
                {
                    exit = true;
                }
                else
                {
                    ReservationCLI resCLI = new ReservationCLI(_connectionString);
                    resCLI.ReservationDisplay(park);
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Searched for sites and enter in dates you want to stay.
        /// </summary>
        private void SearchReservationRun()
        {
            Console.WriteLine("Search for Available Campground Sites");
            int campgroundId = CLIHelper.GetInteger("Which campground (enter 0 to cancel)?:");

            if (campgroundId == 0)
            {
                Console.Clear();
                return;
            }

            else
            {
                //campgroundId = choice;

                DateTime arrivalDate   = CLIHelper.GetDateTime("What is the arrival date? (MM/DD/YYYY): ");
                DateTime departureDate = CLIHelper.GetDateTime("What is the departure date? (MM/DD/YYYY): ");

                IList <CampSite> campSites = campSiteDAO.SearchReservationRun(campgroundId, arrivalDate, departureDate);

                if (campSites.Count == 0)
                {
                    Console.Clear();
                    Console.WriteLine("There are no available campsites for those dates, Please try again.");
                    return;
                }

                else
                {
                    CampGround campGround = campGroundDAO.ViewCampground(campgroundId);

                    decimal cost = campGround.DailyFee * (decimal)(departureDate - arrivalDate).TotalDays;

                    Console.WriteLine();
                    Console.WriteLine("Site NO.  MAX OCCUPANCY  ACCESSIBLE   MAX RV LENGTH    UTILITY  COST");
                    Console.WriteLine();

                    foreach (CampSite campSite in campSites)
                    {
                        Console.WriteLine($"#{campSite.SiteId}\t\t{campSite.MaxOccupancy}\t{campSite.IsAccessible}\t\t{campSite.MaxRvLength}\t\t{campSite.HasUtilties}\t{cost:C2}"); //todo: add daily fee
                    }

                    Console.WriteLine("");
                    CreateReservation(arrivalDate, departureDate);
                }
            }
        }
예제 #21
0
        //Methods
        public Dictionary <int, CampGround> ListCampground(int parkSelection)
        {
            Dictionary <int, CampGround> output = new Dictionary <int, CampGround>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(SQL_Campground, conn);

                    cmd.Parameters.AddWithValue("@ParkId", parkSelection.ToString());

                    SqlDataReader reader = cmd.ExecuteReader();


                    while (reader.Read())
                    {
                        int key = Convert.ToInt32(reader["campground_id"]);

                        CampGround campground = new CampGround
                        {
                            Campground_Id = Convert.ToInt32(reader["campground_id"]),
                            Park_Id       = Convert.ToInt32(reader["park_id"]),
                            Name          = Convert.ToString(reader["name"]),
                            Daily_Fee     = Convert.ToInt32(reader["daily_fee"]),
                            Open_From_Int = Convert.ToInt32(reader["open_from_mm"]),
                            Open_To_Int   = Convert.ToInt32(reader["open_to_mm"]),
                        };


                        output[key] = campground;
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(output);
        }
        public IList <CampGround> DisplayCampGrounds(int parkID) //gets all the campgrounds
        {
            List <CampGround> campground = new List <CampGround>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = SQL_DisplayCampGrounds;
                    cmd.Connection  = connection;
                    cmd.Parameters.AddWithValue("@park_id", parkID);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        CampGround camp = new CampGround();

                        camp.CampgroundId   = Convert.ToInt32(reader["campground_id"]);
                        camp.Name           = Convert.ToString(reader["name"]);
                        camp.OpenFromMonth  = Convert.ToInt32(reader["open_from_mm"]);
                        camp.CloseFromMonth = Convert.ToInt32(reader["open_to_mm"]);
                        camp.DailyFee       = Convert.ToDouble(reader["daily_fee"]);

                        campground.Add(camp);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw;
            }
            return(campground);
        }
예제 #23
0
        public void ReservationDisplay(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                CampgroundsDAL    campgrounds = new CampgroundsDAL(_connectionString);
                List <CampGround> cgList      = new List <CampGround>();
                cgList = campgrounds.GetCampGrounds(park);
                Dictionary <int, CampGround> cgDictionary = new Dictionary <int, CampGround>();

                Console.WriteLine("------------------------------------------------------------------------------------------------");
                Console.WriteLine("                                      Park Campgrounds                                          ");
                Console.WriteLine($"                                          {park.Name}                                          ");
                Console.WriteLine("------------------------------------------------------------------------------------------------");
                Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", " ", "Name", "Open", "Close", "Daily Fee"));

                CampGround campground = new CampGround();
                for (int i = 1; i <= cgList.Count; i++)
                {
                    campground = cgList[i - 1];
                    Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", $"#{i}", campground.Name, campground.OpenMonth, campground.CloseMonth, campground.DailyFee.ToString("c")));
                    cgDictionary.Add(i, campground);
                }


                Console.WriteLine();
                Console.WriteLine("Which campground (enter 0 to cancel)?");
                string selCampground = Console.ReadLine();

                if (selCampground == "0")
                {
                    exit = true;
                }
                else
                {
                    Console.WriteLine();
                    ReservationDAL reservations = new ReservationDAL(_connectionString);
                    Reservation    reservation  = new Reservation();

                    // try catch
                    Console.WriteLine("What is the arrival date? (mm/dd/yyyy)");
                    DateTime arrivalDate = Convert.ToDateTime(Console.ReadLine());
                    reservation.FromDate = arrivalDate;
                    Console.WriteLine("What is the departure date? (mm/dd/yyyy)");
                    DateTime departureDate = Convert.ToDateTime(Console.ReadLine());
                    reservation.ToDate = departureDate;

                    //CampGround campground = new CampGround();
                    int        cgId = cgDictionary[int.Parse(selCampground)].CampgroundId;
                    CampGround camp = cgDictionary[int.Parse(selCampground)];
                    arrivalDate   = Convert.ToDateTime(arrivalDate);
                    departureDate = Convert.ToDateTime(departureDate);

                    //List<Reservation> resList = new List<Reservation>();

                    var resList = reservations.SearchReservations(reservation);


                    bool toExit = false;
                    while (!toExit)
                    {
                        bool isAvailable = (resList.Count != 0);
                        if (isAvailable)
                        {
                            Console.Clear();
                            Console.WriteLine("Results Matching Your Search Criteria: ");
                            Console.WriteLine();

                            Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,-18} | {3,-15} | {4,-15} | {5,-15}", "Site No.", "Max Occup.", "Accessible?", "Max RV Length", "Utility", "Cost"));

                            TimeSpan totalTime = departureDate - arrivalDate;
                            int      totalDays = totalTime.Days;


                            Site        site     = new Site();
                            SiteDAL     sites    = new SiteDAL(_connectionString);
                            List <Site> siteList = new List <Site>();
                            siteList = sites.GetSites(camp);
                            Dictionary <int, Site> siteDictionary = new Dictionary <int, Site>();

                            //double totalCost = campground.DailyFee * totalDays;

                            for (int i = 1; i <= siteList.Count; i++)
                            {
                                site = siteList[i - 1];
                                Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,-18} | {3,-15} | {4,-15} | {5,-15}", site.SiteNumber, site.MaxOccupancy, site.Accessible, site.MaxRvLength, site.Utilities, (campground.DailyFee * totalDays).ToString("c")));
                                siteDictionary.Add(i, site);
                            }

                            Console.WriteLine();
                            Console.WriteLine("Select a site to reserve: ");
                            string selSite = Console.ReadLine();
                            site.SiteNumber = int.Parse(selSite);

                            Console.WriteLine("Enter a name for the reservation: ");
                            string resName = Console.ReadLine();
                            //reservations.CreateReservation(reservation);
                            //reservation.Name = resName;
                            //reservation.ToDate = arrivalDate;
                            //reservation.FromDate = departureDate;

                            reservations.CreateReservation(resName, arrivalDate, departureDate, site.SiteNumber);



                            Random random     = new Random();
                            int    confirmNum = random.Next(000000000, 999999999);
                            Console.WriteLine($"Reservation made. Your confirmation number is: {confirmNum}.");
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("The campsite you have chosen is not available for those dates.");
                            Console.WriteLine("(1) Select new dates");
                            Console.WriteLine("(2) Return to previous menu");

                            string selection = Console.ReadLine();

                            if (selection == "2")
                            {
                                toExit = true;
                            }
                            else
                            {
                                Console.ReadKey();
                            }
                        }
                    }
                    // arrivalDate.CompareTo()
                    // or create a SQL statement that where date is before date and date is after date
                }
            }
        }
예제 #24
0
        //searches for available reservation based on the dates and siteId requested by the user
        private void SearchReservation(IList <CampGround> campGrounds)
        {
            Console.ForegroundColor = (ConsoleColor.Magenta);
            Console.WriteLine("Search for Available Campground Sites");
            int campgroundId = CliHelper.GetInteger("Which campground (enter 0 to cancel)?: ");

            //if statement to return user if no available sites for the specified dates
            if (campgroundId == 0)
            {
                Console.Clear();
                return;
            }

            //if statement that calls method to have user try again if their choice is not one of the displayed campgrounds
            if (!ValidateCampGroundId(campgroundId, campGrounds))
            {
                Console.ForegroundColor = (ConsoleColor.Red);
                Console.WriteLine("Invalid choice. Please try again.");
                Console.WriteLine("");
                SearchReservation(campGrounds);
                return;
            }

            //allows user to input their desired dates
            Console.ForegroundColor = (ConsoleColor.Magenta);
            DateTime arriveDate = CliHelper.GetDateTime("What is the arrival date? (MM/DD/YYYY): ");
            DateTime departDate = CliHelper.GetDateTime("What is the departure date? (MM/DD/YYYY): ");

            IList <Site> sites = siteDAO.SearchReservation(campgroundId, arriveDate, departDate);

            //if statement that lets user try again because there is nothing available
            if (sites.Count == 0)
            {
                Console.Clear();
                Console.ForegroundColor = (ConsoleColor.Red);
                Console.WriteLine("There are no sites available for those dates, try again");
                return;
            }
            //else statement proceeds with available reservation
            else
            {
                Console.ForegroundColor = (ConsoleColor.Magenta);
                CampGround campGround = campGroundDAO.GetSingleCampGround(campgroundId);

                decimal cost = campGround.daily_fee * (decimal)(departDate - arriveDate).TotalDays;

                Console.WriteLine();
                Console.WriteLine("Site NO.".PadRight(20) + "MAX OCCUPANCY".PadRight(20) + "ACCESSIBLE".PadRight(20) + "MAX RV LENGTH".PadRight(20) + "UTILITY".PadRight(20) + "COST");
                Console.WriteLine();

                //foreach loops displays the available sites
                foreach (Site site in sites)
                {
                    Console.ForegroundColor = (ConsoleColor.Magenta);
                    Console.WriteLine($"#{site.siteId}".PadRight(20) + $"{site.maxOccupancy}".PadRight(20) + $"{site.accessible}".PadRight(20) + $"{site.maxRvLength}".PadRight(20) + $"{site.utilities}".PadRight(20) + $"{cost:C2}");
                }
                Console.ForegroundColor = (ConsoleColor.Magenta);
                Console.WriteLine();
                CreateReservation(arriveDate, departDate);
            }
        }