예제 #1
0
 public int InsertReservation(Reservation reservation)
 {
     try
     {
         if (reservation.Space.Id.Equals(string.Empty))
             return 1;
         else if (reservation.Space.ParkingId.Equals(string.Empty))
             return 2;
         else if (reservation.Space.ParkingCampusId.Equals(string.Empty))
             return 3;
         else if (reservation.User.Username.Equals(string.Empty))
             return 4;
         else if (reservation.Vehicle.VehiclePlate.Equals(string.Empty))
             return 6;
         else if (reservation.CheckIn.Equals(string.Empty))
             return 7;
         else if (reservation.CheckOut.Equals(string.Empty))
             return 8;
         else if (reservation.CheckIn > reservation.CheckOut)
             return 9;
         else if (reservation.CheckIn < DateTime.Now)
             return 10;
         else if (reservation.CheckIn == reservation.CheckOut)
             return 11;
         else
         {
             reservationData.InsertReservation(reservation);
             return 0;
         }
     }
     catch (SqlException)
     {
         return 5;
     }
 }
예제 #2
0
 protected void CheckActiveReservation(Reservation reservation)
 {
     switch (reservationRules.SearchActiveReservation(reservation))
     {
         case 0:
             CheckUserReservation(reservation);
             break;
         case 1:
             buttonStyle.buttonStyleRed(buttonErrors, "The space selected already have reservations in that hours.");
             break;
     }
 }
예제 #3
0
 public void InsertReservation(Reservation reservation)
 {
     connection = ManageDatabaseConnection("Open");
     using (SqlCommand insert = new SqlCommand(@"InsertReservation", connection))
     {
         insert.CommandType = CommandType.StoredProcedure;
         insert.Parameters.Add("@SpaceId", SqlDbType.Int).Value = reservation.Space.Id;
         insert.Parameters.Add("@SpaceParkingId", SqlDbType.Int).Value = reservation.Space.ParkingId;
         insert.Parameters.Add("@SpaceCampusId", SqlDbType.Int).Value = reservation.Space.ParkingCampusId;
         insert.Parameters.Add("@UserName", SqlDbType.VarChar).Value = reservation.User.Username;
         insert.Parameters.Add("@VehiclePlate", SqlDbType.VarChar).Value = reservation.Vehicle.VehiclePlate;
         insert.Parameters.Add("@CheckIn", SqlDbType.DateTime).Value = reservation.CheckIn;
         insert.Parameters.Add("@CheckOut", SqlDbType.DateTime).Value = reservation.CheckOut;
         insert.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }
예제 #4
0
 protected void CheckUserReservation(Reservation reservation)
 {
     DataTable dt = reservationData.DataTableUserReservation(Session["User-UserName"].ToString());
     if (dt.Rows.Count > 0)
     {
         if (Convert.ToDateTime(dt.Rows[0]["CheckOut"]) > DateTime.Now)
         {
             buttonStyle.buttonStyleRed(buttonErrors, "You can't have more than one reserve active.");
         }
         else
         {
             InsertReservation(reservation);
         }
     }
     else
         InsertReservation(reservation);
 }
예제 #5
0
        public int SearchActiveReservation(Reservation reservation)
        {
            List<Reservation> activeReservationList = reservationData.SendActiveReservationList(reservationData.SearchActiveReservation(reservation.Space.ParkingCampusId, reservation.Space.ParkingId, reservation.Space.Id));
            List<DateTime> reservationInsideHoursList = new List<DateTime>();
            List<DateTime> activeReservationInsideHoursList = new List<DateTime>();
            if (activeReservationList !=  null)
            {
                for (DateTime i = reservation.CheckIn.AddHours(1); i < reservation.CheckOut; i = i.AddHours(1))
                {
                    reservationInsideHoursList.Add(i);
                }

                foreach (Reservation activeReservation in activeReservationList)
                {
                    if (reservation.CheckIn == activeReservation.CheckIn)
                        return 1;
                    else if (reservation.CheckOut == activeReservation.CheckOut)
                        return 1;

                    for (DateTime i = activeReservation.CheckIn.AddHours(1); i < activeReservation.CheckOut; i = i.AddHours(1))
                    {
                        activeReservationInsideHoursList.Add(i);
                    }

                    foreach (DateTime reservationHour in reservationInsideHoursList)
                    {
                        foreach (DateTime activeReservationHour in activeReservationInsideHoursList)
                        {
                            if (reservationHour == activeReservationHour)
                                return 1;
                        }
                    }
                }
            }
            return 0;
        }
예제 #6
0
        public List<Reservation> SendActiveReservationList(DataTable dataTableReservation)
        {
            List<Reservation> reservationList = new List<Reservation>();
            if (dataTableReservation.Rows.Count > 0)
            {
                for (int i = 0; i < dataTableReservation.Rows.Count; i++)
                {
                    Reservation reservation = new Reservation();
                    reservation.CheckIn = Convert.ToDateTime(dataTableReservation.Rows[i]["CheckIn"]);
                    reservation.CheckOut = Convert.ToDateTime(dataTableReservation.Rows[i]["CheckOut"]);
                    reservationList.Add(reservation);
                }
                return reservationList;

            }
            else
                return null;
        }
예제 #7
0
 protected void InsertReservation(Reservation reservation)
 {
     if (reservation != null)
     {
         switch (reservationRules.InsertReservation(reservation))
         {
             case 0:
                 buttonStyle.buttonStyleBlue(buttonErrors, "Space reserved sucessful.");
                 break;
             case 1:
                 buttonStyle.buttonStyleWhite(buttonErrors, "The campus select is empty.");
                 break;
             case 2:
                 buttonStyle.buttonStyleRed(buttonErrors, "The parking select is empty.");
                 break;
             case 3:
                 buttonStyle.buttonStyleWhite(buttonErrors, "The space select is empty.");
                 break;
             case 4:
                 buttonStyle.buttonStyleRed(buttonErrors, "The user name is empty.");
                 break;
             case 5:
                 buttonStyle.buttonStyleWhite(buttonErrors, "An error ocurred during your reservation.");
                 break;
             case 6:
                 buttonStyle.buttonStyleRed(buttonErrors, "The vehicle plate empty.");
                 break;
             case 7:
                 buttonStyle.buttonStyleWhite(buttonErrors, "The initial hour empty.");
                 break;
             case 8:
                 buttonStyle.buttonStyleRed(buttonErrors, "The final hour is empty.");
                 break;
             case 9:
                 buttonStyle.buttonStyleRed(buttonErrors, "The initial hour can't be highter than the final hour.");
                 break;
             case 10:
                 buttonStyle.buttonStyleRed(buttonErrors, "The initial hour can't be less than the actual hour.");
                 break;
             case 11:
                 buttonStyle.buttonStyleRed(buttonErrors, "The initial hour can't be equals than the final hour.");
                 break;
         }
     }
 }
예제 #8
0
        protected Reservation CreateReservation()
        {
            Reservation reservation = new Reservation();
            Space space = new Space();
            User user = new User();
            Vehicle vehicle = new Vehicle();
            DateTime checkIn = DateTime.Now;
            DateTime checkOut = DateTime.Now;
            TimeSpan initialHour = new TimeSpan();
            TimeSpan finalHour = new TimeSpan();
            try
            {
                if (hiddenCampusValue.Value.Equals(string.Empty))
                    space.ParkingCampusId = Convert.ToInt32(selectCampus.Items[0].Value);
                else
                    space.ParkingCampusId = Convert.ToInt32(hiddenCampusValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The campus select is empty.");
                return null;
            }

            try
            {
                if (hiddenParkingValue.Value.Equals(string.Empty))
                    space.ParkingId = Convert.ToInt32(selectParking.Items[0].Value);
                else
                    space.ParkingId = Convert.ToInt32(hiddenParkingValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The parking select is empty.");
                return null;
            }

            try
            {
                space.Id = Convert.ToInt32(hiddenSpaceValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "Please, select a space.");
                return null;
            }

            try
            {
                if (hiddenVehicleValue.Value.Equals(string.Empty))
                    vehicle.VehiclePlate = selectVehicle.Items[0].Value;
                else
                    vehicle.VehiclePlate = hiddenVehicleValue.Value;
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The vehicle select is empty.");
                return null;
            }

            user.Username = Session["User-UserName"].ToString();
            reservation.Space = space;
            reservation.User = user;
            reservation.Vehicle = vehicle;
            initialHour = CreateCheckIn(initialHour);
            finalHour = CreateCheckOut(finalHour);
            checkIn = checkIn.Date + initialHour;
            checkOut = checkOut.Date + finalHour;
            reservation.CheckIn = checkIn;
            reservation.CheckOut = checkOut;

            return reservation;
        }