public static bool Insertar(Capacitacion cap) { MySqlConnection con; con = conexion.conectar(); string insert = string.Format("INSERT capacitacion(Nombre,Pago_capacitador,Material,Fecha,Capacitadores_id) VALUES('" + cap.Nombre + "','" + cap.Pago_Capacitador + "','" + cap.Material + "',(Select current_date()),'" + cap.Capacitador + "')"); MySqlCommand comando = new MySqlCommand(insert, con); int i = comando.ExecuteNonQuery(); if (i > 0) { return true; } else { return false; } }
public static bool Eliminar(Capacitacion cap) { MySqlConnection con; con = conexion.conectar(); string update = string.Format("DELETE FROM capacitacion where id = '"+cap.id+"'"); MySqlCommand comando = new MySqlCommand(update, con); int i = comando.ExecuteNonQuery(); if (i > 0) { return true; } else { return false; } }
public static bool Actualizar(Capacitacion cap) { MySqlConnection con; con = conexion.conectar(); string update = string.Format("UPDATE capacitacion SET Nombre = '" + cap.Nombre + "', Pago_capacitador = '" + cap.Pago_Capacitador + "',Material= '" + cap.Material + "',Capacitadores_id ='" + cap.Capacitador + "' where id = '"+cap.id+"'"); MySqlCommand comando = new MySqlCommand(update, con); int i = comando.ExecuteNonQuery(); if (i > 0) { return true; } else { return false; } }
private void btnEliCap_gf_Click(object sender, EventArgs e) { if (MetroMessageBox.Show(this, "¿Seguro que deseas eliminar la capacitación?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { Capacitacion cap = new Capacitacion(); cap.id = int.Parse(idCap_gf.Text); if (CapacitacionDAO.Eliminar(cap)) { MessageBox.Show("La capacitacion se ha eliminado", "Eliminacion exitosa", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCapacitacion.Rows.Clear(); LlenardgvCapacitacion(); btnActCap_gf.Enabled = false; btnEliCap_gf.Enabled = false; btnAltCap_gf.Enabled = true; } else { MessageBox.Show("Error en la inserción de la capacitacion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); btnActCap_gf.Enabled = false; btnEliCap_gf.Enabled = false; btnAltCap_gf.Enabled = true; } } catch { MessageBox.Show("Error en los valores", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnAltCap_gf_Click(object sender, EventArgs e) { try { MySqlConnection cnx; cnx = conexion.conectar(); Capacitacion cap = new Capacitacion(); cap.Nombre = nomCap_gf.Text; cap.Pago_Capacitador = double.Parse(pago_Capacitador.Text); cap.Material = double.Parse(matCap.Text); cap.Capacitador = int.Parse(combobox_Capacitador.Text); if (CapacitacionDAO.Insertar(cap)) { MessageBox.Show("La capacitacion se ha dado de alta", "Regristro exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCapacitacion.Rows.Clear(); LlenardgvCapacitacion(); } else { MessageBox.Show("Error en la inserción de la capacitacion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } cnx.Close(); } catch { MessageBox.Show("Error en los valores", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnActCap_gf_Click(object sender, EventArgs e) { try { MySqlConnection cnx; cnx = conexion.conectar(); Capacitacion cap = new Capacitacion(); cap.Nombre = nomCap_gf.Text; cap.Pago_Capacitador = double.Parse(pago_Capacitador.Text); cap.Material = double.Parse(matCap.Text); cap.Capacitador = int.Parse(combobox_Capacitador.Text); cap.id = int.Parse(idCap_gf.Text); if (CapacitacionDAO.Actualizar(cap)) { MetroMessageBox.Show(this, "La capacitacion se ha actualizado", "Regristro exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCapacitacion.Rows.Clear(); LlenardgvCapacitacion(); btnActCap_gf.Enabled = false; btnEliCap_gf.Enabled = false; btnAltCap_gf.Enabled = true; } else { MetroMessageBox.Show(this, "Error en la inserción de la capacitacion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); btnActCap_gf.Enabled = false; btnEliCap_gf.Enabled = false; btnAltCap_gf.Enabled = true; } cnx.Close(); } catch(Exception ex) { MetroMessageBox.Show(this, "Error en los valores " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }