new file: bd.properties

new file:   bd.script
	new file:   bin/CtrlAccesListe.class
	new file:   bin/CtrlLogin.class
	new file:   bin/modele/Disciplines.class
	new file:   bin/modele/Evenements.class
	new file:   bin/modele/Membres.class
	new file:   bin/modele/Participer.class
	new file:   bin/test.class
	new file:   bin/vue/Planning$1.class
	new file:   bin/vue/Planning$2.class
	new file:   bin/vue/Planning$3.class
	new file:   bin/vue/Planning.class
	new file:   lib/hsqldb.jar
	new file:   lib/servlet-2_3-fcs-classfiles.zip
	new file:   lib/sqltool.jar
	new file:   src/CtrlAccesListe.java
	new file:   src/CtrlLogin.java
	new file:   src/modele/Disciplines.java
	new file:   src/modele/Evenements.java
	new file:   src/modele/Membres.java
	new file:   src/modele/Participer.java
	new file:   src/test.java
	new file:   src/vue/Planning.java
This commit is contained in:
Quentin
2013-12-07 15:14:36 +01:00
parent 44c1a9ac42
commit 3fdf7aae3a
24 changed files with 919 additions and 0 deletions

62
src/CtrlAccesListe.java Normal file
View File

@ -0,0 +1,62 @@
import java.awt.Container;
import java.awt.FlowLayout;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JFrame;
import vue.Planning;
import modele.Evenements;
public class CtrlAccesListe {
public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
Evenements e;
ResultSet r;
JFrame f_planning ;
Planning p ;
f_planning = new JFrame("Planning") ;
p = new Planning() ;
Container c = f_planning.getContentPane();
c.setLayout(new FlowLayout());
// cr<63>e le planning <20> la date actuelle
c.add(p);
/*
// c.add(new Planning(2012, 4, 20)) ;
p.color_date(11) ;
p.color_date(20) ;*/
f_planning.pack();
// f_planning.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f_planning.setVisible(true);
f_planning.setResizable(false) ;
e = new Evenements();
e.setEvenement("2012-11-20", 1, "toulouse");
r = e.getEvenement(-1);
while(r.next())
{
String str[]=r.getString("dateE").split("-");
p.color_date(Integer.decode( str[2]));
}
}
}

10
src/CtrlLogin.java Normal file
View File

@ -0,0 +1,10 @@
public class CtrlLogin {
//attributs
//Constructeurs
//méthodes
}

View File

@ -0,0 +1,80 @@
package modele;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Disciplines {
//attributs
//constructueurs
public Disciplines(){}
//methodes
/**
* permet de saisir une discipline pour un entrainement donné
* @param pIdEntrainement
* @param pNomDiscipline
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public void setDiscipline(int pIdEntrainement, String pNomDiscipline) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//insertion nouveau membres
Statement statement = connexion.createStatement() ;
statement.executeUpdate("INSERT INTO Disciplines (nomDiscipline, idEntrainement)"
+ "VALUES ('"+ pIdEntrainement +"', '"+ pIdEntrainement );
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
connexion.close();
}
/**
* permet d'obtenir la discipline pour un entrainement donnée
* @param pIdEntrainement
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public String getDiscipline (int pIdEntrainement) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT nomDiscipline FROM membres WHERE" +
"idEvenement =" + pIdEntrainement);
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat.getString("nomDiscipline");
}
}

View File

@ -0,0 +1,76 @@
package modele;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Evenements {
//attributs
//Constuctueurs
public Evenements(){};
//méthodes
public void setEvenement(String pDate, int pType, String pLieu) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//insertion nouveau membres
Statement statement = connexion.createStatement() ;
statement.executeUpdate("INSERT INTO Evenements (type, dateE, lieu)"
+ "VALUES ('"+ pType +"', '"+ pDate +"', '"+ pLieu +"')" );
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
connexion.close();
}
/**
*
* @param pIdEvenement
* @return un resultSet contenant le ou les infos evenements
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public ResultSet getEvenement(int pIdEvenement) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
if(pIdEvenement == -1)
{
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT * FROM evenements ");
}
else
{
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT * FROM evenements WHERE idEvenement =" + pIdEvenement);
}
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat;
}
}

126
src/modele/Membres.java Normal file
View File

@ -0,0 +1,126 @@
package modele;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Membres {
//attributs
/* private String nom;
private String prenom;
private String adresse;
private String dtn;
private String numTel;
private String droit;
private String dateAdhesion;
private String password;*/
//Constructeurs
public Membres() {}
//méthode
/**
* Insere dans la base un nouveau membres
* @param pNom
* @param pPrenom
* @param pDtn
* @param pNumTel
* @param pAdresse
* @param pDroit
* @param pDateAdhesion
* @param pPassword
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public void setInfo(String pNom, String pPrenom, String pDtn, String pNumTel, String pAdresse,
int pDroit, String pDateAdhesion,String pPassword) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//insertion nouveau membres
Statement statement = connexion.createStatement() ;
statement.executeUpdate("INSERT INTO membres (nom, prenom, adresse,"
+" numTel, droit, password, dtn, dateAdhesion )"
+ "VALUES ('"+ pNom +"', '"+ pPrenom +"', '"+ pAdresse +"',"
+"'"+ pNumTel +"', '"+ pDroit +"', '"+ pPassword +"', "
+"'"+ pDtn +"', '"+ pDateAdhesion +"')");
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
connexion.close();
}
/**
* idMembres les infos du membre ou si -1 alors retourne les infos de tout les membres
* @param pIdMembres
* @return un resultSet contenant le ou les infos membres
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public ResultSet getInfo(int pIdMembre) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
if(pIdMembre == -1)
{
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT * FROM membres ");
}
else
{
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT * FROM membres WHERE idMembre =" + pIdMembre);
}
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat;
}
public void supprimer(int pIdMembre) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
statement.executeUpdate("DROP * WHERE idMembre= " + pIdMembre) ;
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
}
}

163
src/modele/Participer.java Normal file
View File

@ -0,0 +1,163 @@
package modele;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Participer {
//attributs
//constructeurs
public Participer(){};
//méthodes
/**
* permet de saisir le role d'un membre lors d'un evenement
* @param pIdEvenement
* @param pIdMembre
* @param role
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public void setRole(int pIdEvenement, int pIdMembre, int role ) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//insertion nouveau membres
Statement statement = connexion.createStatement() ;
statement.executeUpdate("INSERT INTO participer (idEvenement, idMembre, role)"
+ "VALUES ('"+ pIdEvenement +"', '"+ pIdMembre +"', '"+ role +"')" );
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
connexion.close();
}
/**
* permet d'avoir le role d'un membre lors d'un evenement
* @param pIdEvenement
* @param pIdMembre
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public int getRole(int pIdEvenement, int pIdMembre) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT role FROM evenements WHERE idEvenement = " +
pIdEvenement + " AND idMembre = " + pIdMembre);
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat.getInt("role");
}
/**
* permet de se désincrire un membre d'un evenelement
* @param pIdEvenement
* @param pIdMembre
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SQLException
*/
public void setAnnuler(int pIdEvenement, int pIdMembre) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
statement.executeUpdate("DROP * WHERE idEvenement = " +
pIdEvenement + " AND idMembre = " + pIdMembre);
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
}
public ResultSet getListeParticipants(int pIdEvenement) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT idMembre FROM evenements WHERE idEvenement = " +
pIdEvenement );
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat;
}
public ResultSet getListeParticipation (int pIdMembre) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
{
Statement statement;
ResultSet resultat;
//connexion à la base
Connection connexion = null;
Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
connexion = DriverManager.getConnection("jdbc:hsqldb:file:bd", "sa", "" );
//récupération infos dans la bases
statement = connexion.createStatement();
resultat = statement.executeQuery("SELECT idEvenement FROM evenements WHERE idMembre = " +
pIdMembre );
//fermeture base
statement = connexion.createStatement();
statement.executeQuery("SHUTDOWN");
statement.close();
return resultat;
}
}

42
src/test.java Normal file
View File

@ -0,0 +1,42 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import modele.Evenements;
import modele.Membres;
public class test {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
Membres m;
Evenements e;
ResultSet r;
m = new Membres();
e = new Evenements();
e.setEvenement("2013-10-12", 0, "lol");
//m.setInfo("g", "lo", "2000-05-08", "0568025855", "lol", 1, "2013-05-20", "pp");
r = e.getEvenement(-1);
while(r.next())
{
String str[]=r.getString("dateE").split("-");
System.out.println(str[0]);
System.out.println(str[1]);
System.out.println(str[2]);
System.out.println(r.getDate("dateE"));
}
System.out.println("fin");
}
}

296
src/vue/Planning.java Normal file
View File

@ -0,0 +1,296 @@
package vue;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Planning extends JPanel {
protected int yy;
protected int mm, dd;
protected JButton labs[][];
protected int leadGap = 0;
Calendar calendar = new GregorianCalendar();
protected final int thisYear = calendar.get(Calendar.YEAR);
protected final int thisMonth = calendar.get(Calendar.MONTH);
private JButton b0;
private JComboBox monthChoice;
private JComboBox yearChoice;
private JButton b_inscrire ;
private JButton b_desinscrire ;
private JPanel p_button, p_grille, p_south ;
/**
* Construit un calendrier commencant <20> la date actuelle
*/
public Planning() {
super();
setYYMMDD(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH));
buildGUI();
recompute();
print_button() ;
}
/**
* Construit un calendrier, en donnant le jour, mois, ann<6E>e
*
* @exception IllegalArgumentException
* Si l'ann<6E>e n'est pas correcte
*/
public Planning(int year, int month, int today) {
super();
setYYMMDD(year, month, today);
buildGUI();
recompute();
print_button() ;
}
private void setYYMMDD(int year, int month, int today) {
yy = year;
mm = month;
dd = today;
}
String[] months = { "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin",
"Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre" };
/** Build the GUI. Assumes that setYYMMDD has been called. */
private void buildGUI() {
getAccessibleContext().setAccessibleDescription(
"Calendrier non disponible, desole");
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
JPanel tp = new JPanel();
tp.add(monthChoice = new JComboBox());
for (int i = 0; i < months.length; i++)
monthChoice.addItem(months[i]);
monthChoice.setSelectedItem(months[mm]) ;
monthChoice.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int i = monthChoice.getSelectedIndex();
if (i >= 0) {
mm = i;
recompute();
}
}
});
monthChoice.getAccessibleContext().setAccessibleName("Mois");
monthChoice.getAccessibleContext().setAccessibleDescription(
"Choisir mois");
tp.add(yearChoice = new JComboBox());
yearChoice.setEditable(true);
for (int i = yy - 5; i < yy + 5; i++)
yearChoice.addItem(Integer.toString(i));
yearChoice.setSelectedItem(Integer.toString(yy));
yearChoice.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int i = yearChoice.getSelectedIndex();
if (i >= 0) {
yy = Integer.parseInt(yearChoice.getSelectedItem()
.toString());
recompute();
}
}
});
add(BorderLayout.NORTH, tp);
JPanel bp = new JPanel();
bp.setLayout(new GridLayout(7, 7));
labs = new JButton[6][7];
bp.add(b0 = new JButton("Dimanche"));
bp.add(new JButton("Lundi"));
bp.add(new JButton("Mardi"));
bp.add(new JButton("Mercredi"));
bp.add(new JButton("Jeudi"));
bp.add(new JButton("Vendredi"));
bp.add(new JButton("Samedi"));
ActionListener dateSetter = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String num = e.getActionCommand();
if (!num.equals("")) {
// met le jour actuel d'une couleur
setDayActive(Integer.parseInt(num));
}
}
};
// Ajout des boutons
for (int i = 0; i < 6; i++)
for (int j = 0; j < 7; j++) {
bp.add(labs[i][j] = new JButton(""));
labs[i][j].addActionListener(dateSetter);
}
add(BorderLayout.CENTER, bp);
}
public final static int dom[] = { 31, 28, 31, 30, /* jan fev mar avr */
31, 30, 31, 31, /* mai juin juil aout */
30, 31, 30, 31 /* sep oct nov dec */
};
/** Compute which days to put where, in the Cal panel */
protected void recompute() {
if (mm < 0 || mm > 11)
throw new IllegalArgumentException("Mois " + mm
+ " bad, must be 0-11");
clearDayActive();
calendar = new GregorianCalendar(yy, mm, dd);
leadGap = new GregorianCalendar(yy, mm, 1).get(Calendar.DAY_OF_WEEK) - 1;
int daysInMonth = dom[mm];
if (isLeap(calendar.get(Calendar.YEAR)) && mm == 1)
++daysInMonth;
// R<>initialise le label
for (int i = 0; i < leadGap; i++) {
labs[0][i].setText("");
}
for (int i = 1; i <= daysInMonth; i++) {
JButton b = labs[(leadGap + i - 1) / 7][(leadGap + i - 1) % 7];
b.setText(Integer.toString(i));
}
for (int i = leadGap + 1 + daysInMonth; i < 6 * 7; i++) {
labs[(i) / 7][(i) % 7].setText("");
}
// Shade current day, only if current month
if (thisYear == yy && mm == thisMonth)
setDayActive(dd);
// Recharge l'<27>cran
repaint();
}
/**
* isLeap() returns true if the given year is a Leap Year.
*
* "a year is a leap year if it is divisible by 4 but not by 100, except
* that years divisible by 400 *are* leap years." -- Kernighan &#038; Ritchie,
* _The C Programming Language_, p 37.
*/
public boolean isLeap(int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return true;
return false;
}
/** Set l'ann<6E>e, le mois et le jour */
public void setDate(int yy, int mm, int dd) {
this.yy = yy;
this.mm = mm; // starts at 0, like Date
this.dd = dd;
recompute();
}
/** Met <20> jour le jour actuel */
private void clearDayActive() {
JButton b;
if (activeDay > 0) {
b = labs[(leadGap + activeDay - 1) / 7][(leadGap + activeDay - 1) % 7];
b.setBackground(b0.getBackground());
b.repaint();
activeDay = -1;
}
}
private int activeDay = -1;
/** Set just the day, on the current month */
public void setDayActive(int newDay) {
clearDayActive();
// Entre le nouveau
if (newDay <= 0)
dd = new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
else
dd = newDay;
Component square = labs[(leadGap + newDay - 1) / 7][(leadGap + newDay - 1) % 7];
square.setBackground(Color.red);
square.repaint();
activeDay = newDay;
}
public void setTaskDay(int newDay){
Component square = labs[(leadGap + newDay - 1) / 7][(leadGap + newDay - 1) % 7];
square.setBackground(Color.yellow);
square.repaint();
}
private void print_button() {
// rajouter bouton inscrire / d<>sinscrire, si jour dispo ou non
this.b_inscrire = new JButton("S'inscrire") ;
this.b_desinscrire = new JButton("Se desinscrire") ;
b_inscrire.setEnabled(true) ;
b_desinscrire.setEnabled(false) ;
this.p_grille = new JPanel() ;
this.p_button = new JPanel() ;
this.p_south = new JPanel() ;
p_button.setLayout(new FlowLayout()) ;
p_grille.setLayout(new GridLayout(1, 2));
p_button.add(p_grille) ;
p_grille.add(b_inscrire);
p_grille.add(b_desinscrire) ;
p_south.add(p_button) ;
this.add(p_south, BorderLayout.SOUTH) ;
}
public void color_date(int day) {
setTaskDay(day) ;
}
}