UsbProvider.java
49.2 KB
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
package com.focasoftware.deboinventario;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
/**
* Activity para gestionar la importaci�n de inventarios por USB.
*
* @author GuillermoR
*
*/
public class UsbProvider extends Activity implements DialogPersoSimple {
@NonNull
private Context ctxt = this;
@Nullable
private String uri_usb;
private TableLayout tabla;
private Button boton_volver, boton_seguir, boton_refresh;
private TextView titulo;
@NonNull
private ArrayList<Integer> inventarios_seleccionados = new ArrayList<Integer>();
// private LinkedList<String> colaSQL = new LinkedList<String>();
// private final static Object locker = new Object();
// private boolean terminado = false;
private ProgressDialog popupEspera;
private final static int COLUMNA_ID = 1;
private final static int COLUMNA_CANTIDAD = 4;
private final static int COLUMNA_PATH = 5;
@NonNull
GestorLogEventos log = new GestorLogEventos();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml_usbstream);
log.setUbicacion(ParametrosInventario.CARPETA_LOGTABLET);
log.tipo_0 = Parametros.PREF_LOG_EVENTOS;
log.tipo_2 = Parametros.PREF_LOG_PROCESOS;
log.tipo_3 = Parametros.PREF_LOG_MENSAJES;
log.tipo_4 = Parametros.PREF_LOG_EXCEPCIONES;
log.log("Inicio de UsbProvider", 2);
LinearLayout ll = (LinearLayout) findViewById(R.id.USB_root);
ll.setBackgroundDrawable(getResources().getDrawable(
R.drawable.fondo_recepcion_inventario));
// BUNDLES:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
uri_usb = bundle.getString(Parametros.extra_uri_usb);
// uri_usb = "data/data/com.foca.deboInventario/test/";
} else {
uri_usb = "/udisk/deboInventario/aTablet/";
// uri_usb = "data/data/com.foca.deboInventario/test/";
}
// if(ParametrosInventario.MODO_DEBUG) {
// uri_usb = "data/data/com.foca.deboInventario/test/";
// }
// CARGA ELEMENTOS GRAFICOS:
tabla = (TableLayout) findViewById(R.id.USB_tabla);
boton_volver = (Button) findViewById(R.id.USB_boton_precedente);
boton_seguir = (Button) findViewById(R.id.USB_boton_siguiente);
boton_refresh = (Button) findViewById(R.id.USB_boton_refrescar);
titulo = (TextView) findViewById(R.id.USB_titulo);
titulo.setText("Lista de Inventarios");
// Construir la interfaz visual:
refreshUI();
// SET HANDLERS AND LISTENERS ON BUTTONS:
boton_seguir.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
log.log("[-- 122 --]" + "Se presiono boton seguir", 0);
System.out.println("USBProvider 123 Lanzar menu en espera");
lanzarMenuEspera();
// Puede ser necesario llamar a un metodo secuencial en vez de
// esto en background
// cargarDatosEnBdd(inventarios_seleccionados);
CargarDatosFromUSBtoBDD unaCargaFromUSBtoBDD = new CargarDatosFromUSBtoBDD();
// System.out.println("USBProvider 129 unaCargaFromUSB: "
// + unaCargaFromUSBtoBDD);
unaCargaFromUSBtoBDD.execute(ctxt);
}
});
boton_volver.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
log.log("[-- 138 --]" + "Se presiono boton volver", 0);
Intent intentMB = new Intent(UsbProvider.this,
InventarioMainBoard.class);
startActivity(intentMB);
finish();
}
});
boton_refresh.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// System.out.println("::: USBProvider 153 boton refrescar");
log.log("[-- 150 --]" + "Se presiono boton refrescar", 0);
refreshUI();
inventarios_seleccionados = new ArrayList<Integer>();
boton_seguir.setVisibility(View.INVISIBLE);
}
});
}
private void refreshUI() {
try {
for (int l = tabla.getChildCount() - 1; l > 0; l--) {
tabla.removeViewAt(l);
}
File fileUSB = new File(uri_usb);
if (fileUSB.exists() == true) {
if (fileUSB.isDirectory() == true) {
File[] listaTodosArchivos = fileUSB.listFiles();
for (int i = 0; i < listaTodosArchivos.length; i++) {
File archivo = listaTodosArchivos[i];
PreScanXML preScanner = new PreScanXML();
preScanner.scan(archivo);
TableRow tr = new TableRow(ctxt);
CheckBox chkbox = new CheckBox(ctxt);
TextView tv1 = new TextView(ctxt);
TextView tv2 = new TextView(ctxt);
TextView tv3 = new TextView(ctxt);
TextView tv4 = new TextView(ctxt);
TextView tv5 = new TextView(ctxt); // path del archivo
// (VISIBILITY ==
// GONE)
chkbox.setClickable(false);
tr.addView(chkbox);
tv1.setText(preScanner.numero);
tv1.setTextColor(Color.BLACK);
tv1.setGravity(Gravity.CENTER_HORIZONTAL);
tr.addView(tv1);
tv2.setText(preScanner.descripcion);
tv2.setTextColor(Color.BLACK);
tv2.setGravity(Gravity.CENTER_HORIZONTAL);
tr.addView(tv2);
tv3.setText(preScanner.fecha);
tv3.setTextColor(Color.BLACK);
tv3.setGravity(Gravity.CENTER_HORIZONTAL);
tr.addView(tv3);
tv4.setText(preScanner.cantidad);
tv4.setTextColor(Color.BLACK);
tv4.setGravity(Gravity.CENTER_HORIZONTAL);
tr.addView(tv4);
tv5.setText(archivo.getAbsolutePath());
tv5.setVisibility(View.GONE);
tr.addView(tv5);
tr.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TableRow linea = (TableRow) view;
CheckBox checkBox = (CheckBox) linea
.getChildAt(0);
if (checkBox.isChecked() == false) {
checkBox.setChecked(true);
TextView ttvv = (TextView) linea
.getChildAt(COLUMNA_ID);
inventarios_seleccionados.add(Integer
.parseInt(String.valueOf(ttvv
.getText())));
boton_seguir.setVisibility(View.VISIBLE);
} else {
checkBox.setChecked(false);
TextView ttvv = (TextView) linea
.getChildAt(COLUMNA_ID);
inventarios_seleccionados.remove((Object) Integer
.parseInt(String.valueOf(ttvv
.getText())));
if (inventarios_seleccionados.size() <= 0) {
boton_seguir
.setVisibility(View.INVISIBLE);
}
}
}
});
tabla.addView(tr);
} // end for
} // end if
} else {
showSimpleDialogOK(
"Error",
"No se encuentra el dispositivo "
+ ParametrosInventario.Dispositivo_Import
+ " para la importacion").show();
}
} catch (Exception e) {
log.log("[-- 257 --]" + e.toString(), 4);
showSimpleDialogOK("Error", e.toString()).show();
}
}
public AlertDialog showSimpleDialogOK(String titulo, String mensaje) {
log.log("[-- 264 --]" + "titulo: " + titulo + ", \n mensaje: "
+ mensaje, 3);
AlertDialog.Builder dialogoSimple = new AlertDialog.Builder(this);
dialogoSimple.setCancelable(false).setTitle(titulo).setMessage(mensaje)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(@NonNull DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = dialogoSimple.create();
return alert;
}
@Nullable
public AlertDialog showSimpleDialogSiNo(String titulo, String mensaje,
Class<?> clase) {
log.log("[-- 278 --]" + "titulo: " + titulo + ", \n mensaje: "
+ mensaje, 3);
return null;
}
// Podria ser necesario reactivarlo?
/*
* private void cargarDatosEnBdd(ArrayList<Integer> numeros_inventarios)
* throws ExceptionBDD { // Recuperamos el pedazo que corresponde a este
* inventario: String path = ""; lanzarMenuEspera();
*
* for (int n = 1 ; n < tabla.getChildCount() ; n++) { TableRow linea =
* (TableRow) tabla.getChildAt(n); int num_invent =
* Integer.parseInt(String.valueOf
* (((TextView)linea.getChildAt(1)).getText()));
*
* if (numeros_inventarios.contains(num_invent) == true) { path =
* String.valueOf(((TextView)linea.getChildAt(COLUMNA_PATH)).getText());
*
* File archivo = new File(path);
*
* if (archivo.exists() == true && archivo.isFile() == true) { try { //
* Copiamos el archivo desde el Pen Drive hasta la tablet: (para limitar los
* accesos USB): File carpeta_import = new
* File(ParametrosInventario.URL_CARPETA_USB_IMPORT); File archivo_destino =
* new File(ParametrosInventario.URL_CARPETA_USB_IMPORT +
* archivo.getName());
*
* if (carpeta_import.exists() == false) { archivo.mkdirs();
* archivo.createNewFile(); } else { if (archivo_destino.exists() == true) {
* archivo_destino.delete(); } archivo_destino.createNewFile(); }
*
* copyFile(archivo, archivo_destino);
*
*
* // Analisamos y partimos el archivo XML: ParserXML parseador = new
* ParserXML(); parseador.parser(archivo);
*
* // Borramos memoria BDD: BaseDatos bdd = new BaseDatos(ctxt); //try { //
* bdd.destruirYReconstruir(); //} catch (ExceptionBDD e) { //
* e.printStackTrace(); //}
*
* // Agregamos inventario: Inventario inventario = new Inventario(
* Integer.parseInt
* (parseador.cabecera.get(ParametrosInventario.bal_bdd_inventario_numero)),
* parseador
* .cabecera.get(ParametrosInventario.bal_bdd_inventario_descripcion),
* parseador.cabecera.get(ParametrosInventario.bal_bdd_inventario_fecha),
* 1//Integer.parseInt(parseador.cabecera.get(ParametrosInventario.
* bal_bdd_inventario_estado)) ); bdd.insertInventarioEnBdd(inventario);
*
* // Agregamos los articulos:
* //
* // WARNING
* //// Algunos
* articulos pueden figurar 2 veces o mas en la lista de los articulos //
* por tener codigos de barras diferentes. Hay que fusionarlos! // Eso se
* hace al nivel de la base de datos: cuando agregamos un articulo, //
* controlamos si uno ya existe, y si es el caso, le actualizamos el campo
* de // codigo de barra solamente. for (HashMap<String,String>
* articulo_cabeza: parseador.detallesArticulos.keySet()) {
* HashMap<String,String> articulo_cuerpo =
* parseador.detallesArticulos.get(articulo_cabeza);
*
* Articulo articulo = new Articulo(
* Integer.parseInt(articulo_cabeza.get(ParametrosInventario
* .bal_bdd_articulo_sector)),
* Integer.parseInt(articulo_cabeza.get(ParametrosInventario
* .bal_bdd_articulo_codigo)), new
* ArrayList<String>(Arrays.asList(articulo_cuerpo
* .get(ParametrosInventario.bal_bdd_articulo_codigo_barra))),
* Integer.parseInt
* (articulo_cabeza.get(ParametrosInventario.bal_bdd_articulo_inventario)),
* articulo_cuerpo.get(ParametrosInventario.bal_bdd_articulo_descripcion),
* Double.parseDouble(articulo_cuerpo.get(ParametrosInventario.
* bal_bdd_articulo_precio_venta)),
* Double.parseDouble(articulo_cuerpo.get(ParametrosInventario
* .bal_bdd_articulo_precio_costo)),
* articulo_cuerpo.get(ParametrosInventario.bal_bdd_articulo_foto),
* Integer.parseInt
* (articulo_cuerpo.get(ParametrosInventario.bal_bdd_articulo_cantidad)),
* articulo_cuerpo.get(ParametrosInventario.bal_bdd_articulo_fecha) );
*
* bdd.insertArticuloEnBdd(articulo); }
*
* // Al final borramos el archivo: archivo.delete(); } catch (Exception e)
* { e.printStackTrace(); } } // END of IF (file exists) }// END of IF (num
* del inventario en la lista) }// END of FOR cerrarMenuEspera(); }// END of
* CARGAR DATOS EN BDD
*/
// Creamos el thread que va a ejecutar el trabajo pesado (en una nueva
// clase):
protected class CargarDatosFromUSBtoBDD extends
AsyncTask<Context, Integer, String> {
// Puede ser necesario meterlo en un solo metodo de clase para que no
// haga lio, por que a veces da error
@NonNull
protected String doInBackground(Context... arg0) {
// db.execSQL("UPDATE Usuarios SET nombre='usunuevo' WHERE codigo=6 ");
int step = 0;
String error = "";
boolean todosCorrectos = true;
System.out.println("::: USBProvider 388 doInBackground ");
try {
// Recuperamos el pedazo que corresponde a este inventario:
String path = "";
for (int n = 1; n < tabla.getChildCount(); n++) {
TableRow linea = (TableRow) tabla.getChildAt(n);
int num_invent = Integer
.parseInt(String.valueOf(((TextView) linea
.getChildAt(1)).getText()));
if (inventarios_seleccionados.contains(num_invent) == true) {
path = String.valueOf(((TextView) linea
.getChildAt(COLUMNA_PATH)).getText());
File archivo = new File(path);
if (archivo.exists() == true
&& archivo.isFile() == true) {
try {
// Copiamos el archivo desde el Pen Drive hasta
// la tablet: (para limitar los accesos USB):
File carpeta_import = new File(
ParametrosInventario.URL_CARPETA_USB_IMPORT);
if (carpeta_import.exists() == false) {
carpeta_import.mkdir();
log.log("[-- 411 --]"
+ "carpeta import creada", 3);
}
log.log("carpeta_import = "
+ carpeta_import.getPath(), 3);
log.log("carpeta_import = " + archivo.getName(),
3);
File archivo_destino = new File(
carpeta_import.getPath() + "/"
+ archivo.getName());
// if (archivo_destino.exists() == false) {
// archivo_destino.mkdir();
//
// } else {
// archivo_destino.delete();
// }
log.log("archivo = " + archivo.toString(), 3);
log.log("archivo_destino = "
+ archivo_destino.toString(), 3);
if (archivo_destino.exists() == false) {
log.log("destino antes del copy = false", 3);
} else {
log.log("destino antes del copy = true", 3);
}
copyFile(archivo, archivo_destino);
if (archivo_destino.exists() == false) {
log.log("destino despues= false", 3);
} else {
log.log("destino = true", 3);
}
// Nos dormimos para dejar el tiempo la tablet
// de copiar bien el archivo a la memoria
// interna:
SystemClock.sleep(300);
// Creacion parseador:
ParserImportarXML parseador = new ParserImportarXML();
/*
* // Creamos un thread de trabajo: Thread
* thread = new Thread(new Runnable() {
*
* public void run() { while (terminado ==
* false) { boolean b = true; BaseDatos bdd =
* new BaseDatos(ctxt);
*
*
* synchronized (locker) { b =
* colaSQL.isEmpty(); }
*
* if (b == true) { try { synchronized (this) {
* this.wait(100); } } catch
* (InterruptedException e) {} } else { String
* unaConsultaSQL = ""; synchronized (locker) {
* unaConsultaSQL = colaSQL.poll(); } try {
* bdd.insertDesdeUSBEnBdd(unaConsultaSQL); }
* catch (ExceptionBDD e) {} } } } });
* thread.start();
*/
// Analisamos y partimos el archivo XML:
// ParserImportarXML parseador = new
// ParserImportarXML();
parseador
.parser_importer(
archivo_destino,
Integer.parseInt(String
.valueOf(((TextView) linea
.getChildAt(COLUMNA_CANTIDAD))
.getText())));
try {
BaseDatos bdd = new BaseDatos(ctxt);
ArrayList<String> sentenciaSQL = parseador.listaSQLprocesar;
System.out.println("::: UsbProvider 492 sentenciaSQL = "
+ sentenciaSQL);
System.out.println("::: UsbProvider antes de insertarnUsb");
bdd.insertDesdeUSBEnBdd(sentenciaSQL);
System.out.println("::: UsbProvider 495 bdd = "+ bdd);
bdd.close();
} catch (ExceptionBDD exc) {
return exc.toString();
}
setMenuValue(100);
/*
* // Agregamos inventario: Inventario
* inventario = new Inventario(
* Integer.parseInt(
* parseador.cabecera.get(ParametrosInventario
* .bal_bdd_inventario_numero)),
* parseador.cabecera.get(ParametrosInventario.
* bal_bdd_inventario_descripcion),
* parseador.cabecera.get(ParametrosInventario.
* bal_bdd_inventario_fecha),
* 1//Integer.parseInt
* (parseador.cabecera.get(ParametrosInventario
* .bal_bdd_inventario_estado)) );
* bdd.insertInventarioEnBdd(inventario);
*
*
* // Agregamos los articulos:
* //
*
* // WARNING
*
* //
* //
* Algunos articulos pueden figurar 2 veces o
* mas en la lista de los articulos // por tener
* codigos de barras diferentes. Hay que
* fusionarlos! // Eso se hace al nivel de la
* base de datos: cuando agregamos un articulo,
* // controlamos si uno ya existe, y si es el
* caso, le actualizamos el campo de // codigo
* de barra solamente. int index = 0;
*
* for (HashMap<String,String> articulo_cabeza:
* parseador.detallesArticulos.keySet()) {
* HashMap<String,String> articulo_cuerpo =
* parseador
* .detallesArticulos.get(articulo_cabeza);
*
* Articulo articulo = new Articulo(
* Integer.parseInt
* (articulo_cabeza.get(ParametrosInventario
* .bal_bdd_articulo_sector)),
* Integer.parseInt(articulo_cabeza
* .get(ParametrosInventario
* .bal_bdd_articulo_codigo)), new
* ArrayList<String
* >(Arrays.asList(articulo_cuerpo
* .get(ParametrosInventario
* .bal_bdd_articulo_codigo_barra))),
* Integer.parseInt
* (articulo_cabeza.get(ParametrosInventario
* .bal_bdd_articulo_inventario)),
* articulo_cuerpo.get(ParametrosInventario.
* bal_bdd_articulo_descripcion),
* Double.parseDouble
* (articulo_cuerpo.get(ParametrosInventario
* .bal_bdd_articulo_precio_venta)),
* Double.parseDouble
* (articulo_cuerpo.get(ParametrosInventario
* .bal_bdd_articulo_precio_costo)),
* articulo_cuerpo
* .get(ParametrosInventario.bal_bdd_articulo_foto
* ), Integer.parseInt(articulo_cuerpo.get(
* ParametrosInventario
* .bal_bdd_articulo_cantidad)),
* articulo_cuerpo.
* get(ParametrosInventario.bal_bdd_articulo_fecha
* ) );
*
* bdd.insertArticuloEnBdd(articulo);
*
* index++; popupEspera.setProgress((int) (50 +
* Math.floor((double)index * (double)50/
* (double)parseador.contador)));
*
* }
*/
// Al final borramos el archivo si se inserto
// correctamente en la bd
BaseDatos bdd = new BaseDatos(ctxt);
boolean excepcion = false;
Inventario actual = null;
try {
actual = bdd
.selectInventarioConNumero(num_invent);
} catch (ExceptionBDD e) {
log.log("[-- 556 --]" + e.toString(), 4);
// TODO Auto-generated catch block
e.printStackTrace();
excepcion = true;
}
if (actual != null /* && !excepcion */) {
archivo.delete();
} else {
// Marcar que hubo un problema
todosCorrectos = false;
}
} catch (Exception e) {
log.log("[-- 571 --]" + e.toString(), 4);
return e.toString();
// e.printStackTrace();
// error += "(" + e.toString() + ")";
}
} // END of IF (file exists)
}// END of IF (num del inventario en la lista)
}// END of FOR
} catch (Exception ex) {
log.log("[-- 582 --]" + ex.toString(), 4);
return "Step: " + String.valueOf(step) + " // " + "Error: "
+ error + " // " + ex.toString();
}
if (todosCorrectos) {
return "Importacion exitosa";
} else {
return "Error en el formato del xml";
}
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
cerrarMenuEspera();
TextView tv = (TextView) findViewById(R.id.aaaa);
tv.setText(result);
// Mensaje de aviso de resultado
AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
builder.setMessage(result)
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(@NonNull DialogInterface dialog,
int id) {
dialog.dismiss();
}
})
.setNegativeButton("Salir",
new DialogInterface.OnClickListener() {
public void onClick(@NonNull DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
// Toast.makeText(ctxt, "Resultado obtenido: " + result,
// Toast.LENGTH_LONG).show();
// SystemClock.sleep(3000);
Intent intentSeleccion = new Intent(UsbProvider.this,
InventarioMainBoard.class);
startActivity(intentSeleccion);
finish();
}
} // fin de "protected class CargarDatosRutas"
protected class PreScanXML {
protected String descripcion;
protected String numero;
protected String fecha;
protected String cantidad;
protected String existencia;
protected String deposito;
protected PreScanXML() {
descripcion = "";
numero = "";
fecha = "";
cantidad = "";
existencia = "";
}
private void scan(@NonNull File archivo) {
try {
XmlCleaner.xml_cleaning_spechar(archivo);
} catch (IOException e1) {
log.log("[-- 658 --]" + e1.toString(), 4);
e1.printStackTrace();
}
// PARSER el archivo XML:
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
// Balizas para los 3 datos que necesitamos.
// 0 = dato no parseado ;
// 1 = baliza leida, dato todavia no parseado ;
// 2 = dato recuperado
int bal_descripcion = 0;
int bal_numero = 0;
int bal_fechaInicio = 0;
int bal_cantidad = 0;
double bal_existencia = 0;
double bal_deposito = 0;
public void startElement(String uri, String localName,
@NonNull String qName, Attributes attributes)
throws SAXException {
if (bal_descripcion == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_inventario_descripcion)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
bal_descripcion = 1;
} else if (bal_numero == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_inventario_numero)) {
bal_numero = 1;
} else if (bal_fechaInicio == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_inventario_fechaInicio)) {
bal_fechaInicio = 1;
} else if (bal_cantidad == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_inventario_cantidad)) {
bal_cantidad = 1;
} else if(bal_existencia == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_articulo_existencia_venta)){
bal_existencia = 1 ;
}else if(bal_deposito == 0
&& qName.equalsIgnoreCase(
Parametros.bal_usb_articulo_existencia_deposito)){
bal_deposito = 1 ;
}}
public void characters(@NonNull char ch[], int start, int length)
throws SAXException {
if (bal_descripcion == 1) {
descripcion = String.valueOf(ch).substring(0,
length);
bal_descripcion = 2;
} else if (bal_numero == 1) {
numero = String.valueOf(ch).substring(0, length);
bal_numero = 2;
} else if (bal_fechaInicio == 1) {
fecha = String.valueOf(ch).substring(0, length);
bal_fechaInicio = 2;
} else if (bal_cantidad == 1) {
cantidad = String.valueOf(ch).substring(0, length);
bal_cantidad = 2;
} else if (bal_existencia == 1) {
existencia = String.valueOf(ch).substring(0, length);
bal_existencia = 2;
}else if (bal_deposito == 1) {
deposito = String.valueOf(ch).substring(0, length);
bal_deposito = 2;
}
if (bal_cantidad == 2 && bal_descripcion == 2
&& bal_fechaInicio == 2 && bal_numero == 2
&& bal_existencia == 2 && bal_deposito == 2) {
throw new SAXException("fin");
}
}
};
InputStream inputStream = new FileInputStream(archivo);
Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
InputSource is = new InputSource(reader);
is.setEncoding("ISO-8859-1");
saxParser.parse(is, handler);
} catch (Exception e) {
log.log("[-- 730 --]" + e.toString() + "marcando", 4);
e.printStackTrace();
return;
}
} // end foncion SCAN
} // end CLASS PreScanXML
protected class ParserImportarXML {
protected HashMap<String, String> unArticulo;
protected HashMap<String, String> unInventario;
protected int contador;
protected BaseDatos bdd;
protected ArrayList<String> listaSQLprocesar;
protected long temps1;
protected long temps2;
protected ParserImportarXML() {
unArticulo = new HashMap<String, String>();
unInventario = new HashMap<String, String>();
contador = 0;
bdd = new BaseDatos(ctxt);
listaSQLprocesar = new ArrayList<String>();
}
private void parser_importer(@NonNull File archivo, int cantidad) {
System.out.println("::: USBProvider 820 parser_importer");
final int cantidad_articulos_en_archivo = cantidad;
try {
XmlCleaner.xml_cleaning_spechar(archivo);
} catch (IOException e1) {
e1.printStackTrace();
}
// PARSER el archivo XML:
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
// Balizas para los datos que necesitamos.
// 0 = baliza no leida
// 1 = baliza leida
int flag_descripcion = 0;
int flag_numero = 0;
int flag_fecha = 0;
int flag_articulo = 0;
int flag_sector = 0;
int flag_codigo = 0;
int flag_codigobarra = 0;
int flag_cantidad = 0;
int flag_nom = 0;
int flag_preciocosto = 0;
int flag_precioventa = 0;
double flag_exisventa = 0;
double flag_exisdeposito = 0;
int flag_depsn = 0;
int flag_foto = 0;
public void startElement(String uri, String localName,
@NonNull String qName, Attributes attributes)
throws SAXException {
System.out.println("::: USBProvider 831 ");
/*
* if
* (qName.equalsIgnoreCase(Parametros.bal_usb_articulo_root
* )) { flag_articulo = 1; temps1 = new
* Date().getTime(); setMenuValue((int)
* Math.floor((double)contador * (double)50 /
* (double)cantidad_articulos_en_archivo)); } else
*/if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_sector)) {
flag_sector = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_codigo)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_codigo = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_codigo_barra)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_codigobarra = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_cantidad)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_cantidad = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_descripcion)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_nom = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_precio_costo)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_preciocosto = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_precio_venta)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_precioventa = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_existencia_venta)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_exisventa = 1;
}else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_existencia_deposito)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
// System.out.println("::: USBProvider 912 flagdep ="
// + qName.equalsIgnoreCase(
// Parametros.bal_usb_articulo_existencia_deposito));
flag_exisdeposito = 1;
}else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_depsn)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_depsn = 1;
} else if (flag_articulo == 1
&& qName.equalsIgnoreCase(Parametros.bal_usb_articulo_foto)) {
// Si vemos la baliza de la descripcion, ponemos el
// estado a "1":
flag_foto = 1;
} else if (qName
.equalsIgnoreCase(Parametros.bal_usb_inventario_descripcion)) {
flag_descripcion = 1;
} else if (qName
.equalsIgnoreCase(Parametros.bal_usb_inventario_numero)) {
flag_numero = 1;
} else if (qName
.equalsIgnoreCase(Parametros.bal_usb_inventario_fechaInicio)) {
flag_fecha = 1;
}
}
public void characters(@NonNull char ch[], int start, int length)
throws SAXException {
System.out.println("::: USBProvider 901 ");
if (flag_sector == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_sector,
String.valueOf(ch).substring(0,
length));
flag_sector = 0;
} else if (flag_codigo == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_codigo,
String.valueOf(ch).substring(0,
length));
// System.out.println("::: USBProvider 951 unArticulo codigo= "
// +unArticulo);
flag_codigo = 0;
} else if (flag_codigobarra == 1) {
if (length == 0) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_codigo_barra,
"0");
} else {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_codigo_barra,
String.valueOf(ch).substring(0,
length));
}
flag_codigobarra = 0;
} else if (flag_cantidad == 1) {
if (length == 0) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_cantidad,
"-1");
} else {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_cantidad,
String.valueOf(ch).substring(0,
length));
}
flag_cantidad = 0;
} else if (flag_nom == 1) {
if (length == 0) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_descripcion,
"Art. sin descripcion");
} else {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_descripcion,
String.valueOf(ch).substring(0,
length));
}
flag_nom = 0;
} else if (flag_preciocosto == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_precio_costo,
String.valueOf(ch).substring(0,
length));
flag_preciocosto = 0;
} else if (flag_precioventa == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_precio_venta,
String.valueOf(ch).substring(0,
length));
flag_precioventa = 0;
} else if (flag_exisventa == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_existencia_venta,
String.valueOf(ch).substring(0,
length));
// System.out.println("::: USBProvider 1007 unArticulo exis= "
// +unArticulo);
// System.out.println("::: USBProvider 1008 exis "+ unArticulo
// .put(ParametrosInventario.bal_bdd_articulo_existencia_venta,
// String.valueOf(ch).substring(0,
// length)));
flag_exisventa = 0;
}else if (flag_exisdeposito == 1) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_existencia_deposito,
String.valueOf(ch).substring(0,
length));
// System.out.println("::: USBProvider 1014 dep "+ unArticulo);
// System.out.println("::: USBProvider 1015 dep "+ unArticulo
// .put(ParametrosInventario.bal_bdd_articulo_existencia_deposito,
// String.valueOf(ch).substring(0,
// length)));
flag_exisdeposito = 0;
}else if (flag_foto == 1) {
if (length == 0) {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_foto,
"''");
} else {
unArticulo
.put(ParametrosInventario.bal_bdd_articulo_foto,
String.valueOf(ch).substring(0,
length));
}
flag_foto = 0;
} else if (flag_descripcion == 1) {
unInventario
.put(ParametrosInventario.bal_bdd_inventario_descripcion,
String.valueOf(ch).substring(0,
length));
flag_descripcion = 2;
} else if (flag_numero == 1) {
unInventario
.put(ParametrosInventario.bal_bdd_inventario_numero,
String.valueOf(ch).substring(0,
length));
flag_numero = 2;
} else if (flag_fecha == 1) {
unInventario
.put(ParametrosInventario.bal_bdd_inventario_fechaInicio,
String.valueOf(ch).substring(0,
length));
flag_fecha = 2;
}
System.out.println("::: USBProvider 1059 ");
System.out.println("::: USBProvider 1061 "+ flag_numero);
System.out.println("::: USBProvider 1061 "+ flag_descripcion);
System.out.println("::: USBProvider 1061 "+ flag_fecha);
// System.out.println("::: USBProvider 1006 ");
if (flag_descripcion == 2 && flag_numero == 2
&& flag_fecha == 2) {
// Tenemos todos los campos del inventario, lo
// grabamos en la BDD:
// Posiblemente haya que modificar la forma en que
// se guarda la fecha de inicio por que la guarda
// con otro formato
// 07-05-2012 15:53 --> 2012-05-08 13:08:56
// Guardamos la fecha de inicio en una cadena tal
// como viene en el XML de importacin dd-MM-yyyy
// hh:mm
// String
// fechaDoc=unInventario.get(ParametrosInventario.bal_bdd_inventario_fechaInicio);
// //Generamos una date de esa cadena
// SimpleDateFormat sdf=new
// SimpleDateFormat("dd-MM-yyyy hh:mm");
// Date fechaInicioDoc=sdf.parse(fechaDoc);
// //Generamos otra cadena con el formato nuevo
// yyyy-MM-dd hh:mm:ss
// sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// String
// nuevaFechaInicio=sdf.format(fechaInicioDoc);
//
Inventario inventario = new Inventario(
Integer.parseInt(unInventario
.get(ParametrosInventario.bal_bdd_inventario_numero)),
unInventario
.get(ParametrosInventario.bal_bdd_inventario_descripcion),
unInventario
.get(ParametrosInventario.bal_bdd_inventario_fechaInicio),
unInventario
.get(ParametrosInventario.bal_bdd_inventario_fechaFin),
1, -1);
try {
bdd.insertInventarioEnBdd(inventario);
} catch (ExceptionBDD e) {
log.log("[-- 983 --]" + e.toString(), 4);
e.printStackTrace();
}
flag_descripcion = 0;
flag_numero = 0;
flag_fecha = 0;
flag_articulo = 1;
}
}
public void endElement(String uri, String localName,
@NonNull String qName) throws SAXException {
System.out.println("::: UsbProvider 1118");
if (qName
.equalsIgnoreCase(Parametros.bal_usb_articulo_root)) {
/*
* Articulo articulo = null; try { articulo = new
* Articulo(
* Integer.parseInt(unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_sector)),
* Integer.parseInt(unArticulo
* .get(ParametrosInventario
* .bal_bdd_articulo_codigo)), new
* ArrayList<String>(
* Arrays.asList(unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_codigo_barra))),
* Integer.parseInt
* (unInventario.get(ParametrosInventario
* .bal_bdd_inventario_numero)),
* unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_descripcion),
* Double.parseDouble
* (unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_precio_venta)),
* Double.parseDouble
* (unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_precio_costo)),
* unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_foto),
* Integer.parseInt(unArticulo
* .get(ParametrosInventario
* .bal_bdd_articulo_cantidad)), "" // fecha vaca
* todava );
*
* bdd.insertArticuloEnBdd(articulo); } catch
* (ExceptionBDD e) { } catch (Exception ex) { }
*/
// System.out.println("::: USBProvider 1092 " + unArticulo);
System.out.println("::: UsbProvider 1149");
listaSQLprocesar
.add("INSERT OR REPLACE INTO "
+ ParametrosInventario.tabla_articulos
+ " "
+ "VALUES ("
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_sector)
+ ","
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_codigo)+ ","
+ "0"+ ","
+ "0"+ ","
+ "'"
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_codigo_barra)
+ "' "+ ","
+ "'"
+ "' "
+ "|| coalesce("
+ "',' || (SELECT "
+ ParametrosInventario.bal_bdd_articulo_codigo_barra
+ " "
+ "FROM "
+ ParametrosInventario.tabla_articulos
+ " "
+ "WHERE "
+ ParametrosInventario.bal_bdd_articulo_sector
+ "="
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_sector)
+ " AND "
+ ParametrosInventario.bal_bdd_articulo_codigo
+ "="
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_codigo)
+ " AND "
+ ParametrosInventario.bal_bdd_articulo_inventario
+ "="
+ unInventario
.get(ParametrosInventario.bal_bdd_inventario_numero)
+ "),''),"
+ unInventario
.get(ParametrosInventario.bal_bdd_inventario_numero)
+ ","
+ "'" +
unArticulo
.get(ParametrosInventario.bal_bdd_articulo_cantidad)//Trae la descripcion
+"'"+ ","
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_descripcion)//Trae Pre_vent
+ ","
// + unArticulo
// .get(ParametrosInventario.bal_bdd_articulo_precio_venta)
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_precio_costo)//Trae pre_cost
+ ","
+ unArticulo
.get(ParametrosInventario.bal_bdd_articulo_foto)//foto creo
+ ","
+ "0"//cantidad
+ ",0"
//peso
+ ",0"
// + unArticulo
// .get(ParametrosInventario.bal_bdd_articulo_existencia_venta)
+ ",0"
// + unArticulo
// .get(ParametrosInventario.bal_bdd_articulo_existencia_deposito)
+ ",''"
// + unArticulo
// .get(ParametrosInventario.bal_bdd_articulo_depsn)
+ ","
+ "'',''" + ")");
// System.out.println("::: USBProvider 1160 ExisVenta" + unArticulo
// .get(ParametrosInventario.bal_bdd_articulo_existencia_venta));
// System.out.println("::: USBProvider 1162 " + listaSQLprocesar);
/*
* synchronized (locker) {
* colaSQL.add("INSERT into "+
* ParametrosInventario.tabla_articulos +
* " VALUES (" +
* unArticulo.get(ParametrosInventario.
* bal_bdd_articulo_sector) + "," +
* unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_codigo) + "," + "'" +
* unArticulo.get(ParametrosInventario.
* bal_bdd_articulo_codigo_barra) + "'," +
* unInventario
* .get(ParametrosInventario.bal_bdd_inventario_numero
* ) + "," + "'" +
* unArticulo.get(ParametrosInventario
* .bal_bdd_articulo_descripcion) + "'," +
* unArticulo.get(ParametrosInventario.
* bal_bdd_articulo_precio_venta) + "," +
* unArticulo.get(ParametrosInventario.
* bal_bdd_articulo_precio_costo) + "," + "'" +
* unArticulo
* .get(ParametrosInventario.bal_bdd_articulo_foto)
* + "'," + unArticulo.get(ParametrosInventario.
* bal_bdd_articulo_cantidad) + "," + "''" + ")"); }
*/
contador++;
setMenuValue((int) Math.floor((double) contador
* (double) 98
/ (double) cantidad_articulos_en_archivo));
unArticulo.clear();
}
}
};
System.out.println("::: USBProvider 1267 ");
InputStream inputStream = new FileInputStream(archivo);
Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
InputSource is = new InputSource(reader);
is.setEncoding("ISO-8859-1");
saxParser.parse(is, handler);
// terminado = true;
} catch (Exception e) {
log.log("[-- 1134 --]" + e.toString(), 4);
e.printStackTrace();
}
/*
* DocumentBuilderFactory docFactory = null; DocumentBuilder
* docBuilder = null; Document doc = null;
*
* try { XmlCleaner.xml_cleaning_spechar(archivo); } catch
* (IOException e1) { e1.printStackTrace(); }
*
* try { docFactory = DocumentBuilderFactory.newInstance();
* docBuilder = docFactory.newDocumentBuilder(); doc =
* docBuilder.parse(archivo); } catch (ParserConfigurationException
* e) { e.printStackTrace(); } catch (SAXException e) {
* e.printStackTrace(); } catch (IOException e) {
* e.printStackTrace(); }
*
* // Recorrido del arbol de los datos XML: try { // Primero
* recuperamos los datos del encabezado: // Detalles Inventario :
* numero, descripcion y fecha NodeList listaDescripcion =
* doc.getElementsByTagName
* (Parametros.bal_usb_inventario_descripcion);
* this.cabecera.put(ParametrosInventario
* .CONVERSOR_BALIZAS.usb2bdd(Parametros
* .bal_usb_inventario_descripcion,
* ParametrosInventario.tabla_inventarios),
* String.valueOf(listaDescripcion
* .item(0).getTextContent()).trim());
*
* NodeList listaNumero =
* doc.getElementsByTagName(Parametros.bal_usb_inventario_numero);
* this.cabecera.put(ParametrosInventario.CONVERSOR_BALIZAS.usb2bdd(
* Parametros.bal_usb_inventario_numero,
* ParametrosInventario.tabla_inventarios),
* String.valueOf(listaNumero.item(0).getTextContent()).trim());
*
* NodeList listaFecha =
* doc.getElementsByTagName(Parametros.bal_usb_inventario_fecha);
* this.cabecera.put(ParametrosInventario.CONVERSOR_BALIZAS.usb2bdd(
* Parametros.bal_usb_inventario_fecha,
* ParametrosInventario.tabla_inventarios),
* String.valueOf(listaFecha.item(0).getTextContent()).trim());
*
* // Despues recuperamos todos los datos de los articulos: NodeList
* listaArticulos =
* doc.getElementsByTagName(Parametros.bal_usb_articulo_root);
*
* for (int i = 0 ; i < listaArticulos.getLength() ; i++) {
* setMenuValue((int) Math.floor((double)i * (double)50 /
* (double)listaArticulos.getLength()));
*
* NodeList listaHijos = listaArticulos.item(i).getChildNodes();
* //NodeList listaHijos = listaArticulos.item(i).getChildNodes();
* HashMap<String, String> cabeza = new HashMap<String, String>();
* HashMap<String, String> cuerpo = new HashMap<String, String>();
*
* // Llenamos el CUERPO con todos los datos disponibles: for (int j
* = 0 ; j < listaHijos.getLength() ; j++) { try { String nombre =
* listaHijos.item(j).getNodeName(); String valor =
* listaHijos.item(j).getTextContent().trim().replace(",", ".");
* cuerpo.put(ParametrosInventario.CONVERSOR_BALIZAS.usb2bdd(nombre,
* ParametrosInventario.tabla_articulos) , valor); } catch
* (Exception e) {} }
*
* // Extraemos unos campos de identificacin para fabricar la
* CABEZA: cabeza.put(ParametrosInventario.bal_bdd_articulo_codigo,
* cuerpo.get(ParametrosInventario.bal_bdd_articulo_codigo));
* cabeza.put(ParametrosInventario.bal_bdd_articulo_sector,
* cuerpo.get(ParametrosInventario.bal_bdd_articulo_sector));
* cabeza.put(ParametrosInventario.bal_bdd_articulo_inventario,
* this.
* cabecera.get(ParametrosInventario.bal_bdd_inventario_numero));
*
* // Control de los nmeros, que si no hay nada le ponemos 0: if
* (cuerpo
* .get(ParametrosInventario.bal_bdd_articulo_codigo_barra).trim
* ().length() <= 0) {
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_codigo_barra,
* "0"); }
*
* if (Integer.parseInt(cuerpo.get(ParametrosInventario.
* bal_bdd_articulo_cantidad).trim()) <= 0) {
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_cantidad, "-1");
* }
*
* try { double db =
* Double.parseDouble(cuerpo.get(ParametrosInventario
* .bal_bdd_articulo_precio_venta).trim().replace(",", "."));
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_precio_venta,
* String.valueOf(db)); } catch (Exception e) {
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_precio_venta,
* "0"); }
*
* try { double db =
* Double.parseDouble(cuerpo.get(ParametrosInventario
* .bal_bdd_articulo_precio_costo).trim().replace(",", "."));
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_precio_costo,
* String.valueOf(db)); } catch (Exception e) {
* cuerpo.put(ParametrosInventario.bal_bdd_articulo_precio_costo,
* "0"); }
*
* this.detallesArticulos.put(cabeza,cuerpo);
*
* } // end for
*
* } catch (Exception e) { e.printStackTrace(); } // end try
*/
} // end foncion PARSER
} // end CLASS ParserXML
private void lanzarMenuEspera() {
popupEspera = new ProgressDialog(ctxt);
popupEspera.setCancelable(true);
popupEspera
.setMessage("Por favor, aguarde mientras se cargan los datos de los INVENTARIOS...");
log.log("[-- 1251 --]"
+ "Por favor, aguarde mientras se acargan los datos de los INVENTARIOS...",
3);
popupEspera.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
popupEspera.setMax(100);
popupEspera.setProgress(0);
DialogInterface.OnClickListener listenerClic = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
cerrarMenuEspera();
BaseDatos bdd = new BaseDatos(ctxt);
bdd.borrarInventarioConArticulos(inventarios_seleccionados);
Intent intentMB = new Intent(UsbProvider.this,
InventarioMainBoard.class);
startActivity(intentMB);
finish();
} catch (ExceptionBDD e) {
log.log("[-- 1269 --]" + e.toString(), 4);
}
}
};
popupEspera.setButton(Dialog.BUTTON_NEGATIVE, "Cancelar", listenerClic);
popupEspera.show();
}
private void setMenuValue(int valor) {
popupEspera.setProgress(valor);
}
private void cerrarMenuEspera() {
popupEspera.dismiss();
}
private void copyFile(@NonNull File sourceFile, @NonNull File destFile) throws IOException {
try {
if (!sourceFile.exists()) {
return;
}
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
if (destination != null && source != null) {
destination.transferFrom(source, 0, source.size());
}
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
while (destFile.exists() == false) {
SystemClock.sleep(100);
}
} catch (Exception e) {
log.log(e.toString(), 3);
}
}
} // END CLASS