Exemplo n.º 1
0
        private void btnGuardar_Click_1(object sender, EventArgs e)
        {
            bool     sucess   = false;
            Producto producto = new Producto();

            DataRowView drcategoria = cmbCategoria.SelectedItem as DataRowView;
            int         categoriaid = (int)drcategoria.Row.ItemArray[0];

            sucess = ProductosValidacion(categoriaid);

            venta.producto.ProductoCategoriaId = categoriaid;
            venta.producto.ProveedorId         = proveedorId;
            venta.producto.Nombre      = txtArticulo.Text;
            venta.producto.Descripcion = txtObservacion.Text;
            if (txtPrecio.Text != "")
            {
                venta.producto.Monto = Convert.ToDecimal(txtPrecio.Text);
            }
            if (txtPrecio.Text != "")
            {
                venta.producto.Cantidad = Convert.ToInt32(txtCantidad.Text);
            }
            if (txtprecioventa.Text != "")
            {
                venta.producto.PrecioVenta = Convert.ToInt32(txtprecioventa.Text);
            }

            if (sucess)
            {
                if (Editar == false)
                {
                    if (controller.InsertarProductos(venta.producto))
                    {
                        LimpiarTextBox();
                        ObtenerProductos();
                    }
                }
                if (Editar == true)
                {
                    venta.producto.ProductoId = new Guid(productoId);
                    try
                    {
                        if (controller.ActualizarProductos(venta.producto))
                        {
                            LimpiarTextBox();
                            ObtenerProductos();
                            Editar = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("No se pudo insertar los datos por: " + ex);
                    }
                }
            }
            else
            {
                MessageBox.Show("Ingresar la Categoria, Proveedor y Nombre del Articulo");
            }
        }