Example #1
0
        /// <summary>
        /// Devuelve una lista de Saxofon quecontiene todos los elementos de ese tipo en la BD. Se construyen todos los elementos llamando a GenerateInstrumento.
        /// </summary>
        /// <returns></returns>
        public List <Saxofon> GetSaxofon()
        {
            List <Saxofon> saxofon = new List <Saxofon>();
            Saxofon        aux     = new Saxofon();

            int i = 0;
            List <ETipoSaxofon> tiposSaxofon   = new List <ETipoSaxofon>();
            List <ConsoleColor> color          = new List <ConsoleColor>();
            List <int>          idsInstrumento = new List <int>();

            try
            {
                this.comando = new SqlCommand();

                this.comando.CommandType = CommandType.Text;
                this.comando.CommandText = "SELECT * FROM Saxofon";
                this.comando.Connection  = this.conexion;

                this.conexion.Open();

                this.lector = comando.ExecuteReader();

                while (this.lector.Read())
                {
                    tiposSaxofon.Add((ETipoSaxofon)this.lector["Tipo"]);
                    color.Add((ConsoleColor)this.lector["Color"]);
                    idsInstrumento.Add((int)this.lector["idInstrumento"]);
                    i++;
                }

                this.conexion.Close();

                for (int j = 0; j < i; j++)
                {
                    aux = this.GenerateInstrumento(idsInstrumento[j], tiposSaxofon[j], color[j]);
                    saxofon.Add(aux);
                }

                this.lector.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (this.conexion.State == ConnectionState.Open)
                {
                    this.conexion.Close();
                }
            }

            return(saxofon);
        }
Example #2
0
        /// <summary>
        /// Construye un Saxofon a partir del idInstrumento de la misma y sus propiedades
        /// </summary>

        private Saxofon GenerateInstrumento(int idInstrumento, ETipoSaxofon tipoSaxofon, ConsoleColor color)
        {
            Saxofon aux = new Saxofon();

            try
            {
                this.comando = new SqlCommand();

                this.comando.CommandType = CommandType.Text;
                this.comando.CommandText = "SELECT * FROM Instrumento WHERE id = " + idInstrumento;
                this.comando.Connection  = this.conexion;

                this.conexion.Open();

                this.lector = comando.ExecuteReader();

                while (this.lector.Read())
                {
                    aux = new Saxofon(this.lector["Modelo"].ToString(),
                                      (ECalidad)this.lector["Calidad"],
                                      (bool)this.lector["Usado"],
                                      this.marcas[(int)this.lector["idMarca"]],
                                      (int)this.lector["Stock"],
                                      tipoSaxofon,
                                      color,
                                      (double)this.lector["Precio"]);
                }

                return(aux);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (this.conexion.State == ConnectionState.Open)
                {
                    this.conexion.Close();
                }
            }
        }