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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
| package javaapplication2;
import java.util.Map;
import java.util.Properties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.text.DateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class Test extends JFrame implements ActionListener{
static String nom1,prenom1,ncin1,ninsc1,sexe1,datenaiss1,niveauSco1,etatcivile1,daterec1,datecont1,salaire1,classe1,degre1,regime1,titre1,partie1,arrondissement1,article1,paragraphe1,sousp1;
JLabel hr = new JLabel();
JLabel heure = new JLabel("Heure: ");
JLabel ncin = new JLabel ("Num CIN: " );
JTextField Tncin = new JTextField();
JLabel ninsc = new JLabel("Num Inscription: ");
JTextField Tninsc = new JTextField();
JLabel n = new JLabel("Nom:");
JTextField Tn = new JTextField();
JLabel pr = new JLabel("Prenom:");
JTextField Tp = new JTextField();
JLabel niv = new JLabel("Niveau scolaire:");
JTextField Tniv = new JTextField();
JLabel datenais = new JLabel("Date naissance:");
JTextField Tdatenais = new JTextField();
JLabel sexe = new JLabel("sexe:");
JComboBox Cbsex = new JComboBox();
JLabel etatciv = new JLabel("Etat civile:");
JComboBox Cbetatciv = new JComboBox();
JLabel daterec = new JLabel("Date recrutement:");
JTextField Tdaterec = new JTextField();
JLabel classe = new JLabel("Classe: ");
JComboBox Cbclasse = new JComboBox();
JLabel degre = new JLabel("Degré:");
JComboBox Cbdegre = new JComboBox();
JLabel regime = new JLabel("Regime:");
JTextField Tregime = new JTextField();
JLabel salaire = new JLabel("Salaire:");
JTextField Tsalaire = new JTextField();
JLabel titre = new JLabel("Titre:");
JTextField Ttitre = new JTextField();
JLabel partie = new JLabel("Partie:");
JTextField Tpartie = new JTextField();
JLabel arrondissement = new JLabel("Arrondissement:");
JComboBox Cbarrondissement = new JComboBox();
JLabel datecont = new JLabel("Date contrat:");
JTextField Tdatecont = new JTextField();
JLabel article = new JLabel("Article:");
JTextField Tarticle = new JTextField();
JLabel parag = new JLabel("Paragraphe:");
JTextField Tparag = new JTextField();
JLabel sousparag = new JLabel("Sous-paragraphe:");
JTextField Tsousp = new JTextField();
JLabel vide = new JLabel();
JComboBox Cbvide = new JComboBox();
JButton ajouter = new JButton("Ajouter");
JButton modifier = new JButton("Modifier");
JButton supprimer = new JButton("Supprimer");
JButton recherche = new JButton("Recherche");
JButton quitter = new JButton("Quitter");
JButton annuler = new JButton("Annuler");
JButton next = new JButton(">");
JButton previous = new JButton("<");
public Test(){
this.getContentPane().setLayout(new GridLayout(12,4));
JPanel p = new JPanel();
p.setLayout(new GridLayout(3,4));
p.add(ncin);
p.add(Tncin);
p.add(ninsc);
p.add(Tninsc);
p.add(n);
p.add(Tn);
p.add(pr);
p.add(Tp);
p.add(niv);
p.add(Tniv);
p.add(datenais);
p.add(Tdatenais);
this.getContentPane().add(p);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3,4));
p1.add(sexe);
p1.add(Cbsex);
p1.add(etatciv);
p1.add(Cbetatciv);
p1.add(classe);
p1.add(Cbclasse);
p1.add(degre);
p1.add(Cbdegre);
p1.add(arrondissement);
p1.add(Cbarrondissement);
p1.add(vide);
p1.add(Cbvide);
this.getContentPane().add(p1);
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(3,4));
p2.add(regime);
p2.add(Tregime);
p2.add(salaire);
p2.add(Tsalaire);
p2.add(article);
p2.add(Tarticle);
p2.add(parag);
p2.add(Tparag);
p2.add(sousparag);
p2.add(Tsousp);
p2.add(partie);
p2.add(Tpartie);
this.getContentPane().add(p2);
JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(2,4));
p3.add(daterec);
p3.add(Tdaterec);
p3.add(titre);
p3.add(Ttitre);
p3.add(datecont);
p3.add(Tdatecont);
p3.add(heure);
p3.add(hr);
this.getContentPane().add(p3);
//panel des bouttons:
JPanel p4 = new JPanel();
p4.setLayout(new GridLayout(1,4));
p4.add(ajouter);
p4.add(modifier);
p4.add(recherche);
p4.add(annuler);
this.getContentPane().add(p4);
JPanel p5 = new JPanel();
p5.setLayout(new GridLayout(1,4));
p5.add(supprimer);
p5.add(next);
p5.add(previous);
p5.add(quitter);
this.getContentPane().add(p5);
//listes des Combobox
Cbsex.addItem("MALE");
Cbsex.addItem("FEMELE");
Cbetatciv.addItem("Célibataire");
Cbetatciv.addItem("Marié");
Cbetatciv.addItem("Divorsé");
Cbarrondissement.addItem("");
Cbarrondissement.addItem("Arrondissement financier");
Cbarrondissement.addItem("Arrondissement des ressources en eau");
Cbarrondissement.addItem("Arrondissement personnel");
Cbclasse.addItem("A");
Cbclasse.addItem("B");
Cbclasse.addItem("C");
Cbdegre.addItem("1");
Cbdegre.addItem("2");
Cbdegre.addItem("3");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
this.setTitle("Gestion des Contractuels");
//ajout des ecouteurs:
ajouter.addActionListener(this);
modifier.addActionListener(this);
recherche.addActionListener(this);
annuler.addActionListener(this);
supprimer.addActionListener(this);
quitter.addActionListener(this);
next.addActionListener(this);
previous.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JButton src=(JButton)e.getSource();
if(src==quitter){
System.exit(0);
}
if(src==annuler){
Tn.setText("");
Tp.setText("");
Tncin.setText("");
Tninsc.setText("");
Tniv.setText("");
Tdatenais.setText("");
Tdaterec.setText("");
Tregime.setText("");
Tsalaire.setText("");
Ttitre.setText("");
Tpartie.setText("");
Tdatecont.setText("");
Tarticle.setText("");
Tparag.setText("");
Tsousp.setText("");
}
if(src==ajouter){
String Sn = Tn.getText();
String Sp = Tp.getText();
String Scin = Tncin.getText();
String Snins = Tninsc.getText();
String Snivs = Tniv.getText();
String Sdatenais=Tdatenais.getText();
String Sdaterec=Tdaterec.getText();
String Sdatecont=Tdatecont.getText();
Object Osex = Cbsex.getSelectedItem();
Object Oclasse = Cbclasse.getSelectedItem();
Object Oetat = Cbetatciv.getSelectedItem();
Object Odegre = Cbdegre.getSelectedItem();
String Spartie = Tpartie.getText();
String Sregime = Tregime.getText();
String Stitre = Ttitre.getText();
Object Oarrond = Cbarrondissement.getSelectedItem();
String Sarticle = article.getText();
String Sparag = Tparag.getText();
String Ssousp = Tsousp.getText();
if (Tninsc.getText().length() != 8) {
JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num Inscr", "Information", JOptionPane.ERROR_MESSAGE);
}
if (Tncin.getText().length() != 8) {
JOptionPane.showMessageDialog(null, "Inserez 8 chiffres:Num CINS", "Information", JOptionPane.ERROR_MESSAGE);
}
//Connexion a la base
String req="insert into personnel values('+Sn','+Sdatenais+','+Sdatenrec+','+Sdatecont+', +Sp+,'+Sncin+','+Snins+','+Snivs+','+Sregime+','+Ssalaire+','+Stitre+','+Spartie+','+Sarticle+','+Sparag+','+Ssousp+','+Osex+','+Oetat+','+Oclasse+','+Oarrond+','Odegre+')";
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection Con=DriverManager.getConnection("Mes documents/Personnel");
Statement st = Con.createStatement();
int x = st.executeUpdate(req);
st.close();
Con.close();
}
catch(ClassNotFoundException x){
System.out.println("Erreur");
}
catch(SQLException g){
JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
}
}
if(src==supprimer){
String req="delete from employe";
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection Con=DriverManager.getConnection("Mes documents/Personnel");
Statement st = Con.createStatement();
int x = st.executeUpdate(req);
st.close();
Con.close();
}
catch(ClassNotFoundException x){
System.out.println("Erreur");
}
catch(SQLException g){
JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
}
}
if(src==modifier){
try {
Connection c = new Connection() {
@Override
public Statement createStatement() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getAutoCommit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void commit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isReadOnly() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCatalog(String catalog) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getCatalog() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setHoldability(int holdability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob createClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob createBlob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob createNClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML createSQLXML() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isValid(int timeout) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getClientInfo(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Properties getClientInfo() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
};
c.connecte();
ResultSet rs = c.res("Update nom1,prenom1,ncin1,ninsc1,degre1,salaire1,datenaiss1,classe1,article1 from employe");
if (rs.next()) {
nom1 = rs.getString("Tnom");
prenom1 = rs.getString("Tprenom");
ncin1 = rs.getString("Tncin");
ninsc1 = rs.getString("Tninsc");
degre1 = rs.getString("degre");
salaire1 = rs.getString("salaire");
datenaiss1 = rs.getString("date_naiss");
classe1 = rs.getString("Tclasse");
article1 = rs.getString("Tarticle");
niveauSco1 = rs.getString("Tniv");
partie1 = rs.getString("Tpartie");
paragraphe1 = rs.getString("Tparag");
titre1 = rs.getString("Ttitre");
}
}
catch(SQLException g){
JOptionPane.showMessageDialog(null, "Erreur requete","Alert", JOptionPane.ERROR_MESSAGE);
}
}
}
public static void main(String[] args) {
new Test();
}
} |
Partager