private void validarCompletarReserva(BD bd)
        {
            if (TxtCodigo.Text == "")
            {
                throw new Exception("No ha ingresado ninguna reserva.");
            }
            else
            {
                try
                {
                    string comando = "SELECT * FROM FUGAZZETA.[ReservasModificables] WHERE Id_Reserva = " + TxtCodigo.Text + " AND Id_Hotel = " + menu.hotelActual;
                    SqlDataReader dr = bd.lee(comando);
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            string fechaKey = dr["Fecha_Inicio"].ToString().Substring(0, 10);
                            if (fechaKey != Program.hoy().ToShortDateString())
                            {
                                dr.Close();
                                throw new Exception("No se puede ingresar con ese código de reserva. Corresponde al día " + fechaKey + ".");
                            }
                            TxtId.Text = dr[0].ToString();
                            idCliente = dr[1].ToString();
                            idHotel = dr[2].ToString();
                            TxtHotel.Text = dr[2].ToString();
                            TxtFecReserva.Text = ifNull(dr["Fecha_Reserva"].ToString()).Substring(0, 10);
                            TxtFecInicio.Text = fechaKey;
                            TxtFecFin.Text = dr["Fecha_Fin_Reserva"].ToString().Substring(0, 10);
                            
                            SqlDataReader r2d2;
                            r2d2 = bd.lee("SELECT Descripcion FROM FUGAZZETA.Regimenes WHERE Id_Regimen = " + dr["Id_Regimen"].ToString());
                            while (r2d2.Read())
                                TxtRegimen.Text = r2d2[0].ToString();
                            r2d2.Close();
                        }
                    }
                    else
                    {
                        dr.Close();
                        throw new Exception("Esto puede ser por varios motivos: La reserva no existe, pertenece a otro hotel, se ha cancelado o ya realizó el ingreso.");
                    }
                    dr.Close();
                }
                catch (SqlException sqlEx)
                {
                    throw new Exception("Error " + sqlEx.Number  + " de SQL: " + sqlEx.Message);
                }

            }
        }
        private void BajarHotel_Click(object sender, EventArgs e)
        {
            DialogResult confirmaBaja = MessageBox.Show("Está seguro de deshabilitar este hotel?", "Deshabilitar hotel", MessageBoxButtons.OKCancel);
            if (confirmaBaja == DialogResult.OK)
            {
                BD bd = new BD();
                bd.obtenerConexion();
                string parametros = TxtId.Text + ", '" + Program.hoy().ToShortDateString() + "', '" + HastaPick.Value.ToShortDateString() + "'"; 
                try
                {
                    string query = "EXEC FUGAZZETA.OcupacionEnHotelEnPeriodo " + parametros;
                    SqlDataReader dr = bd.lee(query);
                    if (dr.HasRows)
                    {
                        throw new Exception("Hay reservas en ese período para el hotel.");
                    }
                    else
                    {
                        string query2 = "INSERT INTO FUGAZZETA.HistorialBajasHotel values (" + parametros +  ", '" + TxtMotivo.Text + "')";
                        bd.ejecutar(query2);

                    }

                }
                catch (Exception ex)
                {
                    this.DialogResult = DialogResult.Abort;
                    MessageBox.Show("No se pudo dar de baja el hotel. " + ex.Message);
                }
                
            }

        }
        private void Mostrar_Click(object sender, EventArgs e)
        {
            string condicion = "";
            if (TxtReserva.Text == "") MessageBox.Show("No se ingresó ninguna reserva.", this.Text, MessageBoxButtons.OK);
            else
            {
                idReserva = Int32.Parse(TxtReserva.Text);
                BD bd = new BD();
                bd.obtenerConexion();
                if (menu.usuarioActual != "guest")
                {
                    HotelClick.Enabled = false;
                    idHotel = menu.hotelActual;
                    TxtHotel.Text = idHotel.ToString();
                    condicion = " AND Id_Hotel = " + idHotel;
                }
                //CARGA DATOS ESTADIA
                SqlDataReader dr = bd.lee("SELECT * FROM FUGAZZETA.[ReservasModificables] WHERE Id_Reserva = " + idReserva + condicion);
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        idHotel = Int32.Parse(dr[2].ToString());
                        TxtHotel.Text = idHotel.ToString();
                        Desde.Value = Convert.ToDateTime(dr[4].ToString());
                        Hasta.Value = Convert.ToDateTime(dr[5].ToString());
                        idRegimen = dr[6].ToString();
                    }
                    dr.Close();

                    //CARGA REGIMENES
                    restaurarRegimenes(bd);
                    CbRegimen.Text = idRegimen;
                    string elRegimen = "";
                    for (int i = 0; i < CbRegimen.Items.Count; i++)
                    {
                        if ((CbRegimen.Items[i] as Regimen).id.ToString() == idRegimen)
                            elRegimen = CbRegimen.Items[i].ToString();                        
                    }
                    CbRegimen.Text = elRegimen;


                    //CARGA HABITACIONES
                    cargarYLiberarHabitaciones(bd);
                    GroupReserva.Enabled = true;
                    MostrarDatos.Enabled = false;
                    huboCambios = false;
                }
                else
                {
                    dr.Close();
                    MessageBox.Show("No se encontró la reserva o la misma no pertenece al hotel logueado.", this.Text);
                }
            }
        }
 private void cargarTiposDoc()
 {
     BD bd = new BD();
     string query = "SELECT * FROM FUGAZZETA.TiposDoc";
     SqlDataReader dr = bd.lee(query);
     while (dr.Read())
     {
         CbTipoDoc.Items.Add(new ABM_de_Cliente.TipoDoc(dr[0].ToString(), dr[1].ToString()));
     }
     bd.cerrar();
 }
 public HotelxRol(string idHotel, string idRol)
 {
     BD bd = new BD();
     bd.obtenerConexion();
     string query = "SELECT H.Nombre, R.Nombre FROM FUGAZZETA.Roles R, FUGAZZETA.Hoteles H WHERE H.Id_Hotel = " + idHotel + " AND R.Id_Rol = " + idRol;
     SqlDataReader dr = bd.lee(query);
     while (dr.Read())
     {
         hotel = new Hotel(idHotel, dr[0].ToString());
         rol = new Rol(idRol, dr[1].ToString());
     }
 }
 public Cliente(string unId, string nombreApellido)
 {
     string apn = "";
     BD bd = new BD();
     bd.obtenerConexion();
     SqlDataReader r2d2 = bd.lee("SELECT Apellido,Nombre FROM FUGAZZETA.Clientes WHERE Id_Cliente = " + unId);
     while (r2d2.Read())
         apn = r2d2["Apellido"].ToString() + ", " + r2d2["Nombre"].ToString();
     r2d2.Close();
     bd.cerrar();
     asigna(unId, apn);
 }
 private void CheckOut_Load(object sender, EventArgs e)
 {
     cargarGrilla(GridConsumibles, todos);
     GridCarrito.DataSource = carrito.tabla;
     BD bd2 = new BD();
     bd2.obtenerConexion();
     loadBancos();
     loadTarjetas();
     SqlDataReader dr = bd2.lee("SELECT Id_TipoPago FROM FUGAZZETA.TiposPago WHERE Descripcion = 'Efectivo'");
     while (dr.Read()) OpEfectivo.Tag = dr[0].ToString();
     dr.Close();
     bd2.cerrar();
 }
 public Consumible(string unID, string name)
 {
     asigna(unID, name);
     BD bd = new BD();
     bd.obtenerConexion();
     SqlDataReader dr = bd.lee("SELECT Precio FROM FUGAZZETA.Consumibles where Id_Consumible = " + id);
     while (dr.Read())
     {
         precio = Convert.ToDouble(dr[0].ToString());
     }
     dr.Close();
     bd.cerrar();
 }
 private void CmdIngresar_Click(object sender, EventArgs e)
 {
     if (TxtUser.Text == "guest") Guest_Click(sender, e);
     else
     {
         BD bd = new BD();
         bd.obtenerConexion();
         string comando = "SELECT Username,Contraseña FROM FUGAZZETA.[UsuariosHabilitados] WHERE Username='******'";
         SqlDataReader tabla = bd.lee(comando);
         try
         {
             if (tabla.HasRows)
             {
                 tabla.Read();
                 string pass = tabla[1].ToString();
                 if (Hashing.SHA256Encrypt(TxtPass.Text) == pass)
                 {
                     userActual = TxtUser.Text;
                     LblError.Text = "";
                     bd.ejecutar("EXEC FUGAZZETA.LoginCorrecto '" + TxtUser.Text + "'");
                     tabla.Close();
                     LoginOK login = new LoginOK(this, menu);
                     login.StartPosition = FormStartPosition.CenterScreen;
                     if (login.ShowDialog() == DialogResult.OK)
                         IrAMenuPrincipal(userActual);
                 }
                 else
                 {
                     try
                     {
                         bd.ejecutar("EXEC FUGAZZETA.LoginIncorrecto '" + TxtUser.Text + "'");
                         throw new Exception("Contraseña incorrecta");
                     }
                     catch (SqlException ex)
                     {
                         throw (ex as Exception);
                     }
                 }
                 tabla.Close();
             }
             else throw new Exception("Usuario no encontrado o inhabilitado por el administrador.");
         }
         catch (Exception ex)
         {
             LblError.Visible = true;
             LblError.Text = ex.Message;
         }
         bd.cerrar();
         tabla.Close();
     }
 }
 public BuscarCliente(ITraeBusqueda owner, char funcion)
 {
     InitializeComponent();
     BD bd = new BD();
     bd.obtenerConexion();
     dondeVuelve = owner;
     setearGrid(GridClientes);
     crearBuscador(dondeVuelve, "*", "Clientes");
     SqlDataReader reader = bd.lee("SELECT * FROM FUGAZZETA.TiposDoc");
     while (reader.Read())
         ComboDoc.Items.Add(new TipoDoc(reader[0].ToString(), reader[1].ToString()));
     reader.Close();
     bd.cerrar();
     fx = funcion;
 }
        private void cargarCombos()
        {
            CmbTipo.Items.Clear();

            BD bd = new BD();
            bd.obtenerConexion();
            
            string query = "SELECT * FROM FUGAZZETA.TiposHabitacion ORDER BY Id_TipoHab";
            SqlDataReader dr = bd.lee(query);
            while (dr.Read())
            {
                TipoHabitacion tipo = new TipoHabitacion(dr[0].ToString(), dr[1].ToString());
                CmbTipo.Items.Add(tipo);
            }
            dr.Close();
        }
Ejemplo n.º 12
0
        private void LoginOK_Load(object sender, EventArgs e)
        {
            CbHoteles.Items.Clear();
            string query = "SELECT UHR.Id_Hotel,UHR.Id_Rol FROM FUGAZZETA.Roles R, FUGAZZETA.[Usuarios x Hoteles x Rol] UHR WHERE R.Id_Rol=UHR.Id_Rol AND R.Estado=1 AND UHR.Username = '******'";
            BD bd = new BD();
            bd.obtenerConexion();
            SqlDataReader dr = bd.lee(query);
            while (dr.Read()) CbHoteles.Items.Add(new HotelxRol(dr[0].ToString(), dr[1].ToString()));
            dr.Close();
            bd.cerrar();

            if (CbHoteles.Items.Count == 1){
                loguear(CbHoteles.Items[0]);
                this.DialogResult = DialogResult.OK;
            }
            if (CbHoteles.Items.Count == 0){
                MessageBox.Show("No está habilitado en ningun hotel.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Retry; ;
            }
        }
 private void loadTarjetas()
 {
     BD bd2 = new BD();
     bd2.obtenerConexion();
     CbTipoPago.Items.Clear();
     try
     {
         string comando = "SELECT * FROM FUGAZZETA.TiposPago WHERE Descripcion != 'Efectivo'";
         SqlDataReader respuesta = bd2.lee(comando);
         while (respuesta.Read())
         {
             CbTipoPago.Items.Add(new TipoPago(respuesta[0].ToString(), respuesta[1].ToString()));
         }
         respuesta.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error al completar: " + ex.Message);
     }
     bd2.cerrar();
 }
 private void loadBancos()
 {
     BD bd2 = new BD();
     bd2.obtenerConexion();
     CbBanco.Items.Clear();
     try
     {
         string comando = "SELECT * FROM FUGAZZETA.Bancos";
         SqlDataReader respuesta = bd2.lee(comando);
         while (respuesta.Read())
         {
             CbBanco.Items.Add(new Banco(Int16.Parse(respuesta[0].ToString()),respuesta[1].ToString()));
         }
         respuesta.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error al completar: " + ex.Message);
     }
     bd2.cerrar();
 }
        private void ModificarHotel_Load(object sender, EventArgs e)
        {   
                    
            groupBox1.Enabled = false;
            FechaPick.MaxDate = Program.hoy();
            
            BD bd = new BD();
            string query = "SELECT * FROM FUGAZZETA.Paises ORDER BY Nombre";
            SqlDataReader dr = bd.lee(query);
            while (dr.Read())
            {
                ComboPais.Items.Add(new Pais(dr[0].ToString(), dr[1].ToString()));
            }

            if (funcion=='A'){
                groupBox1.Enabled = true;
                Mostrar.Visible = false;
                label2.Visible=false;
                groupBox2.Enabled = false;
            }
        }
 private void validarContraseña(BD bd)
 {
     if (menu.usuarioActual != "guest")
     {
         if (TxtPass.Text == "")
         {
             throw new Exception("Debe completar una contraseña. ");
         }
         string query = "SELECT Contraseña FROM FUGAZZETA.Usuarios WHERE Username = '******'";
         SqlDataReader dr = bd.lee(query);
         while (dr.Read())
         {
             if (dr[0].ToString() != Hashing.SHA256Encrypt(TxtPass.Text))
             {
                 dr.Close();
                 throw new Exception("La contraseña es incorrecta.");
             }
         }
         dr.Close();
     }
 }
 private void Guest_Click(object sender, EventArgs e)
 {
     BD bd = new BD();
     bd.obtenerConexion();
     string comando = "SELECT Estado FROM FUGAZZETA.Roles WHERE Nombre='Guest'";
     SqlDataReader estado = bd.lee(comando);
     while (estado.Read())
     {
         if (Convert.ToInt32(estado[0]) == 1)
         {
             IrAMenuPrincipal("guest");
             menu.hotelActual = 1;
             menu.rolActual = "Guest";
         }
         else MessageBox.Show("No es posible entrar como guest. Rol Inhabilitado.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     estado.Close();
     bd.cerrar();
     
     
 }
 private void generarLaReserva()
 {
     BD bd = new BD();
     bd.obtenerConexion();
     int idRegimen = (ComboRegimen.SelectedItem as ABM_de_Regimen.Regimen).id;
     string usuario = menuP.usuarioActual;
     string query = "EXEC FUGAZZETA.GenerarReserva " + idClienteActual + ", " + idHotelActual + ", '" + Program.ahora().ToString() + "', '" + DesdePick.Value.ToShortDateString() + "', '" + HastaPick.Value.ToShortDateString() + "', " + idRegimen + ", '" + usuario + "'";
     SqlDataReader reader = bd.lee(query);
     while (reader.Read())
     {
         idReservaGenerada = Int32.Parse(reader[0].ToString());
     }
     reader.Close();
     
     for (int i=0; i < ListHabitaciones.Items.Count; i++)
     {
         string numHabitacion = (ListHabitaciones.Items[i] as ABM_de_Habitacion.Habitacion).numero.ToString();
         query = "INSERT INTO FUGAZZETA.[Habitaciones x Reservas] values (" + idReservaGenerada + ", " + idHotelActual + ", " + numHabitacion + ")";
         bd.ejecutar(query);
     }
     bd.cerrar();
 }
        private void cargar()
        {
            if (funcion == 'M')
            {
                BD bd = new BD();
                bd.obtenerConexion();
                int elId = Convert.ToInt32(tuId);
                string query = "SELECT * FROM FUGAZZETA.Habitaciones WHERE Num_Habitacion = " + elId + " and Id_Hotel = " + tuHotel;
                SqlDataReader dr = bd.lee(query);

                while (dr.Read())
                {
                    TxtNro.Text = dr["Num_Habitacion"].ToString();
                    TxtPiso.Text = dr["Piso"].ToString();
                    TxtDesc.Text = dr["Comodidades"].ToString();
                    
                    string frente = dr["Frente"].ToString();
                    if (frente == "S") { Exterior.Checked = true; }
                    if (frente == "N") { Interior.Checked = true; }

                    string elItem = "";
                    for (int i = 0; i < CmbTipo.Items.Count; i++)
                    {

                        if ((CmbTipo.Items[i] as TipoHabitacion).id.ToString() == dr["Id_TipoHab"].ToString())
                        {
                            elItem = CmbTipo.Items[i].ToString();
                        }
                    }
                    CmbTipo.Text = elItem;

                    ChkHabilitada.Checked = Convert.ToBoolean(dr["Habilitado"].ToString());
                }
                dr.Close();
                                               
                bd.cerrar();
            }
        }
 private void CargarTipoDocNacPaises()
 {
     BD bd = new BD();
     bd.obtenerConexion();
     string query = "SELECT * FROM FUGAZZETA.Paises ORDER BY Nombre";
     SqlDataReader dr = bd.lee(query);
     while (dr.Read())
     {
         Pais pais = new Pais(dr[0].ToString(), dr[1].ToString());
         ComboPais.Items.Add(pais);
         ComboNac.Items.Add(pais);
     }
     dr.Close();
     query = "SELECT * FROM FUGAZZETA.TiposDoc";
     dr = bd.lee(query);
     while (dr.Read()) TipoDoc.Items.Add(new TipoDoc(dr[0].ToString(), dr[1].ToString()));
     bd.cerrar();
 }
        private void actualizarHabitacion()
        {
            BD bd = new BD();
            bd.obtenerConexion();

            string habitacionRepetida = "select * from FUGAZZETA.Habitaciones H where Num_Habitacion=" + TxtNro.Text+" and Id_Hotel="+tuHotel.ToString()+" and Num_Habitacion<>"+tuId;
            SqlDataReader dr = bd.lee(habitacionRepetida);
            while (dr.Read())
            {
                if ((dr.HasRows)) throw new Exception("Ese número de habitación ya existe en el hotel.");
            }
            dr.Close();

            char frente ='N';
            if (Exterior.Checked == true) { frente = 'S'; }
            if (Interior.Checked == true) { frente = 'N'; }
            string comando =
                "UPDATE FUGAZZETA.Habitaciones SET Id_Hotel="+tuHotel.ToString()+
                ", Num_Habitacion =" + TxtNro.Text +
                ", Piso = " + TxtPiso.Text +
                ", Comodidades = '" + TxtDesc.Text +
                "', Frente = '" + frente +
                "', Habilitado = " + Convert.ToSByte(ChkHabilitada.Checked) +
                " WHERE Num_Habitacion = " + tuId+" and Id_Hotel="+tuHotel.ToString();
            bd.ejecutar(comando);
            
            

            bd.cerrar();
            MessageBox.Show("Actualización realizada con éxito");
           
        }
 private void validarDocumento(BD bd)
 {
     string comando = "";
     if(Id.Text=="--"){
             comando = "SELECT Id_TipoDoc, Nro_Doc FROM FUGAZZETA.Clientes WHERE Nro_Doc = " + TxtNroDoc.Text + " AND Id_TipoDoc ";}
         else{
             comando = "SELECT Id_TipoDoc, Nro_Doc FROM FUGAZZETA.Clientes WHERE Id_Cliente<>"+Id.Text+" AND Nro_Doc = " + TxtNroDoc.Text + " AND Id_TipoDoc ";}
     
     if (TipoDoc.SelectedIndex == -1) comando += "IS NULL";
     else comando += "= " + (TipoDoc.SelectedItem as TipoDoc).id.ToString();
     SqlDataReader tabla = bd.lee(comando);
     if (tabla.HasRows)
         {
             tabla.Close();
             throw new Exception("Ya está registrado ese documento en el sistema.");
         }
     tabla.Close();
 }
 private void completaRegimenes(BD db)
 {
     string query = "SELECT R.Id_Regimen, R.Descripcion FROM FUGAZZETA.Regimenes R, FUGAZZETA.[Regimenes x Hotel] H WHERE H.Id_Regimen = R.Id_Regimen and H.Id_Hotel = " + idHotelActual;
     SqlDataReader reader = db.lee(query);
     while (reader.Read())
     {
         ComboRegimen.Items.Add(new ABM_de_Regimen.Regimen(reader[0].ToString(), reader[1].ToString()));
     }
     reader.Close();
 }
        void ITraeBusqueda.agregar(string id, string descripcion)
        {
            BD db = new BD();
            db.obtenerConexion();
            SqlDataReader reader;
            string query;
            switch (nBuscador)
            {
                case 1:
                    bool estaHabilitado = true;
                    query = "SELECT * FROM FUGAZZETA.Clientes WHERE Id_Cliente = " + id;
                    reader = db.lee(query);
                    while (reader.Read())
                    {
                        // Valida al usuario primero. Si no está habilitado, cierra todo.
                        estaHabilitado = Convert.ToBoolean(reader["Habilitado"].ToString());
                        if (!estaHabilitado)
                        {
                            reader.Close();
                            MessageBox.Show("El cliente no está habilitado por la cadena para realizar la reserva. Consulte con Recepción o Administración para regularizar la situación.");
                            this.Close();
                            break;
                        }
                        //Si está validado, completa los datos.
                        SqlDataReader r2d2;
                        idClienteActual = Int32.Parse(id);
                        TxtNombre.Text = reader[1].ToString() + " " + reader[2].ToString();

                        r2d2 = db.lee("SELECT Descripcion FROM FUGAZZETA.TiposDoc WHERE Id_TipoDoc = " + reader[3].ToString());
                        while (r2d2.Read())
                            TxtDoc.Text = r2d2[0].ToString() + " " + reader[4].ToString();
                        //r2d2.Close();
                        r2d2 = db.lee("SELECT Nombre FROM FUGAZZETA.Paises WHERE Id_Pais =" + reader["Nacionalidad"].ToString());
                        while (r2d2.Read())
                            TxtPais.Text = r2d2[0].ToString();
                        r2d2.Close();
                        
                        TxtNac.Text = reader[5].ToString().Substring(0, 10);
                        TxtMail.Text = reader[6].ToString();
                        TxtTelefono.Text = reader[7].ToString();
                        TxtDomicilio.Text = reader[8].ToString() + " " + reader[9].ToString() + " " + reader[10].ToString() + " " + reader[11].ToString();
                        TxtCiudad.Text = reader[12].ToString();
                    }
                    reader.Close();
                    break;
                case 2:
                    ComboRegimen.Items.Clear();
                    idHotelActual = Int32.Parse(id);
                    string texto = "";
                    if (descripcion.Length == 0) texto = id;
                    else texto = descripcion;
                    TxtHotel.Text = texto;
                    completaRegimenes(db);
                    break;
                case 3:
                                       
                    break;
                case 4:
                    ComboRegimen.Text = descripcion;
                    break;
            }
            db.cerrar();
        }
 private void validarMail(BD bd)
 {
     string comando = "";
     if(Id.Text=="--"){
             comando = "SELECT Mail FROM FUGAZZETA.Clientes WHERE Mail='" + TxtMail.Text + "'";}
         else{
             comando = "SELECT Mail FROM FUGAZZETA.Clientes WHERE Id_Cliente<>" + Id.Text + " AND Mail='" + TxtMail.Text + "'";}
     SqlDataReader tabla = bd.lee(comando);
     if (tabla.HasRows)
     {
         tabla.Close();
         throw new Exception("Ya existe un usuario registrado con ese mail.");
     }
     tabla.Close();
 }
        private void Guardar_Click(object sender, EventArgs e)
        {
            try {
               
                ValidarTxt(TxtNro, "Número");
                ValidarTxt(TxtPiso, "Piso");
                if (!Interior.Checked && !Exterior.Checked)
                    throw new Exception("No seleccionó la ubicación.");
                if (CmbTipo.SelectedIndex == -1)
                    throw new Exception("No seleccionó el tipo de habitación.");
                
            if (funcion == 'M')
            {
                DialogResult confirma = MessageBox.Show("Son todos los datos correctos?", "Confirmar actualización de habitacion", MessageBoxButtons.YesNo);

                if (confirma == DialogResult.Yes)
                {
                    actualizarHabitacion();
                }
            }
            else{
            DialogResult confirma = MessageBox.Show("Son todos los datos correctos? Recuerde que el Tipo de Habitación es definitivo", this.Text, MessageBoxButtons.YesNo);

            if (confirma == DialogResult.Yes)
            {
                BD bd = new BD();
                bd.obtenerConexion();
               
                string habitacionRepetida = "select * from FUGAZZETA.Habitaciones H where Num_Habitacion=" + TxtNro.Text+" and Id_Hotel="+tuHotel.ToString();
                SqlDataReader dr = bd.lee(habitacionRepetida);
                while (dr.Read())
                {
                    if ((dr.HasRows)) throw new Exception("Ese número de habitación ya existe en el hotel.");
                }
                dr.Close();

                    char frente='N';
                    if (Exterior.Checked) frente = 'S';
                    if (Interior.Checked) frente = 'N';

                    TipoHabitacion elTipo = CmbTipo.Items[CmbTipo.SelectedIndex] as TipoHabitacion;
                    
                    string query = 
                        "INSERT INTO FUGAZZETA.Habitaciones values ("
                        +tuHotel+","
                        +TxtNro.Text+","
                        +TxtPiso.Text+",'"
                        +frente+"',"
                        +elTipo.id+",'"
                        +TxtDesc.Text+"',"
                        +Convert.ToSByte(ChkHabilitada.Checked) + ")"
                        ;
                    bd.ejecutar(query);
                    bd.cerrar();
                    MessageBox.Show("Habitacion agregada con éxito");
                    this.Close();
                }
                 }
            }
            catch (Exception ex)
                {
                    bd.cerrar();
                    MessageBox.Show("Error: No se pudo ingresar la habitación. " + ex.Message);
                }
        }
 private bool esDuplicado(string id)
 {
     bool duplica=false;
     BD bd = new BD();
     bd.obtenerConexion();
     string query = "SELECT * FROM FUGAZZETA.ClientesDuplicados where Id_Cliente="+id;
     SqlDataReader dr = bd.lee(query);
     while (dr.Read())
         duplica = dr.HasRows;
     dr.Close();
     bd.cerrar();
     return duplica;
 }
 private void validarReserva(BD bd)
 {
     if (TxtCodigo.Text == "")
     {
         throw new Exception("No ingresó ningún código de reserva.");
     }
     else
     {
         string condicion = "";
         if (menu.usuarioActual != "guest")
         {
             condicion = " AND Id_Hotel = " + menu.hotelActual;
         }
         string query = "SELECT * FROM FUGAZZETA.ReservasModificables WHERE Id_Reserva = " + TxtCodigo.Text + condicion;
         SqlDataReader dr = bd.lee(query);
         if (!dr.HasRows)
         {
             dr.Close();
             throw new Exception("La reserva que intenta cancelar no existe, pertenece a otro hotel o ya fue cancelada.");
         }
         dr.Close();
     }
 }
 private void AgregarCliente_Click(object sender, EventArgs e)
 {
     DialogResult exito = new AltaCliente().ShowDialog();
     if (exito == DialogResult.OK)
     {
         BD db = new BD();
         SqlDataReader dr = db.lee("SELECT TOP 1 * FROM FUGAZZETA.Clientes ORDER BY Id_Cliente DESC");
         string id = "";
         string apellidonombre = "";
         while (dr.Read())
         {
             id = dr[0].ToString();
             apellidonombre = dr[2].ToString() + ", " + dr[1].ToString();
         }
         dr.Close();
         dondeVuelve.agregar(id, apellidonombre);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
 private void valida(string tabla,string campo, int id, string mensajeException)
 {
     bool estaHabilitado = true;
     DateTime fechaFin=DesdePick.Value;
     BD bd = new BD();
     bd.obtenerConexion();
     string query = "SELECT Habilitado FROM FUGAZZETA." + tabla + " where " + campo + " = " + id;
     SqlDataReader dr = bd.lee(query);
     while (dr.Read())
     {
         estaHabilitado = Convert.ToBoolean(dr[0].ToString());
     }
     dr.Close();
     if (!estaHabilitado)
     {
         query = "SELECT top 1 Fecha_Fin FROM FUGAZZETA.HistorialBajasHotel where Id_Hotel="+id+" order by Fecha_Inicio";
         dr = bd.lee(query);
         while (dr.Read())
         {
             fechaFin = Convert.ToDateTime(dr[0].ToString());
         }
         if (DesdePick.Value<fechaFin) throw new Exception(mensajeException);
     }
     bd.cerrar();
 }