Beispiel #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string sResultado = ValidarDatos();

                if (sResultado == "")
                {
                    if (txtId.Text == "")
                    {
                        _Producto.Categoria.Id          = Convert.ToInt32(txtCategoriaId.Text);
                        _Producto.Categoria.Descripcion = txtCategoriaDescripcion.Text;
                        _Producto.Descripcion           = txtDescripcion.Text;
                        _Producto.Precio = Convert.ToDouble(txtPrecioVenta.Text);
                        _Producto.Imagen = (byte[])this.Imagen.Tag;

                        MemoryStream ms = new MemoryStream();

                        if (Imagen.Image != null)
                        {
                            Imagen.Image.Save(ms, Imagen.Image.RawFormat);
                        }
                        else
                        {
                            Imagen.Image = Resources.Transparente;
                            Imagen.Image.Save(ms, Imagen.Image.RawFormat);
                        }

                        ProductoBLL miProductoBLL = new ProductoBLL();
                        miProductoBLL.SalvarProducto(_Producto);

                        MessageBox.Show("Datos insertados correctamente");
                        FrmProducto_Load(null, null);
                        // Log de errores
                        _MyLogControlEventos.InfoFormat("Se guardo un producto");

                        this.dgvListaMateriales.Rows.Clear();
                        misMateriales = null;
                    }
                    else
                    {
                        _Producto.Id                    = Convert.ToInt32(txtId.Text);
                        _Producto.Categoria.Id          = Convert.ToInt32(txtCategoriaId.Text);
                        _Producto.Categoria.Descripcion = txtCategoriaDescripcion.Text;
                        _Producto.Descripcion           = txtDescripcion.Text;
                        _Producto.Precio                = Convert.ToDouble(txtPrecioVenta.Text);
                        _Producto.Imagen                = (byte[])this.Imagen.Tag;

                        MemoryStream ms = new MemoryStream();

                        if (Imagen.Image != null)
                        {
                            Imagen.Image.Save(ms, Imagen.Image.RawFormat);
                        }
                        else
                        {
                            Imagen.Image = Resources.Transparente;
                            Imagen.Image.Save(ms, Imagen.Image.RawFormat);
                        }



                        ProductoBLL miProductoBLL = new ProductoBLL();
                        miProductoBLL.SalvarProducto(_Producto);

                        MessageBox.Show("Datos insertados correctamente");
                        FrmProducto_Load(null, null);
                        // Log de errores
                        _MyLogControlEventos.InfoFormat("Se guardo un producto");

                        this.dgvListaMateriales.Rows.Clear();
                        misMateriales = null;
                    }
                }
                else
                {
                    MessageBox.Show("Faltan cargar Datos: \n" + sResultado);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                // Log de errores
                _MyLogControlEventos.InfoFormat("Error al guardar un producto");
            }
        }