コード例 #1
0
        private void Guardar()
        {
            lblResultado.Text = string.Empty;
            Reserva reserva = new Reserva();
            string  mensaje = Estaticas.Validaciones(Controls);

            if (mensaje != "")
            {
                MessageBox.Show(mensaje, "Datos invalidos", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    if (_tipo != AbmTipo.Alta)
                    {
                        reserva.Id = int.Parse(txtIdReserva.Text);
                    }
                    reserva.IdHabitacion      = int.Parse(txtIdHabitacion.Text);
                    reserva.IdCliente         = int.Parse(txtIdCliente.Text);
                    reserva.CantidadHuespedes = int.Parse(txtNroHuespedes.Text);
                    reserva.FechaIngreso      = dtFechaIngreso.Value;
                    reserva.FechaEgreso       = dtFechaEgreso.Value;
                    if (_hh == null)
                    {
                        _hh = _hotelServicios.TraerTodoPorId(int.Parse(txtIdHotel.Text)).SingleOrDefault(x => x.Id == reserva.IdHabitacion);
                        if (_hh == null)
                        {
                            throw new ReservasException("Debe seleccionar una habitacion valida.");
                        }
                    }

                    int resultado = -1;
                    switch (_tipo)
                    {
                    case AbmTipo.Alta:
                        resultado = _hotelServicios.IngresarReserva(reserva, _hh);
                        LogHelper.LogResultado(lblResultado, resultado, "Ingresar Reserva");
                        break;

                    case AbmTipo.Modificacion:
                        resultado = _hotelServicios.ModificarReserva(reserva, _hh);
                        LogHelper.LogResultado(lblResultado, resultado, "Modificar Reserva");
                        break;
                    }
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception e)
                {
                    LogHelper.LogResultado(lblResultado, false, e.Message);
                }
            }
        }