Exemplo n.º 1
0
        public List <Marca> CargarMarcas()
        {
            List <Marca>  Listado  = new List <Marca>();
            SqlConnection Conexion = new SqlConnection();
            SqlCommand    Comando  = new SqlCommand();
            SqlDataReader Leeme;

            try
            {
                Conexion.ConnectionString = "data source=DESKTOP-91LML6F\\SQLEXPRESS; initial catalog=CATALOGO_DB; integrated security=sspi";
                Comando.CommandType       = System.Data.CommandType.Text;
                Comando.CommandText       = "select *from marcas";
                Comando.Connection        = Conexion;
                Conexion.Open();

                Leeme = Comando.ExecuteReader();

                while (Leeme.Read())
                {
                    Marca aux = new Marca();

                    aux.Id          = Leeme.GetInt32(0);
                    aux.NombreMarca = Leeme.GetString(1);

                    Listado.Add(aux);
                }

                return(Listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <Articulo> Listar()
        {
            //// Cambiar Ruta de Conexion en NegocioArticulo, NegocioCategoria y NegocioMarca.
            /// Insaurralde 819VH7M
            ///
            SqlConnection   Conexion = new SqlConnection("data source =DESKTOP-OC9KSLQ\\SQLEXPRESS;initial catalog = CATALOGO_DB;integrated security = sspi;");
            List <Articulo> Listado  = new List <Articulo>();
            SqlCommand      Comando  = new SqlCommand();
            SqlDataReader   Leeme;

            try
            {
                Comando.CommandType = System.Data.CommandType.Text;
                Comando.CommandText = "select P.Id, P.Codigo,P.Nombre, P.Descripcion, M.Descripcion[Marca], C.Descripcion[Categoria], P.ImagenUrl,P.Precio,M.Id, C.Id from ARTICULOS P, MARCAS M, CATEGORIAS C where P.IdMarca = m.Id AND P.IdCategoria = C.Id";
                Comando.Connection  = Conexion;
                Conexion.Open();

                Leeme = Comando.ExecuteReader();

                while (Leeme.Read())
                {
                    Articulo Art = new Articulo();

                    Art.Id          = Leeme.GetInt32(0);
                    Art.Codigo      = Leeme.GetString(1);
                    Art.Nombre      = Leeme.GetString(2);
                    Art.Descripcion = Leeme.GetString(3);

                    Art.Marca             = new Marca();
                    Art.Marca.NombreMarca = Leeme.GetString(4);

                    Art.Categoria = new Categoria();
                    Art.Categoria.NombreCategoria = Leeme.GetString(5);


                    Art.UrlImagen = Leeme.GetString(6);

                    Art.Precio = (double)Leeme.GetDecimal(7);

                    Art.Marca.Id     = Leeme.GetInt32(8);
                    Art.Categoria.Id = Leeme.GetInt32(9);

                    Listado.Add(Art);
                }

                return(Listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                Conexion.Close();
            }
        }
        public List <Producto> Listar()
        {
            SqlConnection Conexion = new SqlConnection("data source=DESKTOP-91LML6F\\SQLEXPRESS; initial catalog=CATALOGO_DB; integrated security=sspi");

            List <Producto> Listado = new List <Producto>();
            SqlCommand      Comando = new SqlCommand();
            SqlDataReader   Leeme;

            try
            {
                Comando.CommandType = System.Data.CommandType.Text;
                //Comando.CommandText = "select *from articulos";

                Comando.CommandText = "select A.Id, A.Codigo,A.Nombre, A.Descripcion, M.Descripcion[Marca], C.Descripcion[Categoria], A.ImagenUrl,A.Precio from ARTICULOS A, MARCAS M, CATEGORIAS C where A.IdMarca = m.Id AND A.IdCategoria = C.Id";
                Comando.Connection  = Conexion;

                Conexion.Open();

                Leeme = Comando.ExecuteReader();

                while (Leeme.Read())
                {
                    Producto auxiliar = new Producto();

                    ////auxiliar.Nombre = (string)Leeme["Nombre"];
                    auxiliar.Id                        = Leeme.GetInt32(0);
                    auxiliar.Codigo                    = Leeme.GetString(1);
                    auxiliar.Nombre                    = Leeme.GetString(2);
                    auxiliar.Descripcion               = Leeme.GetString(3);
                    auxiliar.marca                     = new Marca();
                    auxiliar.marca.NombreMarca         = Leeme.GetString(4);
                    auxiliar.categoria                 = new Categoria();
                    auxiliar.categoria.NombreCategoria = Leeme.GetString(5);
                    auxiliar.ImagenUrl                 = Leeme.GetString(6);
                    auxiliar.Precio                    = (double)Leeme.GetDecimal(7);

                    Listado.Add(auxiliar);
                }


                return(Listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                Conexion.Close();
            }
        }