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 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
package main;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
public class Gestion extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel userConnected;
static DefaultTableModel model;
private JPanel contentPane;
protected JTable classSalarie;
protected JScrollPane JScroll;
private JButton modButton;
private JButton addButton;
private JLabel lblBienvenue;
private JButton deconnectionButton;
private JButton supprButton;
private JLabel lblNom;
private JLabel lblVille;
private JLabel lblCodePostal;
protected static JLabel lblNoPrat;
protected static JTextField textNom;
protected static JComboBox<String> textVille;
protected static JComboBox<String> textFieldCodePostal;
protected static Connection con;
private JMenuBar menuBar;
private JMenu mnCompte;
private JMenuItem mntmModifierCompte;
@SuppressWarnings("unused")
private static String id;
private static String idCategSal;
private static String nomSal;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
System.out.println("Erreur.");
}
});
}
/**
* Create the frame.
*/
public Gestion(String nomSal, String idCategSal, String id) {
con = main.Connexion.getConnection();
Gestion.nomSal = nomSal;
Gestion.idCategSal = idCategSal;
Gestion.id = id;
setBackground(Color.WHITE);
setTitle("GSB | Gestion");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 900, 432);
setMinimumSize(new Dimension(800,432));
menuBar = new JMenuBar();
setJMenuBar(menuBar);
mnCompte = new JMenu("Options");
menuBar.add(mnCompte);
mntmModifierCompte = new JMenuItem("Compte");
mntmModifierCompte.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String query = "SELECT id FROM salarie WHERE id=?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, id);
ResultSet rs = st.executeQuery();
if (rs.next()) {
String id = rs.getString("id");
Account Account = new Account(id);
Account.setLocationRelativeTo(null);
Account.setVisible(true);
}
}
catch (SQLException | NullPointerException e1) {
JOptionPane.showMessageDialog(null, "La connexion à la base de donnée a été perdu.", "Message", JOptionPane.INFORMATION_MESSAGE);
main.Connexion.connection();
con = main.Connexion.getConnection();
e1.printStackTrace();
}
}
});
mnCompte.add(mntmModifierCompte);
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setForeground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
lblBienvenue = new JLabel("Bienvenue,");
userConnected = new JLabel("");
lblNom = new JLabel("Nom :");
textNom = new JTextField();
textNom.setColumns(10);
lblVille = new JLabel("Ville :");
textVille = new JComboBox<String>();
textVille.setEditable(true);
lblCodePostal = new JLabel("Code Postal :");
lblCodePostal.setBounds(17, 124, 75, 16);
textFieldCodePostal = new JComboBox<String>();
textFieldCodePostal.setEditable(true);
lblNoPrat = new JLabel("Aucun praticien trouvé");
lblNoPrat.setVisible(false);
TableAdd();
// Deconnexion
deconnectionButton = new JButton("Déconnexion");
deconnectionButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
Connexion Connexion = new Connexion();
Connexion.setLocationRelativeTo(null);
Connexion.setVisible(true);
}
});
// Suppression d'un praticien
supprButton = new JButton("Supprimer");
supprButton.setEnabled(false);
supprButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = classSalarie.getSelectedRow();
String nom = classSalarie.getModel().getValueAt(row, 0).toString();
String adresse = classSalarie.getModel().getValueAt(row, 1).toString();
String cp = classSalarie.getModel().getValueAt(row, 3).toString();
int result = JOptionPane.showConfirmDialog(null,"Confirmer-vous la suppression ?", "Message",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.YES_OPTION){
try {
String query = "DELETE FROM praticien WHERE nomPraticien=? AND cpPrat=? AND adPrat=?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, nom);
st.setString(2, cp);
st.setString(3, adresse);
int rs = st.executeUpdate();
if (rs > 0) {
JOptionPane.showMessageDialog(null, "Suppression effectuée.", "Message", JOptionPane.INFORMATION_MESSAGE);
updateAll();
}
}
catch (SQLException | NullPointerException e1) {
JOptionPane.showMessageDialog(null, "La connexion à la base de donnée a été perdu.", "Message", JOptionPane.INFORMATION_MESSAGE);
main.Connexion.connection();
con = main.Connexion.getConnection();
e1.printStackTrace();
}
}
}
});
// Modification des informations d'un praticien existant
modButton = new JButton("Modifier");
modButton.setEnabled(false);
modButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = classSalarie.getSelectedRow();
try {
String nom = classSalarie.getModel().getValueAt(row, 0).toString();
String adresse = classSalarie.getModel().getValueAt(row, 1).toString();
String cp = classSalarie.getModel().getValueAt(row, 3).toString();
String query = "SELECT id FROM praticien WHERE nomPraticien=? AND cpPrat=? AND adPrat=?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, nom);
st.setString(2, cp);
st.setString(3, adresse);
ResultSet rs = st.executeQuery();
if (rs.next()) {
String id = rs.getString("id");
FormModification formModification = new FormModification(id);
formModification.setLocationRelativeTo(null);
formModification.setVisible(true);
}
}
catch (SQLException | NullPointerException e1) {
JOptionPane.showMessageDialog(null, "La connexion à la base de donnée a été perdu.", "Message", JOptionPane.INFORMATION_MESSAGE);
main.Connexion.connection();
con = main.Connexion.getConnection();
e1.printStackTrace();
}
}
});
// Ajout d'un nouveau praticien
addButton = new JButton("Ajout");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FormAjout formAjout = new FormAjout();
formAjout.setLocationRelativeTo(null);
formAjout.setVisible(true);
}
});
ListSelectionModel selectionModel = classSalarie.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (classSalarie.getSelectedRow() >= 0) {
supprButton.setEnabled(true);
modButton.setEnabled(true);
}else {
supprButton.setEnabled(false);
modButton.setEnabled(false);
}
}
});
// Recherche d'un praticien
/*
* JButton btnRechercher = new JButton("Rechercher");
* btnRechercher.addActionListener(new ActionListener() { public void
* actionPerformed(ActionEvent e) { updateAll(); } });
*/
// Update de l'ItemListener
ItemListener bypassListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateAll();
}
};
textVille.addItemListener(bypassListener);
textFieldCodePostal.addItemListener(bypassListener);
// Recherche automatique
textVille.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode != KeyEvent.VK_UP && keyCode != KeyEvent.VK_DOWN &&
keyCode != KeyEvent.VK_LEFT && keyCode != KeyEvent.VK_RIGHT &&
keyCode != KeyEvent.VK_ENTER) { // Exclure les touches directionnelles et Entrée
String input = ((JTextField)textVille.getEditor().getEditorComponent()).getText();
textVille.removeAllItems();
textVille.addItem("");
try {
String query = "SELECT name FROM cities WHERE slug LIKE ?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, input + "%");
ResultSet rs = st.executeQuery();
while (rs.next()) {
String item = rs.getString("name");
if (!item.equals(textVille.getItemAt(textVille.getItemCount() - 1))) {
textVille.addItem(item);
}
}
} catch (SQLException ex) {
}
textVille.setPopupVisible(false);
textVille.setPopupVisible(true);
((JTextField)textVille.getEditor().getEditorComponent()).setText(input);
updateAll();
}
}
});
textVille.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object selectedItem = textVille.getSelectedItem();
JTextField focusOwner = ((JTextField) textVille.getEditor().getEditorComponent());
if (selectedItem != null) {
((JTextField) textVille.getEditor().getEditorComponent()).setText(selectedItem.toString());
if (focusOwner.isFocusOwner()) {
textFieldCodePostal.removeAllItems();
try {
String query = "SELECT zip_code FROM cities WHERE name = ?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, selectedItem.toString());
ResultSet rs = st.executeQuery();
while (rs.next()) {
String item = rs.getString("zip_code");
if (!item.equals(textFieldCodePostal.getItemAt(textFieldCodePostal.getItemCount() - 1))) {
textFieldCodePostal.addItem(item);
}
}
} catch (SQLException ex) {
}
}
updateAll();
}
}
});
textNom.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
updateAll();
}
public void removeUpdate(DocumentEvent e) {
updateAll();
}
public void insertUpdate(DocumentEvent e) {
updateAll();
}
});
textFieldCodePostal.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!(Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
|| ((JTextField) textFieldCodePostal.getEditor().getEditorComponent()).getText().length() >= 5) {
e.consume();
}
}
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode != KeyEvent.VK_UP && keyCode != KeyEvent.VK_DOWN &&
keyCode != KeyEvent.VK_LEFT && keyCode != KeyEvent.VK_RIGHT &&
keyCode != KeyEvent.VK_ENTER) { // Exclure les touches directionnelles et Entrée
String input = ((JTextField)textFieldCodePostal.getEditor().getEditorComponent()).getText();
textFieldCodePostal.removeAllItems();
textFieldCodePostal.addItem("");
try {
String query = "SELECT zip_code FROM cities WHERE zip_code LIKE ?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, input + "%");
ResultSet rs = st.executeQuery();
while (rs.next()) {
String item = rs.getString("zip_code");
if (!item.equals(textFieldCodePostal.getItemAt(textFieldCodePostal.getItemCount() - 1))) {
textFieldCodePostal.addItem(item);
}
}
} catch (SQLException ex) {
}
textFieldCodePostal.setPopupVisible(false);
textFieldCodePostal.setPopupVisible(true);
((JTextField)textFieldCodePostal.getEditor().getEditorComponent()).setText(input);
updateAll();
}
}
});
textFieldCodePostal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object selectedItem = textFieldCodePostal.getSelectedItem();
JTextField focusOwner = ((JTextField) textFieldCodePostal.getEditor().getEditorComponent());
if (selectedItem != null) {
((JTextField) textFieldCodePostal.getEditor().getEditorComponent()).setText(selectedItem.toString());
if (focusOwner.isFocusOwner()) {
textVille.removeAllItems();
try {
String query = "SELECT name FROM cities WHERE zip_code = ?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, selectedItem.toString());
ResultSet rs = st.executeQuery();
while (rs.next()) {
String item = rs.getString("name");
if (!item.equals(textVille.getItemAt(textVille.getItemCount() - 1))) {
textVille.addItem(item);
}
}
} catch (SQLException ex) {
}
}
updateAll();
}
}
});
// GroupLayout permettant le responsive
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(7)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNom)
.addGap(2)
.addComponent(textNom, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblVille, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
.addGap(2)
.addComponent(textVille, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblCodePostal)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textFieldCodePostal, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 234, Short.MAX_VALUE)
.addComponent(lblNoPrat))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(supprButton)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(modButton)
.addPreferredGap(ComponentPlacement.RELATED, 526, Short.MAX_VALUE)
.addComponent(addButton))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblBienvenue)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(userConnected, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addGap(261)
.addComponent(deconnectionButton, GroupLayout.PREFERRED_SIZE, 149, GroupLayout.PREFERRED_SIZE))
.addComponent(JScroll, GroupLayout.DEFAULT_SIZE, 769, Short.MAX_VALUE)))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(userConnected, GroupLayout.PREFERRED_SIZE, 13, GroupLayout.PREFERRED_SIZE)
.addComponent(lblBienvenue))
.addComponent(deconnectionButton))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNom)
.addComponent(textNom, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(5)
.addComponent(lblVille))
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(textFieldCodePostal, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
.addComponent(lblCodePostal)
.addComponent(lblNoPrat))
.addComponent(textVille, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(JScroll, GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(supprButton)
.addComponent(modButton)
.addComponent(addButton))
.addGap(9))
);
gl_contentPane.linkSize(SwingConstants.VERTICAL, new Component[] {lblBienvenue, userConnected});
gl_contentPane.linkSize(SwingConstants.HORIZONTAL, new Component[] {textNom, textFieldCodePostal});
contentPane.setLayout(gl_contentPane);
}
// Créer la table
protected void TableAdd() {
// Créer le modèle
model = new DefaultTableModel();
model.addColumn("Nom");
model.addColumn("Adresse");
model.addColumn("Ville");
model.addColumn("Code Postal");
// Rajouter les données
updateAll();
// Créer la table
classSalarie = new JTable(model);
classSalarie.getTableHeader().setReorderingAllowed(false);
classSalarie.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
classSalarie.setDefaultEditor(Object.class, null);
// Définir la largeur des colonnes
classSalarie.getColumnModel().getColumn(0).setPreferredWidth(50);
classSalarie.getColumnModel().getColumn(1).setPreferredWidth(150);
classSalarie.getColumnModel().getColumn(2).setPreferredWidth(100);
classSalarie.getColumnModel().getColumn(3).setPreferredWidth(10);
// Créer le JScrollPane
JScroll = new JScrollPane(classSalarie);
}
// Mets à jour la table
protected void updateAll() {
// Ajouter les données au modèle à partir de la base de données
try {
main.Gestion.model.setRowCount(0);
String nom = textNom.getText();
String ville = ((JTextField)textVille.getEditor().getEditorComponent()).getText();
String cp = ((JTextField)textFieldCodePostal.getEditor().getEditorComponent()).getText();
// Si aucune entrée, ne rien afficher
if (nom.isEmpty() && ville.isEmpty() && cp.isEmpty()) {
lblNoPrat.setVisible(true);
return;
}
// Si le nom est saisi
String query = "SELECT nomPraticien, adPrat, villePrat, cpPrat FROM praticien";
if (!nom.isEmpty()) {
query += " WHERE nomPraticien LIKE ?";
}
// Si la ville est saisie
if (!ville.isEmpty()) {
if (query.contains("WHERE")) {
query += " AND villePrat LIKE ?";
} else {
query += " WHERE villePrat LIKE ?";
}
}
// Si le code postal est saisie
if (!cp.isEmpty()) {
if (query.contains("WHERE")) {
query += " AND cpPrat LIKE ?";
} else {
query += " WHERE cpPrat LIKE ?";
}
}
// Limité le nombre de praticien renvoyé
query += " LIMIT 50";
PreparedStatement st = con.prepareStatement(query);
// Si le nom est saisi
if (!nom.isEmpty()) {
st.setString(1, nom + "%");
}
// Si la ville est saisie
if (!ville.isEmpty()) {
if (!nom.isEmpty()) {
st.setString(2, ville + "%");
} else {
st.setString(1, ville + "%");
}
}
// Si le code postal est saisie
if (!cp.isEmpty()) {
if (!nom.isEmpty()) {
if (!ville.isEmpty()) {
st.setString(3, cp + "%");
} else {
st.setString(2, cp + "%");
}
} else {
if (!ville.isEmpty()) {
st.setString(2, cp + "%");
} else {
st.setString(1, cp + "%");
}
}
}
// System.out.println(query);
ResultSet rs = st.executeQuery();
boolean hasResults = false;
while (rs.next()) {
hasResults = true;
model.addRow(new Object[]{rs.getString("nomPraticien"), rs.getString("adPrat"), rs.getString("villePrat"), rs.getString("cpPrat")});
}
if (!hasResults) {
lblNoPrat.setVisible(true);
} else {
lblNoPrat.setVisible(false);
}
}
catch (SQLException | NullPointerException e1) {
JOptionPane.showMessageDialog(null, "La connexion à la base de donnée a été perdu.", "Message", JOptionPane.INFORMATION_MESSAGE);
main.Connexion.connection();
con = main.Connexion.getConnection();
e1.printStackTrace();
}
}
// Affiche l'utilisateur connecté
public void connecte() {
String CategSal = null;
try {
String query = "SELECT libCategSal FROM categsalarie WHERE id=?;";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, idCategSal);
ResultSet rs = st.executeQuery();
if (rs.next()) {
CategSal = rs.getString("libCategSal");
}
}
catch (SQLException | NullPointerException e1) {
JOptionPane.showMessageDialog(null, "La connexion à la base de donnée a été perdu.", "Message", JOptionPane.INFORMATION_MESSAGE);
main.Connexion.connection();
con = main.Connexion.getConnection();
e1.printStackTrace();
}
userConnected.setText(nomSal+" ("+CategSal+")");
}
} |
Partager