예제 #1
0
        public bool existsReservasConRegimen(Regimen regimen, Hotel hotel)
        {
            String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            SqlCommand    sqlCommand       = new SqlCommand();
            SqlDataReader reader;

            sqlCommand.Parameters.AddWithValue("@idRegimen", regimen.getIdRegimen());
            sqlCommand.Parameters.AddWithValue("@idHotel", hotel.getIdHotel());

            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandText =
                "SELECT RES.idReserva FROM LOS_BORBOTONES.Reserva AS RES " +
                "JOIN LOS_BORBOTONES.EstadoReserva AS ESRE ON ESRE.idReserva = RES.idReserva " +
                "WHERE RES.idRegimen = @idRegimen " +
                "AND RES.idHotel=@idHotel " +
                "AND RES.FechaHasta > LOS_BORBOTONES.fn_getDate()" +
                "AND ESRE.TipoEstado NOT  IN ('RCR','RCC','RCNS');";

            sqlConnection.Open();

            reader = sqlCommand.ExecuteReader();

            bool exist = reader.Read();

            sqlConnection.Close();

            return(exist);
        }
        private void initModificacionHotel()
        {
            RepositorioCategoria repoCategoria = new RepositorioCategoria();

            this.estrellasComboBox.DataSource  = repoCategoria.getAll().OrderBy(c => c.getEstrellas()).ToList();
            this.estrellasComboBox.ValueMember = "Estrellas";

            RepositorioRegimen repoRegimen = new RepositorioRegimen();

            this.regimenesGrid.DataSource = repoRegimen.getAll().OrderBy(r => r.getDescripcion()).ToList();
            regimenesGrid.AutoResizeColumns();
            regimenesGrid.CurrentCell = null;
            regimenesGrid.ClearSelection();
            this.regimenesGrid.Rows[0].Cells[0].Selected = false;
            this.regimenesGrid.Rows[0].Selected          = false;

            this.nombreText.Text   = hotel.getNombre();
            this.paisText.Text     = hotel.getDireccion().getPais();
            this.ciudadText.Text   = hotel.getDireccion().getCiudad();
            this.telefonoText.Text = hotel.getTelefono();
            this.estrellasComboBox.SelectedValue = hotel.getCategoria().getEstrellas();

            this.calleText.Text       = hotel.getDireccion().getCalle();
            this.numeroCalleText.Text = hotel.getDireccion().getNumeroCalle().ToString();
            this.creacionTime.Value   = hotel.getFechaInicioActividades();
            this.emailText.Text       = hotel.getMail();


            foreach (DataGridViewRow row in regimenesGrid.Rows)
            {
                Regimen regimen = (Regimen)row.DataBoundItem;
                if (hotel.getRegimenes().Exists(r => r.getIdRegimen().Equals(regimen.getIdRegimen())))
                {
                    this.regimenesGrid.Rows[row.Index].Cells[0].Selected = true;
                    this.regimenesGrid.Rows[row.Index].Selected          = true;
                }
            }

            this.dataGridCierres.DataSource = this.hotel.getCierresTemporales().OrderBy(c => c.getFechaInicio()).ToList();
            //ESTO LO TENGO QUE HACER PARA QUE NO APAREZCA SIEMPRE SELECCIONADO EL PRIMER ITEM
            dataGridCierres.CurrentCell = null;
            dataGridCierres.ClearSelection();

            //MEJORA DE PERFORMANCE DEL DGV
            this.dataGridReservas.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
            this.dataGridReservas.RowHeadersVisible       = false;
            this.dataGridReservas.DataSource        = this.hotel.getReservas().OrderBy(r => r.getFechaDesde()).ToList();
            this.dataGridReservas.RowHeadersVisible = true;

            //ESTO LO TENGO QUE HACER PARA QUE NO APAREZCA SIEMPRE SELECCIONADO EL PRIMER ITEM
            dataGridReservas.CurrentCell = null;
            dataGridReservas.ClearSelection();
        }
        private void buscarHabitaciones(Regimen regimenParam)
        {
            this.reservarHabitacionButton.Enabled = false;

            DateTime fechaInicio = (DateTime)Utils.validateFields(calendarioDesde.Value, "Fecha Desde");
            DateTime fechaFin    = (DateTime)Utils.validateFields(calendarioHasta.Value, "Fecha Hasta");

            if (fechaInicio < Utils.getSystemDatetimeNow())
            {
                MessageBox.Show("No puede realizar reservas en el pasado", "Error");
                return;
            }
            if (Utils.validateTimeRanges(fechaInicio, fechaFin))
            {
                Hotel hotelSeleccionado = null;
                if (sesion != null && sesion.getHotel() != null)
                {
                    hotelSeleccionado = sesion.getHotel();
                }
                else
                {
                    hotelSeleccionado = (Hotel)Utils.validateFields(comboBoxHotel.SelectedItem, "Hotel");
                } TipoHabitacion tipoHabitacionSeleccionada = null;
                if (comboBoxTipoHabitacion.SelectedItem != null)
                {
                    tipoHabitacionSeleccionada = (TipoHabitacion)comboBoxTipoHabitacion.SelectedItem;
                }
                Regimen regimenSeleccionado = null;

                regimenSeleccionado = (Regimen)comboBoxRegimen.SelectedItem;

                regimenSeleccionado = regimenParam;

                RepositorioHabitacion       repoHabitacion          = new RepositorioHabitacion();
                List <HabitacionDisponible> habitacionesDisponibles = repoHabitacion.getHabitacionesDisponibles(fechaInicio, fechaFin, hotelSeleccionado, tipoHabitacionSeleccionada, regimenSeleccionado, null).OrderBy(hd => hd.getNumeroHabitacion()).ToList();

                if (habitacionesDisponibles.Count == 0)
                {
                    limpiarRegimenesDataGrid();
                    this.regimenesDisponiblesGrid.DataSource    = null;
                    this.habitacionesDisponiblesGrid.DataSource = null;
                    MessageBox.Show("No se encontraron habitaciones disponibles.", "Generar Reserva", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }


                this.habitacionesDisponiblesGrid.DataSource = habitacionesDisponibles;
                this.habitacionesDisponiblesGrid.AutoResizeColumns();
                this.habitacionesDisponiblesGrid.CurrentCell = null;
                this.habitacionesDisponiblesGrid.ClearSelection();
                if (this.habitacionesDisponiblesGrid.Rows.Count > 0)
                {
                    this.habitacionesDisponiblesGrid.Rows[0].Cells[0].Selected = false;
                    this.habitacionesDisponiblesGrid.Rows[0].Selected          = false;
                }

                RepositorioRegimen repoRegimen = new RepositorioRegimen();

                this.regimenesDisponiblesGrid.DataSource = repoRegimen.getByIdHotel(hotelSeleccionado.getIdHotel());
                this.regimenesDisponiblesGrid.AutoResizeColumns();



                if (regimenSeleccionado == null)
                {
                    limpiarRegimenesDataGrid();
                }
                else
                {
                    limpiarRegimenesDataGrid();
                    foreach (DataGridViewRow item in this.regimenesDisponiblesGrid.Rows)
                    {
                        Regimen regimen = item.DataBoundItem as Regimen;
                        if (regimen.getIdRegimen() == regimenSeleccionado.getIdRegimen())
                        {
                            item.Selected = true;
                        }
                    }
                }
            }
        }
예제 #4
0
        public List <HabitacionDisponible> getHabitacionesDisponibles(DateTime fechaInicio, DateTime fechaFin, Hotel hotel, TipoHabitacion tipoHabitacion, Regimen regimen, Reserva reserva)
        {
            List <HabitacionDisponible> habitacionesDisponibles = new List <HabitacionDisponible>();
            RepositorioRegimen          repoRegimen             = new RepositorioRegimen();

            String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            SqlCommand    sqlCommand       = new SqlCommand();
            SqlDataReader reader;

            RepositorioReserva repoReserva = new RepositorioReserva();

            repoReserva.cancelarReservasNoShow(hotel);
            sqlCommand.Parameters.AddWithValue("@fechaInicio", fechaInicio);
            sqlCommand.Parameters.AddWithValue("@fechaFin", fechaFin);

            sqlCommand.Parameters.AddWithValue("@idHotel", hotel.getIdHotel());

            String queryTipoHab = "";

            if (tipoHabitacion != null)
            {
                sqlCommand.Parameters.AddWithValue("@idtipoHabitacion", tipoHabitacion.getIdTipoHabitacion());
                queryTipoHab = "AND HAB.idTipoHabitacion=@idtipoHabitacion ";
            }
            String queryModificarReservaParaTraerLaHabitacionQueYaReserve = reserva == null ? "" : "AND RES.idReserva!=" + reserva.getIdReserva();

            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandText =
                "SELECT HAB.idHabitacion,HAB.Activa,HAB.Numero,HAB.Piso,HAB.Ubicacion,Hab.Descripcion,HAB.idHotel,HAB.idTipoHabitacion,REG.idRegimen FROM LOS_BORBOTONES.Habitacion AS HAB " +
                "JOIN LOS_BORBOTONES.Hotel AS HOT ON HOT.idHotel=HAB.idHotel " +
                "JOIN LOS_BORBOTONES.Regimen_X_Hotel AS RXH ON RXH.idHotel=HOT.idHotel " +
                "JOIN LOS_BORBOTONES.Regimen AS REG ON REG.idRegimen = RXH.idRegimen " +
                "JOIN LOS_BORBOTONES.TipoHabitacion AS TIP ON TIP.idTipoHabitacion=HAB.idTipoHabitacion " +
                "WHERE REG.Activo=1 " +
                "AND HAB.idHotel=@idHotel " +
                "AND HAB.Activa=1 " +
                queryTipoHab +
                "AND NOT EXISTS ( " +
                "SELECT * FROM LOS_BORBOTONES.Reserva_X_Habitacion_X_Cliente AS RXHXC " +
                "JOIN LOS_BORBOTONES.Reserva AS RES ON RES.idReserva = RXHXC.idReserva  " +
                "WHERE HAB.idHabitacion= RXHXC.idHabitacion " +
                queryModificarReservaParaTraerLaHabitacionQueYaReserve +
                "AND  (RES.FechaDesde < @fechaFin AND @fechaInicio < RES.FechaHasta  ) " +
                "AND NOT EXISTS( " +
                "SELECT * FROM LOS_BORBOTONES.EstadoReserva AS ESRE " +
                "WHERE RES.idReserva = ESRE.idReserva " +
                "AND ESRE.TipoEstado  IN ('RCR','RCC','RCNS') " +
                ") " +
                ") " +

                "AND NOT EXISTS (SELECT * FROM LOS_BORBOTONES.CierreTemporal AS CIE WHERE CIE.idHotel= HOT.idHotel AND CIE.FechaInicio < @fechaFin AND @fechaInicio < CIE.FechaFin) ";

            if (regimen != null)
            {
                sqlCommand.Parameters.AddWithValue("@idRegimen", regimen.getIdRegimen());
                sqlCommand.CommandText += " AND REG.idRegimen=@idRegimen ";
            }

            sqlCommand.CommandText += " GROUP BY HAB.idHabitacion, REG.idRegimen, HAB.Activa,HAB.Numero,HAB.Piso,HAB.Ubicacion,HAB.idHotel,HAB.idTipoHabitacion,HAB.Descripcion " +
                                      " ORDER BY HAB.idHabitacion;";

            sqlConnection.Open();

            reader = sqlCommand.ExecuteReader();

            while (reader.Read())
            {
                int    qidHabitacion     = reader.GetInt32(reader.GetOrdinal("idHabitacion"));
                int    qidTipoHabitacion = reader.GetInt32(reader.GetOrdinal("idTipoHabitacion"));
                bool   qactiva           = reader.GetBoolean(reader.GetOrdinal("Activa"));
                int    qnumero           = reader.GetInt32(reader.GetOrdinal("Numero"));
                int    qpiso             = reader.GetInt32(reader.GetOrdinal("Piso"));
                int    qidRegimen        = reader.GetInt32(reader.GetOrdinal("idRegimen"));
                String qubicacion        = reader.GetString(reader.GetOrdinal("Ubicacion"));
                String qdescripcion      = reader.SafeGetString(reader.GetOrdinal("Descripcion"));

                Regimen    qregimen    = repoRegimen.getById(qidRegimen);
                Habitacion qhabitacion = new Habitacion(qidHabitacion, qactiva, qnumero, qpiso, qubicacion, qdescripcion);
                habitacionesDisponibles.Add(new HabitacionDisponible(qhabitacion, qregimen));
            }

            //Cierro Primera Consulta
            sqlConnection.Close();
            return(habitacionesDisponibles);
        }