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
| final JPanel AjoutP = new JPanel();
JLabel titreAjoutP = new JLabel("Ajouter Produit");
JLabel Ajout1=new JLabel("");
Ajout1.setIcon(new ImageIcon("C:\\Users\\UTILISATEUR\\Desktop\\image.jpg"));
Ajout1.add(titreAjoutP);
JLabel jL3 =new JLabel("Veuillez remplir les champs ci-dessous :");
jL3.setBounds(300, 0,700, 100);
jL3.setFont(f0);
Ajout1.add(jL3);
JLabel d = new JLabel("Description ");
d.setFont(f3);
d.setBounds(350,120, 150, 30);
Ajout1.add(d);
final JTextField t = new JTextField("");
t.setBounds(500, 120, 150, 30);
Ajout1.add(t);
JLabel Lib0 = new JLabel("Quantité");
Lib0.setFont(f3);
Lib0.setBounds(350, 200, 150, 30);
Ajout1.add(Lib0);
final JTextField tx2 = new JTextField("");
tx2.setBounds(500, 200, 150, 30);
Ajout1.add(tx2);
JLabel pr = new JLabel("Prix Unitaire");
pr.setBounds(350, 280, 150, 30);
pr.setFont(f3);
Ajout1.add(pr);
final JTextField tx3 = new JTextField("");
Ajout1.add(tx3);
tx3.setBounds(500, 280, 150, 30);
JLabel et = new JLabel("Etat");
et.setBounds(350, 360, 150, 30);
et.setFont(f3);
Ajout1.add(et);
String[] tab = {"","Semi-fini", "Fini"};
final JComboBox combo = new JComboBox (tab);
combo.setFont(f3);
combo.setBounds(500, 360, 150, 30);
Ajout1.add(combo);
JButton bt21 = new JButton("Consulter");
bt21.setBounds(440, 440, 110,35);
bt21.setFont(f3);
Ajout1.add(bt21);
bt21.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent event)
{
JScrollPane js=new JScrollPane();;
JTable jt = new JTable();
DefaultTableModel mod= new DefaultTableModel() {
@Override
public int getColumnCount() {
return 5;
}
@Override
public String getColumnName(int column) {
switch (column) {
case 0:
return "ID_Produit";
case 1:
return "Description";
case 2:
return "Quantité";
case 3:
return "Prix_Unitaire";
case 4:
return "Etat";
default:
return "Unknown";
}
}
};
JFrame jf2 = new JFrame("Stock de produits");
jt.setModel(mod);
jf2.setSize(600, 400);
jf2.setResizable(false);
jf2.add(js);
js.setViewportView(jt);
jf2.setVisible(true);
jf2.setLocation(730, 150);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bd_gl","root","");
ResultSet rs = null;
java.sql.PreparedStatement st = con.prepareStatement("SELECT * FROM produits");
rs = st.executeQuery();
while (rs.next())
{mod.addRow(new Object[]{rs.getString(1), rs.getString(2), rs.getString(3),rs.getString(4),rs.getString(5)}); }
rs.close();
st.close();
con.close();
}
catch (SQLException e) {}
catch (ClassNotFoundException e)
{ // TODO Auto-generated catch block
e.printStackTrace();
}
}
});
JButton btn2 = new JButton("Enregistrer");
btn2.setFont(f3);
btn2.setBounds(690, 440, 130, 35);
Ajout1.add(btn2);
btn2.addActionListener(new ActionListener ()
{
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent event)
{
if(t.getText().isEmpty() || tx2.getText().isEmpty() || tx3.getText().isEmpty() || combo.getSelectedItem().toString().isEmpty() )
{String info = "Vous devez remplir tous les champs !";
javax.swing.JOptionPane.showMessageDialog(null,info);
}
else{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bd_gl","root","");
java.sql.PreparedStatement pst = con.prepareStatement("INSERT INTO produits VALUES (default,?,?,?,?) ");
pst.setString(1, t.getText());
pst.setString(2, tx2.getText());
pst.setString(3, tx3.getText());
pst.setString(4, combo.getSelectedItem().toString());
pst.executeUpdate();
}
catch (SQLException e) {}
catch (ClassNotFoundException e)
{ // TODO Auto-generated catch block
e.printStackTrace();
}
javax.swing.JOptionPane.showMessageDialog(null,"Produit ajouté");
t.setText(null);
tx2.setText(null);
tx3.setText(null);
combo.setSelectedItem("");
}
}
});
JButton b31 = new JButton("Annuler");
b31.setFont(f3);
b31.setBounds(200, 440, 100, 35);
Ajout1.add(b31);
b31.addActionListener(new ActionListener ()
{
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent event)
{
t.setText(null);
tx2.setText(null);
tx3.setText(null);
combo.setSelectedItem("");
}});
AjoutP.add(Ajout1);
onglets.addTab("Ajouter Produit", AjoutP ); |
Partager