-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished the add recherche etudiant interface
- Loading branch information
1 parent
4a3a790
commit 7d93793
Showing
9 changed files
with
303 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ExercicesTP.CRUD; | ||
|
||
public class DemandeDAO { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package ExercicesTP.Helpers; | ||
|
||
import ExercicesTP.CRUD.EtudiantDAO; | ||
|
||
|
||
import javax.swing.*; | ||
import javax.swing.table.AbstractTableModel; | ||
import java.sql.Date; | ||
import java.sql.ResultSet; | ||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
|
||
public class TableModelDemande extends AbstractTableModel { | ||
ArrayList<Object[]> data; | ||
ResultSetMetaData rsmd; | ||
EtudiantDAO dao; | ||
|
||
public TableModelDemande(ResultSet rs, EtudiantDAO dao){ | ||
data = new ArrayList<Object[]>(); | ||
this.dao = dao; | ||
try { | ||
rsmd = rs.getMetaData(); | ||
|
||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
try { | ||
|
||
while (rs.next()) { | ||
Object[] ligne = new Object[rsmd.getColumnCount()]; | ||
for(int i = 0;i<rsmd.getColumnCount();i++){ | ||
ligne[i] = rs.getObject(i+1); | ||
} | ||
data.add(ligne); | ||
} | ||
}catch(SQLException SQLErr){ | ||
System.out.println("Error "+SQLErr); | ||
} | ||
|
||
|
||
} | ||
|
||
public void updateTableWithNewResultSet(ResultSet rs){ | ||
data = new ArrayList<Object[]>(); | ||
try { | ||
rsmd = rs.getMetaData(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
try { | ||
while (rs.next()) { | ||
Object[] ligne = new Object[rsmd.getColumnCount()]; | ||
for(int i = 0;i<rsmd.getColumnCount();i++){ | ||
ligne[i] = rs.getObject(i+1); | ||
} | ||
data.add(ligne); | ||
} | ||
}catch(SQLException SQLErr){ | ||
System.out.println("Error "+SQLErr); | ||
} | ||
fireTableDataChanged(); | ||
} | ||
|
||
|
||
@Override | ||
public int getRowCount() { | ||
return data.size(); | ||
} | ||
|
||
@Override | ||
public int getColumnCount() { | ||
try { | ||
return rsmd.getColumnCount(); | ||
} catch (SQLException e) { | ||
return 0; | ||
} | ||
} | ||
|
||
@Override | ||
public Object getValueAt(int rowIndex, int columnIndex) { | ||
return data.get(rowIndex)[columnIndex]; | ||
} | ||
|
||
@Override | ||
public String getColumnName(int column) { | ||
try { | ||
return rsmd.getColumnName(column + 1); | ||
} catch (SQLException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isCellEditable(int rowIndex, int columnIndex) { | ||
return false; | ||
} | ||
int colmunNameToIndex(String colmunName){ | ||
for (int i = 0; i < getColumnCount(); i++) { | ||
if(getColumnName(i).equalsIgnoreCase(colmunName)){ | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
Boolean stringToBool(String str){ | ||
return str.equalsIgnoreCase("true"); | ||
} | ||
|
||
@Override | ||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { | ||
} | ||
|
||
|
||
public void insertFormation(String nom, String lieu, Date date){ | ||
this.dao.addEtudiant(new Formation(id, titre, dateF, lieu,certification)); | ||
data.add(new Object[]{id, titre, dateF, lieu, certification}); | ||
fireTableDataChanged(); | ||
JOptionPane.showMessageDialog(null, "done"); | ||
} | ||
|
||
|
||
|
||
public void supprimerFormation(int id){ | ||
int option = JOptionPane.showConfirmDialog(null, "est ce que vous etes sure ?"); | ||
if(option == JOptionPane.NO_OPTION || option == JOptionPane.CANCEL_OPTION){ | ||
JOptionPane.showMessageDialog(null, "annulé"); | ||
return; | ||
} | ||
|
||
this.dao.deleteFormation(id); | ||
for(int i = 0; i < data.size(); i++){ | ||
if((int)data.get(i)[colmunNameToIndex("id")] == id){ | ||
data.remove(i); | ||
fireTableDataChanged(); | ||
JOptionPane.showMessageDialog(null, "done"); | ||
return; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package ExercicesTP.IHM; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
import ExercicesTP.CRUD.EtudiantDAO; | ||
import ExercicesTP.Helpers.TableModelFormation; | ||
|
||
public class IHMRechercheEtudiant extends JInternalFrame { | ||
|
||
private JLabel numEtdLabel, nomLabel, prenomLabel, filiereLabel, niveauLabel, groupeLabel, listeDemandesLabel; | ||
private JTextField numEtdField, nomField, prenomField ; | ||
private JComboBox<String> filiereComboBox,demandesBox; | ||
private JComboBox<Integer> niveauComboBox, groupeComboBox; | ||
private JButton ajouterDemandeButton, supprimerDemandeButton, rechercheButton, cancelButton, modifierButton, supprimerButton; | ||
public EtudiantDAO etudiantDAO; | ||
public TableModelFormation model; | ||
JTable jt_Etudiant; | ||
|
||
public IHMRechercheEtudiant(EtudiantDAO dao) { | ||
super("Recherche d'une formation"); | ||
initializeComponents(); | ||
createLayout(); | ||
addEventListeners(); | ||
this.etudiantDAO = dao; | ||
this.setVisible(true); | ||
} | ||
|
||
private void initializeComponents() { | ||
numEtdLabel = new JLabel("Numéro étudiant :"); | ||
nomLabel = new JLabel("Nom :"); | ||
prenomLabel = new JLabel("Prénom :"); | ||
filiereLabel = new JLabel("Filière :"); | ||
niveauLabel = new JLabel("Niveau :"); | ||
groupeLabel = new JLabel("Groupe :"); | ||
listeDemandesLabel = new JLabel("Liste des demandes :"); | ||
|
||
numEtdField = new JTextField(15); | ||
nomField = new JTextField(20); | ||
prenomField = new JTextField(20); | ||
|
||
// Sample data for comboboxes (replace with actual data source) | ||
filiereComboBox = new JComboBox<>(new String[]{"FIA", "Licence Sc Info", "Licence Info de Gest", "Maths Info", "Physique Info", "Chimie Info", "Bio Info", "Eco Info", "Génie Info", "Info de Gestion", "Info de Comm"}); | ||
niveauComboBox = new JComboBox<>(new Integer[]{1, 2, 3}); | ||
groupeComboBox = new JComboBox<>(new Integer[]{1, 2, 3, 4, 5}); | ||
|
||
ajouterDemandeButton = new JButton("Ajouter demande"); | ||
supprimerDemandeButton = new JButton("Supprimer demande"); | ||
rechercheButton = new JButton("Rechercher"); | ||
modifierButton = new JButton("Modifier"); | ||
supprimerButton = new JButton("Supprimer"); | ||
cancelButton = new JButton("Annuler"); | ||
|
||
demandesBox = new JComboBox<String>(); | ||
listeDemandesLabel = new JLabel("Liste des demandes :"); | ||
jt_Etudiant = new JTable(); | ||
String rq = "SELECT titre,lieu,datef FROM FORMATION f,demandeetd d,ETUDIANT e WHERE (e.id=d.idEtudiant) and (f.idF = d.idFormation) ;"; | ||
model = new TableModelFormation(etudiantDAO.selection(rq), etudiantDAO); | ||
jt_Etudiant.setModel(model); | ||
|
||
} | ||
|
||
private void createLayout() { | ||
JPanel panel = new JPanel(new GridBagLayout()); | ||
GridBagConstraints c = new GridBagConstraints(); | ||
JPanel panel2 = new JPanel(new GridBagLayout()); | ||
|
||
// Add labels and corresponding components | ||
c.fill = GridBagConstraints.HORIZONTAL; | ||
addComponent(panel, numEtdLabel, c, 0, 0, 1, 1); | ||
addComponent(panel, numEtdField, c, 1, 0, 2, 1); | ||
addComponent(panel, nomLabel, c, 0, 1, 1, 1); | ||
addComponent(panel, nomField, c, 1, 1, 2, 1); | ||
addComponent(panel, prenomLabel, c, 0, 2, 1, 1); | ||
addComponent(panel, prenomField, c, 1, 2, 2, 1); | ||
addComponent(panel, filiereLabel, c, 0, 3, 1, 1); | ||
addComponent(panel, filiereComboBox, c, 1, 3, 2, 1); | ||
addComponent(panel, niveauLabel, c, 0, 4, 1, 1); | ||
addComponent(panel, niveauComboBox, c, 1, 4, 1, 1); | ||
addComponent(panel, groupeLabel, c, 0, 5, 1, 1); | ||
addComponent(panel, groupeComboBox, c, 1, 5, 1, 1); | ||
|
||
addComponent(panel2, rechercheButton, c, 5, 0, 1, 1); | ||
addComponent(panel2, modifierButton, c, 5, 1, 1, 1); | ||
addComponent(panel2, supprimerButton, c, 5, 2, 1, 1); | ||
addComponent(panel2, cancelButton, c, 5, 3, 1, 1); | ||
|
||
addComponent(panel, ajouterDemandeButton, c, 0, 7, 1, 1); | ||
addComponent(panel, supprimerDemandeButton, c, 1, 7, 1, 1); | ||
addComponent(panel, demandesBox, c, 2,7,1, 1); | ||
|
||
addComponent(panel, listeDemandesLabel, c, 0, 10, 1, 1); | ||
addComponent(panel, jt_Etudiant, c, 2, 10, 6, 1); | ||
|
||
// Add buttons | ||
getContentPane().add(panel); | ||
getContentPane().add(panel2); | ||
getContentPane().setLayout(new FlowLayout()); | ||
modifierButton.setEnabled(false); | ||
supprimerButton.setEnabled(false); | ||
rechercheButton.setEnabled(false); | ||
|
||
|
||
|
||
setSize(700,400); | ||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
setVisible(true); | ||
} | ||
|
||
private void addComponent(JPanel panel, JComponent component, GridBagConstraints c, int x, int y, int width, int height) { | ||
c.gridx = x; | ||
c.gridy = y; | ||
c.gridwidth = width; | ||
c.gridheight = height; | ||
panel.add(component, c); | ||
} | ||
|
||
private void clearInputs() { | ||
//TODO implement | ||
} | ||
|
||
private void addEventListeners() { | ||
//TODO implement | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.