diff --git a/.config b/.config
new file mode 100644
index 0000000..eedc58b
--- /dev/null
+++ b/.config
@@ -0,0 +1,4 @@
+#Configuracion general
+#Sat Nov 16 23:04:44 CET 2019
+tema=0
+ruta=.mes
diff --git a/.mes b/.mes
index 60608bd..e68a0f5 100644
Binary files a/.mes and b/.mes differ
diff --git a/gestiones.xml b/gestiones.xml
new file mode 100644
index 0000000..0a981d0
--- /dev/null
+++ b/gestiones.xml
@@ -0,0 +1 @@
+NOVEMBER2019-1.00Ingresos4.0truezfgabbaf2019-11-164.0Gastos5.0falsefdfsba2019-11-165.0
\ No newline at end of file
diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java
index f87bcbd..28b2f78 100644
--- a/src/Logica/Meses.java
+++ b/src/Logica/Meses.java
@@ -9,8 +9,10 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
+import java.util.Locale;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
@@ -29,7 +31,11 @@ import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+import org.w3c.dom.traversal.NodeIterator;
+import org.xml.sax.SAXException;
public class Meses {
private ArrayList meses;
@@ -157,6 +163,8 @@ public class Meses {
Element nodoGestion;
Element nodoTransaccion;
Element nodoDatos;
+ Element nodoRaizGestion;
+ Element nodoRaizTransaccion;
Text dato;
for(Mes mes:this.meses) {
nodoMeses = documento.createElement("mes");
@@ -177,9 +185,11 @@ public class Meses {
nodoMeses.appendChild(nodoDatos);
dato = documento.createTextNode(String.valueOf(mes.nGestiones));
nodoDatos.appendChild(dato);
+ nodoRaizGestion = documento.createElement("Gestiones");
+ nodoMeses.appendChild(nodoRaizGestion);
for(Gestion gestion:mes.gestiones) {
nodoGestion = documento.createElement("gestion");
- nodoMeses.appendChild(nodoGestion);
+ nodoRaizGestion.appendChild(nodoGestion);
nodoDatos = documento.createElement("Nombre");
nodoGestion.appendChild(nodoDatos);
dato = documento.createTextNode(gestion.getNombre());
@@ -192,21 +202,23 @@ public class Meses {
nodoGestion.appendChild(nodoDatos);
dato = documento.createTextNode(String.valueOf(gestion.esIngreso()));
nodoDatos.appendChild(dato);
+ nodoRaizTransaccion = documento.createElement("Transacciones");
+ nodoGestion.appendChild(nodoRaizTransaccion);
for(Transaccion transaccion:gestion.getElementos()) {
nodoTransaccion = documento.createElement("transaccion");
- nodoGestion.appendChild(nodoTransaccion);
+ nodoRaizTransaccion.appendChild(nodoTransaccion);
nodoDatos = documento.createElement("Nombre");
nodoTransaccion.appendChild(nodoDatos);
dato = documento.createTextNode(transaccion.getNombre());
- nodoTransaccion.appendChild(dato);
+ nodoDatos.appendChild(dato);
nodoDatos = documento.createElement("Fecha");
nodoTransaccion.appendChild(nodoDatos);
dato = documento.createTextNode(transaccion.getDia().toString());
- nodoTransaccion.appendChild(dato);
+ nodoDatos.appendChild(dato);
nodoDatos = documento.createElement("Dinero");
nodoTransaccion.appendChild(nodoDatos);
dato = documento.createTextNode(String.valueOf(transaccion.getDinero()));
- nodoTransaccion.appendChild(dato);
+ nodoDatos.appendChild(dato);
}
}
}
@@ -233,6 +245,57 @@ public class Meses {
}
+ public void importarXML() {
+ this.importarXML("gestiones.xml");
+ }
+
+ public void importarXML(String nombreFichero) {
+ File fichero = new File(nombreFichero);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document documento = builder.parse(fichero);
+ NodeList gestiones = documento.getElementsByTagName("gestion");
+ //NodeList transacciones = documento.getElementsByTagName("transaccion");
+ NodeList meses = documento.getElementsByTagName("mes");
+ for(int h = 0; h < meses.getLength(); h++) {
+ Node mesNodo = meses.item(h);
+ Element elementoMes = (Element) mesNodo;
+ for(int i = 0; i < gestiones.getLength();i++) {
+ Node gestionNodo = gestiones.item(i);
+ Element elementoGestion = (Element) gestionNodo;
+
+ Gestion gestion = this.aniadirGestion(elementoGestion.getElementsByTagName("Nombre").item(0).getChildNodes().item(0).getNodeValue(),
+ Integer.parseInt(elementoMes.getElementsByTagName("anio").item(0).getChildNodes().item(0).getNodeValue()),
+ Month.valueOf(elementoMes.getElementsByTagName("nombre").item(0).getChildNodes().item(0).getNodeValue()),
+ Boolean.parseBoolean(elementoGestion.getElementsByTagName("EsPositivo").item(0).getChildNodes().item(0).getNodeValue()));
+ NodeList transacciones = elementoGestion.getElementsByTagName("transaccion");
+ for(int j=0; j < transacciones.getLength(); j++) {
+ Node transaccio = transacciones.item(j);
+ Element elementoTransaccion = (Element) transaccio;
+ //System.out.println(elementoTransaccion.getElementsByTagName("Fecha").item(0).getChildNodes().item(0).getNodeValue());
+ String[] fecha = elementoTransaccion.getElementsByTagName("Fecha").item(0).getChildNodes().item(0).getNodeValue().split("-");
+ this.aniadirTransaccion(new Transaccion(elementoTransaccion.getElementsByTagName("Nombre").item(0).getChildNodes().item(0).getNodeValue(),
+ Float.parseFloat(elementoTransaccion.getElementsByTagName("Dinero").item(0).getChildNodes().item(0).getNodeValue()),
+ LocalDate.of(Integer.parseInt(fecha[0]), Integer.parseInt(fecha[1]), Integer.parseInt(fecha[2])),
+ gestion),
+ gestion.getNombre(), true);
+ }
+ }
+ }
+
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
}
class Mes implements Serializable{
diff --git a/src/VistaControlador/BarraOpciones.java b/src/VistaControlador/BarraOpciones.java
index ee935cf..5711841 100644
--- a/src/VistaControlador/BarraOpciones.java
+++ b/src/VistaControlador/BarraOpciones.java
@@ -11,6 +11,7 @@ public class BarraOpciones extends JMenuBar{
JMenuItem cambiarRuta;
JMenuItem guardarIns;
JMenuItem exportarXML;
+ JMenuItem importarXML;
JMenu interfaz;
JMenuItem modoOscuro;
JMenuItem modoRosa;
@@ -26,6 +27,8 @@ public class BarraOpciones extends JMenuBar{
this.menuAr.add(this.cambiarRuta);
this.exportarXML = new JMenuItem("Exportar en un XML");
this.menuAr.add(this.exportarXML);
+ this.importarXML = new JMenuItem("Importar en un XML");
+ this.menuAr.add(this.importarXML);
this.interfaz = new JMenu("Interfaz");
this.add(this.interfaz);
this.modoClaro = new JMenuItem("Modo claro");
diff --git a/src/VistaControlador/ControladorBarra.java b/src/VistaControlador/ControladorBarra.java
index 41c0a99..f4c7ae6 100644
--- a/src/VistaControlador/ControladorBarra.java
+++ b/src/VistaControlador/ControladorBarra.java
@@ -3,6 +3,7 @@ package VistaControlador;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
+import java.time.LocalDate;
import javax.swing.JOptionPane;
@@ -65,6 +66,13 @@ public class ControladorBarra implements ActionListener{
}
case "Exportar XLM":{
this.menu.meses.exportarXML();
+ break;
+ }
+ case "Importar XLM":{
+ this.menu.meses.importarXML();
+ this.menu.cargarGestiones(LocalDate.now().getYear(), LocalDate.now().getMonth());
+ this.menu.cargarPestanias();
+ break;
}
}
@@ -77,6 +85,8 @@ public class ControladorBarra implements ActionListener{
this.barra.guardarIns.setActionCommand("Guardar instantanea");
this.barra.exportarXML.addActionListener(this);
this.barra.exportarXML.setActionCommand("Exportar XLM");
+ this.barra.importarXML.addActionListener(this);
+ this.barra.importarXML.setActionCommand("Importar XLM");
this.barra.modoClaro.addActionListener(this);
this.barra.modoClaro.setActionCommand("Modo claro");
this.barra.modoRosa.addActionListener(this);