CCB Premier Import

This commit is contained in:
Christian Cunat-Brulé
2018-07-23 10:52:48 +02:00
commit f55475a23f
765 changed files with 209793 additions and 0 deletions

7
Stock/.classpath Normal file
View File

@@ -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>

17
Stock/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Stock</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>

View File

@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
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.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
Stock/bin/modele/Bdd.class Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Stock/bin/vue/VueMenu.class Normal file

Binary file not shown.

40
Stock/sql.sql Normal file
View File

@@ -0,0 +1,40 @@
Cours de base de données
1. Les requetes select
Soit la base de données suivante Stock avec la seule table produit.
_________________________________________
Create database stock;
use stock;
create table produit (
reference varchar(50) not null,
designation varchar (50),
prix float (5.2),
qte int (5),
categorie varchar(50),
primary key(reference)
);
___________________________________________
insert into produit values ("001", "lait", 1.20, 3, "alimentaire"),
("002", "sucre", 0.90, 10, "alimentaire"),
("003", "savon", 2.20, 5, "beauté"),
("004", "pelle", 6.20, 2, "jardinage");
Question
Afficher tous les produits :
Select * from produit;
Select * from produit where categorie = "alimentaire";
Afficher la référence, désignation, et quantité des
produits ayant un prix supérieur à 1 .
select reference, designation, qte
from produit
where prix > 1;
Select reference, designation from produit where qte <= 2;
Select * from produit
where prix < 1 and categorie = "alimentaire";

View File

@@ -0,0 +1,124 @@
package controleur;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import org.omg.CORBA.UNSUPPORTED_POLICY_VALUE;
import modele.Modele;
import vue.VueAccueil;
import vue.VueDelete;
import vue.VueInsert;
import vue.VueMenu;
public class Gestion extends JFrame implements ActionListener
{
private static VueInsert uneVueInsert ;
private static VueMenu uneVueMenu;
private static VueAccueil uneVueAccueil;
private static VueDelete uneVueDelete;
private JMenuBar uneBarre = new JMenuBar();
private JMenu mnFichier = new JMenu("Fichier");
private JMenu mnOperations = new JMenu("Op<EFBFBD>rations");
private JMenu mnAide = new JMenu("Aide");
private JMenuItem itemQuitter = new JMenuItem("Quitter");
private JMenuItem itemAjouter = new JMenuItem("Ajouter");
private JMenuItem itemLister = new JMenuItem("Lister");
private JMenuItem itemSupprimer= new JMenuItem("Supprimer");
private JMenuItem itemRechercher= new JMenuItem("Rechercher");
private JMenuItem itemApropos = new JMenuItem("Apropos");
public Gestion()
{
this.setTitle("Gestion de stock");
this.setBounds(200, 200, 500, 350);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(null);
uneVueInsert = new VueInsert();
uneVueMenu = new VueMenu();
uneVueAccueil = new VueAccueil();
uneVueDelete = new VueDelete();
this.add(uneVueInsert);
this.add(uneVueMenu);
this.add(uneVueAccueil);
this.add(uneVueDelete);
this.mnFichier.add(this.itemQuitter);
this.mnOperations.add(this.itemAjouter);
this.mnOperations.add(this.itemLister);
this.mnOperations.add(this.itemSupprimer);
this.mnOperations.add(this.itemRechercher);
this.mnAide.add(this.itemApropos);
this.uneBarre.add(this.mnFichier);
this.uneBarre.add(this.mnOperations);
this.uneBarre.add(this.mnAide);
this.setJMenuBar(this.uneBarre);
//rendre les items cliquables
this.itemAjouter.addActionListener(this);
this.itemSupprimer.addActionListener(this);
this.itemLister.addActionListener(this);
this.itemRechercher.addActionListener(this);
this.itemApropos.addActionListener(this);
this.itemQuitter.addActionListener(this);
this.setVisible(true);
}
public static void main(String[] args) {
new Gestion ();
}
public static void rendreVisibleVueInsert(boolean valeur)
{
uneVueInsert.setVisible(valeur);
}
public static void rendreVisibleVueAccueil(boolean valeur)
{
uneVueAccueil.setVisible(valeur);
}
public static void rendreVisibleVueDelete(boolean valeur)
{
uneVueDelete.setVisible(valeur);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==this.itemAjouter)
{
uneVueAccueil.setVisible(false);
uneVueDelete.setVisible(false);
uneVueInsert.setVisible(true);
}else if (e.getSource()==this.itemApropos)
{
uneVueDelete.setVisible(false);
uneVueAccueil.setVisible(true);
uneVueInsert.setVisible(false);
}else if (e.getSource()==this.itemQuitter)
{
this.dispose();
}else if (e.getSource()==this.itemSupprimer)
{
uneVueDelete.setVisible(true);
uneVueAccueil.setVisible(false);
uneVueInsert.setVisible(false);
}
}
}

View File

@@ -0,0 +1,61 @@
package controleur;
public class Produit
{
private String reference, designation;
private int qte;
private float prix ;
public Produit ()
{
this.reference ="";
this.designation ="";
this.qte = 0;
this.prix = 0;
}
public Produit(String reference, String designation, int qte, float prix)
{
this.reference = reference;
this.designation = designation;
this.qte = qte;
this.prix = prix ;
}
public String toString ()
{
return this.reference+"-"+this.designation+"-"+this.qte+"-"+this.prix;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public int getQte() {
return qte;
}
public void setQte(int qte) {
this.qte = qte;
}
public float getPrix() {
return prix;
}
public void setPrix(float prix) {
this.prix = prix;
}
//getters et setters
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

67
Stock/src/modele/Bdd.java Normal file
View File

@@ -0,0 +1,67 @@
package modele;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Bdd
{
private String serveur, bdd, user, mdp;
private Connection maConnexion ;
public Bdd (String serveur, String bdd, String user, String mdp)
{
this.serveur = serveur;
this.bdd = bdd;
this.user = user;
this.mdp = mdp;
this.maConnexion = null;
}
public void chargerPilote ()
{
//verifie la presence du pilote JDBC Mysql
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException exp)
{
System.out.println("Absence du pilote Jdbc !");
}
}
public void seConnecter ()
{
//connexion au serveur et la bdd
this.chargerPilote();
String url ="jdbc:mysql://"+this.serveur+"/"+this.bdd;
try
{
this.maConnexion = DriverManager.getConnection(url, this.user, this.mdp);
}
catch(SQLException exp)
{
System.out.println("Impossible de se connecter a : "+url);
}
}
public void seDeConnecter ()
{
//fermeture de la connexion
try
{
if (this.maConnexion!=null)
{
this.maConnexion.close();
}
}
catch (SQLException exp)
{
System.out.println("Erreur de fermeture de la connexion !");
}
}
public Connection getMaConnexion ()
{
return this.maConnexion;
}
}

View File

@@ -0,0 +1,110 @@
package modele;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import controleur.Produit;
public class Modele
{
public static ArrayList<Produit> selectAll()
{
ArrayList<Produit> lesProduits = new ArrayList<Produit>();
String requete ="Select * from produit ; ";
try
{
Bdd uneBdd = new Bdd("localhost", "stock", "root", "");
uneBdd.seConnecter();
Statement unStat = uneBdd.getMaConnexion().createStatement();
ResultSet unRes = unStat.executeQuery(requete);
while (unRes.next())
{
String reference = unRes.getString("reference");
String designation = unRes.getString("designation");
int qte = unRes.getInt("qte");
float prix = unRes.getFloat("prix");
Produit unProduit = new Produit(reference, designation, qte, prix);
lesProduits.add(unProduit);
}
unStat.close();
unRes.close();
uneBdd.seDeConnecter();
}
catch (SQLException exp)
{
System.out.println("Erreur d'execution de la requete : "+requete);
}
return lesProduits;
}
public static void insert (Produit unProduit)
{
String requete ="insert into produit (reference, designation, qte, prix)"
+ " values ('"+unProduit.getReference()+"','"+unProduit.getDesignation()
+"',"+unProduit.getQte()+","+unProduit.getPrix()+"); ";
try
{
Bdd uneBdd = new Bdd("localhost", "stock", "root", "");
uneBdd.seConnecter();
Statement unStat = uneBdd.getMaConnexion().createStatement();
unStat.execute(requete);
unStat.close();
uneBdd.seDeConnecter();
}
catch (SQLException exp)
{
System.out.println("Erreur d'execution requete : "+requete);
}
}
public static void delete (String reference)
{
String requete = "DELETE FROM Produit WHERE reference ='"+reference+"';";
try
{
Bdd uneBdd = new Bdd("localhost", "stock", "root", "");
uneBdd.seConnecter();
Statement unStat = uneBdd.getMaConnexion().createStatement();
unStat.execute(requete);
unStat.close();
uneBdd.seDeConnecter();
}
catch (SQLException exp)
{
System.out.println("Erreur d'execution requete : "+requete);
}
}
}

View File

@@ -0,0 +1,27 @@
package vue;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class VueAccueil extends JPanel
{
public VueAccueil()
{
this.setBounds(150, 20, 300, 300);
this.setLayout(new GridLayout(4, 1));
this.setBackground(Color.GRAY);
JLabel titre = new JLabel("Logiciel realis<69> le 6-01-2017");
JLabel logo = new JLabel(new ImageIcon("src/images/enregistrer.png"));
this.add(new JLabel());
this.add(titre);
this.add(logo);
this.add(new JLabel());
this.setVisible(true);
}
}

View File

@@ -0,0 +1,65 @@
package vue;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import controleur.Produit;
import modele.Modele;
public class VueDelete extends JPanel implements ActionListener
{
private JComboBox cbxChoix = new JComboBox();
private JButton btOk = new JButton("Ok");
private JLabel lbMessage = new JLabel("");
public VueDelete ()
{
this.setBounds(150, 20, 300, 300);
this.setLayout(new GridLayout(5, 1));
this.setBackground(Color.GRAY);
this.add(new JLabel("Suppression d'un produit"));
this.add(this.cbxChoix);
this.add(this.btOk);
this.add(lbMessage);
this.add(new JLabel());
this.remplirCbx();
this.btOk.addActionListener(this);
this.setVisible(false);
}
public void remplirCbx()
{
ArrayList<Produit> lesProduits = Modele.selectAll();
for (Produit unProduit : lesProduits)
{
this.cbxChoix.addItem(unProduit.toString());
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()== this.btOk)
{
String chaine = this.cbxChoix.getSelectedItem().toString();
String tab[]= chaine.split("-");
Modele.delete(tab[0]);
JOptionPane.showMessageDialog(this, "Suppression effectuee");
this.lbMessage.setText("Suppression effectue");
//on vide tout dans le cbx et on rerempli ou supprimer l'item seclectionne
}
}
}

View File

@@ -0,0 +1,115 @@
package vue;
import java.awt.Color;
import java.awt.GridLayout;
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.JTextField;
import controleur.Produit;
import modele.Modele;
public class VueInsert extends JPanel implements ActionListener
{
private JTextField txtRef = new JTextField();
private JTextField txtDes = new JTextField();
private JTextField txtQte = new JTextField();
private JTextField txtPrix = new JTextField();
private JButton btAnnuler = new JButton("Annuler");
private JButton btEnregistrer = new JButton("Enregistrer");
public VueInsert()
{
this.setBounds(150, 20, 300, 300);
this.setLayout(new GridLayout(6, 2));
this.setBackground(Color.CYAN);
this.add(new JLabel("Insertion"));
this.add(new JLabel(""));
this.add(new JLabel("R<EFBFBD>f<EFBFBD>rence : "));
this.add(this.txtRef);
this.add(new JLabel("D<EFBFBD>signation : "));
this.add(this.txtDes);
this.add(new JLabel("Quantit<EFBFBD> : "));
this.add(this.txtQte);
this.add(new JLabel("Prix : "));
this.add(this.txtPrix);
this.add(this.btAnnuler);
this.add(this.btEnregistrer);
this.btEnregistrer.setIcon(new ImageIcon("src/images/enregistrer.png"));
//rendre les boutons cliquables
this.btAnnuler.addActionListener(this);
this.btEnregistrer.addActionListener(this);
this.setVisible(false);
}
@Override
public void actionPerformed(ActionEvent e) {
this.txtQte.setBackground(Color.WHITE);
this.txtPrix.setBackground(Color.WHITE);
if(e.getSource() == this.btAnnuler)
{
this.txtDes.setText("");
this.txtRef.setText("");
this.txtQte.setText("");
this.txtPrix.setText("");
}
else if (e.getSource()==this.btEnregistrer)
{
String reference = this.txtRef.getText();
String designation = this.txtDes.getText();
int qte;
float prix;
try{
if (reference.equals("")||designation.equals(""))
{
JOptionPane.showMessageDialog(this, "Veuillez saisir la ref ou la des");
}
else
{
qte = Integer.parseInt(this.txtQte.getText());
prix = Float.parseFloat(this.txtPrix.getText());
Produit unProduit = new Produit(reference, designation, qte, prix);
Modele.insert(unProduit);
JOptionPane.showMessageDialog(this, "Insertion reussie");
this.txtDes.setText("");
this.txtRef.setText("");
this.txtQte.setText("");
this.txtPrix.setText("");
}
this.setVisible(false); //fin enregistrement
}
catch(NumberFormatException exp)
{
JOptionPane.showMessageDialog(this, "Erreur de saisie sur la Qte ou prix");
this.txtQte.setBackground(Color.RED);
this.txtPrix.setBackground(Color.RED);
}
}
}
}

View File

@@ -0,0 +1,66 @@
package vue;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import controleur.Gestion;
public class VueMenu extends JPanel implements ActionListener
{
private JButton btAjouter = new JButton("Ajouter");
private JButton btLister = new JButton("Lister");
private JButton btSupprimer = new JButton("Supprimer");
private JButton btRechercher = new JButton("Rechercher");
private JButton btQuitter= new JButton("Quitter");
public VueMenu ()
{
this.setBounds(20, 20, 120, 300);
this.setLayout(new GridLayout(7, 1));
this.setBackground(Color.YELLOW);
this.add(new JLabel());
this.add(this.btAjouter);
this.add(this.btLister);
this.add(this.btSupprimer);
this.add(this.btRechercher);
this.add(this.btQuitter);
this.add(new JLabel());
//rendre les boutons cliquables
this.btAjouter.addActionListener(this);
this.btLister.addActionListener(this);
this.btSupprimer.addActionListener(this);
this.btRechercher.addActionListener(this);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==this.btQuitter)
{
}
else if (e.getSource()==this.btAjouter)
{
Gestion.rendreVisibleVueInsert(true);
Gestion.rendreVisibleVueAccueil(false);
Gestion.rendreVisibleVueDelete(false);
}else if (e.getSource()==this.btSupprimer)
{
Gestion.rendreVisibleVueInsert(false);
Gestion.rendreVisibleVueAccueil(false);
Gestion.rendreVisibleVueDelete(true);
}
}
}