public int Delete() { String query = "DELETE FROM departamento where id_departamento = "+this.id; MySqlConnection con = null; try { con = new Conexion().getConexion(); con.Open(); MySqlCommand sqlCom = new MySqlCommand(query, con); return sqlCom.ExecuteNonQuery(); } catch (Exception ex) { con.Close(); Console.WriteLine("EEROR " + ex.Message); return 0; } }
public List<DepartamentoClass> findAll() { List<DepartamentoClass> depto = null; String query = "select id_departamento, nombre, IFNULL(id_jefe,'Asignar jefe') as id_jefe from departamento"; MySqlConnection con = null; try { con = new Conexion().getConexion(); con.Open(); MySqlCommand sqlCom = new MySqlCommand(query, con); MySqlDataReader res = sqlCom.ExecuteReader(); depto = new List<DepartamentoClass>(); while (res.Read()) { DepartamentoClass rows = new DepartamentoClass(res.GetInt32(0), res.GetString(1), res.GetString(2)); depto.Add(rows); } con.Close(); return depto; } catch (Exception ex) { con.Close(); Console.WriteLine("EEROR "+ex.Message); return depto; } }
public int update() { String query = "update departamento set nombre='" + this.nombre + "', id_jefe= " + int.Parse(this.rut_jefe) + " where id_departamento = "+this.id; MySqlConnection con = null; try { con = new Conexion().getConexion(); con.Open(); MySqlCommand sqlCom = new MySqlCommand(query, con); return sqlCom.ExecuteNonQuery(); } catch (Exception ex) { con.Close(); Console.WriteLine("EEROR " + ex.Message); return 0; } }
public int save() { String query = "insert into departamento (nombre, id_jefe) values('" + this.nombre + "'," + int.Parse(this.rut_jefe) + ")"; MySqlConnection con = null; try { con = new Conexion().getConexion(); con.Open(); MySqlCommand sqlCom = new MySqlCommand(query, con); return sqlCom.ExecuteNonQuery(); } catch (Exception ex) { con.Close(); Console.WriteLine("EEROR " + ex.Message); return 0; } }