//CHECK-OUT private void onCheckout(object sender, EventArgs e) { if (!obtenerReserva()) { return; } Estadia estadiaout = EntityManager.getEntityManager().findBy <Estadia>("estadias.reserva_id", reserva_numero.ToString()); if (estadiaout == null) { MessageBox.Show("Primero debe hacer el check-in"); return; } //Validacion de que la salida no se haya hecho antes if (estadiaout.cant_noches != 0) { MessageBox.Show("La estadia ya ha sido efectivizada con anterioridad"); return; } //Calculo de la cantidad de noches que se hospedo int dias_desde_ingreso = DateTime.Compare(DateTime.Parse(fecha).Date, DateTime.Parse(reserva.fecha_inicio).Date); int cant_noches = int.Parse(DateTime.Parse(fecha).Subtract(DateTime.Parse(estadiaout.fecha_inicio)).TotalDays.ToString()); if (dias_desde_ingreso >= 0 && reserva.cant_noches >= cant_noches) { estadiaout.cant_noches = cant_noches; try { estadiaout.save(); } catch (ValidationException exception) { MessageBox.Show(exception.Message); return; } catch (SqlException exception) { MessageBox.Show(exception.Message); return; } Navigator.nextForm(this, new FrbaHotel.Registrar_Consumible.Form1(estadiaout)); } else { MessageBox.Show("Debe seleccionar una fecha posterior a la fecha de ingreso para hacer el checkout"); } }
//CHECK-IN private void onCheckIn(object sender, EventArgs e) { //Validacion de que exista la reserva if (!obtenerReserva()) { return; } Estadia es = EntityManager.getEntityManager().findBy <Estadia>("reserva_id", reserva.id.ToString()); //Validacion de que no se haya hecho el ingreso antes if (es != null) { MessageBox.Show("La estadia ya ha sido validada con anteriodad"); return; } //Comparacion de fechas, unicamente se puede ingresar el dia en que se reservo if (DateTime.Compare(DateTime.Parse(fecha).Date, DateTime.Parse(reserva.fecha_inicio).Date) == 0) { reserva.reserva_estado = 6; //reserva.fecha_cancelacion = ""; Estadia estadia = new Estadia(); estadia.fecha_inicio = fecha; estadia.reserva = reserva; try { reserva.save(); estadia.save(); } catch (ValidationException exception) { MessageBox.Show(exception.Message); return; } catch (SqlException exception) { MessageBox.Show(exception.Message); return; } MessageBox.Show("La estadía ha sido validada"); Navigator.nextForm(this, new FrbaHotel.Views.Registrar_Estadia.Ingreso(estadia)); } else if (DateTime.Compare(DateTime.Parse(fecha).Date, DateTime.Parse(reserva.fecha_inicio).Date) != 0) { MessageBox.Show("La fecha ingresada no es igual a la reservada"); } }