private void Btnguardar_Click(object sender, EventArgs e) { try { clases.Plataforma objeto = new clases.Plataforma(); objeto.Descripcion = txtnombre.Text.ToUpper().Trim(); objeto.IdServidor = Convert.ToInt32(cmbservidor.SelectedValue); objeto.IdTipoPlataforma = Convert.ToInt32(cmbtipoplataforma.SelectedValue); if (txtnombre.Text != "" && clases.Plataforma.Insertar(objeto, opcion, pIdPlataforma) > 0) { MessageBox.Show("Operacion Correcta", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearScreen(); } else { MessageBox.Show("Operacion Incorrecta", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception error) { MessageBox.Show("Error: " + error); } }
public static int Insertar(clases.Plataforma objeto, int opcion, int id) { clases.Conexion conexion = new clases.Conexion(); int retorno; MySqlCommand cmd; try { if (opcion == 0) { conexion.AbrirConexion(); cmd = new MySqlCommand("PROC_INSERTAR_PLATAFORMA(@NOMBRE,@SERVIDOR,@TIPO)", conexion.conexion); cmd.Parameters.AddWithValue("@NOMBRE", objeto.Descripcion); cmd.Parameters.AddWithValue("@SERVIDOR", objeto.IdServidor); cmd.Parameters.AddWithValue("@TIPO", objeto.IdTipoPlataforma); } else { conexion.AbrirConexion(); cmd = new MySqlCommand("PROC_MODIFICAR_PLATAFORMA(@NOMBRE,@SERVIDOR,@TIPO,@ID)", conexion.conexion); cmd.Parameters.AddWithValue("@NOMBRE", objeto.Descripcion); cmd.Parameters.AddWithValue("@SERVIDOR", objeto.IdServidor); cmd.Parameters.AddWithValue("@TIPO", objeto.IdTipoPlataforma); cmd.Parameters.AddWithValue("@ID", id); } retorno = cmd.ExecuteNonQuery(); conexion.CerrarConexion(); return(retorno); } catch (Exception ex) { MessageBox.Show(ex.Message); conexion.CerrarConexion(); return(0); } }