tselle
Messages postés2Date d'inscriptionmardi 9 novembre 2010StatutMembreDernière intervention24 mai 2010
-
19 mai 2010 à 00:09
tselle
Messages postés2Date d'inscriptionmardi 9 novembre 2010StatutMembreDernière intervention24 mai 2010
-
24 mai 2010 à 14:53
Salut à tous!
Je suis bloqué dans mon projet java.En fait j'ai une liste déroulante avec laquelle si je sélectionne un choix, lorsque je clique sur mon bouton d'ajout, je veux insérer automatiquement la valeur sélectionnée dans ma base de données.
Pour ce faire j'ai utilisé une base de données mysql que j'ai nommé immo_base.
Dans cette base, j'ai une table "client", avec les champs(idclient(varchar(20)), pnomclient(varchar(20)), nomclient(varchar(15)), numtclient(varchar(15)), datenreg(varchar(20)), heurenreg(varchar(20)), etat(varchar(15)), typetransaction(varchar(10)), surface(varchar(15)), nombre(int(10)), prixunitaire(varchar(20)), designationobjet(varchar(20)).
Pour réaliser l'interface avec les listes déroulantes j'ai utilisé une méthode que j'ai nommé "FonctionAjouteCl" et pour réaliser l'enregistrement du client j'ai utilisé une méthode que j'ai nommé "FonctionEnregistrementCl".
Voilà le code que j'ai fait pour pouvoir réaliser ça:
package Projet__F_C;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.Date;
public class GestionInterne implements ActionListener,ItemListener{
//Les différentes zones qui composent mon interface
JPanel contenu,ZoneSuperieure,ZoneCentrale,ZoneInferieure;
JTextArea ZoneAffichage;
//Les differents boutons du menu
JButton boutAjoute,boutModifieSupprime,boutRecherche,boutPaie,boutQuitte;
//Elements de FonctionConnection
Connection maco;
Statement stm;
ResultSet rss;
cadre.setContentPane(contenu);
cadre.setSize(600,700);
cadre.setTitle("Gestion Interne de l'Agence");
cadre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cadre.setVisible(true);
}
public void FonctionConnection(){
maco = null;
try{
Class.forName("com.mysql.jdbc.Driver");
maco = DriverManager.getConnection("jdbc:mysql://localhost/immo_base","root","");
String infoConnection = "Connection Réalisée avec Succés";
ZoneAffichage.setText(infoConnection);
}
catch(Exception E){
String infoConnection = "La connection à la base de données n'a pas été réalisée";
ZoneAffichage.setText(infoConnection);
}
}
public void FonctionReglement(){
ZoneCentrale.removeAll();
BorderLayout positionnementReglement = new BorderLayout();
ZoneCentrale.setLayout(positionnementReglement);
titreReglement = new JLabel(" Règlement de la transaction");
titreReglement.setForeground(Color.BLUE);
saisiReglement = new JPanel();
GridLayout positionnementsaisiReglement = new GridLayout(5,2);
saisiReglement.setLayout(positionnementsaisiReglement);
affichenumquittanceidclient = new JLabel("NuméroQuittanceIdClient:");
affichezonenumquittanceidclient = new JTextField(15);
affichemode = new JLabel("Mode:");
affichezonemode = new JTextField(15);
affichedate = new JLabel("Date:");
affichezonedate = new JTextField(15);
afficheheure = new JLabel("Heure:");
affichezoneheure = new JTextField(15);
boutValiderReglement = new JButton("Valider la paie");
boutValiderReglement.addActionListener(this);
boutAnnulerReglement = new JButton("Annuler la paie");
boutAnnulerReglement.addActionListener(this);
public void FonctionAjoute(){
ZoneCentrale.removeAll();
BorderLayout positionnementAjoute = new BorderLayout();
ZoneCentrale.setLayout(positionnementAjoute);
titreajoute = new JLabel(" Faites le choix de votre ajout");
titreajoute.setForeground(Color.BLUE);
choixajoute = new JPanel();
GridLayout positionnementchoixajoute = new GridLayout(1,1);
choixajoute.setLayout(positionnementchoixajoute);
ajouteCl = new JButton("Cliquer ici pour ajouter un Client");
ajouteCl.addActionListener(this);
ajouteEmp = new JButton("Cliquer ici pour ajouter un Employe");
ajouteEmp.addActionListener(this);
choixajoute.add(ajouteCl);
choixajoute.add(ajouteEmp);
ZoneCentrale.add(titreajoute,"North");
ZoneCentrale.add(choixajoute,"Center");
contenu.validate();
}
public void FonctionAjouteEmp(){
ZoneCentrale.removeAll();
BorderLayout positionnementAjouteEmp = new BorderLayout();
ZoneCentrale.setLayout(positionnementAjouteEmp);
titreAjouteEmp = new JLabel(" Votre Espace d'ajout d'Employe");
titreAjouteEmp.setForeground(Color.BLUE);
saisiAjouteEmp = new JPanel();
GridLayout positionnementsaisiAjouteEmp = new GridLayout(6,2);
saisiAjouteEmp.setLayout(positionnementsaisiAjouteEmp);
matricule = new JLabel("Matricule:");
zonematricule = new JTextField(10);
pnomemploye = new JLabel("Prénom:");
zonepnomemploye = new JTextField(20);
nomemploye = new JLabel("Nom:");
zonenomemploye = new JTextField(15);
intituleservice = new JLabel("Service:");
zoneintituleservice = new JTextField(25);
enregistreAjouteEmp = new JButton("Enregistrer l'Ajout");
enregistreAjouteEmp.addActionListener(this);
annuleAjouteEmp = new JButton("Annuler l'Ajout");
annuleAjouteEmp.addActionListener(this);
public void FonctionAjouteCl(){
ZoneCentrale.removeAll();
BorderLayout positionnementAjouteCl = new BorderLayout();
ZoneCentrale.setLayout(positionnementAjouteCl);
titreAjouteCl = new JLabel(" Votre Espace d'Espace d'ajout de Client");
titreAjouteCl.setForeground(Color.BLUE);
saisiAjouteCl = new JPanel();
GridLayout positionnementsaisiAjouteCl = new GridLayout(15,2);
saisiAjouteCl.setLayout(positionnementsaisiAjouteCl);
idclient = new JLabel("Identifiant:");
zoneidclient = new JTextField(10);
pnomclient = new JLabel("Prénom:");
zonepnomclient = new JTextField(25);
nomclient = new JLabel("Nom:");
zonenomclient = new JTextField(25);
numtclient = new JLabel("Téléphone:");
zonenumtclient = new JTextField(20);
datenreg = new JLabel("Date:");
zonedatenreg = new JTextField(15);
heurenreg = new JLabel("Heure:");
zoneheurenreg = new JTextField(15);
etat = new JLabel("L'état du Client:");
typetransaction = new JLabel("Type de la transaction:");
Frame etatCl = new Frame("L'état du client");
etatCl.setLayout(new FlowLayout());
Choice et = new Choice();
et.addItem("Régulier");
et.addItem("Irrégulier");
et.addItemListener(this);
etatCl.add(et);
//etatCl.show();
etatCl.pack();
Frame typetransactionCl = new Frame("Le type de transaction");
typetransactionCl.setLayout(new FlowLayout());
Choice typt = new Choice();
typt.addItem("Vente");
typt.addItem("Location");
typt.addItemListener(this);
typetransactionCl.add(typt);
//typetransactionCl.show();
typetransactionCl.pack();
surface = new JLabel("Surface:");
zonesurface = new JTextField(15);
nombre = new JLabel("Nombre de pièce:");
zonenombre = new JTextField(10);
prixunitaire = new JLabel("Prix Unitaire:");
zoneprixunitaire = new JTextField(10);
designationobjet = new JLabel("L'objet de la transaction");
Frame designationobjetCl = new Frame("L'objet de la transaction");
designationobjetCl.setLayout(new FlowLayout());
Choice desob = new Choice();
desob.addItem("Appartement");
desob.addItem("Villa");
desob.addItem("Studio");
desob.addItem("Terrain");
desob.addItem("Bureau");
desob.addItem("Salle de Céréminie");
desob.addItemListener(this);
designationobjetCl.add(desob);
designationobjetCl.pack();
enregistreAjouteCl = new JButton("Enregistrer l'Ajout");
enregistreAjouteCl.addActionListener(this);
annuleAjouteCl = new JButton("Annuler l'Ajout");
annuleAjouteCl.addActionListener(this);
catch(SQLException erreurRequete)
{
ZoneAffichage.setText("Erreure de requête" +erreurRequete);
}
}
public void FonctionRecherche(){
ZoneCentrale.removeAll();
BorderLayout positionnementRecherche = new BorderLayout();
ZoneCentrale.setLayout(positionnementRecherche);
titreRecherche = new JLabel(" Faites le choix de votre recherche");
titreRecherche.setForeground(Color.BLUE);
choixRecherche = new JPanel();
GridLayout positionnementchoixRecherche = new GridLayout(1,1);
choixRecherche.setLayout(positionnementchoixRecherche);
RechercheCl = new JButton("Cliquer ici pour rechercher un client");
RechercheCl.addActionListener(this);
RechercheEmp = new JButton("Cliquer ici pour rechercher un employé");
RechercheEmp.addActionListener(this);
choixRecherche.add(RechercheCl);
choixRecherche.add(RechercheEmp);
ZoneCentrale.add(titreRecherche,"North");
ZoneCentrale.add(choixRecherche,"Center");
contenu.validate();
}
public void FonctionRechercheEmp(){
ZoneCentrale.removeAll();
BorderLayout dispositionRechercheEmp = new BorderLayout();
ZoneCentrale.setLayout(dispositionRechercheEmp);
titreRechercheEmp = new JLabel(" Recherche d'un Employé");
saisiRechercheEmp = new JPanel();
FlowLayout dispositionsaisiRechercheEmp = new FlowLayout();
saisiRechercheEmp.setLayout(dispositionsaisiRechercheEmp);
indicationRechercheEmp = new JLabel("Matricule de l'Employé à recherché");
zoneRechercheEmp = new JTextField(10);
afficherRechercheEmp = new JButton("Afficher la Recherche");
afficherRechercheEmp.addActionListener(this);
public void FonctionResultatRechercheEmp(){
ZoneCentrale.removeAll();
titreResultatRechercheEmp = new JLabel(" Résultat de la recherche");
saisiResultatRechercheEmp = new JPanel();
GridLayout positionnementResultatRechercheEmp = new GridLayout(4,2);
saisiResultatRechercheEmp.setLayout(positionnementResultatRechercheEmp);
affichematricule = new JLabel("Matricule:");
zoneaffichematricule = new JTextField(15);
affichepnomemploye = new JLabel("Prénom:");
zoneaffichepnomemploye = new JTextField(15);
affichenomemploye = new JLabel("Nom:");
zoneaffichenomemploye = new JTextField(15);
afficheintituleservice = new JLabel("Service:");
zoneafficheintituleservice = new JTextField(15);