From 85c17dbe6fa16d1188ebf7367ba688555408b954 Mon Sep 17 00:00:00 2001
From: "emile.malcuit" <lalorceyemile@gmail.com>
Date: Thu, 13 Mar 2025 09:51:28 +0100
Subject: [PATCH] =?UTF-8?q?Observation=20Fini=20de=20l'affichage=20=C3=A0?=
 =?UTF-8?q?=20l'insertion=20SQL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 GSBapplication/src/Metier/Observation.java    | 24 +++++-
 .../src/acces_aux_donnes/observationSQL.java  | 50 +++++++++++++
 .../src/presentation/jffAjoutObservation.form | 75 ++++++++++++++++++-
 .../src/presentation/jffAjoutObservation.java | 71 ++++++++++++++++--
 4 files changed, 212 insertions(+), 8 deletions(-)

diff --git a/GSBapplication/src/Metier/Observation.java b/GSBapplication/src/Metier/Observation.java
index 8ad7ccc..4fd5939 100644
--- a/GSBapplication/src/Metier/Observation.java
+++ b/GSBapplication/src/Metier/Observation.java
@@ -14,8 +14,15 @@ public class Observation {
      * observation = l'observation d'un m�dicament
      */
     private String observation;
+    private String idMedoc;
+    private int idPraticien;
 
-    
+    //Constructeur
+    public Observation(String idMedoc,int idPraticien, String observ){
+        this.idMedoc = idMedoc;
+        this.idPraticien = idPraticien;
+        this.observation = observ;
+    }
     
     //LES GUETTEUR
     /**
@@ -25,6 +32,21 @@ public class Observation {
         return observation;
     }
     
+    /**
+     * @return l'identifiant du m�dicament 
+     */
+    public String getIdMedoc(){
+        return this.idMedoc;
+    }
+    
+    /**
+     * 
+     * @return l'identifiant du praticien
+     */
+    public int getIdPraticien(){
+        return this.idPraticien;
+    }
+    
     
     
     
diff --git a/GSBapplication/src/acces_aux_donnes/observationSQL.java b/GSBapplication/src/acces_aux_donnes/observationSQL.java
index 3bff386..2789b3b 100644
--- a/GSBapplication/src/acces_aux_donnes/observationSQL.java
+++ b/GSBapplication/src/acces_aux_donnes/observationSQL.java
@@ -4,10 +4,60 @@
  */
 package acces_aux_donnes;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
 /**
  *
  * @author emile.lalorcey
  */
 public class observationSQL {
+    private Connection connexionTest;
+    private Statement stmt = 	null;
+    private ResultSet result = 	null;
     
+    public observationSQL() {
+        connexionTest = connexionSQL.getConnect("10.121.38.75","bdgsb","adminGSB","mdpGSB");
+    }
+    
+    public int compterLignes(){
+        int nbLignes = 0;
+        try {
+            stmt = connexionTest.createStatement();
+            // Acc�s � la table 
+            result = stmt.executeQuery("SELECT COUNT(idObservation) From OBSERVATION");
+            if (result.next()) {
+                nbLignes = Integer.parseInt(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 nbLignes;
+    }
+    
+
+    public int ajouterObservation(String idMedoc, int idPraticien, String observation){
+        int passer = 1000;
+        int nbLignes = this.compterLignes();
+        try {
+            stmt = connexionTest.createStatement();
+            // Acc�s � la table 
+            passer = stmt.executeUpdate("INSERT INTO OBSERVATION(idObservation, idMedoc, idPraticien, observation) "
+                    + "VALUES ("+(nbLignes+1)+",'"+idMedoc+"',"+idPraticien+",\""+observation+"\");");
+            
+            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 passer;
+    }
 }
diff --git a/GSBapplication/src/presentation/jffAjoutObservation.form b/GSBapplication/src/presentation/jffAjoutObservation.form
index 769eecd..9b0db47 100644
--- a/GSBapplication/src/presentation/jffAjoutObservation.form
+++ b/GSBapplication/src/presentation/jffAjoutObservation.form
@@ -23,13 +23,84 @@
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
+          <Group type="102" attributes="0">
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Group type="102" alignment="1" attributes="0">
+                      <EmptySpace max="32767" attributes="0"/>
+                      <Component id="jLTitre" min="-2" max="-2" attributes="0"/>
+                      <EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
+                      <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
+                  </Group>
+                  <Group type="102" attributes="0">
+                      <Group type="103" groupAlignment="0" attributes="0">
+                          <Group type="102" alignment="0" attributes="0">
+                              <EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
+                              <Component id="jScrollPane1" min="-2" pref="348" max="-2" attributes="0"/>
+                          </Group>
+                          <Group type="102" alignment="0" attributes="0">
+                              <EmptySpace min="-2" pref="158" max="-2" attributes="0"/>
+                              <Component id="jBsoumettre" min="-2" max="-2" attributes="0"/>
+                          </Group>
+                      </Group>
+                      <EmptySpace min="0" pref="23" max="32767" attributes="0"/>
+                  </Group>
+              </Group>
+              <EmptySpace max="-2" attributes="0"/>
+          </Group>
       </Group>
     </DimensionLayout>
     <DimensionLayout dim="1">
       <Group type="103" groupAlignment="0" attributes="0">
-          <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
+          <Group type="102" alignment="0" attributes="0">
+              <EmptySpace max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="1" attributes="0">
+                  <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
+                  <Component id="jLTitre" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace type="separate" max="-2" attributes="0"/>
+              <Component id="jScrollPane1" min="-2" pref="157" max="-2" attributes="0"/>
+              <EmptySpace type="separate" max="-2" attributes="0"/>
+              <Component id="jBsoumettre" min="-2" max="-2" attributes="0"/>
+              <EmptySpace pref="46" max="32767" attributes="0"/>
+          </Group>
       </Group>
     </DimensionLayout>
   </Layout>
+  <SubComponents>
+    <Component class="javax.swing.JLabel" name="jLabel1">
+      <Properties>
+        <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
+          <Image iconType="3" name="/img/logodetoure.gif"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="jLTitre">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="Soumettez votre observation"/>
+      </Properties>
+    </Component>
+    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+      <AuxValues>
+        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JTextArea" name="jTAobservation">
+          <Properties>
+            <Property name="columns" type="int" value="20"/>
+            <Property name="rows" type="int" value="5"/>
+          </Properties>
+        </Component>
+      </SubComponents>
+    </Container>
+    <Component class="javax.swing.JButton" name="jBsoumettre">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="Soumettre"/>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jBsoumettreActionPerformed"/>
+      </Events>
+    </Component>
+  </SubComponents>
 </Form>
diff --git a/GSBapplication/src/presentation/jffAjoutObservation.java b/GSBapplication/src/presentation/jffAjoutObservation.java
index c5d9af7..52c9f73 100644
--- a/GSBapplication/src/presentation/jffAjoutObservation.java
+++ b/GSBapplication/src/presentation/jffAjoutObservation.java
@@ -4,17 +4,22 @@
  */
 package presentation;
 
+import acces_aux_donnes.observationSQL;
+
 /**
  *
  * @author emile.lalorcey
  */
 public class jffAjoutObservation extends javax.swing.JFrame {
-
+    private String idMedoc;
+    private int idPraticien;
     /**
      * Creates new form jffAjoutObservation
      */
-    public jffAjoutObservation() {
+    public jffAjoutObservation(String idMedoc,int idPraticien) {
         initComponents();
+        this.idMedoc = idMedoc;
+        this.idPraticien = idPraticien;
     }
 
     /**
@@ -26,22 +31,73 @@ public class jffAjoutObservation extends javax.swing.JFrame {
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private void initComponents() {
 
+        jLabel1 = new javax.swing.JLabel();
+        jLTitre = new javax.swing.JLabel();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        jTAobservation = new javax.swing.JTextArea();
+        jBsoumettre = new javax.swing.JButton();
+
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
+        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/logodetoure.gif"))); // NOI18N
+
+        jLTitre.setText("Soumettez votre observation");
+
+        jTAobservation.setColumns(20);
+        jTAobservation.setRows(5);
+        jScrollPane1.setViewportView(jTAobservation);
+
+        jBsoumettre.setText("Soumettre");
+        jBsoumettre.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jBsoumettreActionPerformed(evt);
+            }
+        });
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 400, Short.MAX_VALUE)
+            .addGroup(layout.createSequentialGroup()
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                        .addComponent(jLTitre)
+                        .addGap(65, 65, 65)
+                        .addComponent(jLabel1))
+                    .addGroup(layout.createSequentialGroup()
+                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addGroup(layout.createSequentialGroup()
+                                .addGap(23, 23, 23)
+                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE))
+                            .addGroup(layout.createSequentialGroup()
+                                .addGap(158, 158, 158)
+                                .addComponent(jBsoumettre)))
+                        .addGap(0, 23, Short.MAX_VALUE)))
+                .addContainerGap())
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 300, Short.MAX_VALUE)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+                    .addComponent(jLabel1)
+                    .addComponent(jLTitre))
+                .addGap(18, 18, 18)
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(18, 18, 18)
+                .addComponent(jBsoumettre)
+                .addContainerGap(46, Short.MAX_VALUE))
         );
 
         pack();
     }// </editor-fold>//GEN-END:initComponents
 
+    private void jBsoumettreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBsoumettreActionPerformed
+        observationSQL observ = new observationSQL();
+        observ.ajouterObservation(this.idMedoc, this.idPraticien, jTAobservation.getText());
+    }//GEN-LAST:event_jBsoumettreActionPerformed
+
     /**
      * @param args the command line arguments
      */
@@ -72,11 +128,16 @@ public class jffAjoutObservation extends javax.swing.JFrame {
         /* Create and display the form */
         java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
-                new jffAjoutObservation().setVisible(true);
+                //new jffAjoutObservation().setVisible(true);
             }
         });
     }
 
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JButton jBsoumettre;
+    private javax.swing.JLabel jLTitre;
+    private javax.swing.JLabel jLabel1;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JTextArea jTAobservation;
     // End of variables declaration//GEN-END:variables
 }
-- 
2.47.2