package base_de_donnee;
import application.BDD;
import application.Parameter;
import application.ResultSetTableModel;
import java.sql.*;
import javax.swing.JOptionPane;
/**
*
* @author USER
*/
public class Utilisateur extends javax.swing.JFrame {
//declaration
ResultSet rs;
BDD db;
public Utilisateur() {
db= new BDD(new Parameter().HOST_BD,new Parameter().USERNAME_DB,new Parameter().PASSWORD_DB,new Parameter().IPHOST,new Parameter().PORT);
initComponents();
table();
}
//Fonction Table
public void table(){
String a[]={"id","id_user","username","password","type"};
rs = db.querySelect(a,"utilisateur");
table_user.setModel (new ResultSetTableModel(rs));
}
void actualiser(){
txt_id.setText("");
txt_us.setText("");
txt_pa.setText("");
com_ty.setSelectedItem("Type");
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
UTILISATEURjLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
table_user = new javax.swing.JTable();
ModifBT = new javax.swing.JButton();
RechBT = new javax.swing.JButton();
AjouBT = new javax.swing.JButton();
SupprBT = new javax.swing.JButton();
UserjLabel2 = new javax.swing.JLabel();
PassjLabel = new javax.swing.JLabel();
RechjLabel = new javax.swing.JLabel();
TypjLabel = new javax.swing.JLabel();
txt_rech = new javax.swing.JTextField();
txt_us = new javax.swing.JTextField();
txt_id = new javax.swing.JTextField();
ActuBT = new javax.swing.JButton();
txt_pa = new javax.swing.JTextField();
com_rech = new javax.swing.JComboBox();
IdjLabel = new javax.swing.JLabel();
com_ty = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
UTILISATEURjLabel.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N
UTILISATEURjLabel.setText("Utilisateur");
getContentPane().add(UTILISATEURjLabel);
UTILISATEURjLabel.setBounds(200, 19, 106, 28);
table_user.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"id", "id_user", "username", "password", "type"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(table_user);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(10, 53, 494, 88);
ModifBT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
ModifBT.setText("Modifier");
ModifBT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ModifBTActionPerformed(evt);
}
});
getContentPane().add(ModifBT);
ModifBT.setBounds(250, 180, 80, 30);
RechBT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
RechBT.setText("Recherche");
RechBT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RechBTActionPerformed(evt);
}
});
getContentPane().add(RechBT);
RechBT.setBounds(370, 330, 100, 30);
AjouBT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
AjouBT.setText("Ajouter");
AjouBT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AjouBTActionPerformed(evt);
}
});
getContentPane().add(AjouBT);
AjouBT.setBounds(170, 180, 80, 30);
SupprBT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
SupprBT.setText("Supprimer");
SupprBT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SupprBTActionPerformed(evt);
}
});
getContentPane().add(SupprBT);
SupprBT.setBounds(330, 180, 100, 30);
UserjLabel2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
UserjLabel2.setText("username");
getContentPane().add(UserjLabel2);
UserjLabel2.setBounds(20, 290, 69, 22);
PassjLabel.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
PassjLabel.setText("password");
getContentPane().add(PassjLabel);
PassjLabel.setBounds(20, 330, 80, 22);
RechjLabel.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
RechjLabel.setText("Recherche par catégorie:");
getContentPane().add(RechjLabel);
RechjLabel.setBounds(370, 290, 140, 17);
TypjLabel.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
TypjLabel.setText("type");
getContentPane().add(TypjLabel);
TypjLabel.setBounds(20, 380, 31, 22);
txt_rech.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
txt_rech.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_rechActionPerformed(evt);
}
});
getContentPane().add(txt_rech);
txt_rech.setBounds(520, 330, 80, 30);
txt_us.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
txt_us.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_usActionPerformed(evt);
}
});
getContentPane().add(txt_us);
txt_us.setBounds(120, 290, 210, 30);
txt_id.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
txt_id.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_idActionPerformed(evt);
}
});
getContentPane().add(txt_id);
txt_id.setBounds(120, 250, 80, 30);
ActuBT.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
ActuBT.setText("Actualiser");
ActuBT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ActuBTActionPerformed(evt);
}
});
getContentPane().add(ActuBT);
ActuBT.setBounds(430, 180, 100, 30);
txt_pa.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
txt_pa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_paActionPerformed(evt);
}
});
getContentPane().add(txt_pa);
txt_pa.setBounds(120, 330, 80, 30);
com_rech.setEditable(true);
com_rech.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
com_rech.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "id_user", "username", "password", "type" }));
getContentPane().add(com_rech);
com_rech.setBounds(520, 280, 120, 30);
IdjLabel.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
IdjLabel.setText("id_user");
getContentPane().add(IdjLabel);
IdjLabel.setBounds(20, 250, 52, 22);
com_ty.setEditable(true);
com_ty.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
com_ty.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cachier", "directeur" }));
getContentPane().add(com_ty);
com_ty.setBounds(120, 380, 90, 30);
pack();
}// //GEN-END:initComponents
private void ModifBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifBTActionPerformed
if(txt_id.getText().equals("") || txt_us.getText().equals("") || txt_pa.getText().equals("") || com_ty.getSelectedItem().equals("Type")){
JOptionPane.showMessageDialog(this,"SVP entrer les informations complete");
}else{
String[] colon = {"id_user","username","password","type"};
String[] inf = {txt_id.getText(),txt_us.getText(),txt_pa.getText(), com_ty.getSelectedItem().toString()};
String id = String.valueOf(table_user.getValueAt(table_user.getSelectedRow(),0));
System.out.println(db.queryUpdate("utilisateur", colon, inf,"id'" + id + "'"));
table();
actualiser();
}
}//GEN-LAST:event_ModifBTActionPerformed
private void RechBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RechBTActionPerformed
if(txt_rech.getText().equals(""))//si le textfield de recherche est vide le programe il va affiche "SVP entrer quelque chose
{
JOptionPane.showConfirmDialog(this, "SVP entrer quelque chose");
} else{
if(com_rech.getSelectedItem().equals("id_user")){
rs = db.querySelectAll("utilisateur", "id_user LIKE'%" + txt_rech.getText() + "%'");
table_user.setModel(new ResultSetTableModel(rs));
}else if(com_rech.getSelectedItem().equals("userneme")){
rs = db.querySelectAll("utilisateur","username LIKE '%" + txt_rech.getText() + "%'");
table_user.setModel(new ResultSetTableModel(rs));
}else if(com_rech.getSelectedItem().equals("password")){
rs = db.querySelectAll("utilisateur","password LIKE '%" + txt_rech.getText() + "%'");
table_user.setModel(new ResultSetTableModel(rs));
}else if(com_rech.getSelectedItem().equals("type")){
rs = db.querySelectAll("utilisateur","type LIKE'%" + txt_rech.getText() + "%'");
table_user.setModel(new ResultSetTableModel(rs));
}
}
}//GEN-LAST:event_RechBTActionPerformed
private void AjouBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AjouBTActionPerformed
if(txt_id.getText().equals("")|| txt_us.getText().equals("")|| txt_pa.getText().equals("")|| com_ty.getSelectedItem().equals("Type")){
JOptionPane.showMessageDialog(this,"SVP entrer les informations complete");
}else{
String[] colon = {"id_user","username","password","type"};
String[] inf = {txt_id.getText(),txt_us.getText(),txt_pa.getText(),com_ty.getSelectedItem().toString()};
System.out.println(db.queryInsert("utilisateur", colon, inf));
table();
actualiser();
}
}//GEN-LAST:event_AjouBTActionPerformed
private void SupprBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupprBTActionPerformed
String id = String.valueOf(table_user.getValueAt(table_user.getSelectedRow(), 0));
if(JOptionPane.showConfirmDialog(this,"est ce que vous ĂȘtes sure que vous voulez supprimer","Attention !!!",JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
db.queryDelete("utilisateur","id="+ id);
}else{
return;
}
table();
}//GEN-LAST:event_SupprBTActionPerformed
private void txt_rechActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_rechActionPerformed
}//GEN-LAST:event_txt_rechActionPerformed
private void txt_usActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_usActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txt_usActionPerformed
private void txt_idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_idActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txt_idActionPerformed
private void ActuBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ActuBTActionPerformed
actualiser();
table();
}//GEN-LAST:event_ActuBTActionPerformed
private void txt_paActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_paActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txt_paActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Utilisateur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Utilisateur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Utilisateur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Utilisateur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Utilisateur().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ActuBT;
private javax.swing.JButton AjouBT;
private javax.swing.JLabel IdjLabel;
private javax.swing.JButton ModifBT;
private javax.swing.JLabel PassjLabel;
private javax.swing.JButton RechBT;
private javax.swing.JLabel RechjLabel;
private javax.swing.JButton SupprBT;
private javax.swing.JLabel TypjLabel;
private javax.swing.JLabel UTILISATEURjLabel;
private javax.swing.JLabel UserjLabel2;
private javax.swing.JComboBox com_rech;
private javax.swing.JComboBox com_ty;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table_user;
private javax.swing.JTextField txt_id;
private javax.swing.JTextField txt_pa;
private javax.swing.JTextField txt_rech;
private javax.swing.JTextField txt_us;
// End of variables declaration//GEN-END:variables
}