Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //Insertar
            if (Editar == false)
            {
                try
                {
                    ObjCN.InsertProduct(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, Convert.ToInt32(txtPrecio.Text), Convert.ToInt32(txtStock.Text));
                    MessageBox.Show("Se Guardo Correctamente");
                    MostrarProducto();
                    LimpiarForm();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("no se pudo insertar el registro" + ex);
                }

                //Editar
            }
            if (Editar == true)
            {
                try
                {
                    ObjCN.EditarProduc(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, Convert.ToInt32(txtPrecio.Text), Convert.ToInt32(txtStock.Text), Convert.ToInt32(idProducto));
                    MessageBox.Show("Se Edito correctamente");
                    MostrarProducto();
                    LimpiarForm();
                    Editar = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("no se pudo editar el producto" + ex);
                }
            }
        }
 private void btnregistrar_Click(object sender, EventArgs e)
 {
     if (Editar == false)
     {
         if (MessageBox.Show("Desea agregar un nuevo producto?", "", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
         {
             try
             {
                 if (textcodigo.Text == "" || textnombre.Text == "" || textprecio.Text == "")
                 {
                     MessageBox.Show("Llene todos los campos porfavor", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 else
                 {
                     objetoCN.InsertarProduc(textcodigo.Text, textnombre.Text, textprecio.Text);
                     //MessageBox.Show("Datos registrados con exito");
                     MostrarProductos();
                     limpiarForm();
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Este codigo ya existe");
             }
         }
     }
     if (Editar == true)
     {
         if (MessageBox.Show("Desea actualizar los datos?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             try
             {
                 objetoCN.EditarProduc(textcodigo.Text, textnombre.Text, textprecio.Text, ID);
                 // MessageBox.Show("Datos actualizados con exito");
                 MostrarProductos();
                 limpiarForm();
                 Editar = false;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Llene todos los campos porfavor", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
     }
 }