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
|
package College;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class EmpruntFactory
{
static Connection con = null;
static PreparedStatement ps = null;
static EmpruntProf empruntP = new EmpruntProf();
static EmpruntEleve empruntE = new EmpruntEleve();
public static void InsertP()
{
int idE = Integer.parseInt(EmpruntFrame.saisirIDE.getText().trim());
String cat = EmpruntFrame.saisirCat.getSelectedItem().toString();
int idM = Integer.parseInt(EmpruntFrame.saisirIDM.getText().trim());
String dtEP = EmpruntProf.dateEmprunt();
String dtRP = EmpruntProf.dateRetour();
Professeur pfs = ProfFactory.Select(idE);
Materiel mat = MaterielFactory.Select(idM);
if (cat.equals("Professeur") && pfs.empruntPossible() && mat.empruntable())
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/emprunts", "root", "sa@admin");
ps = con.prepareStatement("INSERT INTO empruntsprof (ID_Prof,ID_Mat,Date_Emprunt,Date_Retour) VALUES (?,?,?,?)");
ps.setInt(1,idE);
ps.setInt(2,idM);
ps.setString(3,dtEP);
ps.setString(4,dtRP);
ps.execute();
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
else if (!mat.empruntable() || !cat.equals("Professeur") || !pfs.empruntPossible())
ET LA JE NE SAIS PAS QUOI METTRE
} |