コード例 #1
0
        public static List <Reserva> ListarReservasActivas()
        {
            List <Reserva> ListarReservas = new List <Reserva>();
            SqlConnection  cnn            = new SqlConnection(Constantes.CONEXION);

            try
            {
                SqlCommand cmd = new SqlCommand("ListarReservasActivas", cnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cnn.Open();
                SqlDataReader lector = cmd.ExecuteReader();
                while (lector.Read())
                {
                    Hotel      hotel = PersistenciaHoteles.Buscar((string)lector[0]);
                    Habitacion hab   = PersistenciaHabitaciones.Buscar(hotel, (int)lector[1]);
                    Cliente    cli   = PersistenciaClientes.Buscar((string)lector[2]);
                    Reserva    res   = new Reserva(hab, cli, (DateTime)lector[3], (DateTime)lector[4], (string)lector[5], (int)lector[6]);
                    ListarReservas.Add(res);
                }
                return(ListarReservas);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            { cnn.Close(); }
        }
コード例 #2
0
        public static Reserva Buscar(int id)
        {
            SqlConnection cnn = new SqlConnection(Constantes.CONEXION);
            Reserva       r   = null;

            try
            {
                SqlCommand cmd = new SqlCommand("BuscarReserva", cnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", id);
                cnn.Open();
                SqlDataReader lector = cmd.ExecuteReader();
                if (lector.Read())
                {
                    Hotel      hotel = PersistenciaHoteles.Buscar((string)lector[1]);
                    Habitacion hab   = PersistenciaHabitaciones.Buscar(hotel, (int)lector[2]);
                    Cliente    cli   = PersistenciaClientes.Buscar((string)lector[3]);
                    r = new Reserva(hab, cli, (DateTime)lector[4], (DateTime)lector[5], (string)lector[6], (int)lector[0]);
                }
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { cnn.Close(); }
            return(r);
        }