diff --git a/GSBapplication/src/acces_aux_donnes/familleMedocSQL.java b/GSBapplication/src/acces_aux_donnes/familleMedocSQL.java index f56f009..38e5bb4 100644 --- a/GSBapplication/src/acces_aux_donnes/familleMedocSQL.java +++ b/GSBapplication/src/acces_aux_donnes/familleMedocSQL.java @@ -6,8 +6,10 @@ package acces_aux_donnes; import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Vector; /** * @@ -22,6 +24,65 @@ public class familleMedocSQL { connexionTest = connexionSQL.getConnect("10.121.38.75","bdgsb","adminGSB","mdpGSB"); } + public Vector rechercheFamille(){ + Vector famille = new Vector(); + + try { + stmt = connexionTest.createStatement(); + // Accès à la table + result = stmt.executeQuery("SELECT fLibelle FROM FAMILLE;"); + while(result.next()) { // Le praticien a été touvé + famille.add(result.getString(1)); + } + result.close(); + stmt.close(); + }catch (SQLException ex) { + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return famille; + } + + public String rechercheCodeFamille(String libelle){ + String code = ""; + try { + stmt = connexionTest.createStatement(); + // Accès à la table + result = stmt.executeQuery("SELECT fCode FROM FAMILLE WHERE fLibelle ='"+ libelle +"';"); + while(result.next()) { // Le praticien a été touvé + code = result.getString(1); + } + result.close(); + stmt.close(); + }catch (SQLException ex) { + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return code; + } + + public Vector rechercherMedocFamille(String libelle){ + Vector famille = new Vector(); + try { + stmt = connexionTest.createStatement(); + // Accès à la table + result = stmt.executeQuery("SELECT mNomCommercial FROM MEDICAMENT WHERE fCode ='"+ libelle +"';"); + while(result.next()) { // Le praticien a été touvé + famille.add(result.getString(1)); + } + result.close(); + stmt.close(); + }catch (SQLException ex) { + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return famille; + } + + diff --git a/GSBapplication/src/presentation/jffFamilleMedoc.form b/GSBapplication/src/presentation/jffFamilleMedoc.form index 519dfbf..b3d2108 100644 --- a/GSBapplication/src/presentation/jffFamilleMedoc.form +++ b/GSBapplication/src/presentation/jffFamilleMedoc.form @@ -23,20 +23,40 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - @@ -50,7 +70,12 @@ - + + + + + + @@ -81,5 +106,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GSBapplication/src/presentation/jffFamilleMedoc.java b/GSBapplication/src/presentation/jffFamilleMedoc.java index 6639e20..1f1de93 100644 --- a/GSBapplication/src/presentation/jffFamilleMedoc.java +++ b/GSBapplication/src/presentation/jffFamilleMedoc.java @@ -6,7 +6,10 @@ package presentation; import Metier.Medicament; import acces_aux_donnes.MedicamentSQL; +import acces_aux_donnes.familleMedocSQL; import java.util.ArrayList; +import java.util.Vector; +import javax.swing.DefaultComboBoxModel; /** * @@ -19,6 +22,8 @@ public class jffFamilleMedoc extends javax.swing.JFrame { */ public jffFamilleMedoc() { initComponents(); + familleMedocSQL famille = new familleMedocSQL(); + jCBFamille.setModel(new DefaultComboBoxModel(famille.rechercheFamille())); } /** @@ -34,6 +39,8 @@ public class jffFamilleMedoc extends javax.swing.JFrame { jLRecherche = new javax.swing.JLabel(); jTFRecherche = new javax.swing.JTextField(); jBRechercheValide = new javax.swing.JButton(); + jCBFamille = new javax.swing.JComboBox<>(); + jCBMedocListe = new javax.swing.JComboBox<>(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -54,22 +61,48 @@ public class jffFamilleMedoc extends javax.swing.JFrame { } }); + jCBFamille.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + jCBFamille.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jCBFamilleActionPerformed(evt); + } + }); + + jCBMedocListe.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + jCBMedocListe.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jCBMedocListeActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(344, Short.MAX_VALUE) - .addComponent(jLabel1) - .addContainerGap()) .addGroup(layout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(jLRecherche) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jTFRecherche, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jBRechercheValide) - .addGap(27, 27, 27)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(20, 20, 20) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLRecherche) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jTFRecherche, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(58, 58, 58)) + .addGroup(layout.createSequentialGroup() + .addComponent(jCBFamille, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(42, 42, 42))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jBRechercheValide) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jCBMedocListe, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(31, 31, 31)))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1))) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -81,7 +114,11 @@ public class jffFamilleMedoc extends javax.swing.JFrame { .addComponent(jLRecherche) .addComponent(jTFRecherche, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jBRechercheValide)) - .addContainerGap(227, Short.MAX_VALUE)) + .addGap(29, 29, 29) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jCBFamille, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jCBMedocListe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(287, Short.MAX_VALUE)) ); pack(); @@ -112,6 +149,36 @@ public class jffFamilleMedoc extends javax.swing.JFrame { } }//GEN-LAST:event_jBRechercheValideActionPerformed + private void jCBFamilleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBFamilleActionPerformed + familleMedocSQL famille = new familleMedocSQL(); + Vector medocFamille = new Vector(); + String libelleFamille = jCBFamille.getSelectedItem().toString(); + String codeFamille = famille.rechercheCodeFamille(libelleFamille); + medocFamille = famille.rechercherMedocFamille(codeFamille); + jCBMedocListe.setModel(new DefaultComboBoxModel(medocFamille)); + + + + }//GEN-LAST:event_jCBFamilleActionPerformed + + private void jCBMedocListeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBMedocListeActionPerformed + String nomMedoc = jCBMedocListe.getSelectedItem().toString(); + System.out.println(nomMedoc); + MedicamentSQL medocTest = new MedicamentSQL(); + ArrayList rechercheMedoc = new ArrayList(); + rechercheMedoc = medocTest.rechercherMedicament(nomMedoc); + if (rechercheMedoc.get(0) != null) { + String idTrouve = rechercheMedoc.get(0); + String nomTrouve = rechercheMedoc.get(1); + String compositionTrouve = rechercheMedoc.get(2); + String effetTrouve = rechercheMedoc.get(3); + String contreIndicationTrouve = rechercheMedoc.get(4); + String imgTrouve = "/img/"+ idTrouve +".jpg"; + Medicament medocTrouve = new Medicament(idTrouve, nomTrouve , compositionTrouve, effetTrouve, contreIndicationTrouve,imgTrouve); + new jffInfoMedoc(medocTrouve).setVisible(true); + } + }//GEN-LAST:event_jCBMedocListeActionPerformed + /** * @param args the command line arguments */ @@ -149,6 +216,8 @@ public class jffFamilleMedoc extends javax.swing.JFrame { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jBRechercheValide; + private javax.swing.JComboBox jCBFamille; + private javax.swing.JComboBox jCBMedocListe; private javax.swing.JLabel jLRecherche; private javax.swing.JLabel jLabel1; private javax.swing.JTextField jTFRecherche;