public static int Insertar(clases.Servicio 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_SERVICIO(@NOMBRE,@APP,@PLATAFORMA,@SERVIDOR)", conexion.conexion); cmd.Parameters.AddWithValue("@NOMBRE", objeto.Descripcion); cmd.Parameters.AddWithValue("@APP", objeto.IdApp); cmd.Parameters.AddWithValue("@PLATAFORMA", objeto.IdPlataforma); cmd.Parameters.AddWithValue("@SERVIDOR", objeto.IdServidor); } else { conexion.AbrirConexion(); cmd = new MySqlCommand("PROC_MODIFICAR_SERVICIO(@NOMBRE,@APP,@PLATAFORMA,@SERVIDOR,@ID)", conexion.conexion); cmd.Parameters.AddWithValue("@NOMBRE", objeto.Descripcion); cmd.Parameters.AddWithValue("@APP", objeto.IdApp); cmd.Parameters.AddWithValue("@PLATAFORMA", objeto.IdPlataforma); cmd.Parameters.AddWithValue("@SERVIDOR", objeto.IdServidor); cmd.Parameters.AddWithValue("@ID", id); } retorno = cmd.ExecuteNonQuery(); conexion.CerrarConexion(); return(retorno); } catch (Exception ex) { MessageBox.Show(ex.Message); conexion.CerrarConexion(); return(0); } }
private void Btnguardar_Click(object sender, EventArgs e) { try { clases.Servicio objeto = new clases.Servicio(); objeto.Descripcion = txtnombre.Text.ToUpper().Trim(); objeto.IdApp = cmbaplicacion.SelectedValue.ToString(); objeto.IdPlataforma = cmbplataforma.SelectedValue.ToString(); objeto.IdServidor = cmbservidor.SelectedValue.ToString(); if (txtnombre.Text != "" && clases.Servicio.Insertar(objeto, opcion, pideservicio) > 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); } }