1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
package serveur;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
import java.rmi.*;
//import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
//import java.util.*;
//import java.util.Date;
import javax.swing.JOptionPane;
//import frame.Fenetre;
import frame.IClient;
public class IClientImpl extends UnicastRemoteObject implements IClient {
boolean creer,trouve,creer1;
Connection connection=null;
Statement st = null;
ResultSet rs = null;
int numc1,recupmin;
String sep = File.separator ;
Client c;
public IClientImpl()throws RemoteException{
super();
}
public boolean valider(String prenom,String nom,String adresse,double tel,int jour,int mois,int annee,int heure,int minute,String canal)throws RemoteException
{
System.setSecurityManager(new RMISecurityManager());
c=new Client(prenom,nom,adresse,tel,jour,mois,annee,heure,minute,canal);
// CONNEXION A LA BASE DE DONNEES
try{
Class.forName("org.gjt.mm.mysql.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/stage", "root", "passer");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Driver introuvable : ");
cnfe.printStackTrace();
}
catch(SQLException sqle)
{
System.out.println("Erreur SQL : ");
sqle.printStackTrace();
}
try
{
System.out.println("avant ");
st=connection.createStatement();
rs=st.executeQuery("SELECT `minute` from `rendezvous` where `mois`="+ mois +" and `jour`="+ jour +" and `heure`="+ heure +"");
while (rs.next())
{
recupmin = rs.getInt(1);
System.out.println ("numclient: " +recupmin);
if(recupmin==minute)
{
System.out.println("trouve");
trouve=true;
break;
}
else
{
trouve=false;
System.out.println(" absent");
}
}
}
catch(SQLException sql){}
if(trouve==true)
{
JOptionPane.showMessageDialog (null,"Un Rendez-vous à été déjà pris à cette heure","Message d'alerte",
JOptionPane.INFORMATION_MESSAGE, null);
}
if(trouve==false)
{
String sep = File.separator ;
File fichierc = new File ("/home/charles"+sep+"clients"+sep+"client"+c.getTel()+".call");
File fichiers = new File ("/home/charles"+sep+"scripts"+sep+"client"+c.getTel()+"call");
//Creation du fichier call
try {
if(!fichierc.exists())
{
creer=fichierc.createNewFile ( );
}
else creer=fichierc.delete();
}
catch ( IOException fic)
{
fic.printStackTrace() ;
}
try {
FileWriter fw = new FileWriter( fichierc ,true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Channel: "+canal);
bw.newLine();
bw.write ("MaxRetries: 0");
bw.newLine();
bw.write ("RetryTime: 30");
bw.newLine();
bw.write ("WaitTime: 30");
bw.newLine();
bw.write ("Context: default");
bw.newLine();
bw.write ("Extension: "+tel);
bw.newLine();
bw.close ( ) ;
fw.close();
}
catch(IOException f){}
//Creation du fichier batch
try {
if(!fichiers.exists())
{
creer1=fichiers.createNewFile ( );
}
else creer1=fichiers.delete();
}
catch ( IOException b)
{
b.printStackTrace() ;
}
try {
FileWriter fwc = new FileWriter( fichiers ,true);
BufferedWriter bwc = new BufferedWriter(fwc);
bwc.write("mv /home/charles/clients/client"+c.getTel()+".call /var/spool/asterisk/outgoing/");
bwc.close ( ) ;
fwc.close();
}
catch ( IOException c)
{
c.printStackTrace() ;
}
try
{
Runtime.getRuntime().exec("/usr/bin/at -f /home/charles/scripts/client"+c.getTel()+"call " +heure+":"+minute+" "+mois+""+jour+""+annee+"");
//System.out.print("/usr/bin/at -f /home/charles/scripts/client"+id+"call " +heure+":"+minute+" "+mois+jour+annee+"");
}
catch (IOException d){ }
try
{
System.out.println("insertion info rendez-vous ");
st=connection.createStatement();
System.out.println("avant2 ");
int req1=st.executeUpdate("INSERT INTO `clients` (`nom` , `prenom` , `adresse` , `tel`) VALUES ('"+ nom +"', '"+ prenom +"', '"+ adresse +"', "+ tel +")");
System.out.println("Select");
rs=st.executeQuery("SELECT `numclient` from `clients` where `tel`="+ tel +" ");
while (rs.next())
{
numc1 = rs.getInt(1);
System.out.println ("numclient: " +numc1);
}
//st=connection.executeQuery("SELECT `id_rv` from rendezvous where numclient="+numc+")");
int req2=st.executeUpdate("INSERT INTO `rendezvous` (`numclient` ,`annee` , `mois` , `jour` , `heure`, `minute`) VALUES ("+ numc1 +", "+ annee +", "+ mois +", "+ jour +", "+ heure +", "+ minute +")");
System.out.println("apres");
}
catch(SQLException sql){}
} //Fin if(trouve==false)
return creer;
}
} |
Partager