129 lines
5.0 KiB
Java
129 lines
5.0 KiB
Java
package fr.iutfbleau.projetIHM2022FI2.Graphic;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.util.Iterator;
|
|
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.*;
|
|
|
|
import fr.iutfbleau.projetIHM2022FI2.API.AbstractGroupeFactory;
|
|
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.Graphic.View.PaintGroupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.MNP.AbstractGroupeFactoryNP;
|
|
import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP;
|
|
|
|
public class Graphic{
|
|
private PaintGroupe paint;
|
|
private JFrame fenetre;
|
|
private AbstractGroupeFactory agf;
|
|
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);
|
|
this.getPromo();
|
|
this.fenetre.setVisible(true);
|
|
/*
|
|
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());
|
|
}*/
|
|
}
|
|
|
|
private void getPromo(){
|
|
this.agf=null;
|
|
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(
|
|
"SELECT `id`, `nom`, `min`, `max`, `value`, `id-parent` FROM `Groupe` join `TYPE` on Groupe.Type=TYPE.name ORDER BY Groupe.id ASC; ");
|
|
try{
|
|
ResultSet rs = pst.executeQuery();
|
|
try{
|
|
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);
|
|
this.agf=new AbstractGroupeFactoryNP(promo);
|
|
this.addSousGroupe(promo);
|
|
}
|
|
while(rs.next()){
|
|
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);
|
|
}
|
|
}
|
|
}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");
|
|
}
|
|
}
|
|
private void addSousGroupe(Groupe g){
|
|
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(
|
|
"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`;");
|
|
try{
|
|
pst.setInt(g.getId(), 1);
|
|
ResultSet rs=pst.executeQuery();
|
|
try{
|
|
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);
|
|
}
|
|
}catch(SQLException e){
|
|
System.out.println("erreur dans la prise de resultat");
|
|
}
|
|
rs.close();
|
|
}catch(SQLException e){
|
|
//ils n'ont pas de sous groupe
|
|
System.out.println(g.getId() + "est le pere");
|
|
}
|
|
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");
|
|
}
|
|
}
|
|
}
|