protected void btnSeleccionarhot_Click(object sender, EventArgs e)
 {
     try
     {
         EstadoInicial();
         if (GVHoteles.SelectedIndex != -1)
         {
             int               indice   = GVHoteles.SelectedIndex;
             Hotel             hotel    = LogicaHoteles.Buscar(GVHoteles.Rows[GVHoteles.SelectedIndex].Cells[1].Text);
             List <Habitacion> ListaHab = LogicaHabitaciones.ListarHabitaciones(hotel);
             GVHabitaciones.DataBind();
             if (ListaHab.Count > 0)
             {
                 GVHabitaciones.DataSource = ListaHab;
                 GVHabitaciones.DataBind();
                 btnSeleccionarHab.Enabled = true;
             }
             else
             {
                 GVHabitaciones.DataSource = null;
                 GVHabitaciones.DataBind();
                 btnSeleccionarHab.Enabled = false;
                 lblMensaje.Text           = "El hotel no tiene habitaciones";
             }
         }
         else
         {
             lblMensaje.Text = "Seleccione un hotel primero.";
         }
     }
     catch (Exception ex)
     { lblMensaje.Text = ex.Message; }
 }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            lblMensaje.Text = "";
            if (!IsPostBack)
            {
                Session["ListaHoteles"] = LogicaHoteles.ListarHoteles();
                if (((List <Hotel>)Session["ListaHoteles"]).Count != 0)
                {
                    cboHoteles.DataSource     = (List <Hotel>)Session["ListaHoteles"];
                    cboHoteles.DataTextField  = "NombreHotel";
                    cboHoteles.DataValueField = "NombreHotel";
                    cboHoteles.DataBind();
                }
                else
                {
                    lblMensaje.Text = "No hay hoteles en la base de datos.";
                }
            }

            //Muestro las Habitaciones para el Hotel Seleccionado.
            if (((List <Hotel>)Session["ListaHoteles"]).Count != 0)
            {
                Session["ListaHabitaciones"] = LogicaHabitaciones.ListarHabitaciones(LogicaHoteles.Buscar(cboHoteles.SelectedValue));
                if (((List <Habitacion>)Session["ListaHabitaciones"]).Count != 0)
                {
                    GVCompleto.DataSource = (List <Habitacion>)Session["ListaHabitaciones"];
                    GVCompleto.DataBind();
                    btnSeleccionar.Enabled = true;
                }
                else
                {
                    lblMensaje.Text       = "No hay habitaciones en este hotel.";
                    GVCompleto.DataSource = null;
                    GVCompleto.DataBind();
                    Session["ListaHabitaciones"] = null;
                    GVSeleccion.DataSource       = null;
                    GVSeleccion.DataBind();
                    btnSeleccionar.Enabled = false;
                }
            }
        }
        catch (Exception ex)
        { lblMensaje.Text = ex.Message; }
    }