Exemplo n.º 1
0
        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");
                    }
                }
            }
        }
        private void BtnConfirmarSalida_Click(object sender, EventArgs e)
        {
            Factura_Reservacion f = new Factura_Reservacion();

            if (txtTotalAPagar.Text == "0")
            {
                //no debe
                f.IdReservacion = id;
                f.IdHuesped     = Convert.ToInt32(txtIdCliente.Text);
                f.Empleado      = txtAtendidoPor.Text;
                f.TotalAPagar   = Convert.ToSingle(txtTotalAPagar.Text);
                f.Fecha         = dtpFechaActual.Value;
                // f.FormaDePago = cmbFormaPago.Text;
                f.SubTotal = Convert.ToSingle(dgvFill.Rows[0].Cells[12].Value);
                // RESERVACION PASA DE CHECKED IN A CHECKED OUT
                Reservacion reserva = new Reservacion();
                reserva.IdReservacion = f.IdReservacion;
                reserva.CheckOut(reserva);
                // HABITACION PASA DE OCUPADA A DISPONIBLE Y SU ESTADO DE RESERVADA PASA A NEGATIVO
                Habitacion hab = new Habitacion();
                hab.IdHabitacion = Convert.ToInt32(dgvFill.Rows[0].Cells[3].Value);
                hab.CambiarEstados(hab.IdHabitacion, "Disponible");
                hab.IsReserved(hab.IdHabitacion, 0);
                FrmCorrecto.confirmacionForm("AGREGADO");
            }
            else
            {
                //debe
                if (cmbFormaPago.Text == string.Empty)
                {
                    ErrorDatosFaltantes.confirmacionForm("ERROR");
                }
                else
                {
                    if (cmbFormaPago.Text == "Tarjeta")
                    {
                        if (txtNombre.Text == string.Empty || txtTotalAPagar.Text == string.Empty || txtBoxDigitos.Text == string.Empty || txtBoxCompania.Text == string.Empty || txtAtendidoPor.Text == string.Empty)
                        {
                            ErrorDatosFaltantes.confirmacionForm("ERROR");
                        }
                        else
                        {
                            f.IdReservacion   = id;
                            f.IdHuesped       = Convert.ToInt32(txtIdCliente.Text);
                            f.Empleado        = txtAtendidoPor.Text;
                            f.TotalAPagar     = Convert.ToSingle(txtTotalAPagar.Text);
                            f.FormaDePago     = cmbFormaPago.Text;
                            f.SubTotal        = Convert.ToSingle(dgvFill.Rows[0].Cells[12].Value);
                            f.Fecha           = dtpFechaActual.Value;
                            f.UltimosDigitos  = Convert.ToInt32(txtBoxDigitos.Text);
                            f.CompaniaTarjeta = txtBoxCompania.Text;
                            if (txtDescuento.Text == string.Empty)
                            {
                                //do nothing
                            }
                            else
                            {
                                f.Descuento = Convert.ToSingle(txtDescuento.Text);
                            }


                            if (f.InsertTarjeta(f) == true)
                            {
                                // RESERVACION PASA DE SIN CONFIRMAR A CHECK IN
                                Reservacion reserva = new Reservacion();
                                reserva.IdReservacion = f.IdReservacion;
                                reserva.Confirmar(reserva);
                                // HABITACION PASA DE DISPONIBLE A OCUPADA
                                Habitacion hab = new Habitacion();
                                hab.IdHabitacion = Convert.ToInt32(dgvFill.Rows[0].Cells[3].Value);
                                hab.CambiarEstados(hab.IdHabitacion, "Disponible");
                                //   hab.IsReserved(hab.IdHabitacion, 1);
                                FrmCorrecto.confirmacionForm("CORRECTO");
                                f.IdFactura         = f.SelectIdFactura();
                                btnImprimir.Enabled = true;
                            }
                            else
                            {
                                FrmSeguroCerrar.confirmacionForm("ERROR");
                            }
                        }
                    }
                    if (cmbFormaPago.Text == "Efectivo")
                    {
                        if (txtNombre.Text == string.Empty || txtEfectivo.Text == string.Empty || txtTotalAPagar.Text == string.Empty || txtCambio.Text == string.Empty || txtAtendidoPor.Text == string.Empty)
                        {
                            ErrorDatosFaltantes.confirmacionForm("ERROR");
                        }
                        else
                        {
                            /*
                             * @IdReservacion, @IdHuesped, @SubTotal, @TotalAPagar, @Fecha, @FormaDePago, @EfectivoRecibido, @Devuelta
                             */
                            f.IdReservacion = id;
                            f.IdHuesped     = Convert.ToInt32(txtIdCliente.Text);
                            f.Empleado      = txtAtendidoPor.Text;
                            f.TotalAPagar   = Convert.ToSingle(txtTotalAPagar.Text);
                            f.Fecha         = dtpFechaActual.Value;
                            f.FormaDePago   = cmbFormaPago.Text;
                            f.SubTotal      = Convert.ToSingle(dgvFill.Rows[0].Cells[12].Value);
                            if (txtDescuento.Text == string.Empty)
                            {
                                //do nothing
                            }
                            else
                            {
                                f.Descuento = Convert.ToSingle(txtDescuento.Text);
                            }
                            if (txtEfectivo.Text == string.Empty)
                            {
                                //do nothing
                            }
                            else
                            {
                                f.EfectivoRecibido = Convert.ToSingle(txtEfectivo.Text);
                            }
                            if (txtCambio.Text == string.Empty)
                            {
                                //do nothing
                                ErrorDatosFaltantes.confirmacionForm("ERROR");
                            }
                            else
                            {
                                f.Devuelta = Convert.ToSingle(txtCambio.Text);
                            }

                            if (f.InsertEfectivo(f) == true && txtCambio.Text != "")
                            {
                                // RESERVACION PASA DE SIN CONFIRMAR A CHECK IN
                                Reservacion reserva = new Reservacion();
                                reserva.IdReservacion = f.IdReservacion;
                                reserva.Confirmar(reserva);
                                // HABITACION PASA DE OCUPADA A DISPONIBLE

                                Habitacion hab = new Habitacion();
                                hab.IdHabitacion = Convert.ToInt32(dgvFill.Rows[0].Cells[3].Value);
                                hab.CambiarEstados(hab.IdHabitacion, "Disponible");
                                //  hab.IsReserved(hab.IdHabitacion, 1);
                                FrmCorrecto.confirmacionForm("CORRECTO");
                                f.IdFactura         = f.SelectIdFactura();
                                btnImprimir.Enabled = true;
                            }
                            else
                            {
                                //  MessageBox.Show("Ha ocurrido un error al facturar.");
                            }
                        }
                    }
                }
            }
        }