CCB Premier Import
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="C:/Users/chris/Documents/Christian/workspace/mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>PPE2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,12 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,191 @@
|
||||
Créer la base données Ecole :
|
||||
|
||||
Créer les tables suivantes :
|
||||
|
||||
Classe (idclasse, libelle, salle, nbEleves)
|
||||
Eleve (ideleve, civilite, nom, prenom, idclasse#)
|
||||
|
||||
|
||||
Create database Ecole;
|
||||
Use Ecole;
|
||||
Create table Classe(
|
||||
idclasse int (3) NOT NULL AUTO_INCREMENT,
|
||||
libelle varchar (10),
|
||||
salle varchar (15),
|
||||
nbEleves int(3),
|
||||
primary key(idclasse)
|
||||
);
|
||||
|
||||
Create table Eleve(
|
||||
ideleve int (3) NOT NULL AUTO_INCREMENT,
|
||||
civilite varchar(30),
|
||||
nom varchar(30),
|
||||
prenom varchar(30),
|
||||
idclasse int(3) NOT NULL,
|
||||
primary key (ideleve),
|
||||
foreign key (idclasse) references Classe (idclasse)
|
||||
);
|
||||
|
||||
insert into Classe values
|
||||
(null, "SIO SLAM 2", "salle 2", 0),
|
||||
(null, "SIO SISR 2", "salle 3", 1);
|
||||
|
||||
insert into Eleve values
|
||||
(null, "Monsieur", "Mozar", "Kevin", 2);
|
||||
insert into Eleve values
|
||||
(null, "Madame", "Marie", "Ellen", 1);
|
||||
|
||||
Afficher les triggers
|
||||
show triggers ;
|
||||
|
||||
Rappel : 6 triggers
|
||||
Action : avant before, apres after
|
||||
Requete : update, delete, insert
|
||||
Ancien enregistrement: old
|
||||
Nouveau enregistrement: new
|
||||
Old: quand il y a delete, update
|
||||
New: quand il y a insert, update
|
||||
Créer un trigger qui permet d incrementer le nb eleves de la classe
|
||||
à chaque insertion d un eleve
|
||||
|
||||
delimiter |
|
||||
create trigger After_insert_Eleve
|
||||
After insert on Eleve
|
||||
For each row
|
||||
Begin
|
||||
Update classe
|
||||
Set nbEleves = nbEleves + 1
|
||||
where idclasse = new.idclasse;
|
||||
End |
|
||||
delimiter ;
|
||||
|
||||
insert into Eleve values
|
||||
(null, "Madame", "Marie", "Ellen", 1);
|
||||
|
||||
Supprimer un trigger
|
||||
Drop trigger After_insert_Eleve ;
|
||||
|
||||
Créer un trigger qui permet de décrémenter le nombre d eleves
|
||||
à chaque suppression d un eleve de la classe.
|
||||
|
||||
delimiter |
|
||||
create trigger Alter_delete_Eleve
|
||||
After delete on Eleve
|
||||
For each row
|
||||
Begin
|
||||
update classe
|
||||
Set nbEleves = nbEleves -1
|
||||
where idclasse = old.idclasse;
|
||||
|
||||
end |
|
||||
delimiter ;
|
||||
|
||||
|
||||
delete from Eleve where ideleve=1;
|
||||
-- cree un trigger pour changer un eleve d'une classe à une autre
|
||||
|
||||
delimiter |
|
||||
create trigger After_Update_Eleve
|
||||
After update on Eleve
|
||||
For each row
|
||||
Begin
|
||||
update classe
|
||||
Set nbEleves = nbEleves -1
|
||||
where idclasse = old.idclasse;
|
||||
update classe
|
||||
Set nbEleves = nbEleves +1
|
||||
where idclasse = new.idclasse;
|
||||
End |
|
||||
delimiter ;
|
||||
|
||||
update eleve set idclasse=2 where ideleve = 2;
|
||||
|
||||
ecrire un trigger qui permet a chaque suppresion dun eleve de stocker
|
||||
dans une table a creer ancieneleve avec les memes champs aux quels on
|
||||
ajoute la date de la suppresion.
|
||||
|
||||
create table ancienEleve(
|
||||
idEleve int(3) NOT NULL AUTO_INCREMENT,
|
||||
civilite varchar(30),
|
||||
nom varchar(30),
|
||||
prenom varchar(30),
|
||||
dateDepart date,
|
||||
PRIMARY KEY (idEleve)
|
||||
);
|
||||
|
||||
delimiter |
|
||||
create trigger After_Delete_Eleve
|
||||
After delete on Eleve
|
||||
For each row
|
||||
Begin
|
||||
insert into ancienEleve values(
|
||||
null,
|
||||
old.civilite,
|
||||
old.nom,
|
||||
old.prenom,
|
||||
now()
|
||||
);
|
||||
end |
|
||||
delimiter ;
|
||||
|
||||
Trigger qui controle les donnees avant insertion.
|
||||
|
||||
Syntaxe :
|
||||
Alternative
|
||||
if condition then
|
||||
instruction SQL
|
||||
end ;
|
||||
if condition then
|
||||
instruction SQL
|
||||
else
|
||||
instruction SQL
|
||||
end;
|
||||
|
||||
Affectation
|
||||
Set champ = valeur ;
|
||||
Declaration
|
||||
Declare variable type ;
|
||||
Declare variable type default valeur;
|
||||
|
||||
Exo : ecrire un trigger qui verifie avant insertion que si la civilite
|
||||
n est pas Mr ou Mme, par defaut elle sera egal à Mr.
|
||||
|
||||
|
||||
delimiter |
|
||||
create trigger Before_Insert_Eleve
|
||||
Before insert on Eleve
|
||||
For each row
|
||||
|
||||
Begin
|
||||
if (new.civilite <> 'Mr' and new.civilite <> 'Mme') then
|
||||
set new.civilite = 'Mr';
|
||||
end if;
|
||||
end |
|
||||
|
||||
delimiter ;
|
||||
|
||||
ajouter le champ age dans la table eleve.
|
||||
Mettez ce champ a zero pour tous les eleves
|
||||
modifier le trigger qui verifie que si à l insertion le champ age est negatif
|
||||
on insere la valeur 0.
|
||||
|
||||
ALTER TABLE Eleve ADD age int(3);
|
||||
|
||||
update eleve set age = 0;
|
||||
|
||||
delimiter |
|
||||
create trigger Before_Insert_Eleve
|
||||
Before insert on Eleve
|
||||
For each row
|
||||
|
||||
Begin
|
||||
if (new.civilite <> 'Mr' and new.civilite <> 'Mme') then
|
||||
set new.civilite = 'Mr';
|
||||
end if;
|
||||
if (new.age < 0) then
|
||||
set new.age = 0;
|
||||
end if;
|
||||
end |
|
||||
|
||||
delimiter ;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
drop database if exists PPE2;
|
||||
create database PPE2;
|
||||
use PPE2;
|
||||
|
||||
create table Profil (
|
||||
idprofil int (3) not null auto_increment,
|
||||
nom varchar (50),
|
||||
prenom varchar (50),
|
||||
adresse varchar (100),
|
||||
mail varchar (100),
|
||||
mdp varchar (50),
|
||||
droits varchar (50),
|
||||
primary key (idprofil)
|
||||
);
|
||||
|
||||
insert into Profil values
|
||||
(null, "admin Nom", "admin Prenom", "rue de Paris", "admin@gmail.com", "123", "tout"),
|
||||
(null, "user Nom", "user Prenom", "rue de Lyon", "user@gmail.com", "123", "0-0-1");
|
||||
|
||||
create table client (
|
||||
|
||||
idclient int(5) not null auto_increment,
|
||||
nom varchar(50),
|
||||
prenom varchar(50),
|
||||
email varchar(50),
|
||||
adresse varchar(50),
|
||||
primary key (idclient)
|
||||
);
|
||||
|
||||
insert into client values ("","ben", "oka","oka@gmail.com","rue de paris, limoges"),
|
||||
("","Edwina", "serine","ed@gmail.com","rue de lyon, paris"),
|
||||
("","kamar", "elie","kamar@gmail.com","rue de lille, Lyon");
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package controleur;
|
||||
|
||||
public class Client
|
||||
{
|
||||
private int idclient;
|
||||
private String nom, prenom, email, adresse;
|
||||
|
||||
public Client()
|
||||
{
|
||||
this.idclient =0;
|
||||
this.nom = this.prenom=this.adresse=this.email="";
|
||||
}
|
||||
public Client (int idClient, String nom, String prenom, String email, String adresse)
|
||||
{
|
||||
this.idclient= idClient;
|
||||
this.nom = nom;
|
||||
this.prenom = prenom;
|
||||
this.email = email;
|
||||
this.adresse = adresse;
|
||||
}
|
||||
public Client ( String nom, String prenom, String email, String adresse)
|
||||
{
|
||||
this.idclient= 0;
|
||||
this.nom = nom;
|
||||
this.prenom = prenom;
|
||||
this.email = email;
|
||||
this.adresse = adresse;
|
||||
}
|
||||
public int getIdclient() {
|
||||
return idclient;
|
||||
}
|
||||
public void setIdclient(int idclient) {
|
||||
this.idclient = idclient;
|
||||
}
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
public String getPrenom() {
|
||||
return prenom;
|
||||
}
|
||||
public void setPrenom(String prenom) {
|
||||
this.prenom = prenom;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public String getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
public void setAdresse(String adresse) {
|
||||
this.adresse = adresse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package controleur;
|
||||
|
||||
import vue.Connexion;
|
||||
|
||||
public class Gestion
|
||||
{
|
||||
private static Connexion uneConnexion;
|
||||
|
||||
public Gestion()
|
||||
{
|
||||
uneConnexion = new Connexion();
|
||||
uneConnexion.rendreVisible(true);
|
||||
}
|
||||
|
||||
public static void rendreVisible(boolean val)
|
||||
{
|
||||
uneConnexion.rendreVisible(val);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new Gestion();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package controleur;
|
||||
|
||||
public class Profil
|
||||
{
|
||||
private String nom, prenom, adresse, mail, mdp, droits;
|
||||
|
||||
public Profil(String nom, String prenom, String adresse, String mail, String mdp, String droits)
|
||||
{
|
||||
this.nom = nom;
|
||||
this.prenom = prenom;
|
||||
this.adresse = adresse;
|
||||
this.mail = mail;
|
||||
this.mdp = mdp;
|
||||
this.droits = droits;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getPrenom() {
|
||||
return prenom;
|
||||
}
|
||||
|
||||
public void setPrenom(String prenom) {
|
||||
this.prenom = prenom;
|
||||
}
|
||||
|
||||
public String getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public void setAdresse(String adresse) {
|
||||
this.adresse = adresse;
|
||||
}
|
||||
|
||||
public String getMail() {
|
||||
return mail;
|
||||
}
|
||||
|
||||
public void setMail(String mail) {
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
public String getMdp() {
|
||||
return mdp;
|
||||
}
|
||||
|
||||
public void setMdp(String mdp) {
|
||||
this.mdp = mdp;
|
||||
}
|
||||
|
||||
public String getDroits() {
|
||||
return droits;
|
||||
}
|
||||
|
||||
public void setDroits(String droits) {
|
||||
this.droits = droits;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,60 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
public class BDD
|
||||
{
|
||||
private String serveur, nombdd, user, mdp;
|
||||
private Connection maConnexion;
|
||||
|
||||
public BDD(String serveur, String nombdd, String user, String mdp)
|
||||
{
|
||||
this.serveur = serveur;
|
||||
this.nombdd = nombdd;
|
||||
this.user = user;
|
||||
this.mdp = mdp;
|
||||
this.maConnexion = null;
|
||||
}
|
||||
|
||||
public void chargerPilote()
|
||||
{
|
||||
// vérifie la présence du pilote JDBC MySQL
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
catch(ClassNotFoundException exp) {
|
||||
System.out.println("Abscence du pilote JDBC !");
|
||||
}
|
||||
}
|
||||
|
||||
public void seConnecter()
|
||||
{
|
||||
// connexion au serveur de la BDD
|
||||
this.chargerPilote();
|
||||
String url = "jdbc:mysql://" + this.serveur + "/" + this.nombdd;
|
||||
|
||||
try {
|
||||
this.maConnexion = DriverManager.getConnection(url, this.user, this.mdp);
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("Impossible de se connecter à " + url);
|
||||
}
|
||||
}
|
||||
|
||||
public void seDeconnecter()
|
||||
{
|
||||
// déconnexion au serveur de la BDD
|
||||
try {
|
||||
if(this.maConnexion != null) this.maConnexion.close();
|
||||
}
|
||||
catch(SQLException exp) {
|
||||
System.out.println("La déconnexion a échoué !");
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getMaConnexion()
|
||||
{
|
||||
return this.maConnexion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import controleur.Profil;
|
||||
|
||||
public class Modele
|
||||
{
|
||||
public static ArrayList<Profil> selectAll()
|
||||
{
|
||||
ArrayList<Profil> lesProfils = new ArrayList<Profil>();
|
||||
String requete = "select * from Profil;";
|
||||
|
||||
try {
|
||||
BDD uneBDD = new BDD("localhost", "ppe2", "root", "");
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
|
||||
while(unRes.next())
|
||||
{
|
||||
String nom = unRes.getString("nom");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String adresse = unRes.getString("adresse");
|
||||
String mail = unRes.getString("mail");
|
||||
String mdp = unRes.getString("mdp");
|
||||
String droits = unRes.getString("droits");
|
||||
|
||||
Profil unProfil = new Profil(nom, prenom, adresse, mail, mdp, droits);
|
||||
lesProfils.add(unProfil);
|
||||
}
|
||||
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
|
||||
return lesProfils;
|
||||
}
|
||||
|
||||
public static void insert(Profil unProfil)
|
||||
{
|
||||
String requete = "insert into Profil (nom, prenom, adresse, mail, mdp, droits) values ('"
|
||||
+ unProfil.getNom() + "', '"
|
||||
+ unProfil.getPrenom() + "', '"
|
||||
+ unProfil.getAdresse() + "', '"
|
||||
+ unProfil.getMail() + "', '"
|
||||
+ unProfil.getMdp() + "', '"
|
||||
+ unProfil.getDroits() + "');";
|
||||
try {
|
||||
BDD uneBDD = new BDD("localhost", "ppe2", "root", "");
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
|
||||
public static void delete(String mail)
|
||||
{
|
||||
String requete = "delete from Profil where mail='" + mail + "';";
|
||||
|
||||
try {
|
||||
BDD uneBDD = new BDD("localhost", "ppe2", "root", "");
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
unStat.execute(requete);
|
||||
unStat.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
}
|
||||
|
||||
public static Profil selectWhere(String mail, String mdp)
|
||||
{
|
||||
String requete = "select * from Profil where mail='" + mail + "' and mdp='" + mdp + "';";
|
||||
|
||||
Profil unProfil = null;
|
||||
try {
|
||||
BDD uneBDD = new BDD("localhost", "ppe2", "root", "");
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
|
||||
if(unRes.next())
|
||||
{
|
||||
String nom = unRes.getString("nom");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String adresse = unRes.getString("adresse");
|
||||
String droits = unRes.getString("droits");
|
||||
|
||||
unProfil = new Profil(nom, prenom, adresse, mail, mdp, droits);
|
||||
}
|
||||
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
|
||||
return unProfil;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package modele;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import controleur.Client;
|
||||
|
||||
public class ModeleClient
|
||||
{
|
||||
public static ArrayList<Client> selectAll()
|
||||
{
|
||||
ArrayList<Client> lesClients = new ArrayList<Client>();
|
||||
String requete = "select * from Client;";
|
||||
|
||||
try {
|
||||
BDD uneBDD = new BDD("localhost", "ppe2", "root", "");
|
||||
uneBDD.seConnecter();
|
||||
|
||||
Statement unStat = uneBDD.getMaConnexion().createStatement();
|
||||
ResultSet unRes = unStat.executeQuery(requete);
|
||||
|
||||
while(unRes.next())
|
||||
{
|
||||
String nom = unRes.getString("nom");
|
||||
String prenom = unRes.getString("prenom");
|
||||
String adresse = unRes.getString("adresse");
|
||||
String email = unRes.getString("email");
|
||||
int idclient = unRes.getInt("idclient");
|
||||
|
||||
Client unClient = new Client(idclient, nom, prenom, email, adresse);
|
||||
lesClients.add(unClient);
|
||||
}
|
||||
|
||||
unStat.close();
|
||||
unRes.close();
|
||||
uneBDD.seDeconnecter();
|
||||
}
|
||||
catch(SQLException exp)
|
||||
{
|
||||
System.out.println("Erreur d'execution de la requete " + requete);
|
||||
}
|
||||
|
||||
return lesClients;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package vue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class Connexion extends JFrame
|
||||
{
|
||||
public Connexion()
|
||||
{
|
||||
ImageIcon logo = new ImageIcon(new ImageIcon("src/images/choosemyday_logo.png").getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
|
||||
this.setIconImage(logo.getImage());
|
||||
this.setTitle("ChooseMyDay");
|
||||
this.setBounds(200, 200, 430, 450);
|
||||
this.getContentPane().setBackground(new Color(254, 231, 240));
|
||||
|
||||
this.setLayout(null); // pas de grille
|
||||
this.setResizable(false); // la fenêtre ne pourra pas être redimensionnée
|
||||
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
JLabel lbLogo = new JLabel(logo);
|
||||
lbLogo.setBounds(150, 0, 150, 150);
|
||||
this.add(lbLogo);
|
||||
|
||||
JLabel lbTitre = new JLabel("Bienvenue");
|
||||
lbTitre.setBounds(170, 150, 110, 20);
|
||||
lbTitre.setFont(new Font(lbTitre.getText(), Font.PLAIN, 20));
|
||||
this.add(lbTitre);
|
||||
|
||||
this.add(new VueConnexion());
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void rendreVisible(boolean val)
|
||||
{
|
||||
this.setVisible(val);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package vue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import controleur.Gestion;
|
||||
import controleur.Profil;
|
||||
|
||||
public class Generale extends JFrame implements ActionListener
|
||||
{
|
||||
private JMenuBar uneBarre = new JMenuBar();
|
||||
private JMenu mnFichier = new JMenu("Fichier");
|
||||
private JMenu mnGestion = new JMenu("Gestion");
|
||||
private JMenu mnAide = new JMenu("Aide");
|
||||
|
||||
//private JMenuItem itmProfil = new JMenuItem("Profil");
|
||||
private JMenuItem itmModifier = new JMenuItem("Modifier");
|
||||
private JMenuItem itmQuitter = new JMenuItem("Quitter");
|
||||
|
||||
private JMenuItem itemLister = new JMenuItem("Lister Clients");
|
||||
|
||||
|
||||
private VueClients uneVueClient = new VueClients();
|
||||
private VueAccueil uneVueAccueil ;
|
||||
|
||||
public Generale(Profil unProfil)
|
||||
{
|
||||
ImageIcon logo = new ImageIcon(new ImageIcon("src/images/choosemyday_logo.png").getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
|
||||
this.setIconImage(logo.getImage());
|
||||
this.setTitle("Accueil");
|
||||
this.setBounds(200, 200, 430, 450);
|
||||
this.getContentPane().setBackground(new Color(254, 231, 240));
|
||||
|
||||
this.setLayout(null);
|
||||
this.setResizable(false);
|
||||
|
||||
this.uneVueAccueil = new VueAccueil(unProfil);
|
||||
this.add(uneVueAccueil);
|
||||
|
||||
this.add(uneVueClient);
|
||||
|
||||
|
||||
this.uneBarre.add(this.mnFichier);
|
||||
this.uneBarre.add(this.mnGestion);
|
||||
this.uneBarre.add(this.mnAide);
|
||||
|
||||
this.mnFichier.add(this.itmQuitter);
|
||||
this.mnGestion.add(this.itmModifier);
|
||||
|
||||
this.mnGestion.add(this.itemLister);
|
||||
|
||||
this.itemLister.addActionListener(this);
|
||||
|
||||
this.itmQuitter.addActionListener(this);
|
||||
this.itmModifier.addActionListener(this);
|
||||
//this.itmProfil.addActionListener(this);
|
||||
|
||||
this.setJMenuBar(this.uneBarre);
|
||||
|
||||
JLabel lbTitre = new JLabel("Accueil");
|
||||
lbTitre.setBounds(170, 10, 110, 20);
|
||||
lbTitre.setFont(new Font(lbTitre.getText(), Font.PLAIN, 20));
|
||||
this.add(lbTitre);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if(e.getSource() == this.itmQuitter)
|
||||
{
|
||||
Gestion.rendreVisible(true);
|
||||
|
||||
this.setVisible(false);
|
||||
}
|
||||
else if (e.getSource()==this.itemLister)
|
||||
{
|
||||
//rendre visible panel Clients
|
||||
uneVueAccueil.setVisible(false);
|
||||
uneVueClient.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package vue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import controleur.Profil;
|
||||
|
||||
public class VueAccueil extends JPanel
|
||||
{
|
||||
public VueAccueil(Profil unProfil)
|
||||
{
|
||||
this.setBounds(70, 50, 300, 250);
|
||||
this.setBackground(Color.pink);
|
||||
this.setLayout(null);
|
||||
|
||||
JLabel lbProfil = new JLabel("Votre Profil");
|
||||
lbProfil.setBounds(90, 10, 150, 40);
|
||||
lbProfil.setFont(new Font(lbProfil.getText(), Font.PLAIN + Font.BOLD, 18));
|
||||
this.add(lbProfil);
|
||||
|
||||
JTextArea txtTitre = new JTextArea();
|
||||
txtTitre.setBounds(20, 50, 280, 200);
|
||||
//txtTitre.setBounds(x, y, width, height);
|
||||
txtTitre.setEditable(false);
|
||||
txtTitre.setBackground(Color.pink);
|
||||
txtTitre.setFont(new Font(txtTitre.getText(), Font.PLAIN, 15));
|
||||
// txtTitre.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
|
||||
|
||||
txtTitre.setText( "\n Nom : " + unProfil.getNom()
|
||||
+ "\n Prénom : " + unProfil.getPrenom()
|
||||
+ "\n Adresse : " + unProfil.getAdresse()
|
||||
+ "\n Droits : " + unProfil.getDroits());
|
||||
this.add(txtTitre);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
// TODO Stub de la méthode généré automatiquement
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package vue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import controleur.Client;
|
||||
import modele.ModeleClient;
|
||||
|
||||
public class VueClients extends JPanel implements ActionListener
|
||||
{
|
||||
private JLabel titre = new JLabel("Liste des clients ");
|
||||
private JTable tableClients;
|
||||
|
||||
public VueClients ()
|
||||
{
|
||||
this.setBounds(50, 30, 350, 250);
|
||||
this.setLayout(null);
|
||||
this.setBackground(Color.CYAN);
|
||||
this.titre.setBounds(100, 10, 100, 20);
|
||||
this.add(this.titre);
|
||||
|
||||
String titres [] = {"id Client", "Nom", "Prénom", "Email","Adresse"};
|
||||
|
||||
this.tableClients = new JTable(this.extraireClients(), titres);
|
||||
|
||||
JScrollPane uneScroll = new JScrollPane(this.tableClients);
|
||||
uneScroll.setBounds(10, 10, 340, 240);
|
||||
this.add(uneScroll);
|
||||
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
}
|
||||
|
||||
//extraire les clients
|
||||
|
||||
public Object [][] extraireClients ()
|
||||
{
|
||||
ArrayList <Client> lesClients = ModeleClient.selectAll();
|
||||
Object [][] donnees = new Object [lesClients.size()][5];
|
||||
int i =0;
|
||||
for (Client unClient : lesClients)
|
||||
{
|
||||
donnees[i][0] = unClient.getIdclient();
|
||||
donnees[i][1] = unClient.getNom();
|
||||
donnees[i][2] = unClient.getPrenom();
|
||||
donnees[i][3] = unClient.getEmail();
|
||||
donnees[i][4] = unClient.getAdresse();
|
||||
i++;
|
||||
}
|
||||
return donnees;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package vue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import controleur.Gestion;
|
||||
import controleur.Profil;
|
||||
import modele.Modele;
|
||||
|
||||
public class VueConnexion extends JPanel implements ActionListener
|
||||
{
|
||||
private JTextField txtMail = new JTextField();
|
||||
private JPasswordField txtMdp = new JPasswordField();
|
||||
private JButton btAnnuler = new JButton("Annuler");
|
||||
private JButton btSeConnecter = new JButton("Se connecter");
|
||||
|
||||
public VueConnexion()
|
||||
{
|
||||
this.setBounds(70, 200, 300, 150);
|
||||
this.setLayout(new GridLayout(3, 2));
|
||||
this.setBackground(Color.pink);
|
||||
|
||||
JLabel lbMail = new JLabel(" E-mail :");
|
||||
lbMail.setFont(new Font(lbMail.getText(), Font.PLAIN, 16));
|
||||
this.add(lbMail);
|
||||
this.add(this.txtMail);
|
||||
|
||||
JLabel lbMdp = new JLabel(" Mot de passe :");
|
||||
lbMdp.setFont(new Font(lbMdp.getText(), Font.PLAIN, 16));
|
||||
this.add(lbMdp);
|
||||
this.add(this.txtMdp);
|
||||
|
||||
this.add(this.btAnnuler);
|
||||
this.btAnnuler.setIcon(new ImageIcon(new ImageIcon("src/images/choix1.png").getImage().getScaledInstance(15, 15, Image.SCALE_DEFAULT)));
|
||||
this.btAnnuler.addActionListener(this);
|
||||
|
||||
this.add(this.btSeConnecter);
|
||||
this.btSeConnecter.setIcon(new ImageIcon(new ImageIcon("src/images/choix2.png").getImage().getScaledInstance(15, 15, Image.SCALE_DEFAULT)));
|
||||
this.btSeConnecter.addActionListener(this);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if(e.getSource() == this.btAnnuler)
|
||||
{
|
||||
this.txtMail.setText("");
|
||||
this.txtMdp.setText("");
|
||||
}
|
||||
else if(e.getSource() == this.btSeConnecter)
|
||||
{
|
||||
String mail = this.txtMail.getText();
|
||||
String mdp = new String(this.txtMdp.getPassword());
|
||||
|
||||
Profil unProfil = Modele.selectWhere(mail, mdp);
|
||||
if(unProfil == null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Veuillez vérifier vos identifiants !");
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Connexion réussie\n"
|
||||
+ "Bienvenue M./Mme " + unProfil.getNom() + " " + unProfil.getPrenom());
|
||||
|
||||
// ouvrir le menu général
|
||||
new Generale(unProfil);
|
||||
this.txtMail.setText("");
|
||||
this.txtMdp.setText("");
|
||||
Gestion.rendreVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user