Exemplo n.º 1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtNombreProducto.Text.Trim().Equals("") || txtStock.Text.Trim().Equals("") ||
                txtPrecioCompra.Text.Trim().Equals("") || txtPrecioVenta.Text.Trim().Equals(""))
            {
                MessageBox.Show("Los campos son obligatorios");
                return;
            }
            byte[] imagenByte = null;
            //pasar la imagen que se encuentra en el pictureBox a un array de bytes
            if (imagenPicture.Image != null)
            {
                MemoryStream ms = new MemoryStream();
                imagenPicture.Image.Save(ms, imagenPicture.Image.RawFormat);
                imagenByte = ms.GetBuffer();
            }
            else
            {
                imagenByte = null;
            }

            CacheProductos        productos = new CacheProductos();
            ModeloDominioProducto dominio   = new ModeloDominioProducto();

            if (Operacion == "Agregar")
            {
                productos.Nombre       = txtNombreProducto.Text.Trim();
                productos.Descripcion  = txtDescipcion.Text.Trim();
                productos.IdMarca      = Convert.ToInt32(comboMarca.SelectedValue);
                productos.IdCategoria  = Convert.ToInt32(comboCategoria.SelectedValue);
                productos.Stock        = Convert.ToInt32(txtStock.Text.Trim());
                productos.Imagen       = imagenByte;
                productos.Fecha        = FechaDate.Value;
                productos.PrecioCompra = Convert.ToDecimal(txtPrecioCompra.Text.Trim());
                productos.PrecioVenta  = Convert.ToDecimal(txtPrecioVenta.Text.Trim());

                dominio.InsertarProducto(productos);
                Mensaje.Notificacion("Guardado correctamente");
                Reset();
            }
            else if (Operacion == "Editar")
            {
                productos.IdP          = Convert.ToInt32(idProducto);
                productos.Nombre       = txtNombreProducto.Text.Trim();
                productos.Descripcion  = txtDescipcion.Text.Trim();
                productos.IdMarca      = Convert.ToInt32(comboMarca.SelectedValue);
                productos.IdCategoria  = Convert.ToInt32(comboCategoria.SelectedValue);
                productos.Stock        = Convert.ToInt32(txtStock.Text.Trim());
                productos.Imagen       = imagenByte;
                productos.Fecha        = FechaDate.Value;
                productos.PrecioCompra = Convert.ToDecimal(txtPrecioCompra.Text.Trim());
                productos.PrecioVenta  = Convert.ToDecimal(txtPrecioVenta.Text.Trim());
                dominio.EditarProducto(productos);
                Mensaje.Notificacion("Producto actualizado correctamente");
                this.Close();
            }
        }
Exemplo n.º 2
0
        public void ListaCategoria()
        {
            ModeloDominioProducto producto = new ModeloDominioProducto();

            producto.ListaCategoria(comboCategoria);
        }
Exemplo n.º 3
0
        public void ListarMarca()
        {
            ModeloDominioProducto producto = new ModeloDominioProducto();

            producto.ListarMarca(comboMarca);
        }