Пример #1
0
        /// <summary>
        /// Modifica un globo. Si los modelos del globo son iguales, entonces ese es el que va a modificar.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool ModificarGlobo(Globo param)
        {
            bool ret = true;

            try
            {
                this.command = new SqlCommand();

                this.command.Parameters.AddWithValue("@Marca", param.Marca);
                this.command.Parameters.AddWithValue("@Modelo", param.Modelo);
                this.command.Parameters.AddWithValue("@VelocidadMaxima", param.VelocidadMaxima);
                this.command.Parameters.AddWithValue("@AlturaMaxima", param.AlturaMaxima);
                this.command.Parameters.AddWithValue("@Peso", param.Peso);
                this.command.Parameters.AddWithValue("@Largo", param.Largo);
                this.command.Parameters.AddWithValue("@Ancho", param.Ancho);
                this.command.Parameters.AddWithValue("@Anio", param.Anio);
                this.command.Parameters.AddWithValue("@CapacidadAire", param.CapacidadAire);
                this.command.Parameters.AddWithValue("@Pasajeros", param.Pasajeros);

                string sql = "UPDATE dbo.Globos";
                sql += " SET Marca = @Marca, Modelo = @Modelo, VelocidadMaxima = @VelocidadMaxima," +
                       " AlturaMaxima = @AlturaMaxima, Peso = @Peso, Largo = @Largo, Ancho = @Ancho," +
                       " Anio = @Anio, CapacidadAire = @CapacidadAire, Pasajeros = @Pasajeros";
                sql += " WHERE Modelo = @Modelo";

                this.command.CommandType = CommandType.Text;
                this.command.CommandText = sql;
                this.command.Connection  = this.connection;

                this.connection.Open();

                int hayCambios = this.command.ExecuteNonQuery();

                if (hayCambios == 0)
                {
                    ret = false;
                }
            }
            catch (Exception)
            {
                ret = false;
            }
            finally
            {
                if (this.connection.State == ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Agrega un globo a la tabla Globos
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool AgregarGlobo(Globo param)
        {
            bool ret = true;

            try
            {
                string sql = "INSERT INTO dbo.Globos (Marca, Modelo, VelocidadMaxima, AlturaMaxima," +
                             " Peso, Largo, Ancho, Anio, CapacidadAire, Pasajeros) VALUES (";
                sql = sql + "'" + param.Marca + "','" + param.Modelo + "'," + param.VelocidadMaxima.ToString() +
                      "," + param.AlturaMaxima.ToString() + "," + param.Peso.ToString() + "," + param.Largo.ToString()
                      + "," + param.Ancho.ToString() + "," + param.Anio.ToString() + "," + param.CapacidadAire.ToString() +
                      "," + param.Pasajeros.ToString() + ")";

                this.command             = new SqlCommand();
                this.command.CommandType = CommandType.Text;
                this.command.CommandText = sql;
                this.command.Connection  = this.connection;

                this.connection.Open();

                int hayCambios = this.command.ExecuteNonQuery();

                if (hayCambios == 0)
                {
                    ret = false;
                }
            }
            catch (Exception)
            {
                ret = false;
            }
            finally
            {
                if (this.connection.State == ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            return(ret);
        }
Пример #3
0
        /// <summary>
        /// TraerDatos selecciona de cada base de datos individual (aviones, helicopteros, globos), las filas de datos, y las
        /// agrega a una Lista<Aeronave>, que luego devuelve. Creé una variable var aux porque tuve problemas con el GetFloat(),
        /// que no me permitía pasar las variables de tipo float.
        /// </summary>
        /// <returns></returns>
        public Lista <Aeronave> TraerDatos()
        {
            Lista <Aeronave> lista = new Lista <Aeronave>(50);

            try
            {
                this.command = new SqlCommand();

                this.command.CommandType = CommandType.Text;
                this.command.CommandText = "SELECT * FROM dbo.Aviones";
                this.command.Connection  = this.connection;

                this.connection.Open();

                this.reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Avion avion = new Avion();
                    float peso  = avion.Peso;

                    avion.Marca           = reader[0].ToString();
                    avion.Modelo          = reader[1].ToString();
                    avion.VelocidadMaxima = reader.GetInt32(2);
                    avion.AlturaMaxima    = reader.GetInt32(3);
                    var aux = reader[4];
                    avion.Peso  = float.Parse(aux.ToString());
                    aux         = reader[5];
                    avion.Largo = float.Parse(aux.ToString());
                    aux         = reader[6];
                    avion.Ancho = float.Parse(aux.ToString());
                    avion.Anio  = reader.GetInt32(7);
                    int auxTipoAvion = reader.GetInt32(8);
                    int auxMotor     = reader.GetInt32(9);

                    switch (auxTipoAvion)
                    {
                    case 0:
                        avion.Tipo = EAvion.Jet;
                        break;

                    case 1:
                        avion.Tipo = EAvion.Ligero;
                        break;

                    case 2:
                        avion.Tipo = EAvion.Comercial;
                        break;
                    }

                    switch (auxMotor)
                    {
                    case 0:
                        avion.Motor = EMotores.Propulsores;
                        break;

                    case 1:
                        avion.Motor = EMotores.DeReaccion;
                        break;
                    }

                    lista.Agregar(avion);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (this.connection.State == ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            try
            {
                this.command = new SqlCommand();

                this.command.CommandType = CommandType.Text;
                this.command.CommandText = "SELECT * FROM dbo.Helicopteros";
                this.command.Connection  = this.connection;

                this.connection.Open();

                this.reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Helicoptero helicoptero = new Helicoptero();

                    helicoptero.Marca           = reader.GetString(0);
                    helicoptero.Modelo          = reader.GetString(1);
                    helicoptero.VelocidadMaxima = reader.GetInt32(2);
                    helicoptero.AlturaMaxima    = reader.GetInt32(3);
                    var aux = reader[4];
                    helicoptero.Peso = float.Parse(aux.ToString());
                    aux = reader[5];
                    helicoptero.Largo = float.Parse(aux.ToString());
                    aux = reader[6];
                    helicoptero.Ancho   = float.Parse(aux.ToString());
                    helicoptero.Anio    = reader.GetInt32(7);
                    helicoptero.Rotores = reader.GetInt32(8);
                    int auxTipoHelicoptero = reader.GetInt32(9);

                    switch (auxTipoHelicoptero)
                    {
                    case 0:
                        helicoptero.Tipo = EHelicoptero.Militar;
                        break;

                    case 1:
                        helicoptero.Tipo = EHelicoptero.Sanitario;
                        break;

                    case 2:
                        helicoptero.Tipo = EHelicoptero.Civil;
                        break;
                    }

                    lista.Agregar(helicoptero);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (this.connection.State == ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            try
            {
                this.command = new SqlCommand();

                this.command.CommandType = CommandType.Text;
                this.command.CommandText = "SELECT * FROM dbo.Globos";
                this.command.Connection  = this.connection;

                this.connection.Open();

                this.reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Globo globo = new Globo();

                    globo.Marca           = reader.GetString(0);
                    globo.Modelo          = reader.GetString(1);
                    globo.VelocidadMaxima = reader.GetInt32(2);
                    globo.AlturaMaxima    = reader.GetInt32(3);
                    var aux = reader[4];
                    globo.Peso          = float.Parse(aux.ToString());
                    aux                 = reader[5];
                    globo.Largo         = float.Parse(aux.ToString());
                    aux                 = reader[6];
                    globo.Ancho         = float.Parse(aux.ToString());
                    globo.Anio          = reader.GetInt32(7);
                    globo.CapacidadAire = reader.GetInt32(8);
                    globo.Pasajeros     = reader.GetInt32(9);

                    lista.Agregar(globo);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (this.connection.State == ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            return(lista);
        }