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
| public class MyDefaultCellEditor extends DefaultCellEditor implements FocusListener, KeyListener {
// actionHandler = new CellEditorActionHandler();
public MyDefaultCellEditor(JTextField textField) {
super(textField);
setClickCountToStart(0);
editorComponent = textField;
editorComponent.setBorder(null);
editorComponent.addFocusListener(this);
}
public void focusGained(FocusEvent e) {
ligne = table.getSelectedRow();
colo = table.getSelectedColumn();
}
public void focusLost(FocusEvent e) {
pane= new JOptionPane();
String temp = table.getValueAt(ligne, colo).toString();
int etat = 0;
String quantite, Prix;
//GESTION DE LA COLONNE SAISIE NUM ARTICLE
if(table.getSelectedColumn()==0){
if (temp.length() != 0) {
int temp2 = Integer.parseInt(temp);
for (int i = 0; i < liste.size(); i++) {
if (temp2 == liste.get(i)) {
pane.showMessageDialog(null, "Cet article a déjà été saisi","Avertissement",pane.WARNING_MESSAGE);
table.setValueAt("", ligne, 0);
etat = 1;
}
}
if (etat == 0) {
liste.add(temp2);
for (int i = 0; i < arts.getArticle().size(); i++) {
if (temp2 == arts.getArticle().get(i).getNumArt()
&& arts.getArticle().get(i).getQuantiteArt()!=0) {
num=i;
int nbArt=arts.getArticle().get(i).getQuantiteArt();
int trouve=0;
for(int etatArt=0; etatArt<nbArt; etatArt++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt)==1 && trouve==0 ){
int choix = pane.showConfirmDialog(null, "Il existe un article réservé.\nVoulez-vous le vendre maintenant?",
"Article Reservé", JOptionPane.WARNING_MESSAGE);
if (choix ==0) {
arts.getArticle().get(i).getEtatArt().set(etatArt, 2);
Utils ut = new Utils();
ut.Marshall(arts);
}
else {
int cpt=0;
for(int etatArt2=0; etatArt2<nbArt; etatArt2++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt2)==2){
cpt++;
}
}
if (cpt==0) {
for (int x = 0; x < liste.size(); x++) {
if (temp2 == liste.get(x)) {
liste.remove(x);
}
}
}
}
trouve=1;
}
}
int trouve1=0;
for(int etatArt=0; etatArt<nbArt; etatArt++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt)==2 && trouve1==0){
table.setValueAt(""+1, ligne, colo+1);
quantite= table.getValueAt(ligne, colo+1).toString();
table.setValueAt(arts.getArticle().get(i)
.getDescriptifArt(), ligne, colo + 2);
table.setValueAt(String.valueOf(arts.getArticle()
.get(i).getPrixCliArt()), ligne, colo + 3);
Prix=table.getValueAt(ligne, colo+3).toString();
prixHT=Float.parseFloat(quantite)*Float.parseFloat(Prix) ;
prixTT= prixTT + prixHT;
table.setValueAt(String.valueOf(prixHT), ligne, colo + 4);
jlbTotalBord.setText((String.valueOf(prixTT)));
prixTTC=(float)(prixTT*1.195);
jlbTotalTtcR.setText((String.valueOf(prixTTC)));
trouve1=1;
}
}
}
}
if (table.getValueAt(ligne, 2).toString().length()!=0){
tm.addRow("");
}
else{
pane.showMessageDialog(null, "Cet article n'existe pas!",
"Avertissement",pane.WARNING_MESSAGE);
table.setValueAt("", ligne, 0);
}
}
}
}
//GESTION DE LA SAISIE DE LA QUANTITE
if(table.getSelectedColumn()==1){
int QteArt=arts.getArticle().get(num).getQuantiteArt();
int count=0;
for(int nbArt=0; nbArt<QteArt; nbArt++){
if (arts.getArticle().get(num).getEtatArt().get(nbArt)==1 || arts.getArticle().get(num).getEtatArt().get(nbArt)==2){
count++;
}
}
for (int i = 0; i < arts.getArticle().size(); i++) {
int nbQuantite= Integer.parseInt(table.getValueAt(ligne, 1).toString());
int ArtNum= Integer.parseInt(table.getValueAt(ligne, 0).toString());
if (ArtNum == arts.getArticle().get(i).getNumArt()&&
arts.getArticle().get(i).getQuantiteArt()!=0) {
if(nbQuantite<=count){
int nbArt=arts.getArticle().get(i).getQuantiteArt();
int trouve=0;
for(int etatArt=0; etatArt<nbArt; etatArt++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt)==1 && trouve==0 ){
int choix = pane.showConfirmDialog(null, "Il existe un article réservé.\nVoulez-vous le vendre maintenant?",
"Article Reservé", JOptionPane.WARNING_MESSAGE);
if (choix ==0) {
arts.getArticle().get(i).getEtatArt().set(etatArt, 2);
Utils ut = new Utils();
ut.Marshall(arts);
}
else {
int cpt=0;
for(int etatArt2=0; etatArt2<nbArt; etatArt2++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt2)==2){
cpt++;
}
}
if (cpt>0) table.setValueAt(""+cpt, ligne, 1);
else
pane.showMessageDialog(null, "jereror: "+count,
"Avertissement",pane.WARNING_MESSAGE);
}
trouve=1;
}
}
int trouve2=0;
for(int etatArt=0; etatArt<nbArt; etatArt++){
if(arts.getArticle().get(i).getEtatArt().get(etatArt)==2 && trouve2==0){
quantite= table.getValueAt(ligne, colo).toString();
table.setValueAt(String.valueOf(arts.getArticle()
.get(i).getPrixCliArt()), ligne, colo + 2);
Prix=table.getValueAt(ligne, colo+2).toString();
prixHT=Float.parseFloat(quantite)*Float.parseFloat(Prix) ;
System.out.println("le prix HT est "+prixHT);
prixTT= prixTT - Float.parseFloat(Prix);
System.out.println("le prix avant est "+prixTT);
prixTT= prixTT + prixHT;
System.out.println("le prix apres est "+prixTT);
table.setValueAt(String.valueOf(prixHT), ligne, colo + 3);
jlbTotalBord.setText((String.valueOf(prixTT)));
prixTTC=(float)(prixTT*1.195);
jlbTotalTtcR.setText((String.valueOf(prixTTC)));
trouve2=1;
}
}
}
else{
pane.showMessageDialog(null, "la quantite est superieur a la quantite existante qui est: "+count,
"Avertissement",pane.WARNING_MESSAGE);
float prixHt=Float.parseFloat(table.getValueAt(ligne, 4).toString());
jlbTotalBord.setText(""+0);
jlbTotalTtcR.setText(""+0);
table.setValueAt("", ligne, 4);
}
}
}
}
} |
Partager