示例#1
0
        protected void btnActualizarProducto_Click(object sender, EventArgs e)
        {
            ProductoLogica logica = new ProductoLogica();

            byte[] imagen = null;
            using (BinaryReader reader = new BinaryReader(fluImagen.PostedFile.InputStream))
            {
                if (fluImagen.PostedFile != null)
                {
                    byte[] image = reader.ReadBytes(fluImagen.PostedFile.ContentLength);
                    imagen = image;
                }
            }
            Producto producto = new Producto()
            {
                IdProducto  = Convert.ToInt32(txtIdProducto.Text),
                Nombre      = txtNombreProducto.Text,
                Descripcion = txtDescripcionProducto.Text,
                Categoria   = new CategoriaLogica().SeleccionarPorID(Convert.ToInt32(cmbCategoria.SelectedItem.Value.ToString())),
                Imagen      = imagen,
                Precio      = Convert.ToDouble(NudPrecio.Text)
            };

            logica.Insertar(producto);
            LLenarGridProductos();
            txtNombreProducto.Text      = "";
            txtDescripcionProducto.Text = "";
            cmbCategoria.SelectedIndex  = 0;
            NudPrecio.Text                = "";
            divIdProducto.Visible         = false;
            btnActualizarProducto.Visible = false;
            btnBorrarProducto.Visible     = false;
            btnAgregarProducto.Visible    = true;
            gridProductos.SelectedIndex   = -1;
        }