From e19bc4b45cdad225f97da4d8acaa2b3a382e4238 Mon Sep 17 00:00:00 2001 From: LMAGallois Date: Tue, 15 Dec 2020 22:14:13 +0100 Subject: [PATCH] bdd --- .../Clavardage/src/controller/Controller.java | 32 ++++++++++++++----- .../Clavardage/src/controller/Historique.java | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Application/Clavardage/src/controller/Controller.java b/Application/Clavardage/src/controller/Controller.java index 77e4a46..560acba 100644 --- a/Application/Clavardage/src/controller/Controller.java +++ b/Application/Clavardage/src/controller/Controller.java @@ -10,6 +10,7 @@ import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import javax.swing.JOptionPane; @@ -29,7 +30,7 @@ public class Controller { private ListeningThreadUDP udp_connect_thread; private ListeningThreadTCPConnection tcp_connect_thread; private ArrayList tcp_chats_threads = new ArrayList(); // listes des utilisateurs actifs - + private Historique histoire; /** * Constructor of Controller * @parametres @@ -45,7 +46,8 @@ public class Controller { * - notification aux autres utilisateurs actifs *

*/ - private Controller(int portUDPsend,int portUDPlistening,int portTCP) { + private Controller(int portUDPsend,int portUDPlistening,int portTCP,Historique histoire) { + this.histoire=histoire; InetAddress addIP = null; try { @@ -88,7 +90,8 @@ public class Controller { * - notification aux autres utilisateurs actifs *

*/ - private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo) { + private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo,Historique histoire) { + this.histoire=histoire; InetAddress addIP = null; try { @@ -127,7 +130,9 @@ public class Controller { public ArrayList getTcp_chats_threads() { return tcp_chats_threads; } - + public Historique getHistory() { + return histoire; + } /*** SETTERS ***/ public void setMyUser(LocalUser myUser) { this.myUser = myUser; @@ -144,7 +149,9 @@ public class Controller { public void setTcp_chats_threads(ArrayList tcp_chats_threads) { this.tcp_chats_threads = tcp_chats_threads; } - + public void setHistory(Historique histoire) { + this.histoire=histoire; + } /** @@ -347,10 +354,18 @@ public class Controller { e.printStackTrace(); } String input; + String dateString; + Date date; + Calendar date1=Calendar.getInstance(); + String s2 = (this.myUser.getPseudo()+" reçoit un message"); try { while (!(input=in.readLine()).equals("end")) { System.out.print("client_recoit:"+input); + date=new Date(); + date1.setTime(date); + dateString=date1.toString(); + this.getHistory().saveMessage(this.getMyUser(), getMyUser().getRemoteUsersList().get(index),input ,dateString ); } } catch (IOException e) { // TODO Auto-generated catch block @@ -424,9 +439,10 @@ public class Controller { /*************************************************************************************************************************/ public static void main(String[] args) throws IOException, InterruptedException { - Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike"); - Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice"); - Controller ctr1 = new Controller(12225,20001,22221); // Notre utilisateur local + Historique histoire=new Historique(); + Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike",histoire); + Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice",histoire); + Controller ctr1 = new Controller(12225,20001,22221,histoire); // Notre utilisateur local // Création de l'interface ctr1.hisView=Interface.createAndShowGUI(ctr1); diff --git a/Application/Clavardage/src/controller/Historique.java b/Application/Clavardage/src/controller/Historique.java index ac9abf6..ec5a086 100644 --- a/Application/Clavardage/src/controller/Historique.java +++ b/Application/Clavardage/src/controller/Historique.java @@ -62,7 +62,7 @@ public class Historique { } } - public String retrieveMessage(model.User user1, model.RemoteUser user2) throws SQLException { + public String retrieveMessage(model.LocalUser user1, model.RemoteUser user2) throws SQLException { this.setRSSent(this.bdd.getStatement().executeQuery("SELECT"+user1.getIPcode()+","+user2.getIPcode()+",? ,? FROM table")); this.setRSReceived(this.bdd.getStatement().executeQuery("SELECT"+user2.getIPcode()+","+user1.getIPcode()+",?, ? FROM table")); //this.setRSMDSent(this.getRSSent().getMetaData());