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
| import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.event.ListSelectionListener;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.UIManager;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JList;
import java.awt.List;
import javax.swing.AbstractListModel;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
public class Fornisseur extends JFrame {
private JPanel contentPane;
final JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
private JTextField textField_6;
private JTextField textField_7;
private JTextField textField_8;
private JTextField textField_9;
private JTextField textField_10;
private JTextField textField_11;
private ResultSet rs= null;
Connection con = null;
Statement stmt=null;
List list_1 =new List();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Fornisseur frame = new Fornisseur();
frame.setVisible(true);
frame.setTitle("Gestion des Fournisseurs");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Fornisseur() {
try
{
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e)
{}
try {
con=DriverManager.getConnection("jdbc:mysql://localhost/laboratoire","root","");
} catch(SQLException e) { }
executeRequest() ;
select();
/** menu bar **/
JMenuBar br=new JMenuBar();
JMenu a=new JMenu("Fournisseur");
JMenu c=new JMenu("Actions");
JMenuItem nouveau=new JMenuItem("nouveau fournisseur");
JMenuItem Quitter=new JMenuItem("Quitter");
JMenuItem commander =new JMenuItem("commander");
a.add(nouveau);
a.addSeparator();
a.add(Quitter);
c.add(commander);
br.add(a);
br.add(c);
this.setJMenuBar(br);
commander.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
Commander fram = new Commander();
fram.setVisible(true);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 819, 665);
contentPane = new JPanel();
contentPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
contentPane.setLayout(null);
setContentPane(contentPane);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBorder(UIManager.getBorder("DesktopIcon.border"));
panel.setBounds(20, 31, 723, 67);
contentPane.add(panel);
JPanel panel_1 = new JPanel();
panel_1.setLayout(null);
panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
panel_1.setBounds(10, 98, 419, 482);
contentPane.add(panel_1);
JLabel Fournisseur = new JLabel("Fournisseur :");
Fournisseur.setFont(new Font("Vani", Font.BOLD, 12));
Fournisseur.setBounds(23, 25, 96, 14);
panel_1.add(Fournisseur);
JLabel Adresse = new JLabel("Responsable :");
Adresse.setFont(new Font("Vani", Font.BOLD, 12));
Adresse.setBounds(26, 62, 96, 14);
panel_1.add(Adresse);
JLabel Ville = new JLabel("Domaine : ");
Ville.setFont(new Font("Vani", Font.BOLD, 12));
Ville.setBounds(26, 103, 93, 14);
panel_1.add(Ville);
JLabel lblCodePostal = new JLabel("Code Postal :");
lblCodePostal.setFont(new Font("Vani", Font.BOLD, 12));
lblCodePostal.setBounds(23, 192, 109, 14);
panel_1.add(lblCodePostal);
JLabel lblResponsable = new JLabel("Adresse:");
lblResponsable.setFont(new Font("Vani", Font.BOLD, 12));
lblResponsable.setBounds(23, 145, 109, 14);
panel_1.add(lblResponsable);
JLabel lblTel = new JLabel("Tel :");
lblTel.setFont(new Font("Vani", Font.BOLD, 12));
lblTel.setBounds(23, 329, 56, 14);
panel_1.add(lblTel);
JLabel lblFax = new JLabel("Fax :");
lblFax.setFont(new Font("Vani", Font.BOLD, 12));
lblFax.setBounds(246, 329, 46, 14);
panel_1.add(lblFax);
JLabel lblNTva = new JLabel("N TVA :");
lblNTva.setFont(new Font("Vani", Font.BOLD, 12));
lblNTva.setBounds(23, 369, 46, 14);
panel_1.add(lblNTva);
JLabel lblRferance = new JLabel("R\u00E9ference :");
lblRferance.setFont(new Font("Vani", Font.BOLD, 12));
lblRferance.setBounds(26, 456, 96, 14);
panel_1.add(lblRferance);
textField = new JTextField();
textField.setBounds(128, 20, 216, 20);
panel_1.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(127, 62, 217, 20);
panel_1.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setBounds(128, 98, 216, 20);
panel_1.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setBounds(128, 140, 216, 20);
panel_1.add(textField_3);
textField_3.setColumns(10);
textField_4 = new JTextField();
textField_4.setBounds(128, 187, 216, 20);
panel_1.add(textField_4);
textField_4.setColumns(10);
textField_5 = new JTextField();
textField_5.setBounds(222, 226, 217, 20);
panel_1.add(textField_5);
textField_5.setColumns(10);
textField_6 = new JTextField();
textField_6.setBounds(127, 277, 217, 20);
panel_1.add(textField_6);
textField_6.setColumns(10);
textField_7 = new JTextField();
textField_7.setBounds(127, 324, 109, 20);
panel_1.add(textField_7);
textField_7.setColumns(10);
textField_8 = new JTextField();
textField_8.setBounds(294, 324, 115, 20);
panel_1.add(textField_8);
textField_8.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("Ville :");
lblNewLabel_2.setFont(new Font("Vani", Font.BOLD, 12));
lblNewLabel_2.setBounds(23, 231, 46, 14);
panel_1.add(lblNewLabel_2);
textField_9 = new JTextField();
textField_9.setBounds(128, 364, 216, 20);
panel_1.add(textField_9);
textField_9.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("Pays :");
lblNewLabel_3.setFont(new Font("Vani", Font.BOLD, 12));
lblNewLabel_3.setBounds(23, 282, 46, 14);
panel_1.add(lblNewLabel_3);
textField_10 = new JTextField();
textField_10.setBounds(127, 402, 217, 20);
panel_1.add(textField_10);
textField_10.setColumns(10);
textField_11 = new JTextField();
textField_11.setBounds(128, 451, 216, 20);
panel_1.add(textField_11);
textField_11.setColumns(10);
JLabel lblEmail = new JLabel("EMail :");
lblEmail.setFont(new Font("Vani", Font.BOLD, 12));
lblEmail.setBounds(23, 405, 46, 14);
panel_1.add(lblEmail);
JPanel panel_2 = new JPanel();
panel_2.setLayout(null);
panel_2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
panel_2.setBounds(456, 121, 322, 473);
contentPane.add(panel_2);
/** ajouter uen liste **/
list_1.setMultipleSelections(false);
list_1.setBounds(45, 56, 213, 292);
panel_2.add(list_1);
list_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("l'element selectionné est:" +list_1.getSelectedItem());
}
});
JButton btnNewButton = new JButton("nouveau\r\n");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField_11.setText("");
textField.setText("");
textField_1.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField_5.setText("");
textField_6.setText("");
textField_7.setText("");
textField_8.setText("");
textField_9.setText("");
textField_10.setText("");
}
});
btnNewButton.setBounds(10, 33, 89, 23);
panel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("Supprimer");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
supprimer();
}
});
btnNewButton_1.setBounds(206, 33, 89, 23);
panel.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("Editer");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
editer();
}
});
btnNewButton_2.setBounds(305, 33, 89, 23);
panel.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("Enregistrer");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String a=textField.getText();
list_1.add(a);
insert();
}
});
btnNewButton_3.setBounds(107, 33, 89, 23);
panel.add(btnNewButton_3);
JButton btnNewButton_4 = new JButton("New button");
btnNewButton_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btnNewButton_4.setBounds(472, 33, 89, 23);
panel.add(btnNewButton_4);
JLabel lblNewLabel = new JLabel("Liste Fournisseur");
lblNewLabel.setBackground(Color.PINK);
lblNewLabel.setFont(new Font("Vani", Font.BOLD, 12));
lblNewLabel.setToolTipText("");
lblNewLabel.setBounds(20, 11, 143, 28);
panel_2.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Info");
lblNewLabel_1.setFont(new Font("Vani", Font.BOLD, 12));
lblNewLabel_1.setBounds(200, 16, 71, 14);
panel_2.add(lblNewLabel_1);
JLabel lblDossier = new JLabel("Donn\u00E9es");
lblDossier.setFont(new Font("Vani", Font.BOLD, 13));
lblDossier.setBounds(165, 98, 86, 25);
contentPane.add(lblDossier);
}
/** la methode select **/
public ResultSet executeRequest()
{
try {
stmt=con.createStatement();
String req="select * from fournisseur ; ";
rs=stmt.executeQuery(req);
} catch (SQLException ee)
{
ee.printStackTrace();
}
return rs;
}
/** afficher la liste des fournisseurs **/
public void select()
{
try {
while(rs.next())
{
list_1.add(rs.getString(2));
}
} catch (SQLException e2)
{
e2.printStackTrace();
}
}
/** nouveau fournisseur **/
public void insert()
{
try
{
stmt=con.createStatement();
String req = "INSERT INTO fournisseur (ID_fournisseur,nomFourn,responsable,domaineFourn,rue,codePostal,ville,pays,telFourn,fax,tva,eMail) VALUES ('"+textField_11.getText()+"','"+textField.getText()+"','"+textField_1.getText()+"','"+textField_2.getText()+"','"+textField_3.getText()+"','"+textField_4.getText()+"','"+textField_5.getText()+"','"+textField_6.getText()+"','"+textField_7.getText()+"','"+textField_8.getText()+"','"+textField_9.getText()+"','"+textField_10.getText()+"')";
int nbMaj = stmt.executeUpdate ( req ) ;
//con.close();
}catch (Exception em)
{
System.out.println("ERROR :"+em.getMessage());
}
textField_11.setText("");
textField.setText("");
textField_1.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField_5.setText("");
textField_6.setText("");
textField_7.setText("");
textField_8.setText("");
textField_9.setText("");
textField_10.setText("");
}
/** supprimer fournisseur **/
public void supprimer()
{
int t = list_1.getSelectedIndex();
String text = list_1.getItem(t);
try
{
String req ="DELETE FROM fournisseur WHERE nomFourn='"+text+"'";
int nbMaj =stmt.executeUpdate(req);
con.close();
}catch (Exception el)
{
System.out.println("ERROR :"+el.getMessage());
}
list_1.remove(t);
}
/** Editer fournisseur **/
public void editer()
{
String text = new String( );
int i = list_1.getSelectedIndex();
text = list_1.getItem(i);
try {
stmt=con.createStatement();
String req="select * from fournisseur where nomFourn='"+text+"'";
ResultSet res=stmt.executeQuery(req);
while (res.next())
{
textField_11.setText(res.getString(1));
textField.setText(res.getString(2));
textField_1.setText(res.getString(3));
textField_2.setText(res.getString(4));
textField_3.setText(res.getString(5));
textField_4.setText(res.getString(6));
textField_5.setText(res.getString(7));
textField_6.setText(res.getString(8));
textField_7.setText(res.getString(9));
textField_8.setText(res.getString(10));
textField_9.setText(res.getString(11));
textField_10.setText(res.getString(12));
}
}catch (Exception el)
{
System.out.println("ERROR :"+el.getMessage());
}
}
public String getListe()
{
String texte=list_1.getSelectedItem();
return texte;
}
} |
Partager