Example #1
0
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            //Get values from input fields
            try
            {
                if (this.txtCantidadNoches.Text == "0" || this.txtNombreHuesped.Text == string.Empty || this.txtNumeroHabitacion.Text == string.Empty || this.txtPrecioPorNoche.Text == "0" || this.txtCanal.Text == string.Empty || txtComentario.Text == string.Empty || txtTotalNoche.Text == "0" || nudCantidadAdultos.Value == 0)
                {
                    MessageBox.Show("Falta ingresar algunos datos");
                }
                else
                {
                    nuevaReservacion.IdHuesped        = Convert.ToInt32(dgvHuesped.CurrentRow.Cells[0].Value.ToString());
                    nuevaReservacion.FechaLlegada     = dtpFechaLlegada.Value;
                    nuevaReservacion.FechaSalida      = dtpFechaSalida.Value;
                    nuevaReservacion.PrecioPorNoche   = float.Parse(txtPrecioPorNoche.Text);
                    nuevaReservacion.CantidadNoches   = Convert.ToInt32(txtCantidadNoches.Text);
                    nuevaReservacion.CantidadAdultos  = Convert.ToInt32(nudCantidadNinos.Value);
                    nuevaReservacion.CantidadInfantes = Convert.ToInt32(nudCantidadNinos.Value);
                    nuevaReservacion.Canal            = txtCanal.Text;
                    nuevaReservacion.Comentario       = txtComentario.Text;
                    nuevaReservacion.TotalPorEstadia  = float.Parse(txtTotalNoche.Text);
                    int idHabitacion = Convert.ToInt32(dgvHabitaciones.CurrentRow.Cells[0].Value.ToString());
                    int rev          = nuevaReservacion.SelectIdReservacion();
                    MessageBox.Show("ID DE RESERVACION:" + rev);
                    if (nuevaReservacion.Insert(nuevaReservacion) == true)
                    {
                        try
                        {
                            if (nuevaReservacion.Insert_reservacion_habitacion(idHabitacion, rev))
                            {
                                MessageBox.Show("Se ha insertado correctamente.");
                            }
                            else
                            {
                            }

                            //Insert a reservacion_hab
                            //nuevaReservacion.Insert_reservacion_habitacion(idHabitacion, Convert.ToInt32(nuevaReservacion.SelectIdReservacion()));
                        }
                        catch (Exception)
                        {
                        }

                        txtCantidadNoches.Clear();
                        dtpFechaLlegada.Value = DateTime.Now;
                        dtpFechaSalida.Value  = DateTime.Now;
                        txtPrecioPorNoche.Clear();
                        nudCantidadAdultos.Value = 0;
                        nudCantidadNinos.Value   = 0;
                        txtCanal.Clear();
                        txtComentario.Clear();
                        txtTotalNoche.Clear();
                        dgvHabitaciones.DataSource = habitacion.Select();
                        dgvHuesped.DataSource      = obj.VistaTabla();
                        btnGuardar.Enabled         = true;

                        MessageBox.Show("La reservación ha sido registrada.");
                    }
                    else
                    {
                        MessageBox.Show("Error al registrar reservación.");
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            if (editar == false)
            {
                if (this.txtBoxNombre.Text == string.Empty || this.txtBoxTipoHabitacion.Text == string.Empty || this.txtBoxNoches.Text == string.Empty || this.txtBoxTotal.Text == string.Empty)
                {
                    ErrorDatosFaltantes.confirmacionForm("ERROR");
                }
                else
                {
                    r.CantidadAdultos  = Convert.ToInt32(numAdultos.Value);
                    r.CantidadInfantes = Convert.ToInt32(numInfantes.Value);
                    r.Canal            = txtBoxCanal.Text;
                    r.Comentario       = txtBoxComentarios.Text;
                    r.PrecioPorNoche   = float.Parse(txtBoxPrecio.Text, CultureInfo.InvariantCulture.NumberFormat);
                    r.TotalPorEstadia  = float.Parse(txtBoxTotal.Text, CultureInfo.InvariantCulture.NumberFormat);


                    if (r.Insert(r) == true)
                    {
                        if (r.Insert_reservacion_habitacion(r.SelectIdReservacion(), r.IdHabitacion) == true)
                        {
                            Habitacion hab = new Habitacion();
                            hab.IsReserved(r.IdHabitacion, 1);
                            // MessageBox.Show("Sure");
                            Clear();

                            dateTimePickerLlegada.MinDate = DateTime.Today;
                            dateTimePickerSalida.MinDate  = DateTime.Today.AddDays(1);
                            calcularNoches();


                            FrmCorrecto.confirmacionForm("CORRECTO");
                        }
                    }
                    else
                    {
                        FrmSeguroCerrar.confirmacionForm("ERROR");
                    }
                }
            }
            if (editar == true)
            {
                if (this.txtBoxNombre.Text == string.Empty || this.txtBoxTipoHabitacion.Text == string.Empty || this.txtBoxNoches.Text == string.Empty || this.txtBoxTotal.Text == string.Empty)
                {
                    ErrorDatosFaltantes.confirmacionForm("ERROR");
                }
                else
                {
                    r.CantidadAdultos  = Convert.ToInt32(numAdultos.Value);
                    r.CantidadInfantes = Convert.ToInt32(numInfantes.Value);
                    r.Canal            = txtBoxCanal.Text;
                    r.Comentario       = txtBoxComentarios.Text;
                    r.PrecioPorNoche   = float.Parse(txtBoxPrecio.Text, CultureInfo.InvariantCulture.NumberFormat);
                    r.TotalPorEstadia  = float.Parse(txtBoxTotal.Text, CultureInfo.InvariantCulture.NumberFormat);
                    if (r.Update(r) == true)
                    {
                        if (r.Update_reservacion_habitacion(r.IdReservacion, r.IdHabitacion) == true)
                        {
                            btnBuscarCliente.Enabled = true;
                        }

                        dateTimePickerLlegada.MinDate = DateTime.Today;
                        dateTimePickerSalida.MinDate  = DateTime.Today.AddDays(1);
                        FrmCorrecto.confirmacionForm("CORRECTO");
                    }

                    else
                    {
                        FrmCorrecto.confirmacionForm("CORRECTO");
                    }
                }
            }
        }