maj V1.0.1 (JRE 1.7 with JDK 1.8)
This commit is contained in:
parent
955364ae50
commit
6894c2e51f
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_261">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
@ -19,5 +19,6 @@
|
||||
<classpathentry kind="lib" path="C:/Users/pabr6/Library jar/apache.poi.ooxml with dependances/xmlbeans-3.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/pabr6/Library jar/apache.tika with dependances/commons-io-2.11.0.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/pabr6/Library jar/juniversalchardet-2.4.0.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/pabr6/Library jar/xml-apis-1.4.01.wso2v1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -21,9 +21,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
@ -126,6 +126,6 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
|
||||
org.eclipse.jdt.core.incompleteClasspath=error
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,10 +8,13 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class base {
|
||||
|
||||
@ -29,32 +32,70 @@ public class base {
|
||||
|
||||
String defaultValue = "2022-2023";
|
||||
String userInput = JOptionPane.showInputDialog("Quelle est l'année universitaire ? ",defaultValue);
|
||||
|
||||
userInput = "Years_" + supprimeCaracatresSpeciaux.TousLesCaracatresSpeciaux(userInput);
|
||||
|
||||
if(!userInput.isEmpty()) {
|
||||
nBase.addChild(new noeud(userInput));
|
||||
nBase.setAttribut("defaut_Year", userInput);
|
||||
|
||||
String directoryName = Paths.get("").toAbsolutePath().toString()+ "/base.xml";
|
||||
Path outputFilePath = Paths.get(directoryName);
|
||||
try {
|
||||
BufferedWriter fichier = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8);
|
||||
fichier.write(nBase.toWrite());
|
||||
fichier.close();
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
JLabel texte = new JLabel("<html><p>La base de données a été créée.</p></html>");
|
||||
JOptionPane.showMessageDialog(frame, texte);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return nBase;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
String regex = "(\\d{4})-(\\d{4})";
|
||||
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(userInput);
|
||||
|
||||
if (matcher.matches()) {
|
||||
int firstNumber = Integer.parseInt(matcher.group(1));
|
||||
int secondNumber = Integer.parseInt(matcher.group(2));
|
||||
|
||||
if (firstNumber < secondNumber) {
|
||||
|
||||
if(!userInput.isEmpty()) {
|
||||
userInput = "Years_" + supprimeCaracatresSpeciaux.TousLesCaracatresSpeciaux(userInput);
|
||||
nBase.addChild(new noeud(userInput));
|
||||
nBase.setAttribut("defaut_Year", userInput);
|
||||
|
||||
String directoryName = Paths.get("").toAbsolutePath().toString()+ "/base.xml";
|
||||
Path outputFilePath = Paths.get(directoryName);
|
||||
try {
|
||||
BufferedWriter fichier = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8);
|
||||
fichier.write(nBase.toWrite());
|
||||
fichier.close();
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
JLabel texte = new JLabel("<html><p>La base de données a été créée.</p></html>");
|
||||
JOptionPane.showMessageDialog(frame, texte);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return nBase;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
System.out.println("Le format est valide, mais le premier nombre n'est pas inférieur au second nombre.");
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>Le format est valide, la première année n'est pas inférieure à la seconde année.</p>"
|
||||
+ "<p>Exemple de format : 2023-2024</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
}
|
||||
} else {
|
||||
System.out.println("Le format est invalide.");
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>Le format est invalide.</p>"
|
||||
+ "<p>Exemple de format : 2023-2024</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, message, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
JOptionPane.showMessageDialog(null, "Erreur détectée !", "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
return null;
|
||||
|
||||
|
8
src/baseUFRHG/commandes.java
Normal file
8
src/baseUFRHG/commandes.java
Normal file
@ -0,0 +1,8 @@
|
||||
package baseUFRHG;
|
||||
|
||||
public class commandes {
|
||||
|
||||
public static noeud nBase = null;
|
||||
|
||||
|
||||
}
|
@ -9,6 +9,8 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class demarre extends JFrame {
|
||||
@ -60,9 +62,11 @@ public class demarre extends JFrame {
|
||||
btnCreate.setIcon(new ImageIcon(demarre.class.getResource("/resources/exportbasetoexcel.png")));
|
||||
btnCreate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
noeud nBase = recupeBases.recupeLaBase();
|
||||
if(commandes.nBase==null) {
|
||||
commandes.nBase = recupeBases.recupeLaBase();
|
||||
}
|
||||
//Exporte la base dans un classeur Excel.
|
||||
exportBaseToExcel.export(nBase);
|
||||
exportBaseToExcel.export();
|
||||
}
|
||||
});
|
||||
btnCreate.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
@ -114,7 +118,10 @@ public class demarre extends JFrame {
|
||||
btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/gestionnaire.png")));
|
||||
btnTutoriels.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new gestionnaire();
|
||||
if(commandes.nBase==null) {
|
||||
commandes.nBase = recupeBases.recupeLaBase();
|
||||
}
|
||||
afficheGestionnaire();
|
||||
}
|
||||
});
|
||||
// btnTutoriels.setIcon(new ImageIcon(demarre.class.getResource("/resources/tutoriel.png")));
|
||||
@ -163,4 +170,36 @@ public class demarre extends JFrame {
|
||||
btnNewButton_1.setBounds(10, 378, 356, 30);
|
||||
frmEvalwriter.getContentPane().add(btnNewButton_1);
|
||||
}
|
||||
|
||||
|
||||
private void afficheGestionnaire() {
|
||||
if(commandes.nBase.getNumberChildren()>0) {
|
||||
if(commandes.nBase.getAttributes("defaut_Year")!=null) {
|
||||
String defautYear = commandes.nBase.getAttributes("defaut_Year");
|
||||
if(commandes.nBase.getChild(defautYear)!=null) {
|
||||
if(commandes.nBase.getChild(defautYear).getNumberChildren()>0) {
|
||||
new gestionnaire();
|
||||
}else {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>Dans la base de données, il n'y a pas de donnée"
|
||||
+ "<br>pour l'année universitaire " + defautYear +"</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>Dans la base de données, il n'y a pas d'année universitaire par défaut.</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}else {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>Dans la base de données est vide.</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,22 @@
|
||||
package baseUFRHG;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class exportBaseToExcel {
|
||||
|
||||
|
||||
|
||||
public static void export(noeud nBase) {
|
||||
public static void export() {
|
||||
|
||||
// Données
|
||||
Object[][] data = new Object[nBase.getChild(nBase.getAttributes("defaut_Year")).getNumberChildren()][29];
|
||||
Object[][] data = new Object[commandes.nBase.getChild(commandes.nBase.getAttributes("defaut_Year")).getNumberChildren()][29];
|
||||
|
||||
|
||||
|
||||
int indexFormation = 0 ;
|
||||
for(noeud formation : nBase.getChild(nBase.getAttributes("defaut_Year")).getChildren()) {
|
||||
for(noeud formation : commandes.nBase.getChild(commandes.nBase.getAttributes("defaut_Year")).getChildren()) {
|
||||
|
||||
|
||||
|
||||
@ -85,7 +89,15 @@ public class exportBaseToExcel {
|
||||
indexFormation++;
|
||||
}
|
||||
|
||||
new CreateCalcWorkbook(data);
|
||||
if(data.length>0) {
|
||||
new CreateCalcWorkbook(data);
|
||||
}else {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>La base de données est nulle.</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,6 +13,9 @@ import java.util.Map;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
@ -29,7 +32,6 @@ public class gestionnaire extends JFrame {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
noeud nBase = null;
|
||||
|
||||
private JPanel contentPane;
|
||||
private JFrame frame;
|
||||
@ -40,23 +42,28 @@ public class gestionnaire extends JFrame {
|
||||
private JTable table;
|
||||
private JScrollPane scrollPane_1;
|
||||
private JLabel lblNewLabel;
|
||||
private String defautYear = null;
|
||||
private JPanel panelNorth;
|
||||
private JMenu mnNewMenu;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public gestionnaire() {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
|
||||
|
||||
if(commandes.nBase==null) {
|
||||
commandes.nBase = recupeBases.recupeLaBase();
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initialize() {
|
||||
frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setBounds(100, 100, 1200, 651);
|
||||
frame.setTitle("Gestionnaire Base des inscriptions des étudiants");
|
||||
frame.setLocationRelativeTo(null); // Centre la fenêtre à l'écran
|
||||
@ -66,9 +73,7 @@ public class gestionnaire extends JFrame {
|
||||
|
||||
frame.setContentPane(contentPane);
|
||||
|
||||
|
||||
|
||||
nBase = recupeBases.recupeLaBase();
|
||||
|
||||
cYears = new JComboBox<String>();
|
||||
cYears.setLocation(10, 25);
|
||||
cYears.setSize(168, 32);
|
||||
@ -84,25 +89,39 @@ public class gestionnaire extends JFrame {
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
List<String> lGroupeTD = new ArrayList<String>();
|
||||
for(noeud nChild : nBase.getChildren()) {
|
||||
lGroupeTD.add(" - ");
|
||||
for(noeud nChild : commandes.nBase.getChildren()) {
|
||||
cYears.addItem(nChild.getName());
|
||||
for(noeud nFormation : nChild.getChildren()) {
|
||||
cFormations.addItem(nFormation.getName());
|
||||
String GroupeTD = nFormation.getAttributes().get("Groupe_TD");
|
||||
if(GroupeTD!=null) if(!GroupeTD.isEmpty()) {
|
||||
if(!lGroupeTD.contains(GroupeTD))lGroupeTD.add(GroupeTD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
defautYear = commandes.nBase.getAttributes("defaut_Year");
|
||||
cYears.setSelectedItem(defautYear);
|
||||
cFormations.setSelectedIndex(0);
|
||||
|
||||
|
||||
|
||||
cYears.setVisible(true);
|
||||
cFormations.setVisible(true);
|
||||
cGroupeTD.setVisible(true);
|
||||
|
||||
|
||||
// Ajout d'un ActionListener à la JComboBox
|
||||
cFormations.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
majTable();
|
||||
majTableFormation();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Ajout d'un ActionListener à la JComboBox
|
||||
cGroupeTD.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
majTableGroupes();
|
||||
}
|
||||
});
|
||||
|
||||
@ -113,54 +132,84 @@ public class gestionnaire extends JFrame {
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
|
||||
|
||||
scrollPane_1 = new JScrollPane();
|
||||
scrollPane_1.setViewportBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||||
|
||||
contentPane.add(scrollPane_1);
|
||||
contentPane.add(scrollPane_1, BorderLayout.CENTER);
|
||||
scrollPane_1.setViewportView(table);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel, BorderLayout.NORTH);
|
||||
panel.setLayout(null);
|
||||
panel.setPreferredSize(new Dimension(400, 80));
|
||||
panel.setBackground(Color.gray);
|
||||
panel.add(cYears);
|
||||
panel.add(cFormations);
|
||||
JPanel panelFiltre = new JPanel();
|
||||
// contentPane.add(panelFiltre, BorderLayout.CENTER);
|
||||
panelFiltre.setLayout(null);
|
||||
panelFiltre.setPreferredSize(new Dimension(400, 80));
|
||||
panelFiltre.setBackground(Color.gray);
|
||||
panelFiltre.add(cYears);
|
||||
panelFiltre.add(cFormations);
|
||||
|
||||
JLabel lblYears = new JLabel("Année");
|
||||
lblYears.setFont(new Font("Tahoma", Font.BOLD, 12));
|
||||
lblYears.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblYears.setBounds(10, 11, 72, 14);
|
||||
panel.add(lblYears);
|
||||
panelFiltre.add(lblYears);
|
||||
|
||||
JLabel lblFormation = new JLabel("Formation");
|
||||
lblFormation.setFont(new Font("Tahoma", Font.BOLD, 12));
|
||||
lblFormation.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblFormation.setBounds(188, 11, 101, 14);
|
||||
panel.add(lblFormation);
|
||||
panelFiltre.add(lblFormation);
|
||||
|
||||
lblNewLabel = new JLabel("Groupe TD");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
|
||||
lblNewLabel.setBounds(489, 11, 121, 14);
|
||||
panel.add(lblNewLabel);
|
||||
panelFiltre.add(lblNewLabel);
|
||||
|
||||
|
||||
panel.add(cGroupeTD);
|
||||
panelFiltre.add(cGroupeTD);
|
||||
|
||||
majTable();
|
||||
panelNorth = new JPanel();
|
||||
contentPane.add(panelNorth, BorderLayout.NORTH);
|
||||
panelNorth.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
|
||||
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
JMenu fileMenu = new JMenu("Fichier");
|
||||
JMenuItem openItem = new JMenuItem("Ouvrir");
|
||||
JMenuItem saveItem = new JMenuItem("Enregistrer");
|
||||
JMenuItem exitItem = new JMenuItem("Quitter");
|
||||
|
||||
fileMenu.add(openItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.addSeparator(); // Ajouter une séparation entre les éléments du menu
|
||||
fileMenu.add(exitItem);
|
||||
|
||||
menuBar.add(fileMenu);
|
||||
|
||||
|
||||
panelNorth.add(menuBar, BorderLayout.NORTH);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
panelNorth.add(panelFiltre);
|
||||
|
||||
|
||||
|
||||
majTableFormation();
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void majTable() {
|
||||
noeud nYears = nBase.getChild(cYears.getSelectedItem().toString());
|
||||
private void majTableFormation() {
|
||||
noeud nYears = commandes.nBase.getChild(cYears.getSelectedItem().toString());
|
||||
|
||||
if(nYears!=null) {
|
||||
noeud nFormation = nYears.getChild(cFormations.getSelectedItem().toString());
|
||||
|
||||
|
||||
String[] head = new String[31] ;
|
||||
String[][] data = new String[nFormation.getChildren().size()-1][31] ;
|
||||
|
||||
@ -172,12 +221,8 @@ public class gestionnaire extends JFrame {
|
||||
String key = entry.getKey();
|
||||
head[indexCol] = key;
|
||||
}else {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
data[indexRow-1][indexCol] = value;
|
||||
if(key.equals("Groupe_TD")) {
|
||||
|
||||
}
|
||||
}
|
||||
indexCol++;
|
||||
}
|
||||
@ -185,11 +230,37 @@ public class gestionnaire extends JFrame {
|
||||
}
|
||||
|
||||
|
||||
cGroupeTD.removeAllItems();
|
||||
|
||||
List<String> lGroupeTD = new ArrayList<String>();
|
||||
lGroupeTD.add(" - ");
|
||||
if(nFormation!=null) {
|
||||
for(noeud nStudent : nFormation.getChildren()) {
|
||||
if(nStudent.getAttributes("Groupe_TD")!=null) {
|
||||
String GroupeTD = nStudent.getAttributes("Groupe_TD");
|
||||
if(GroupeTD!=null) {
|
||||
if(supprimeCaracatresSpeciaux.TousLesCaracatresSpeciaux(GroupeTD).length()>0) {
|
||||
if(!lGroupeTD.contains(GroupeTD)) {
|
||||
lGroupeTD.add(GroupeTD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String option : lGroupeTD) {
|
||||
cGroupeTD.addItem(option);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
table.setModel(new DefaultTableModel(data, head));
|
||||
|
||||
for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {
|
||||
// Obtention de la colonne à l'index donné
|
||||
table.getColumnModel().getColumn(columnIndex).setWidth(getMaxColumnWidth(table, columnIndex));
|
||||
table.getColumnModel().getColumn(columnIndex).setPreferredWidth(getMaxColumnWidth(table, columnIndex));
|
||||
}
|
||||
|
||||
table.revalidate();
|
||||
@ -201,6 +272,61 @@ public class gestionnaire extends JFrame {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void majTableGroupes() {
|
||||
String GroupeTD = (String) cGroupeTD.getSelectedItem();
|
||||
if(GroupeTD!=null) {
|
||||
noeud nYears = commandes.nBase.getChild(cYears.getSelectedItem().toString());
|
||||
if(nYears!=null) {
|
||||
noeud nFormation = nYears.getChild(cFormations.getSelectedItem().toString());
|
||||
|
||||
|
||||
String[] head = new String[31] ;
|
||||
String[][] data = new String[nFormation.getChildren().size()-1][31] ;
|
||||
|
||||
|
||||
int indexRow = 0;
|
||||
for(noeud nStudent : nFormation.getChildren()) {
|
||||
int indexCol = 0;
|
||||
boolean trouve = false;
|
||||
for (Map.Entry<String, String> entry : nStudent.getAttributes().entrySet()) {
|
||||
if(indexRow==0) {
|
||||
String key = entry.getKey();
|
||||
head[indexCol] = key;
|
||||
indexCol++;
|
||||
trouve=true;
|
||||
}else {
|
||||
String value = entry.getValue();
|
||||
if(nStudent.getAttributes("Groupe_TD").equals(GroupeTD)) {
|
||||
data[indexRow-1][indexCol] = value;
|
||||
indexCol++;
|
||||
trouve=true;
|
||||
}
|
||||
if(GroupeTD.equals(" - ")) {
|
||||
data[indexRow-1][indexCol] = value;
|
||||
indexCol++;
|
||||
trouve=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(trouve)indexRow++;
|
||||
}
|
||||
|
||||
table.setModel(new DefaultTableModel(data, head));
|
||||
|
||||
for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {
|
||||
// Obtention de la colonne à l'index donné
|
||||
table.getColumnModel().getColumn(columnIndex).setPreferredWidth(getMaxColumnWidth(table, columnIndex));
|
||||
}
|
||||
|
||||
table.revalidate();
|
||||
table.repaint();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Détermine la largeur de la colonne max pour ajustement.
|
||||
* @param table
|
||||
@ -208,7 +334,7 @@ public class gestionnaire extends JFrame {
|
||||
* @return
|
||||
*/
|
||||
private static int getMaxColumnWidth(JTable table, int columnIndex) {
|
||||
int maxWidth = 40;
|
||||
int maxWidth = 36;
|
||||
|
||||
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer();
|
||||
|
||||
@ -223,6 +349,11 @@ public class gestionnaire extends JFrame {
|
||||
}
|
||||
|
||||
|
||||
return maxWidth;
|
||||
}
|
||||
return maxWidth+4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,14 +16,17 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
public class importAllBaseToExcel {
|
||||
|
||||
public static void lecture(File file) {
|
||||
if(commandes.nBase==null) {
|
||||
commandes.nBase = recupeBases.recupeLaBase();
|
||||
}
|
||||
|
||||
noeud nBase = recupeBases.recupeLaBase();
|
||||
|
||||
int compteur = 0 ;
|
||||
|
||||
try (FileInputStream fileInputStream = new FileInputStream(file.getAbsolutePath());
|
||||
Workbook workbook = new XSSFWorkbook(fileInputStream)) {
|
||||
|
||||
int numSheets = workbook.getNumberOfSheets();
|
||||
int compteur = 0 ;
|
||||
|
||||
|
||||
|
||||
for (int sheetIndex = 0; sheetIndex < numSheets; sheetIndex++) {
|
||||
@ -41,7 +44,7 @@ public class importAllBaseToExcel {
|
||||
|
||||
if(indexCol==0) { // Colonne formation
|
||||
if(cell.getCellType() == CellType.STRING) {
|
||||
nBF = nBase.getChild(cell.getStringCellValue());
|
||||
nBF = commandes.nBase.getChild(cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,13 +109,11 @@ public class importAllBaseToExcel {
|
||||
|
||||
System.out.println(); // Nouvelle ligne entre les feuilles
|
||||
}
|
||||
|
||||
JOptionPane.showInternalMessageDialog(null, "Nombre de modification : " +String.valueOf(compteur));
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null, e.toString(), "Erreur dans la class importAllBaseToExcel", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
sauvegardeXMLBase.save(nBase);
|
||||
sauvegardeXMLBase.saveModif(commandes.nBase, compteur);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package baseUFRHG;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class lecture {
|
||||
|
||||
|
||||
@ -13,23 +17,30 @@ public class lecture {
|
||||
noeud nBase = recupeBases.recupeLaBase();
|
||||
|
||||
|
||||
|
||||
// lecture et création d'un noeud à partir d'un fichier CSV
|
||||
try {
|
||||
File fileData = FileChooserCSV.retourneFileCSV();
|
||||
if(fileData!=null) {
|
||||
String filePath = fileData.getAbsolutePath();
|
||||
noeudCSV = lectureCSV.noeudCSV(filePath);
|
||||
if(nBase!=null) {
|
||||
// lecture et création d'un noeud à partir d'un fichier CSV
|
||||
try {
|
||||
File fileData = FileChooserCSV.retourneFileCSV();
|
||||
if(fileData!=null) {
|
||||
String filePath = fileData.getAbsolutePath();
|
||||
noeudCSV = lectureCSV.noeudCSV(filePath);
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
// ajoute les étudiants qui n'existent pas, dans la base.
|
||||
nBase = majBase.addStudents(nBase,noeudCSV);
|
||||
}else {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel message = new JLabel("<html><p>La base de données est nulle.</p></html>");
|
||||
panel.add(message);
|
||||
JOptionPane.showMessageDialog(null, panel, "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
// ajoute les étudiants qui n'existent pas, dans la base.
|
||||
nBase = majBase.addStudents(nBase,noeudCSV);
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,10 +18,24 @@ public class sauvegardeXMLBase {
|
||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(directoryName), StandardCharsets.UTF_8))) {
|
||||
writer.write(nBase.toWrite());
|
||||
JOptionPane.showMessageDialog(null, "La base a été sauvegardée.", "Sauvegarde", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null, e.toString(), "Erreur dans la méthode save", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void saveModif(noeud nBase,Integer nbreModif) {
|
||||
// Sauvegarde de la base
|
||||
String directoryName = Paths.get("").toAbsolutePath().toString()+ "/base.xml";
|
||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(directoryName), StandardCharsets.UTF_8))) {
|
||||
writer.write(nBase.toWrite());
|
||||
JOptionPane.showMessageDialog(null, "Les " + nbreModif +" modifications ont été enregistrées dans la base.", "Sauvegarde", JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null, e.toString(), "Erreur dans la méthode save", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user