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
|
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
public class JtablePeriode extends AbstractTableModel
{
private static final long serialVersionUID = 0;
private String[] columnNames = {"ID","Classe", "Nom semestre", "Date début", "Date fin"};
private Object[][] data;
public int getColumnCount() {return columnNames.length;}
public int getRowCount() {return data.length;}
public int getSelectedRow() {
return 0;
}
public String getColumnName(int col) {return columnNames[col];}
public Object getValueAt(int row, int col) {return data[row][col];}
public Class getColumnClass(int c) {return getValueAt(0,c).getClass();}
public boolean setRowSelectionAllowed(boolean rowSelectionAllowed)
{
return true;
}
public boolean isCellEditable(int row, int col) {
if ( col==0 ) {
return ( false );
} else {
return ( true );
}
}
public void setValueAt(Object value, int row, int col)
{
data[row][col] = value;
fireTableCellUpdated(row,col);
}
public JtablePeriode() {
ArrayList test = TablePeriode.selectDonnees();
int j = 0;
this.data = new Object[test.size()][5];
for (int i=0;i<test.size();i++) {
TablePeriode per = (TablePeriode) test.get(i);
this.data[j] = new Object[5];
this.data[j][0] = per.idToString(); // révupère l'id de la table periode
this.data[j][1] = per.fkClasseToString(); // la fk -> pk de la table classe
this.data[j][2] = per.getNomPeriode();
this.data[j][3] = per.getDebutPeriode();
this.data[j][4] = per.getFinPeriode();
j++;
}
}
// update des champs de la table periode
public void fireTableCellUpdated(int row, int column) {
java.sql.Connection connection = DataBase.getConnection();
try
{
Statement statementUpdate = connection.createStatement ();
switch(column)
{
case 1: String update0 = "UPDATE periode SET fkclasse = '"+ this.data[row][column] +"' where pkperiode ='"+this.data[row][0]+"'";
statementUpdate.execute (update0);
break;
case 2: String update1 = "UPDATE periode SET nomperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
statementUpdate.execute (update1);System.out.println(column);
break;
case 3: String update2 = "UPDATE periode SET datedebutperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
statementUpdate.execute (update2);System.out.println(column);
break;
case 4: String update3 = "UPDATE periode SET datefinperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
statementUpdate.execute (update3);System.out.println(column);
break;
default:System.out.println("ERREUR");
}
statementUpdate.execute ("COMMIT;");
statementUpdate.close ();
}
catch (SQLException exception)
{
exception.printStackTrace ();
}
}
} |
Partager