L'historique fonctionne.
This commit is contained in:
parent
e8da463444
commit
f272c11f91
2 changed files with 27 additions and 13 deletions
|
@ -48,13 +48,15 @@ public class GestionnaireHistorique {
|
|||
|
||||
|
||||
|
||||
public void recuperer(String id1, String id2) {
|
||||
public String recuperer(String id1, String id2) {
|
||||
|
||||
String id = combiner(id1, id2);
|
||||
|
||||
Statement st;
|
||||
Statement st = null;
|
||||
int rs1;
|
||||
ResultSet rs2;
|
||||
ResultSet rs2 = null;
|
||||
Connection con = null;
|
||||
String history = "";
|
||||
|
||||
String query1 =
|
||||
"CREATE TABLE IF NOT EXISTS " + id
|
||||
|
@ -64,10 +66,11 @@ public class GestionnaireHistorique {
|
|||
+ "PRIMARY KEY (id) );";
|
||||
|
||||
String query2 = "SELECT * FROM " + id
|
||||
+ " ORDRE BY id;";
|
||||
+ " ORDER BY id;";
|
||||
|
||||
|
||||
try {
|
||||
Connection con = Liaison.getConnection();
|
||||
con = Liaison.getConnection();
|
||||
|
||||
st = con.createStatement();
|
||||
|
||||
|
@ -78,7 +81,8 @@ public class GestionnaireHistorique {
|
|||
|
||||
while(rs2.next()) {
|
||||
System.out.println("Historic SUCCESS");
|
||||
System.out.println(rs2.getString(2)); //indice commence à 1
|
||||
history += GestionnaireNom.instance().nomFromId(rs2.getString(2)) + ": "; //indice commence à 1
|
||||
history += rs2.getString(3) + "\n";
|
||||
}
|
||||
|
||||
// à mettre dans un finally
|
||||
|
@ -86,11 +90,14 @@ public class GestionnaireHistorique {
|
|||
st.close();
|
||||
con.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
catch (SQLException e) {
|
||||
System.out.println("Erreur : Historic BDD");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return history;
|
||||
|
||||
}
|
||||
|
||||
|
@ -104,7 +111,7 @@ public class GestionnaireHistorique {
|
|||
int rs;
|
||||
|
||||
String query = "INSERT INTO " + id
|
||||
+ "(expediteur, msg) VALUES (" + expediteur + ", " + msg + ");";
|
||||
+ " (expediteur, msg) VALUES ('" + expediteur + "', '" + msg + "');"; //à réécrire pour éviter les injections
|
||||
|
||||
try {
|
||||
Connection con = Liaison.getConnection();
|
||||
|
|
|
@ -7,6 +7,9 @@ import javax.swing.JFrame;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import bdd.GestionnaireHistorique;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
|
@ -58,12 +61,11 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
|
|||
else
|
||||
{
|
||||
historicField.setText(historicField.getText() + GestionnaireNom.instance().nomFromId(session.getIdDestination()) + " s'est déconnecté(e).\n");
|
||||
this.finDeSession(0);
|
||||
this.finDeSession();
|
||||
}
|
||||
}
|
||||
|
||||
public void finDeSession(int i) {
|
||||
System.out.println(i);
|
||||
public void finDeSession() {
|
||||
gestionnaireClavardage.instance().deleteSession(session);
|
||||
this.setSession(null);
|
||||
System.out.println(this.session);
|
||||
|
@ -73,11 +75,15 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
|
|||
String message = textField.getText();
|
||||
if (!message.isEmpty() && this.session != null) {
|
||||
textField.setText("");
|
||||
historicField.setText(historicField.getText() + GestionnaireNom.instance().nomFromId(session.getIdSource()) +": " + message + "\n");
|
||||
historicField.append(GestionnaireNom.instance().nomFromId(session.getIdSource()) +": " + message + "\n");
|
||||
session.send(GestionnaireNom.instance().nomFromId(session.getIdSource()) + ": " + message+"\n");
|
||||
GestionnaireHistorique.instance().ajouter(this.session.getIdSource(), this.session.getIdDestination(), this.session.getIdSource(), message);
|
||||
}
|
||||
}
|
||||
|
||||
private void récupérerHistorique() {
|
||||
historicField.append(GestionnaireHistorique.instance().recuperer(this.session.getIdSource(), this.session.getIdDestination()));
|
||||
}
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
|
@ -104,6 +110,7 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
|
|||
historicField.setEditable(false);
|
||||
scrollPane.setViewportView(historicField);
|
||||
historicField.setColumns(10);
|
||||
this.récupérerHistorique();
|
||||
|
||||
|
||||
textField = new JTextField();
|
||||
|
@ -131,7 +138,7 @@ public class DiscussionUI extends JFrame implements PropertyChangeListener{
|
|||
DiscussionUI window = (DiscussionUI) windowEvent.getSource();
|
||||
if (window.session != null) {
|
||||
System.out.println(window.session);
|
||||
window.finDeSession(1);
|
||||
window.finDeSession();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue