package sgcpi;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.Object;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.swing.table.DefaultTableModel;
class JFC extends JFrame {
JTabbedPane onglets;
JPanel onglet1;
JPanel onglet2;
JButton AJOUTER,SUPPRIMER,Modifier,FERMER,ARCHIVE,SAVE;
JLabel CompteL,CompteL1,CompteL2,NomL,PrenomL,AdresseL,Type_ConsL;
JTextField NomTF,PrenomTF,AdresseTF,Type_ConsTF;
JTable table=new JTable();
JTable table1=new JTable();
JScrollPane sp=new JScrollPane();
JScrollPane sp1=new JScrollPane();
private Iterable<Object> IDds;
@SuppressWarnings("static-access")
JFC() {
onglets = new JTabbedPane();
onglet1 = new JPanel();
onglet1.setBackground(new Color(217, 233, 238));
AJOUTER=new JButton("AJOUTER");
AJOUTER= new JButton(new ImageIcon("/home/anoir/Bureau/icone/Mashup-MaXo/actions/add.png"));
onglet1.add(AJOUTER);
onglet1.setLayout(null);
AJOUTER.setBounds(5,560,100,90);
AJOUTER.setForeground(new Color(0,0,0));
AJOUTER.setBorderPainted(false);
AJOUTER.setContentAreaFilled(false);
AJOUTER.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
AJOUTER();
}
});
SUPPRIMER=new JButton("SUPPRIMER");///media/doc/etude/icone/Mashup-MaXo/actions/add.png
SUPPRIMER= new JButton(new ImageIcon("/home/anoir/Bureau/icone/Mashup-MaXo/actions/dialog-cancel.png"));
onglet1.add(SUPPRIMER);
onglet1.setLayout(null);
SUPPRIMER.setBounds(230,560,100,90);
SUPPRIMER.setForeground(new Color(0,0,0));
SUPPRIMER.setBorderPainted(false);
SUPPRIMER.setContentAreaFilled(false);
Modifier=new JButton(new ImageIcon("/home/anoir/Bureau/icone/Mashup-MaXo/actions/gtk-edit.png"));
onglet1.add(Modifier);
onglet1.setLayout(null);
Modifier.setBounds(460,560,100,90);
Modifier.setForeground(new Color(0,0,0));
Modifier.setBorderPainted(false);
Modifier.setContentAreaFilled(false);
FERMER=new JButton(new ImageIcon("/home/anoir/Bureau/icone/Mashup-MaXo/actions/system-suspend-hibernate.png"));
onglet1.add(FERMER);
onglet1.setLayout(null);
FERMER.setBounds(640,560,100,90);
FERMER.setForeground(new Color(0,0,0));
FERMER.setBorderPainted(false);
FERMER.setContentAreaFilled(false);
FERMER.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
CompteL=new JLabel("GESTIONS DES INFIRMIER");
onglet1.add(CompteL);
onglet1.setLayout(null);
CompteL.setBounds(10,15, 700,120);
CompteL.setForeground(new Color(71,129,172));
//CompteL.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
CompteL.setIcon(new javax.swing.ImageIcon("/home/anoir/Bureau/icone/professional-icons/gwil40130.jpg"));
CompteL.setFont(new Font("Monotype Corsiva",Font.BOLD,30));
NomL=new JLabel("Nom :");
onglet1.add(NomL);
onglet1.setLayout(null);
NomL.setFont(new Font("Monotype Corsiva",Font.BOLD,20));
NomL.setForeground(new Color(51,129,172));
NomL.setBounds(10,140, 100, 30);
PrenomL=new JLabel("PRENOM :");
onglet1.add(PrenomL);
onglet1.setLayout(null);
PrenomL.setFont(new Font("Monotype Corsiva",Font.BOLD,20));
PrenomL.setForeground(new Color(51,129,172));
PrenomL.setBounds(10,155, 200, 90);
AdresseL=new JLabel("ADRESSE :");
onglet1.add(AdresseL);
onglet1.setLayout(null);
AdresseL.setFont(new Font("Monotype Corsiva",Font.BOLD,20));
AdresseL.setForeground(new Color(51,129,172));
AdresseL.setBounds(330,110, 200, 90);
Type_ConsL=new JLabel("Type_Consult:");
onglet1.add(Type_ConsL);
onglet1.setLayout(null);
Type_ConsL.setFont(new Font("Monotype Corsiva",Font.BOLD,20));
Type_ConsL.setForeground(new Color(51,129,172));
Type_ConsL.setBounds(330,155, 200, 90);
NomTF=new JTextField();
NomTF.setBounds(135,140, 180, 27);
NomTF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
NomTF.requestFocus();
PrenomTF=new JTextField();
PrenomTF.setBounds(135, 185, 180, 27);
PrenomTF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
AdresseTF=new JTextField();
AdresseTF.setBounds(480, 140, 180, 27);
AdresseTF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
Type_ConsTF=new JTextField();
Type_ConsTF.setBounds(480, 185, 180, 27);
Type_ConsTF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
onglet1.add(NomTF);
onglet1.add(PrenomTF);
onglet1.add(AdresseTF);
onglet1.add(Type_ConsTF);
table.setAutoCreateRowSorter(true); //trier la table
table.setModel(new javax.swing.table.DefaultTableModel(new Object [][] { },new String [] {"IDCons", "NOM","PRENOM","Adresse","Type_Cons"}));
table.getColumnModel().getColumn(0).setPreferredWidth(50);
table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setPreferredWidth(100);
table.getColumnModel().getColumn(3).setPreferredWidth(100);
table.getColumnModel().getColumn(4).setPreferredWidth(100);
table.getTableHeader().setFont(new Font("Times New Roman",Font.BOLD,17));
table.getTableHeader().setReorderingAllowed(false);
table.setRowHeight(22);
table.setFont(new Font("Times New Roman",Font.BOLD,14));
table.setOpaque(false);
table.setForeground(new Color(33,53,105));
sp.setViewportView(table);
sp.setBounds(3,270,710,300);
sp.setOpaque(false);
onglet1.setLayout(null);
onglet1.add(sp);
onglet2 = new JPanel();
onglet2.setBackground(new Color(171, 233, 198));
CompteL1=new JLabel("GESTIONS DES COMPTES");
onglet2.add(CompteL1);
onglet2.setLayout(null);
CompteL1.setBounds(10,15, 700,120);
CompteL1.setForeground(new Color(71,129,172));
//CompteL1.setIcon(new javax.swing.ImageIcon("/media/doc/etude/icone/professional-icons/gwil40102.jpg"));
CompteL1.setFont(new Font("Monotype Corsiva",Font.BOLD,30));
AJOUTER=new JButton("AJOUTER");
AJOUTER= new JButton(new ImageIcon("/home/anoir/Bureau/icone/Mashup-MaXo/actions/add.png"));
onglet2.add(AJOUTER);
onglet2.setLayout(null);
AJOUTER.setBounds(10,60,100,90);
AJOUTER.setForeground(new Color(0,0,0));
AJOUTER.setBorderPainted(false);
AJOUTER.setContentAreaFilled(false);
onglets.addTab("GESTION DES COMPTES",onglet1);
//AJOUTER.setBounds(100,200,300,40);
onglets.addTab("MODIFICATION DE MOT DE PASSE",new ImageIcon(""),onglet2);
getContentPane().add(onglets);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(750,700);
setLocationRelativeTo(null); //pour centrer la fenetre
setResizable(false);
}
public static void main(String[] args) {
JFrame fen =new JFC();
fen.setVisible(true);
}
void AJOUTER(){
String erreur="";
if(NomTF.getText().isEmpty())
erreur+="Nom est vide !\n";
else
if(NomTF.getText().length()>25)
erreur+="Nom est déppassé 25 caractères !\n";
if(PrenomTF.getText().isEmpty())
erreur+="Prénom est vide !\n";
else
if(PrenomTF.getText().length()>25)
erreur+="Prénom est déppassè 25 caractères !";
if(AdresseTF.getText().isEmpty())
erreur+="Mot de passe est vide !\n";
else
if(AdresseTF.getText().length()>25)
erreur+="Mot de passe est déppassé 25 caractères !";
else
if(Type_ConsTF.getText().length()>25)
erreur+="Mot de passe est déppassé 25 caractères !";
if(erreur.isEmpty()){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpaPU");
EntityManager em = emf.createEntityManager();
EntityTransaction transac = em.getTransaction();
transac.begin();
Consultant nouvelleInfermier = new Consultant();
nouvelleInfermier.setIDCons(null);
nouvelleInfermier.setNom(NomTF.getText());
nouvelleInfermier.setPrenom(PrenomTF.getText());
nouvelleInfermier.setAdresse(AdresseTF.getText());
nouvelleInfermier.setTypeCons(Type_ConsTF.getText());
em.persist(nouvelleInfermier);
transac.commit();
em.close();
emf.close();
NomTF.setText("");
PrenomTF.setText("");
AdresseTF.setText("");
Type_ConsTF.setText("");
Filtrage1();
}else
JOptionPane.showMessageDialog(this,erreur,"Erreur ...",JOptionPane.ERROR_MESSAGE);
}
void Filtrage1(){
while(table.getRowCount()>0){
((DefaultTableModel)table.getModel()).removeRow(0);
}
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpaPU");
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT c FROM Consultant c WHERE c.nom like :nom and c.prenom like :prenom and c.adresse like :adresse and c.typeCons like :typeCons order by c.ID_Cons" );
query.setParameter("nom", NomTF.getText()+"%");
query.setParameter("prenom", PrenomTF.getText()+"%");
query.setParameter("nom",AdresseTF.getText()+"%");
query.setParameter("prenom", Type_ConsTF.getText()+"%");
java.util.List noms = query.getResultList();
Consultant c=null;
for (Object nom : noms) {
c=(Consultant)nom;
Object[] donnee = new Object[]{c.getIDCons(),c.getNom(),c.getPrenom(),c.getAdresse(),c.getTypeCons()};
((DefaultTableModel)table.getModel()).addRow(donnee);
}
em.close();
emf.close();
}
}
Partager