private void buttonConsultar_Click(object sender, EventArgs e) { { if (comboBoxRegimen.SelectedIndex == -1) { new ListadoRegimenHotel(idHotel, comboBoxRegimen).ShowDialog(); } if (habitaciones.Count == 0) { MessageBox.Show("No ingresó ninguna habitación", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); FormHandler.limpiar(groupBox2); return; } if (comboBoxRegimen.SelectedIndex == -1) { MessageBox.Show("Debe completar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (numericUpDownCantPersonas.Value == 0) { MessageBox.Show("Seleccione la cantidad de huespedes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } reserva = new Reserva(idHotel, habitaciones, comboBoxRegimen.SelectedValue.ToString(), (int)numericUpDownCantPersonas.Value); var cantNoches = reserva.cantNoches(dateTimePickerFechaDesde, dateTimePickerFechaHasta); if (numericUpDownCantPersonas.Value > reserva.cantPersonasQueEntran()) { MessageBox.Show("La cantidad de personas ingresada no entran en las habitaciones seleccionadas.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dateTimePickerFechaDesde.Value < ConfigManager.FechaSistema) { MessageBox.Show("La fecha de inicio de la reserva no puede ser anterior a la fecha actual.\n\nLa fecha de hoy es: " + ConfigManager.FechaSistema.ToString("yyyy-MM-dd"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cantNoches <= 0) { MessageBox.Show("Ingrese fechas válidas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { precioNoche = reserva.precioPorNoche(); textBoxPrecioPorNoche.Text = "U$S " + precioNoche.ToString(); textBoxCantNoches.Text = cantNoches.ToString(); textBoxPrecioTotal.Text = "U$S " + (cantNoches * precioNoche).ToString(); } } }
private void buttonGenerar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCantNoches.Text)) { MessageBox.Show("Consulte los datos de su reserva antes de generarla", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { var cantNoches = reserva.cantNoches(dateTimePickerFechaDesde, dateTimePickerFechaHasta); if (cantNoches <= 0) { MessageBox.Show("Ingrese fechas válidas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (numericUpDownCantPersonas.Value == 0) { MessageBox.Show("Seleccione la cantidad de huespedes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (idCliente == null) { MessageBox.Show("Ingrese el cliente para ponerlo a nombre de la reserva actual", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (DBHandler.SPWithBool("MATOTA.HotelHabilitadoParaFechasReserva", new List <SqlParameter> { new SqlParameter("@idHotel", idHotel), new SqlParameter("@fechaInicioReserva", dateTimePickerFechaDesde.Value), new SqlParameter("@fechaFinReserva", dateTimePickerFechaHasta.Value) })) { MessageBox.Show("El hotel seleccionado se encuentra inhabilitado durante las fechas de su reserva", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { var idReserva = DBHandler.SPWithValue("MATOTA.AltaReserva", new List <SqlParameter> { new SqlParameter("@idHotel", idHotel), new SqlParameter("@fechaReserva", ConfigManager.FechaSistema), new SqlParameter("@fechaDesde", dateTimePickerFechaDesde.Value), new SqlParameter("@fechaHasta", dateTimePickerFechaHasta.Value), new SqlParameter("@cantidadNoches", cantNoches), new SqlParameter("@idRegimen", comboBoxRegimen.SelectedValue), new SqlParameter("@idCliente", idCliente), new SqlParameter("@precioBase", precioNoche * cantNoches), new SqlParameter("@cantidadPersonas", numericUpDownCantPersonas.Value.ToString()), }); habitaciones.ForEach(hab => DBHandler.SPWithValue("MATOTA.agregarHabitacionesReservadas", new List <SqlParameter> { new SqlParameter("@nroHabitacion", hab), new SqlParameter("@idReserva", idReserva), new SqlParameter("@idHotel", idHotel) })); MessageBox.Show("Reserva realizada con éxito, el código de su reserva es: " + idReserva, "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception) { MessageBox.Show("Ocurrió un error al realizar la reserva.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }