Exemplo n.º 1
0
        private void button_Save_Click(object sender, EventArgs e)
        {
            string      myQuery;
            DbResultSet rs;
            int         idReserva;

            if (!CheckFields())
            {
                return;
            }

            if (this.button_Save.Text.Equals("Submit"))
            {
                idReserva = Convert.ToInt32(textBox_idReserva.Text);
                int idEstadia = DbManager.Process_CheckIn(idReserva, currentHotel, currentUser);

                if (idEstadia < 0)
                {
                    MessageBox.Show("No se pudo procesar el Check-In",
                                    "Reserva cancelada",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    return;
                }

                foreach (int Huesped in Huespedes)
                {
                    myQuery = "INSERT INTO ENER_LAND.Huespedes_Alojados (idEstadia, idHuesped) " +
                              "VALUES (" + idEstadia.ToString() + ", " + Huesped.ToString() + ")";

                    rs = DbManager.dbSqlStatementExec(myQuery);
                    if (rs.operationState == 1)
                    {
                        MessageBox.Show("No se pudo Agregar el Huesped. Posible fallo en la Base de Datos");
                        return;
                    }
                }

                MessageBox.Show("Check-In Correcto");
                FormPadre.Show();
                this.Dispose();
                return;
            }


            if (this.button_Save.Text.Equals("Add Huesped"))
            {
                ABM_de_Cliente.GestionHuesped formBusqueda = new FrbaHotel.ABM_de_Cliente.GestionHuesped(this);
                formBusqueda.Show();
                formBusqueda.Cargar_Busqueda(false); // No es Busqueda Reserva
            }

            if (this.button_Save.Text.Equals("Check"))
            {
                myQuery = "SELECT DISTINCT idHotel " +
                          "FROM ENER_LAND.Reserva_Habitacion R " +
                          "WHERE R.idReserva = " + textBox_idReserva.Text + " " +
                          "AND R.idHotel = " + currentHotel.ToString();

                rs = DbManager.GetDataTable(myQuery);

                if (rs.operationState == 1)
                {
                    MessageBox.Show("Fallo en BD");
                    return;
                }

                if (rs.dataTable.Rows.Count == 0)
                {
                    MessageBox.Show("La reserva no corresponde al hotel en el que se encuentra logueado.",
                                    "Hotel incorrecto",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    return;
                }

                myQuery = "SELECT   R1.idReserva, " +
                          "R1.idEstado_Reserva, " +
                          "R1.Cantidad_Dias, " +
                          "R1.Cantidad_Huespedes, " +
                          "R1.FechaDesde, " +
                          "R1.idHuesped, " +
                          "H.Habilitado, " +
                          "R2.Descripcion " +
                          "FROM ENER_LAND.Reserva R1, ENER_LAND.Regimen R2, ENER_LAND.Huesped H " +
                          "WHERE R1.idRegimen = R2.idRegimen " +
                          "AND H.idHuesped = R1.idHuesped " +
                          "AND R1.idReserva = " + textBox_idReserva.Text;

                rs = DbManager.GetDataTable(myQuery);

                if (rs.dataTable.Rows.Count == 1)
                {
                    int      idEstado_Reserva;
                    int      Cantidad_Dias;
                    int      Cantidad_Huespedes;
                    int      habilitado;
                    DateTime FechaDesde;
                    int      idHuesped;
                    string   Regimen_Descripcion;

                    idReserva           = Convert.ToInt32(rs.dataTable.Rows[0]["idReserva"].ToString());
                    idEstado_Reserva    = Convert.ToInt32(rs.dataTable.Rows[0]["idEstado_Reserva"].ToString());
                    Cantidad_Dias       = Convert.ToInt32(rs.dataTable.Rows[0]["Cantidad_Dias"].ToString());
                    Cantidad_Huespedes  = Convert.ToInt32(rs.dataTable.Rows[0]["Cantidad_Huespedes"].ToString());
                    FechaDesde          = Convert.ToDateTime(rs.dataTable.Rows[0]["FechaDesde"].ToString());
                    idHuesped           = Convert.ToInt32(rs.dataTable.Rows[0]["idHuesped"].ToString());
                    habilitado          = Convert.ToInt32(rs.dataTable.Rows[0]["Habilitado"].ToString());
                    Regimen_Descripcion = rs.dataTable.Rows[0]["Descripcion"].ToString();

                    if (idEstado_Reserva == 3 || idEstado_Reserva == 4 || idEstado_Reserva == 5)
                    {
                        MessageBox.Show("La reserva no es correcta",
                                        "Reserva cancelada",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                        return;
                    }

                    if (habilitado == 0)
                    {
                        MessageBox.Show("El Huesped se encuentra inhabilitado",
                                        "Huesped Incorrecto",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                        return;
                    }

                    textBox_CantHuespedes.Text = Cantidad_Huespedes.ToString();
                    textBox_CantidadDias.Text  = Cantidad_Dias.ToString();
                    textBox_Regimen.Text       = Regimen_Descripcion;

                    if (!FechaDesde.Equals(@FrbaHotel.Properties.Settings.Default.Fecha))
                    {
                        MessageBox.Show("La fecha de la reserva no es correcta",
                                        "Fecha erronea",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                        return;
                    }

                    if (Cantidad_Huespedes > 1)
                    {
                        button_Save.Text = "Add Huesped";
                    }
                    else
                    {
                        button_Save.Text = "Submit";
                    }

                    Huespedes.Add(idHuesped);
                }
            }

            Cargar_Huespedes();
        }