Ejemplo n.º 1
0
        //method sites
        public List <ReservationAndSite> GetSites(DateTime startDate, DateTime endDate, Campground campground)
        {
            List <ReservationAndSite> output = new List <ReservationAndSite>();

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

                    SqlCommand cmd = new SqlCommand(SQL_AvailableSites, conn);
                    cmd.Parameters.AddWithValue("@startdate", startDate);
                    cmd.Parameters.AddWithValue("@enddate", endDate);
                    cmd.Parameters.AddWithValue("@camp", campground.campgroundId);

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        ReservationAndSite thisSite = GetSiteFromReader(reader);
                        output.Add(thisSite);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(output);
        }
Ejemplo n.º 2
0
        //method create reservation
        public int MakeReservation(ReservationAndSite newReservation)
        {
            int reservationConfirmation = 0;

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

                    SqlCommand cmd = new SqlCommand(SQL_CreateReservation, conn);
                    cmd.Parameters.AddWithValue("@siteid", newReservation.siteId);
                    cmd.Parameters.AddWithValue("@name", newReservation.reservationName);
                    cmd.Parameters.AddWithValue("@startdate", newReservation.startDate);
                    cmd.Parameters.AddWithValue("@enddate", newReservation.endDate);
                    //cmd.Parameters.AddWithValue("@getdate", newReservation.createDate);


                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.RecordsAffected > 0)
                    {
                        conn.Close();
                        conn.Open();
                        //Select reservation_id from reservation where name = @name and creationdate =
                        SqlCommand cmd2 = new SqlCommand(SQL_GetResId, conn);
                        reservationConfirmation = (int)cmd2.ExecuteScalar();
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(reservationConfirmation);
        }
Ejemplo n.º 3
0
        public static ReservationAndSite SelectFrom(List <ReservationAndSite> someSites)
        {
            ReservationAndSite output = new ReservationAndSite();

            Console.Clear();
            Console.Write("\t");
            ReservationAndSite.DrawInfoHead();

            foreach (ReservationAndSite item in someSites)
            {
                int position = someSites.IndexOf(item) + 1;
                Console.Write($"[{position}]\t");
                item.DrawInfo();
            }
            while (output.selected == false)
            {
                string input = Console.ReadKey(true).KeyChar.ToString();
                int.TryParse(input, out int x);
                if (0 < x && x <= someSites.Count)
                {
                    output          = someSites[x - 1];
                    output.selected = true;
                }
            }
            return(output);
        }
Ejemplo n.º 4
0
        //covert site from database
        private ReservationAndSite GetSiteFromReader(SqlDataReader reader)
        {
            ReservationAndSite convertSite = new ReservationAndSite();

            convertSite.siteId         = Convert.ToInt32(reader["site_id"]);
            convertSite.campgroundName = Convert.ToString(reader["Campground"]);
            convertSite.siteNum        = Convert.ToInt32(reader["Site_Number"]);
            convertSite.totalPrice     = Convert.ToDecimal(reader["Total_Cost"]);

            return(convertSite);
        }
Ejemplo n.º 5
0
        void SiteSeach()
        {
            CampSqlDAL sqlParks = new CampSqlDAL(dbConnectionString);

            ReservationAndSite reservation = new ReservationAndSite();

            Park       park = MenuHelper.SelectFrom(sqlParks.GetParks());
            Campground camp = MenuHelper.SelectFrom(sqlParks.GetCampgrounds(park));

            bool correct = false;

            while (!correct)
            {
                Console.Clear();
                Campground.DrawInfoHead();
                camp.DrawInfo();
                Console.WriteLine();
                Console.Write("Arrival date: ");
                reservation.GetDate(true);


                Console.Clear();
                Campground.DrawInfoHead();
                camp.DrawInfo();
                Console.WriteLine();
                Console.Write("Departure date: ");
                reservation.GetDate(false);

                Console.Clear();
                Campground.DrawInfoHead();
                camp.DrawInfo();
                Console.WriteLine();
                Console.WriteLine($"Arrival date: " + reservation.startDate.ToShortDateString() + "\t Departure date: " + reservation.endDate.ToShortDateString());
                correct = MenuHelper.GetConfirmation();
            }

            ReservationAndSite selectedSite = MenuHelper.SelectFrom(sqlParks.GetSites(reservation.startDate, reservation.endDate, camp));

            correct = false;
            while (!correct)
            {
                while (reservation.reservationName == null)
                {
                    Console.Clear();
                    Campground.DrawInfoHead();
                    camp.DrawInfo();
                    Console.WriteLine();
                    Console.WriteLine($"Arrival date: " + reservation.startDate.ToShortDateString() + "\t Departure date: " + reservation.endDate.ToShortDateString());
                    Console.Write("Reservation Name: ");
                    reservation.GetName();
                }
                Console.Clear();
                Campground.DrawInfoHead();
                camp.DrawInfo();
                Console.WriteLine();
                Console.WriteLine($"Arrival date: " + reservation.startDate.ToShortDateString() + "\t Departure date: " + reservation.endDate.ToShortDateString());
                Console.Write("Reservation Name: " + reservation.reservationName);
                Console.WriteLine();
                correct = MenuHelper.GetConfirmation();
            }
            reservation.siteId = selectedSite.siteId;

            int resID = sqlParks.MakeReservation(reservation);

            Console.WriteLine("Your confirmation number is: " + resID);
            MenuHelper.EnterToRelease();
        }