public static int search_occupied(Reserva reserva) { SqlCommand command = new SqlCommand(); command.CommandText = "PUNTO_ZIP.sp_reserva_occupied"; command.Parameters.Add(new SqlParameter("@p_hotel_id", SqlDbType.Int)); command.Parameters["@p_hotel_id"].Value = reserva.id_hotel; command.Parameters.Add(new SqlParameter("@p_tipo_hab", SqlDbType.VarChar, 255)); command.Parameters["@p_tipo_hab"].Value = reserva.tipo_habitacion; command.Parameters.Add(new SqlParameter("@p_fecha_desde", SqlDbType.DateTime)); command.Parameters["@p_fecha_desde"].Value = reserva.fecha_inicio; command.Parameters.Add(new SqlParameter("@p_fecha_hasta", SqlDbType.DateTime)); command.Parameters["@p_fecha_hasta"].Value = reserva.fecha_fin; var returnParameter_occupied = command.Parameters.Add(new SqlParameter("@p_total", SqlDbType.Int)); returnParameter_occupied.Direction = ParameterDirection.Output; ProcedureHelper.execute(command, "chequear ocupacion hotel", false); int ocupacion = Convert.ToInt16(command.Parameters["@p_total"].Value); return(ocupacion); }
public static void update_reserva(Reserva reserva) { SqlCommand command = new SqlCommand(); command.CommandText = "PUNTO_ZIP.sp_assign_room"; command.Parameters.Add(new SqlParameter("@p_hotel_id", SqlDbType.Int)); command.Parameters["@p_hotel_id"].Value = reserva.id_hotel; command.Parameters.Add(new SqlParameter("@p_client_id", SqlDbType.Int)); command.Parameters["@p_client_id"].Value = reserva.clienteId; command.Parameters.Add(new SqlParameter("@p_id_usuario", SqlDbType.VarChar, 20)); command.Parameters["@p_id_usuario"].Value = VarGlobal.usuario.id; //command.Parameters.Add(new SqlParameter("@p_checkin", SqlDbType.DateTime)); //command.Parameters["@p_checkin"].Value = reserva.fecha_inicio; command.Parameters.AddWithValue("@p_checkin", reserva.fecha_inicio); command.Parameters.Add(new SqlParameter("@p_id_reserva", SqlDbType.Int)); command.Parameters["@p_id_reserva"].Value = reserva.id; command.Parameters.Add(new SqlParameter("@p_stay", SqlDbType.Int)); Int32 days = Convert.ToInt32((reserva.fecha_fin - reserva.fecha_inicio).TotalDays); command.Parameters["@p_stay"].Value = days; command.Parameters.Add(new SqlParameter("@p_tipo_habitacion", SqlDbType.VarChar, 255)); command.Parameters["@p_tipo_habitacion"].Value = reserva.tipo_habitacion; command.Parameters.Add(new SqlParameter("@p_regimen", SqlDbType.VarChar, 255)); command.Parameters["@p_regimen"].Value = reserva.tipo_regimen; command.Parameters.Add(new SqlParameter("@p_update", SqlDbType.Bit)); command.Parameters["@p_update"].Value = 1; var retorno = ProcedureHelper.execute(command, "update reserva", false); if (retorno == -1) { MessageBox.Show("No se pudo actualizar la reserva para las fechas seleccionadas y habitacion seleccionada"); } else { MessageBox.Show("La reserva fue actualizada con exito"); } }
public static void search(Reserva reserva, DataGridView dgvReserva) { SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "PUNTO_ZIP.sp_reserva_listar"; command.Parameters.Add(new SqlParameter("@p_hotel_id", SqlDbType.Int)); command.Parameters["@p_hotel_id"].Value = reserva.id_hotel; command.Parameters.Add(new SqlParameter("@p_nombre", SqlDbType.VarChar, 255)); if (reserva.nombre == string.Empty) { command.Parameters["@p_nombre"].Value = null; } else { command.Parameters["@p_nombre"].Value = reserva.nombre; } command.Parameters.Add(new SqlParameter("@p_apellido", SqlDbType.VarChar, 255)); if (reserva.apellido == string.Empty) { command.Parameters["@p_apellido"].Value = null; } else { command.Parameters["@p_apellido"].Value = reserva.apellido; } command.Parameters.Add(new SqlParameter("@p_res_id", SqlDbType.Int)); command.Parameters["@p_res_id"].Value = reserva.id; DataGridViewHelper.fill(command, dgvReserva); }
private void buttonBuscar_Click(object sender, EventArgs e) { buttonGuardar.Enabled = false; dtFechaDesde.Enabled = false; dtFechaHasta.Enabled = false; dgvRegimen.DataSource = null; dgvRegimen.Refresh(); dgvTipoHabitacion.DataSource = null; dgvTipoHabitacion.Refresh(); Boolean isValid = Validaciones.validAndRequiredInt32(txtIdReserva.Text, "El numero de la reserva es obligatorio y numerico"); if (!isValid) { return; } int reservaHotel = ReservaHelper.search_hotel_by_reserva(Convert.ToInt32(txtIdReserva.Text)); if (VarGlobal.usuario.id == "guest") { VarGlobal.usuario.hotel = reservaHotel; } else { if (reservaHotel != VarGlobal.usuario.hotel) { MessageBox.Show("El numero de reserva no pertenece a este hotel"); return; } } if (reservaHotel == 0) { MessageBox.Show("El numero de reserva no existe"); return; } Reserva reserva = this.getDataToSearch(); ReservaHelper.search_reserva(reserva); if (reserva.fecha_inicio <= VarGlobal.FechaHoraSistema) { MessageBox.Show("Ya paso el plazo para modificar esta reserva con fecha de inicio: " + reserva.fecha_inicio.Date.ToShortDateString() + ". Hoy es: " + VarGlobal.FechaHoraSistema.Date.ToShortDateString()); return; } ReservaHelper.search_regimen(VarGlobal.usuario.hotel, dgvRegimen); ReservaHelper.search_tipo_hab(VarGlobal.usuario.hotel, dgvTipoHabitacion); dtFechaDesde.Value = reserva.fecha_inicio; dtFechaHasta.Value = dtFechaDesde.Value.AddDays(reserva.estadia); for (int i = 0; i < dgvRegimen.RowCount; i++) { if (dgvRegimen.Rows[i].Cells[0].Value.ToString() == reserva.tipo_regimen) { dgvRegimen.Rows[i].Selected = true; this.dgvRegimen.CurrentCell = this.dgvRegimen.Rows[i].Cells[0]; } else { if (i < dgvRegimen.RowCount - 1) { dgvRegimen.Rows[i].Selected = false; } } } for (int i = 0; i < dgvTipoHabitacion.RowCount; i++) { if (dgvTipoHabitacion.Rows[i].Cells[0].Value.ToString() == reserva.tipo_habitacion) { dgvTipoHabitacion.Rows[i].Selected = true; this.dgvTipoHabitacion.CurrentCell = this.dgvTipoHabitacion.Rows[i].Cells[0]; } else { if (i < dgvTipoHabitacion.RowCount - 1) { dgvTipoHabitacion.Rows[i].Selected = false; } } } buttonGuardar.Enabled = true; dtFechaDesde.Enabled = true; dtFechaHasta.Enabled = true; }
private void buttonSearch_Click(object sender, EventArgs e) { Reserva reserva = this.getDataToSearch(); ReservaHelper.search(reserva, dgvReserva); }
private void buttonReservar_Click(object sender, EventArgs e) { Boolean estaTodoOk = true; if (dgvTipoHabitacion.Rows.Count <= 0) { MessageBox.Show("El hotel no tiene habitaciones registradas"); estaTodoOk = false; return; } if (dgvRegimen.Rows.Count <= 0) { MessageBox.Show("El hotel no tiene regimenes registrados"); estaTodoOk = false; return; } if (dgvClient.Rows.Count == 0) { MessageBox.Show("Debe seleccionar algun cliente ya registrado, o registrar uno nuevo"); estaTodoOk = false; return; } else { if (dgvClient.CurrentRow.Selected == false) { MessageBox.Show("Debe seleccionar algun cliente ya registrado, o registrar uno nuevo"); estaTodoOk = false; } } if (VarGlobal.usuario.id == "guest" && cmbHotel.SelectedValue.ToString() != String.Empty) { VarGlobal.usuario.hotel = Convert.ToInt32(cmbHotel.SelectedValue.ToString()); ReservaHelper.search_regimen(VarGlobal.usuario.hotel, dgvRegimen); ReservaHelper.search_tipo_hab(VarGlobal.usuario.hotel, dgvTipoHabitacion); //estaTodoOk = false; } else { if (VarGlobal.usuario.id == "guest") { MessageBox.Show("Debe seleccionar algun hotel"); estaTodoOk = false; return; } } if (VarGlobal.usuario.id == "guest" && cmbHotel.Text == "") { MessageBox.Show("Debe seleccionar algun hotel"); estaTodoOk = false; return; } if (estaTodoOk) { Reserva reserva = this.getdataConsulta(); if (ReservaHelper.reservar(reserva)) { this.Close(); } } }