Beispiel #1
0
        public ArrayList leer_productos(int Categoria1)
        {
            string string1 = "", string2 = "";

            if (Categoria1 > -1)
            {
                string1 = "where Categoria = ";
                string2 = Convert.ToString(Categoria1);
            }

            try
            {
                ListaProductos = new ArrayList();
                ListaProductos.Clear();

                Producto producto = null;
                connServ.Abrir();

                using (SqlCommand command = new SqlCommand())
                {    //                                0    1        2      3         4        5     6          7
                    command.CommandText = "SELECT Id,Nombre,Categoria,Precio,PrecioOferta,Foto,Stock,StockComprometido FROM Productos " + string1 + string2;
                    command.Connection  = connServ.Conexion();

                    SqlDataReader rdr = command.ExecuteReader();

                    while (rdr.Read())
                    {
                        DAOSQL.DAOSQLCategorias miDAOSQLCat = DAOSQL.DAOSQLCategorias.Instancia();

                        /*
                         * byte[] image = (byte[])command.ExecuteScalar();
                         * MemoryStream ms1 = new MemoryStream(image);
                         * exceptionPictureBox.Image = Bitmap.FromStream (ms1);  //this is how it should be.  I was using Image.FromStream and was getting error.
                         */
                        byte[]       image             = (byte[])rdr.GetValue(5);
                        MemoryStream ms1               = new MemoryStream(image);
                        Image        Foto              = Bitmap.FromStream(ms1);
                        int          Id                = Convert.ToInt32(rdr.GetValue(0));
                        string       Nombre            = rdr.GetValue(1).ToString();
                        Categoria    Cat               = miDAOSQLCat.UnObjetoCategoria((int)rdr.GetValue(2));
                        double       Precio            = Convert.ToDouble(rdr.GetValue(3));
                        double       PrecioOferta      = Convert.ToDouble(rdr.GetValue(4));
                        int          Stock             = Convert.ToInt32(rdr.GetValue(6));
                        int          StockComprometido = Convert.ToInt32(rdr.GetValue(7));

                        producto = new Producto(Id, Nombre, Precio, Cat, PrecioOferta, Foto, Stock, StockComprometido);
                        ListaProductos.Add(producto);
                    }
                    rdr.Close();
                }
                connServ.Cerrar();
            }
            catch
            {
                throw new ArgumentException("Error Cargando Productos");
            }
            return(ListaProductos);
        }