Example #1
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     //INSERTAR
     if (Editar == false)
     {
         try
         {
             objetoCN.InsertarProd(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text);
             MessageBox.Show("Se inserto correctamente");
             MostrarProductos();
             limpiarForm();
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo insertar los datos por: " + ex);
         }
     }
     //EDITAR
     if (Editar == true)
     {
         try
         {
             objetoCN.EditarProd(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto);
             MessageBox.Show("Se edito correctamente");
             MostrarProductos();
             limpiarForm();
             Editar = false;
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo editar los datos por: " + ex);
         }
     }
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // I  N   S  E  R  T  A  R
            if (Editar == false)
            {
                try
                {
                    objetoCN.InsertarProd(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text);
                    MessageBox.Show("Se agrego correctamente!");
                    MostrarProductos();
                    limpiarForm();
                }
                catch (Exception EX)
                {
                    MessageBox.Show("No se pudo agregar los datos" + EX);
                }
            }

            // E  D  I  T  A  R
            if (Editar == true)
            {
                try
                {
                    objetoCN.EditarProd(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto);
                    MessageBox.Show("Se edito correctamente");
                    MostrarProductos();
                    limpiarForm();
                    Editar = false; // Esto para que vuelva a insertar
                }
                catch (Exception)
                {
                    MessageBox.Show("No se pudo editar");
                }
            }
        }
Example #3
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     if (!Editar)
     {
         try
         {
             objetoCN.InsertarProd(txtNombre.Text, txtDesc.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text);
             MessageBox.Show("Se inserto correctamente!");
             MostrarProductos();
             LimpiarControles();
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo insertar el registro por: " + ex);
         }
     }
     else
     {
         try
         {
             objetoCN.EditarProd(txtNombre.Text, txtDesc.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto);
             MessageBox.Show("Se edito correctamente!");
             MostrarProductos();
             LimpiarControles();
             Editar = false;
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo editar el registro por: " + ex);
         }
     }
 }
Example #4
0
 private void Guardado_Click(object sender, EventArgs e)
 {
     if (EDITAR == false)
     {
         try
         {
             ObjetoCN.InsertarProd(texNombre.Text, textDescripcion.Text, textMarca.Text, textPrecio.Text, textStock.Text);
             MessageBox.Show("Se inserto correctamente");
             MostrarProductos();
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo insertar los datos por: " + ex);
         }
     }
     if (EDITAR == true)
     {
         try
         {
             ObjetoCN.EditProd(idProducto, texNombre.Text, textDescripcion.Text, textMarca.Text, textPrecio.Text, textStock.Text);
             MessageBox.Show("Se edito correctamente");
             MostrarProductos();
             LimpiarForm();
             EDITAR = false;
         }
         catch (Exception m)
         {
             MessageBox.Show("No se ha podido insertar los datos: " + m);
         }
     }
 }
Example #5
0
        private void bttnAgregar_Click(object sender, EventArgs e)
        {
            // se creo una condicion si editar es false entonces agregara , pero si editar es true.
            if (editar == false)
            {
                try
                {
                    obj_CN.InsertarProd(txtNombre.Text, txtPrecio.Text, txtStock.Text, cmbCategoria.SelectedValue.ToString());

                    MessageBox.Show("Ingresado");
                    MostrarProductos();
                    limpiarForm();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al Ingresar " + ex);
                }
            }
            // si la condicion resulta true  se podra editar.
            if (editar == true)
            {
                try
                {
                    obj_CN.EditarProd(txtNombre.Text, txtPrecio.Text, txtStock.Text, cmbCategoria.SelectedValue.ToString(), idprod);
                    MessageBox.Show("Fila fue Editada exitosamente.");
                    MostrarProductos();
                    limpiarForm();
                    editar = false; // se desactiva para que el bttnGuardar pueda agregar registros y no continue editando.
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al Editar " + ex);
                }
            }
        }
Example #6
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (Editar == false && Convert.ToInt32(cbCate.SelectedValue) != 0)
            {
                try
                {
                    //INSERTA DATOS A TABLA, CONEXION SQL. (TABLA 1)
                    _Crud.InsertarProd(txtNombre.Text, txtDescrip.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, Convert.ToInt32(cbCate.SelectedValue), estado);
                    MostrarProdcs();


                    //INSERTA DATO A TABLA TEMPORAL (TABLA 2)
                    tabla.Rows.Add(txtNombre.Text);

                    dgvTemporal.DataSource = tabla;

                    MessageBox.Show("El registro se agregó correctamente.");
                    limpiarForm();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("no se pudo insertar los datos por: " + ex);
                }
            }
            if (Editar == true)
            {
                try
                {
                    _Crud.EditarProd(txtNombre.Text, txtDescrip.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, Convert.ToInt32(cbCate.SelectedValue), idProd);
                    MessageBox.Show("se edito correctamente");
                    MostrarProdcs();
                    limpiarForm();
                    Editar = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("no se pudo editar los datos por: " + ex);
                }
            }
        }
Example #7
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     //En este caso vamos a buscar Insertar el producto ya que es necesario que la variable editar = false
     if (Editar == false)
     {
         try
         {
             // Hacemos un try de insertar productos usando el objeto que creamos al principio de la form
             // Hacemos un mensaje, Volovemos a mostrar los productos y limpiamos la hoja donde escribimos los datos
             objetoCN.InsertarProd(txtNombre.Text, txtDesc.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text);
             MessageBox.Show("Se inserto correctamente");
             MostrarProductos();
             limpiarForm();
         }
         catch (Exception ex)
         {
             // Hacemos un catch por si hay un error
             MessageBox.Show("no se pudo insertar los datos por: " + ex);
         }
     }
     // En este caso vamos a editar un producto ya que la variable editar = True
     if (Editar == true)
     {
         try{
             // Hacemos un try de editar productos usando el objeto que creamos al principio de la form
             // hacemos un mensaje, volvemos a mostrar los productos y limpiamos la hoja donde escribimos los datos
             // Tambien ponemos la variable Editar devuelta en False para dejar de editar
             objetoCN.EditarProd(txtNombre.Text, txtDesc.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto);
             MessageBox.Show("Se edito correctamente");
             MostrarProductos();
             limpiarForm();
             Editar = false;
         }
         catch (Exception ex)
         {
             // hacemos un catch por si hay un error
             MessageBox.Show("no se pudo Editar los datos por: " + ex);
         }
     }
 }
        //Agregar VIdeoJuego
        private void button_Agregar_Click(object sender, EventArgs e)
        {
            try
            {
                string nombreVg;
                nombreVg = TextBox_Nombre.Text;
                listatemporal.Add(nombreVg);
                listBox1.DataSource = null;
                listBox1.DataSource = listatemporal;

                objetoCN.InsertarProd(TextBox_Nombre.Text, textBox1.Text, textBox2.Text);
                MessageBox.Show("Agregado a la tabla de dbo.Productos");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex);
            }

            pictureBox1.Image   = null;
            TextBox_Nombre.Text = "";
            textBox1.Text       = "";
            textBox2.Text       = "";
        }
Example #9
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (Editar == false)
            {
                try
                {
                    //se envian los tectos tal cual se capturan de tipo string en el formulario no se hace
                    //ninguna converción
                    objetoCN.InsertarProd(txtNombre.Text, textDescrip.Text, textPrecio.Text, txtStock.Text);
                    MessageBox.Show("Se insertó correctamente");

                    MostrarProdutos();
                    limpiar();
                }
                catch (Exception er)
                {
                    MessageBox.Show("Ha ocurrrido un error al insetar los datos " + er);
                }
            }
            if (Editar)
            {
                try
                {
                    //se envian los textos tal cual se capturan de tipo string en el formulario no se hace
                    //ninguna converción
                    objetoCN.EditarProd(txtNombre.Text, textDescrip.Text, textPrecio.Text, txtStock.Text, idProducto);
                    MessageBox.Show("Se Editó correctamente");
                    Editar = false;
                    MostrarProdutos();
                    limpiar();
                }
                catch (Exception er)
                {
                    MessageBox.Show("Ha ocurrrido un error al editar los datos " + er);
                }
            }
        }
Example #10
0
 private void b_guardar_Click(object sender, EventArgs e)
 {
     if (Editar == false)
     {
         try
         {
             objetoCN.InsertarProd(t_id.Text, t_descripcion.Text, t_existencia.Text, t_preciocosto.Text, t_precioventa.Text, t_cantidadminima.Text, cb_foliofactura.SelectedItem.ToString());
             objma = new Form_Mensaje_A("Producto agregadó correctamente");
             objma.Show();
             MostrarProductos();
             Limpiar_Datos();
         }
         catch (Exception ex)
         {
             objme = new Form_Mensaje_E("Ha ocurridó un error");
             objme.Show();
         }
     }
     if (Editar == true)
     {
         try
         {
             objetoCN.EditarProd(t_id.Text, t_descripcion.Text, t_existencia.Text, t_preciocosto.Text, t_precioventa.Text, t_cantidadminima.Text);
             objma = new Form_Mensaje_A("Producto editadó correctamente");
             objma.Show();
             MostrarProductos();
             Limpiar_Datos();
             Editar = false;
         }
         catch (Exception ex)
         {
             objme = new Form_Mensaje_E("Ha Ocurridó un error");
             objme.Show();
         }
     }
 }