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
| package v1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.GregorianCalendar;
import javax.swing.*;
public class FormulaireAjout extends JFrame {
private FenetrePrincipale fen;
private JLabel labIDInstal, labDateInst, labCom, labDuree, labRefProc, labCodeSoft, labRespRes, labCodeOS, labProf;
private JTextField jtfIDInstal, jtfDateInst, jtfCom, jtfDuree, jtfRefProc;
private JPanel jpForm, jpBut;
private JButton butok, butreset, butRet;
private JComboBox<String> jcbCodeOS, jcbSoft, jcbRespRes, jcbProf;
Object[] tabRespres, tabProf, tabCodeOS, tabCodeSoft;
private Container cont;
public FormulaireAjout(FenetrePrincipale f) {
super("Ajout");
try {
this.fen = f;
this.setBounds(0, 0, 700, 500);
this.setLocationRelativeTo(null);
jpBut = new JPanel();
jpBut.setLayout(new FlowLayout());
jpForm = new JPanel();
jpForm.setLayout(new GridLayout());
labIDInstal = new JLabel("ID Instal :");
labIDInstal.setHorizontalAlignment(SwingConstants.RIGHT);
labDateInst = new JLabel("date instal (AAAAMMJJ) :");
labDateInst.setHorizontalAlignment(SwingConstants.RIGHT);
labCom = new JLabel("Commentaire :");
labCom.setHorizontalAlignment(SwingConstants.RIGHT);
labDuree = new JLabel("Durée (min) :");
labDuree.setHorizontalAlignment(SwingConstants.RIGHT);
labRefProc = new JLabel("Reférence de la procédure :");
labRefProc.setHorizontalAlignment(SwingConstants.RIGHT);
labCodeSoft = new JLabel("Code Software :");
labCodeSoft.setHorizontalAlignment(SwingConstants.RIGHT);
labRespRes = new JLabel("Responsable réseau :");
labRespRes.setHorizontalAlignment(SwingConstants.RIGHT);
labProf = new JLabel("professeur :");
labProf.setHorizontalAlignment(SwingConstants.RIGHT);
labCodeOS = new JLabel("Code OS :");
labCodeOS.setHorizontalAlignment(SwingConstants.RIGHT);
jtfIDInstal = new JTextField(10);
ActForm aLForm = new ActForm();
jtfIDInstal.addActionListener(aLForm);
jtfDateInst = new JTextField(8);
jtfCom = new JTextField(50);
jtfDuree = new JTextField(4);
jtfRefProc = new JTextField(10);
butok = new JButton("Ok");
butreset = new JButton("Reset");
butRet = new JButton("Retour");
butreset.addActionListener(aLForm);
butok.addActionListener(aLForm);
butRet.addActionListener(aLForm);
jpBut.add(butRet);
jpBut.add(butreset);
jpBut.add(butok);
cont = getContentPane();
cont.setLayout(new BorderLayout());
cont.add(jpForm, BorderLayout.NORTH);
cont.add(jpBut, BorderLayout.SOUTH);
String sqlInstr;
sqlInstr = "select Matricule from responsableReseaux order by Matricule ";
PreparedStatement psRespres = fen.getMaConnexion().prepareStatement(sqlInstr);
tabRespres = AccessBDGen.creerListe1Colonne(psRespres);
sqlInstr = "select NomPrenom from responsableReseaux order by NomPrenom ";
PreparedStatement psRespResNom = fen.getMaConnexion().prepareStatement(sqlInstr);
Object[] tabRespResNom = AccessBDGen.creerListe1Colonne(psRespResNom);
sqlInstr = "select CodeProf from Professeur order by CodeProf ";
PreparedStatement psProf = fen.getMaConnexion().prepareStatement(sqlInstr);
tabProf = AccessBDGen.creerListe1Colonne(psProf);
sqlInstr = "select NomPrenom from Professeur order by NomPrenom";
PreparedStatement psProfNom = fen.getMaConnexion().prepareStatement(sqlInstr);
Object[] tabProfNom = AccessBDGen.creerListe1Colonne(psProfNom);
sqlInstr = "select CodeSoftware from Software order by CodeSoftware";
PreparedStatement psCodeSoftware = fen.getMaConnexion().prepareStatement(sqlInstr);
tabCodeSoft = AccessBDGen.creerListe1Colonne(psCodeSoftware);
sqlInstr = "select Nom from Software order by CodeSoftware";
PreparedStatement psNomCodeSoftware = fen.getMaConnexion().prepareStatement(sqlInstr);
Object[] TabNomCodeSoftware = AccessBDGen.creerListe1Colonne(psNomCodeSoftware);
sqlInstr = "select CodeOS from Os order by CodeOS";
PreparedStatement psCodeOS = fen.getMaConnexion().prepareStatement(sqlInstr);
tabCodeOS = AccessBDGen.creerListe1Colonne(psCodeOS);
sqlInstr = "select Libelle from Os order by CodeOS";
PreparedStatement psNomCodeOS = fen.getMaConnexion().prepareStatement(sqlInstr);
Object[] TabNomCodeOS = AccessBDGen.creerListe1Colonne(psNomCodeOS);
jcbCodeOS = new JComboBox(tabCodeOS);
jcbSoft = new JComboBox(tabCodeSoft);
jcbRespRes = new JComboBox(tabRespres);
jcbProf = new JComboBox(tabProf);
jpForm.add(labIDInstal);
jpForm.add(jtfIDInstal);
jpForm.add(labCodeSoft);
jpForm.add(jcbSoft);
jpForm.add(labCodeOS);
jpForm.add(jcbCodeOS);
jpForm.add(labDateInst);
jpForm.add(jtfDateInst);
jpForm.add(labDuree);
jpForm.add(jtfDuree);
jpForm.add(labRespRes);
jpForm.add(jcbRespRes);
jpForm.add(labProf);
jpForm.add(jcbProf);
jpForm.add(labRefProc);
jpForm.add(jtfRefProc);
jpForm.add(labCom);
jpForm.add(jtfCom);
this.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
private class ActForm implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == butreset) {
jtfIDInstal.setText("");
jtfDateInst.setText("");
jtfDuree.setText("");
jtfRefProc.setText("");
jtfCom.setText("");
}
if (e.getSource() == butRet) {
fen.getCont().removeAll();
PanneauAccueil panAcc = new PanneauAccueil(fen);
fen.getCont().add(panAcc);
fen.getCont().repaint();
fen.getCont().setVisible(true);
}
if (e.getSource() == butok) {
String date = jtfDateInst.getText();
try {
if (date.length() != 8)
throw new ExceptionDate(date);
String an = date.substring(0, 4);
String mo = date.substring(4, 6);
String jo = date.substring(6, 8);
int j = Integer.parseInt(jo);
int m = Integer.parseInt(mo);
int a = Integer.parseInt(an);
String sqlInstruction = "insert into installation(IdInstallation,DateInstallation,"
+ "Commentaires,DureeInstallation,RefProcedureInstallation,"
+ "CodeSoftware,Matricule,CodeOs) values (?,?,?,?,?,?,?,?)";
PreparedStatement myPrepStat = fen.getMaConnexion().prepareStatement(sqlInstruction);
if (jtfIDInstal.getText().equals("") == false)
myPrepStat.setInt(1, Integer.parseInt(jtfIDInstal.getText()));
else {
throw new ExceptionChampVide("IdInstallation");
}
myPrepStat.setDate(2, new java.sql.Date(new GregorianCalendar(a, m - 1, j).getTimeInMillis()));
if (jtfCom.getText().equals("") == false)
myPrepStat.setString(3, jtfCom.getText());
else
myPrepStat.setNull(3, Types.VARCHAR);
if (jtfDuree.getText().equals("") == false)
myPrepStat.setInt(4, Integer.parseInt(jtfDuree.getText()));
else
myPrepStat.setNull(4, Types.SMALLINT);
if (jtfRefProc.getText().equals("") == false)
myPrepStat.setString(5, jtfRefProc.getText());
else
myPrepStat.setNull(5, Types.VARCHAR);
String codeOS = (String) tabCodeOS[jcbCodeOS.getSelectedIndex()];
myPrepStat.setString(8, codeOS);
String codeSoft = (String) tabCodeSoft[jcbSoft.getSelectedIndex()];
myPrepStat.setString(8, codeSoft);
String RespRes = (String) tabRespres[jcbRespRes.getSelectedIndex()];
myPrepStat.setString(16, RespRes);
String Prof = (String) tabProf[jcbProf.getSelectedIndex()];
myPrepStat.setString(16, Prof);
}
catch (ExceptionChampVide e3) {
JOptionPane.showMessageDialog(null, e3, "Le champs est vide", JOptionPane.ERROR_MESSAGE);
}
catch (NumberFormatException e4) {
JOptionPane.showMessageDialog(null, e4.getMessage(), "Le numéro est incorrect",
JOptionPane.ERROR_MESSAGE);
}
catch (ExceptionDate e1) {
JOptionPane.showMessageDialog(null, e1, "La date est incorrecte", JOptionPane.ERROR_MESSAGE);
}
catch (Exception e2) {
JOptionPane.showMessageDialog(null, e2.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
}
}
} |
Partager