From d06e7d198ace1ed5938ef54fdbf613d8ebcba9f5 Mon Sep 17 00:00:00 2001 From: dangj501 Date: Fri, 17 May 2024 18:02:40 -0600 Subject: [PATCH] Los demas DAOS --- .../mx/uv/Controller/DAO_Administrador.java | 24 ++++ .../java/mx/uv/Controller/DAO_Carrrera.java | 1 + .../mx/uv/Controller/DAO_Documentacion.java | 115 +++++++++++++++++ .../java/mx/uv/Controller/DAO_Examen.java | 108 ++++++++++++++++ .../java/mx/uv/Controller/DAO_FichaI.java | 118 ++++++++++++++++++ .../java/mx/uv/Controller/DAO_FichaP.java | 113 +++++++++++++++++ .../main/java/mx/uv/Model/Documentacion.java | 108 ++++++++++++++++ 7 files changed, 587 insertions(+) create mode 100644 backend/src/main/java/mx/uv/Controller/DAO_Documentacion.java create mode 100644 backend/src/main/java/mx/uv/Controller/DAO_Examen.java create mode 100644 backend/src/main/java/mx/uv/Controller/DAO_FichaI.java create mode 100644 backend/src/main/java/mx/uv/Controller/DAO_FichaP.java create mode 100644 backend/src/main/java/mx/uv/Model/Documentacion.java diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java b/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java index 0816966..589b070 100644 --- a/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java +++ b/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java @@ -36,6 +36,30 @@ public class DAO_Administrador{ return resultado; } + public static boolean ValidarAdministrador(Administrador administrador){ + Statement stm = null; + Connection conn = null; + boolean verificacion =false; + ResultSet rs = null; + conn = cn.conectar(); + + try { + String sql ="select * from administrador " + + "where matricula= '"+administrador.getMatricula()+"' and contrasena='"+administrador.getContrasena()+"'"; + stm = (Statement) conn.createStatement(); + rs = stm.executeQuery(sql); + if(rs.next()){ + verificacion = true; + }else{ + verificacion = false; + } + conn.close(); + } catch (SQLException ex) { + System.err.println(ex); + } + return verificacion; + } + public boolean agregarAdministrador(Administrador administrador){ PreparedStatement stm = null; Connection conn = null; diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java b/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java index 9df5267..7f66a52 100644 --- a/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java +++ b/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java @@ -50,6 +50,7 @@ public class DAO_Carrrera{ stm.setString(3, carrera.getModalidad()); stm.setString(4, carrera.getCampus()); stm.setDouble(5, carrera.getCosto()); + diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Documentacion.java b/backend/src/main/java/mx/uv/Controller/DAO_Documentacion.java new file mode 100644 index 0000000..4b4aa1a --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAO_Documentacion.java @@ -0,0 +1,115 @@ +package mx.uv.Controller; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.Statement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import mx.uv.Model.Documentacion; + +public class DAO_Documentacion { + + private static Conexion cn = Conexion.getInstance(); + + @SuppressWarnings("null") + public List dameDocumentacion() { + Statement stm = null; + ResultSet rs = null; + Connection conn = null; + List resultado = new ArrayList<>(); + + try { + String sql = "SELECT * from documentacion"; + stm = conn.createStatement(); + rs = stm.executeQuery(sql); + while (rs.next()) { + Documentacion u = new Documentacion(rs.getInt(1), rs.getBytes(2), rs.getBytes(3),rs.getBytes(4), rs.getBytes(5),rs.getBytes(6), rs.getBytes(7), rs.getBytes(8), rs.getBytes(9), rs.getBytes(10)); + resultado.add(u); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return resultado; + } + + public static boolean agregarDocumentacion(Documentacion documentacion){ + PreparedStatement stm = null; + Connection conn = null; + boolean msj= false; + + conn = cn.conectar(); + + try{ + String sql ="INSERT INTO `documentacion` (`id`,`acta_nacimiento`, `certificado_bachillerato`, `curp`, `ine`, `ine_tutor`, `certificado_medico`, `comprobante`, `fotografia`, `constancia`) VALUES(?,?,?,?,?,?,?,?,?,?);"; + stm = (PreparedStatement) conn.prepareStatement(sql); + stm.setInt(1, documentacion.getId()); + stm.setBytes(2, documentacion.getActaNacimiento()); + stm.setBytes(3, documentacion.getCertificadoBachillerato()); + stm.setBytes(4, documentacion.getCurp()); + stm.setBytes(5, documentacion.getIne()); + stm.setBytes(6, documentacion.getIneTutor()); + stm.setBytes(7, documentacion.getCertificadoMedico()); + stm.setBytes(8, documentacion.getComprobante()); + stm.setBytes(9, documentacion.getFotografia()); + stm.setBytes(10, documentacion.getConstancia()); + + + + + + }catch(Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm,conn); + } + return msj; + + } + + + private static void cerrarConexiones(PreparedStatement stm,Connection conn) { + if (stm != null) { + try { + stm.close(); + } catch (Exception e) { + System.out.println(e); + } + stm = null; + } + try { + conn.close(); + cn.cerrarConexion(); + } catch (Exception e) { + System.out.println(e); + } + } + + public static boolean eliminarDocumentacion(int idDocumentacion){ + return false; + } + + public static boolean editarDocumentacion(Documentacion documentacion){ + PreparedStatement stm = null; + Connection conn = null; + boolean verificacion =false; + conn = cn.conectar(); + + try{ + String sql ="UPDATE `documentacion` SET `acta_nacimiento` = '"+documentacion.getActaNacimiento()+"',`certificado_bachillerato` = '"+documentacion.getCertificadoBachillerato()+"',`curp` = '"+documentacion.getCurp()+"',`ine` = '"+documentacion.getIne()+"', `ine_tutor` = '"+documentacion.getIneTutor()+"',`certificado_medico` = '"+documentacion.getCertificadoMedico()+"',`comprobante` = '"+documentacion.getComprobante()+"',`fotografia` = '"+documentacion.getFotografia()+"',`constancia` = '"+documentacion.getConstancia()+"' WHERE `id` = '"+documentacion.getId()+"';"; + stm = conn.prepareStatement(sql); + stm.executeUpdate(); + verificacion = true; + }catch (SQLException ex) { + System.err.println(ex); + }finally{ + cerrarConexiones(stm, conn); + cn.cerrarConexion(); + } + return verificacion; + } +} diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Examen.java b/backend/src/main/java/mx/uv/Controller/DAO_Examen.java new file mode 100644 index 0000000..3a65b25 --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAO_Examen.java @@ -0,0 +1,108 @@ +package mx.uv.Controller; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import mx.uv.Model.Examen; + +public class DAO_Examen { + private static Conexion cn = Conexion.getInstance(); + + public static List obtenerExamenes() { + Statement stm = null; + ResultSet rs = null; + Connection conn = null; + List resultado = new ArrayList<>(); + + conn = cn.conectar(); + + try { + String sql = "SELECT * FROM examen"; + stm = conn.createStatement(); + rs = stm.executeQuery(sql); + while (rs.next()) { + Examen examen = new Examen( + rs.getInt("id"), + rs.getDouble("calificacion"), + rs.getBoolean("derecho_inscripcion"), + rs.getInt("id_alumno") + ); + resultado.add(examen); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return resultado; + } + + public static boolean agregarExamen(Examen examen) { + PreparedStatement stm = null; + Connection conn = null; + boolean agregado = false; + + conn = cn.conectar(); + + try { + String sql = "INSERT INTO examen (calificacion, derecho_inscripcion, id_alumno) VALUES (?, ?, ?)"; + stm = conn.prepareStatement(sql); + stm.setDouble(1, examen.getCalificacion()); + stm.setBoolean(2, examen.isDerechoInscripcion()); + stm.setInt(3, examen.getIdAlumno()); + + agregado = stm.executeUpdate() > 0; + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm, conn); + } + return agregado; + } + + public static boolean editarExamen(Examen examen) { + PreparedStatement stm = null; + Connection conn = null; + boolean actualizado = false; + + conn = cn.conectar(); + + try { + String sql = "UPDATE examen SET calificacion = ?, derecho_inscripcion = ?, id_alumno = ? WHERE id = ?"; + stm = conn.prepareStatement(sql); + stm.setDouble(1, examen.getCalificacion()); + stm.setBoolean(2, examen.isDerechoInscripcion()); + stm.setInt(3, examen.getIdAlumno()); + stm.setInt(4, examen.getId()); + + actualizado = stm.executeUpdate() > 0; + } catch (SQLException ex) { + System.err.println(ex); + } finally { + cerrarConexiones(stm, conn); + } + return actualizado; + } + + public static boolean eliminarExamen(int idExamen) { + return false; + } + + private static void cerrarConexiones(PreparedStatement stm, Connection conn) { + if (stm != null) { + try { + stm.close(); + } catch (Exception e) { + System.out.println(e); + } + } + if (conn != null) { + try { + conn.close(); + cn.cerrarConexion(); + } catch (Exception e) { + System.out.println(e); + } + } + } +} diff --git a/backend/src/main/java/mx/uv/Controller/DAO_FichaI.java b/backend/src/main/java/mx/uv/Controller/DAO_FichaI.java new file mode 100644 index 0000000..35a93c0 --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAO_FichaI.java @@ -0,0 +1,118 @@ +package mx.uv.Controller; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import mx.uv.Model.FichaI; + +public class DAO_FichaI { + private static Conexion cn = Conexion.getInstance(); + + public static List obtenerFichas() { + Statement stm = null; + ResultSet rs = null; + Connection conn = null; + List resultado = new ArrayList<>(); + + conn = cn.conectar(); + + try { + String sql = "SELECT * FROM fichaI"; + stm = conn.createStatement(); + rs = stm.executeQuery(sql); + while (rs.next()) { + FichaI ficha = new FichaI( + rs.getInt("id_alumno"), + rs.getInt("id_carrera"), + rs.getInt("id_tutor"), + rs.getInt("id_documentacion"), + rs.getDate("fecha_inicio"), + rs.getDate("fecha_fin") + ); + resultado.add(ficha); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return resultado; + } + + public static boolean agregarFichaI(FichaI ficha) { + PreparedStatement stm = null; + Connection conn = null; + boolean agregado = false; + + conn = cn.conectar(); + + try { + String sql = "INSERT INTO fichaI (id_alumno, id_carrera, id_tutor, id_documentacion, fecha_inicio, fecha_fin) VALUES (?, ?, ?, ?, ?, ?)"; + stm = conn.prepareStatement(sql); + stm.setInt(1, ficha.getIdAlumno()); + stm.setInt(2, ficha.getIdCarrera()); + stm.setInt(3, ficha.getIdTutor()); + stm.setInt(4, ficha.getIdDocumentacion()); + stm.setDate(5, new java.sql.Date(ficha.getFechaInicio().getTime())); + stm.setDate(6, new java.sql.Date(ficha.getFechaFin().getTime())); + + agregado = stm.executeUpdate() > 0; + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm, conn); + } + return agregado; + } + + + public static boolean editarFichaI(FichaI ficha) { + PreparedStatement stm = null; + Connection conn = null; + boolean actualizado = false; + + conn = cn.conectar(); + + try { + String sql = "UPDATE fichaI SET id_carrera = ?, id_tutor = ?, id_documentacion = ?, fecha_inicio = ?, fecha_fin = ? WHERE id_alumno = ?"; + stm = conn.prepareStatement(sql); + stm.setInt(1, ficha.getIdCarrera()); + stm.setInt(2, ficha.getIdTutor()); + stm.setInt(3, ficha.getIdDocumentacion()); + stm.setDate(4, new java.sql.Date(ficha.getFechaInicio().getTime())); + stm.setDate(5, new java.sql.Date(ficha.getFechaFin().getTime())); + stm.setInt(6, ficha.getIdAlumno()); + + actualizado = stm.executeUpdate() > 0; + } catch (SQLException ex) { + System.err.println(ex); + } finally { + cerrarConexiones(stm, conn); + } + return actualizado; + } + + + public static boolean eliminarFicha(int idAlumno) { + return false; + } + + + private static void cerrarConexiones(PreparedStatement stm, Connection conn) { + if (stm != null) { + try { + stm.close(); + } catch (Exception e) { + System.out.println(e); + } + } + if (conn != null) { + try { + conn.close(); + cn.cerrarConexion(); + } catch (Exception e) { + System.out.println(e); + } + } + } +} diff --git a/backend/src/main/java/mx/uv/Controller/DAO_FichaP.java b/backend/src/main/java/mx/uv/Controller/DAO_FichaP.java new file mode 100644 index 0000000..7e3f8d5 --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAO_FichaP.java @@ -0,0 +1,113 @@ +package mx.uv.Controller; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import mx.uv.Model.FichaP; + +public class DAO_FichaP { + private static Conexion cn = Conexion.getInstance(); + + // Método para obtener todas las fichas + public static List dameFichasP() { + Statement stm = null; + ResultSet rs = null; + Connection conn = null; + List resultado = new ArrayList<>(); + + conn = cn.conectar(); + + try { + String sql = "SELECT * FROM fichaP"; + stm = conn.createStatement(); + rs = stm.executeQuery(sql); + while (rs.next()) { + FichaP ficha = new FichaP( + rs.getInt("id"), + rs.getInt("id_alumno"), + rs.getInt("id_carrera"), + rs.getDate("fecha_inicio"), + rs.getDate("fecha_fin") + ); + resultado.add(ficha); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return resultado; + } + + public static boolean agregarFichaP(FichaP ficha) { + PreparedStatement stm = null; + Connection conn = null; + boolean agregado = false; + + conn = cn.conectar(); + + try { + String sql = "INSERT INTO fichaP (id_alumno, id_carrera, fecha_inicio, fecha_fin) VALUES (?, ?, ?, ?)"; + stm = conn.prepareStatement(sql); + stm.setInt(1, ficha.getIdAlumno()); + stm.setInt(2, ficha.getIdCarrera()); + stm.setDate(3, new java.sql.Date(ficha.getFechaInicio().getTime())); + stm.setDate(4, new java.sql.Date(ficha.getFechaFin().getTime())); + + agregado = stm.executeUpdate() > 0; + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm, conn); + } + return agregado; + } + + public static boolean editarFichaP(FichaP ficha) { + PreparedStatement stm = null; + Connection conn = null; + boolean actualizado = false; + + conn = cn.conectar(); + + try { + String sql = "UPDATE fichaP SET id_alumno = ?, id_carrera = ?, fecha_inicio = ?, fecha_fin = ? WHERE id = ?"; + stm = conn.prepareStatement(sql); + stm.setInt(1, ficha.getIdAlumno()); + stm.setInt(2, ficha.getIdCarrera()); + stm.setDate(3, new java.sql.Date(ficha.getFechaInicio().getTime())); + stm.setDate(4, new java.sql.Date(ficha.getFechaFin().getTime())); + stm.setInt(5, ficha.getId()); + + actualizado = stm.executeUpdate() > 0; + } catch (SQLException ex) { + System.err.println(ex); + } finally { + cerrarConexiones(stm, conn); + } + return actualizado; + } + + + public static boolean eliminarFichaP(int id) { + return false; + } + + private static void cerrarConexiones(PreparedStatement stm, Connection conn) { + if (stm != null) { + try { + stm.close(); + } catch (Exception e) { + System.out.println(e); + } + } + if (conn != null) { + try { + conn.close(); + cn.cerrarConexion(); + } catch (Exception e) { + System.out.println(e); + } + } + } +} diff --git a/backend/src/main/java/mx/uv/Model/Documentacion.java b/backend/src/main/java/mx/uv/Model/Documentacion.java new file mode 100644 index 0000000..542b835 --- /dev/null +++ b/backend/src/main/java/mx/uv/Model/Documentacion.java @@ -0,0 +1,108 @@ +package mx.uv.Model; + +public class Documentacion { + private int id; + private byte[] actaDeNacimiento; + private byte[] certificadoBachillerato; + private byte[] curp; + private byte[] ine; + private byte[] ineTutor; + private byte[] certificadoMedico; + private byte[] comprobante; + private byte[] fotografia; + private byte[] constancia; + + public Documentacion(int id, byte[] actaDeNacimiento, byte[] certificadoBachillerato, byte[] curp, byte[] ine, byte[] ineTutor, byte[] certificadoMedico, byte[] comprobante, byte[] fotografia, byte[] constancia){ + this.id=id; + this.actaDeNacimiento=actaDeNacimiento; + this.certificadoBachillerato=certificadoBachillerato; + this.curp=curp; + this.ine=ine; + this.ineTutor=ineTutor; + this.certificadoMedico=certificadoMedico; + this.comprobante=comprobante; + this.fotografia=fotografia; + this.constancia=constancia; + } + + public void setId(int id){ + this.id=id; + } + + public void setActaNacimiento(byte[] actaDeNacimiento){ + this.actaDeNacimiento=actaDeNacimiento; + } + + public void setCertificadoBachillerato(byte[] certificadoBachillerato){ + this.certificadoBachillerato=certificadoBachillerato; + } + + public void setCurp(byte[] curp){ + this.curp=curp; + } + + public void setIne(byte[] ine){ + this.ine=ine; + } + + public void setIneTutor(byte[] ineTutor){ + this.ineTutor=ineTutor; + } + + public void setCertificadoMedico(byte[] certificadoMedico){ + this.certificadoMedico=certificadoMedico; + } + + public void setComprobante(byte[] comprobante){ + this.comprobante=comprobante; + } + + public void setFoto(byte[] fotografia){ + this.fotografia=fotografia; + } + + public void setConstancia(byte[] constancia){ + this.constancia=constancia; + } + + public int getId(){ + return id; + } + + public byte[] getActaNacimiento(){ + return actaDeNacimiento; + } + + public byte[] getCertificadoBachillerato(){ + return certificadoBachillerato; + } + + public byte[] getCurp(){ + return curp; + } + + public byte[] getIne(){ + return ine; + } + + public byte[] getIneTutor(){ + return ineTutor; + } + + public byte[] getCertificadoMedico(){ + return certificadoMedico; + } + + public byte[] getComprobante(){ + return comprobante; + } + + public byte[] getFotografia(){ + return fotografia; + } + + public byte[] getConstancia(){ + return constancia; + } + +}