Exemplo n.º 1
0
 private void btnInsertar_Click(object sender, EventArgs e)
 {
     try
     {
         var nombre        = txtNombre.Text;
         var descripcion   = txtDescripcion.Text;
         var precioCosto   = txtPrecioCosto.Text;
         var stock         = nupStock.Value;
         var categorias    = cbCategorias.SelectedIndex + 1;
         var marca         = txtTalla.Text;
         var precioMayor   = txtPrecioMayor.Text;
         var precioDetalle = txtPrecioDetalle.Text;
         var color         = txtColor.Text;
         if (!String.IsNullOrEmpty(nombre) && !String.IsNullOrEmpty(descripcion) && !String.IsNullOrEmpty(marca) && !String.IsNullOrEmpty(color))
         {
             var producto = new Producto
             {
                 Nombre         = txtNombre.Text,
                 Descripcion    = txtDescripcion.Text,
                 PrecioCosto    = Convert.ToDouble(txtPrecioCosto.Text),
                 Cantidad_Stock = Convert.ToInt32(nupStock.Value),
                 IdCategoria    = cbCategorias.SelectedIndex + 1,
                 PrecioDetalle  = Convert.ToDouble(txtPrecioDetalle.Text),
                 PrecioMayor    = Convert.ToDouble(txtPrecioMayor.Text),
                 Color          = txtColor.Text,
                 Talla          = txtTalla.Text,
             };
             prod.InsertarProducto(producto);
             MessageBox.Show("Producto insertado", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
             ActualizarGridView();
             txtNombre.Clear();
             txtDescripcion.Clear();
             txtPrecioCosto.Clear();
             txtPrecioDetalle.Clear();
             txtPrecioMayor.Clear();
             nupStock.Value = 0;
             txtTalla.Clear();
             txtColor.Clear();
         }
         else
         {
             MessageBox.Show("Faltan datos", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     } //try
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Ocurrió un error: {0}", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error));
     }
 }