2022-11-12 19:19:37 +01:00
package fr.iutfbleau.projetIHM2022FI2.Graphic ;
import java.sql.PreparedStatement ;
import java.sql.SQLException ;
2022-11-13 00:37:08 +01:00
import java.util.Iterator ;
2022-11-12 19:19:37 +01:00
import java.util.LinkedList ;
import java.util.Objects ;
import java.sql.Connection ;
import org.mariadb.jdbc.* ;
import java.sql.DriverManager ;
import java.sql.ResultSet ;
import javax.swing.JFrame ;
import javax.swing.* ;
import java.awt.* ;
2022-11-12 22:11:05 +01:00
import fr.iutfbleau.projetIHM2022FI2.API.AbstractGroupeFactory ;
2022-11-12 19:19:37 +01:00
import fr.iutfbleau.projetIHM2022FI2.API.Groupe ;
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe ;
import fr.iutfbleau.projetIHM2022FI2.Graphic.View.PaintGroupe ;
2022-11-12 22:11:05 +01:00
import fr.iutfbleau.projetIHM2022FI2.MNP.AbstractGroupeFactoryNP ;
2022-11-12 19:19:37 +01:00
import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP ;
public class Graphic {
private PaintGroupe paint ;
private JFrame fenetre ;
2022-11-12 22:11:05 +01:00
private AbstractGroupeFactory agf ;
2022-11-12 19:19:37 +01:00
public Graphic ( ) {
this . fenetre = new JFrame ( " Gestion des étudiants " ) ;
this . fenetre . setSize ( 1000 , 720 ) ;
this . fenetre . setLocation ( 200 , 200 ) ;
this . fenetre . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ;
2022-11-12 23:27:30 +01:00
this . getPromo ( ) ;
2022-11-12 19:19:37 +01:00
this . fenetre . setVisible ( true ) ;
2022-11-13 00:37:08 +01:00
/ *
System . out . println ( this . agf . getPromotion ( ) . monPrint ( ) ) ;
Groupe racineDeLaPartition = agf . getPromotion ( ) . getSousGroupes ( ) . iterator ( ) . next ( ) ;
System . out . println ( racineDeLaPartition . monPrint ( ) ) ;
for ( Groupe g : racineDeLaPartition . getSousGroupes ( ) ) {
System . out . println ( g . monPrint ( ) ) ;
} * /
2022-11-12 19:19:37 +01:00
}
2022-11-12 23:27:30 +01:00
private void getPromo ( ) {
2022-11-12 23:14:18 +01:00
this . agf = null ;
2022-11-12 19:19:37 +01:00
try {
Class . forName ( " org.mariadb.jdbc.Driver " ) ;
try {
Connection cnx = DriverManager . getConnection (
" jdbc:mariadb://dwarves.iut-fbleau.fr/chaignea " ,
" chaignea " , " Chaigneauphpmyadmin " ) ;
try {
PreparedStatement pst = cnx . prepareStatement (
2022-11-12 21:33:46 +01:00
" SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name ORDER BY Groupe.id ASC; " ) ;
2022-11-12 19:19:37 +01:00
try {
ResultSet rs = pst . executeQuery ( ) ;
try {
2022-11-12 23:14:18 +01:00
if ( rs . first ( ) ) {
Groupe promo = new GroupeNP ( rs . getInt ( 1 ) , rs . getString ( 2 ) , rs . getInt ( 3 ) , rs . getInt ( 4 ) , TypeGroupe . getType ( rs . getString ( 5 ) ) , null ) ;
2022-11-13 00:37:08 +01:00
this . agf = new AbstractGroupeFactoryNP ( promo ) ;
this . addSousGroupe ( promo ) ;
2022-11-12 23:14:18 +01:00
}
2022-11-12 19:19:37 +01:00
while ( rs . next ( ) ) {
2022-11-13 00:37:08 +01:00
Groupe g = new GroupeNP ( rs . getInt ( 1 ) , rs . getString ( 2 ) , rs . getInt ( 3 ) , rs . getInt ( 4 ) , TypeGroupe . getType ( rs . getString ( 5 ) ) , null ) ;
if ( agf . knows ( g ) = = false ) {
agf . addGroupe ( g ) ;
this . addSousGroupe ( g ) ;
2022-11-12 19:19:37 +01:00
}
}
} catch ( SQLException e ) {
System . out . println ( " erreur dans la prise de resultat " ) ;
}
rs . close ( ) ;
} catch ( SQLException e ) {
System . out . println ( " erreur dans le resultat " ) ;
}
pst . close ( ) ;
} catch ( SQLException e ) {
System . out . println ( " erreur dans la preparation " ) ;
}
cnx . close ( ) ;
} catch ( SQLException e ) {
System . out . println ( " Erreur dans la connexion! " ) ;
}
} catch ( ClassNotFoundException e ) {
System . out . println ( " pilote non disponible " ) ;
}
2022-11-12 23:14:18 +01:00
}
private void addSousGroupe ( Groupe g ) {
2022-11-12 23:27:30 +01:00
try {
Class . forName ( " org.mariadb.jdbc.Driver " ) ;
try {
Connection cnx = DriverManager . getConnection (
" jdbc:mariadb://dwarves.iut-fbleau.fr/chaignea " ,
" chaignea " , " Chaigneauphpmyadmin " ) ;
try {
PreparedStatement pst = cnx . prepareStatement (
2022-11-13 00:37:08 +01:00
" SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name where Groupe.`id-parent`=? and Groupe.id!=Groupe.`id-parent`; " ) ;
2022-11-12 23:27:30 +01:00
try {
2022-11-13 00:37:08 +01:00
pst . setInt ( g . getId ( ) , 1 ) ;
ResultSet rs = pst . executeQuery ( ) ;
2022-11-12 23:27:30 +01:00
try {
2022-11-13 00:37:08 +01:00
while ( rs . next ( ) ) {
System . out . println ( g . getName ( ) + " " + rs . getString ( 2 ) ) ;
Groupe nouveau = new GroupeNP ( rs . getInt ( 1 ) , rs . getString ( 2 ) , rs . getInt ( 3 ) , rs . getInt ( 4 ) , TypeGroupe . getType ( rs . getString ( 5 ) ) , g ) ;
this . agf . addGroupe ( nouveau ) ;
g . addSousGroupe ( nouveau ) ;
this . addSousGroupe ( nouveau ) ;
}
2022-11-12 23:27:30 +01:00
} catch ( SQLException e ) {
System . out . println ( " erreur dans la prise de resultat " ) ;
}
rs . close ( ) ;
} catch ( SQLException e ) {
2022-11-13 00:37:08 +01:00
//ils n'ont pas de sous groupe
System . out . println ( g . getId ( ) + " est le pere " ) ;
2022-11-12 23:27:30 +01:00
}
pst . close ( ) ;
} catch ( SQLException e ) {
System . out . println ( " erreur dans la preparation " ) ;
}
cnx . close ( ) ;
} catch ( SQLException e ) {
System . out . println ( " Erreur dans la connexion! " ) ;
}
} catch ( ClassNotFoundException e ) {
System . out . println ( " pilote non disponible " ) ;
2022-11-12 19:19:37 +01:00
}
2022-11-12 23:27:30 +01:00
}
2022-11-12 19:19:37 +01:00
}