diff --git a/.classpath b/.classpath index de44daf..d6ee83a 100644 --- a/.classpath +++ b/.classpath @@ -2,10 +2,22 @@ - - + + + + + + + + + + + + + + diff --git a/Cherry.jasper b/Cherry.jasper new file mode 100644 index 0000000..c81dfe7 Binary files /dev/null and b/Cherry.jasper differ diff --git a/Cherry.jrxml b/Cherry.jrxml new file mode 100644 index 0000000..28b0705 --- /dev/null +++ b/Cherry.jrxml @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="132" splitType="Stretch"> + <image> + <reportElement x="456" y="0" width="99" height="132" uuid="97705585-a0b5-4ec7-86f3-ae10c220e6af"/> + <imageExpression><![CDATA["invoice_logo.png"]]></imageExpression> + </image> + <frame> + <reportElement mode="Opaque" x="0" y="0" width="451" height="95" backcolor="#000000" uuid="6c6ca4e1-17cd-4913-93d6-5e670ea9ae8a"/> + <staticText> + <reportElement style="Title" x="0" y="0" width="370" height="66" uuid="a2a2cac8-5a7d-4487-8c54-dab235ce4e21"/> + <textElement> + <font size="40" isBold="false"/> + </textElement> + <text><![CDATA[Datos de los usuarios]]></text> + </staticText> + </frame> + <frame> + <reportElement mode="Opaque" x="0" y="100" width="451" height="32" forecolor="#000000" backcolor="#003366" uuid="e3c14156-5b51-4201-918b-97fdc012e5d4"/> + <textField pattern="EEEEE dd MMMMM yyyy"> + <reportElement x="307" y="12" width="144" height="20" forecolor="#FFFFFF" uuid="5c3301e7-a737-4c59-8a2f-a6c79fd1adb8"/> + <textElement textAlignment="Right"> + <font size="12"/> + </textElement> + <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> + </textField> + </frame> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ConsultasInformes.sql b/ConsultasInformes.sql new file mode 100644 index 0000000..5abbf3d --- /dev/null +++ b/ConsultasInformes.sql @@ -0,0 +1,23 @@ +select count(transacciones.id), sum(transacciones.precio) +from transacciones +join gestiones on gestiones.id = transacciones.idGestion +where gestiones.idUsuario = 1; + +select gestiones.descripcion, month(transacciones.fecha), sum(precio), gestiones.idUsuario +from transacciones +join gestiones on transacciones.idGestion = gestiones.id +where gestiones.idUsuario = 1 +group by idGestion, month(fecha); + +select transacciones.descripcion, gestiones.descripcion, usuarios.usuario, transacciones.precio, transacciones.fecha +from transacciones +join gestiones on transacciones.idGestion = gestiones.id +join usuarios on usuarios.id = gestiones.idUsuario +where year(transacciones.fecha)="2019" +order by usuario; + +select usuarios.id, usuarios.usuario +from usuarios; + +select distinct year(transacciones.fecha) +from transacciones; \ No newline at end of file diff --git a/DataAdapter.xml b/DataAdapter.xml new file mode 100644 index 0000000..4178ffa --- /dev/null +++ b/DataAdapter.xml @@ -0,0 +1,2 @@ + +ew Data Adapter 1org.mariadb.jdbc.Driverroot1234truejdbc:mariadb://localhost:3306/informes \ No newline at end of file diff --git a/Grafico.jasper b/Grafico.jasper new file mode 100644 index 0000000..16f554f Binary files /dev/null and b/Grafico.jasper differ diff --git a/Grafico.jrxml b/Grafico.jrxml new file mode 100644 index 0000000..bf27a89 --- /dev/null +++ b/Grafico.jrxml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Graficos_gastos.jasper b/Graficos_gastos.jasper new file mode 100644 index 0000000..7426e85 Binary files /dev/null and b/Graficos_gastos.jasper differ diff --git a/Graficos_gastos.jrxml b/Graficos_gastos.jrxml new file mode 100644 index 0000000..79f1e20 --- /dev/null +++ b/Graficos_gastos.jrxml @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="96" splitType="Stretch"> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + <line> + <reportElement x="0" y="80" width="556" height="1" uuid="806ce5df-1219-4876-ae0c-ca7405b1f246"> + <property name="local_mesure_unitheight" value="pixel"/> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + </reportElement> + </line> + <staticText> + <reportElement x="415" y="10" width="50" height="20" uuid="0f86baff-6386-4f3f-b3fe-2388707babe8"/> + <box rightPadding="4"/> + <textElement textAlignment="Right"/> + <text><![CDATA[Date:]]></text> + </staticText> + <textField pattern="EEEEE dd MMMMM yyyy"> + <reportElement x="465" y="10" width="84" height="20" uuid="bb10dbe1-0a4f-4722-9953-c163b63cf979"/> + <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> + </textField> + <image hAlign="Center"> + <reportElement x="0" y="0" width="65" height="60" uuid="94883631-a913-43e2-b182-ab8d77d0181e"/> + <imageExpression><![CDATA["invoice_logo.png"]]></imageExpression> + </image> + <textField pattern="EEEEE dd MMMMM yyyy"> + <reportElement x="465" y="30" width="84" height="20" uuid="3836ce65-eca3-4cad-a6de-b1818def0a2b"/> + <textFieldExpression><![CDATA["INV0001"]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="415" y="30" width="50" height="20" uuid="0b3f9342-da78-4cfa-9fc5-2301c4749678"/> + <box rightPadding="4"/> + <textElement textAlignment="Right"/> + <text><![CDATA[Invoice #]]></text> + </staticText> + <staticText> + <reportElement x="95" y="0" width="315" height="25" uuid="e622555d-198b-4ccd-a4a1-c59c53304058"> + <property name="local_mesure_unitheight" value="pixel"/> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + </reportElement> + <textElement> + <font size="19" isBold="true"/> + </textElement> + <text><![CDATA[Grafico de gastos de cada usuario]]></text> + </staticText> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Informe1.pdf b/Informe1.pdf new file mode 100644 index 0000000..3d4a495 Binary files /dev/null and b/Informe1.pdf differ diff --git a/Invoice.jasper b/Invoice.jasper new file mode 100644 index 0000000..df8d2a9 Binary files /dev/null and b/Invoice.jasper differ diff --git a/Invoice.jrxml b/Invoice.jrxml new file mode 100644 index 0000000..68dfa60 --- /dev/null +++ b/Invoice.jrxml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="82" splitType="Stretch"> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + <line> + <reportElement x="0" y="80" width="556" height="1" uuid="806ce5df-1219-4876-ae0c-ca7405b1f246"> + <property name="local_mesure_unitheight" value="pixel"/> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + </reportElement> + </line> + <staticText> + <reportElement x="415" y="10" width="50" height="20" uuid="0f86baff-6386-4f3f-b3fe-2388707babe8"/> + <box rightPadding="4"/> + <textElement textAlignment="Right"/> + <text><![CDATA[Date:]]></text> + </staticText> + <textField pattern="EEEEE dd MMMMM yyyy"> + <reportElement x="465" y="10" width="84" height="20" uuid="bb10dbe1-0a4f-4722-9953-c163b63cf979"/> + <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> + </textField> + <image hAlign="Center"> + <reportElement x="0" y="0" width="65" height="60" uuid="94883631-a913-43e2-b182-ab8d77d0181e"/> + <imageExpression><![CDATA["invoice_logo.png"]]></imageExpression> + </image> + <textField pattern="EEEEE dd MMMMM yyyy"> + <reportElement x="465" y="30" width="84" height="20" uuid="3836ce65-eca3-4cad-a6de-b1818def0a2b"/> + <textFieldExpression><![CDATA["INV0001"]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="415" y="30" width="50" height="20" uuid="0b3f9342-da78-4cfa-9fc5-2301c4749678"/> + <box rightPadding="4"/> + <textElement textAlignment="Right"/> + <text><![CDATA[Invoice #]]></text> + </staticText> + <staticText> + <reportElement x="95" y="0" width="210" height="25" uuid="e622555d-198b-4ccd-a4a1-c59c53304058"> + <property name="local_mesure_unitheight" value="pixel"/> + <property name="com.jaspersoft.studio.unit.height" value="px"/> + </reportElement> + <textElement> + <font size="19" isBold="true"/> + </textElement> + <text><![CDATA[Your company name]]></text> + </staticText> + <staticText> + <reportElement x="95" y="55" width="205" height="15" uuid="b8cc42fd-b569-497d-834d-7e854040ad18"/> + <text><![CDATA[900800700]]></text> + </staticText> + <staticText> + <reportElement x="95" y="25" width="205" height="15" uuid="c226e44d-3bb5-4145-b0b3-903bf1d79fde"/> + <text><![CDATA[Calle inventada 17]]></text> + </staticText> + <staticText> + <reportElement x="95" y="40" width="205" height="15" uuid="b96f7183-44f8-43ad-ba60-43d8fbf50b6e"/> + <text><![CDATA[Madrid]]></text> + </staticText> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index dfe691c..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/VistaControlador/ -/Logica/ diff --git a/bin/VistaControlador/BarraOpciones.class b/bin/VistaControlador/BarraOpciones.class new file mode 100644 index 0000000..1195e92 Binary files /dev/null and b/bin/VistaControlador/BarraOpciones.class differ diff --git a/bin/VistaControlador/ControladorAniadirVisualizar.class b/bin/VistaControlador/ControladorAniadirVisualizar.class new file mode 100644 index 0000000..ad1bfeb Binary files /dev/null and b/bin/VistaControlador/ControladorAniadirVisualizar.class differ diff --git a/bin/VistaControlador/ControladorBarra.class b/bin/VistaControlador/ControladorBarra.class new file mode 100644 index 0000000..82ec005 Binary files /dev/null and b/bin/VistaControlador/ControladorBarra.class differ diff --git a/bin/VistaControlador/ControladorInforme.class b/bin/VistaControlador/ControladorInforme.class new file mode 100644 index 0000000..c66f249 Binary files /dev/null and b/bin/VistaControlador/ControladorInforme.class differ diff --git a/bin/VistaControlador/ControladorPanelGestion.class b/bin/VistaControlador/ControladorPanelGestion.class new file mode 100644 index 0000000..b3ba19f Binary files /dev/null and b/bin/VistaControlador/ControladorPanelGestion.class differ diff --git a/bin/VistaControlador/ControladorPanelInterfaz.class b/bin/VistaControlador/ControladorPanelInterfaz.class new file mode 100644 index 0000000..6f3a79f Binary files /dev/null and b/bin/VistaControlador/ControladorPanelInterfaz.class differ diff --git a/bin/VistaControlador/ControladorPanelModificar.class b/bin/VistaControlador/ControladorPanelModificar.class new file mode 100644 index 0000000..7002e29 Binary files /dev/null and b/bin/VistaControlador/ControladorPanelModificar.class differ diff --git a/bin/VistaControlador/Menu$1.class b/bin/VistaControlador/Menu$1.class new file mode 100644 index 0000000..c802b63 Binary files /dev/null and b/bin/VistaControlador/Menu$1.class differ diff --git a/bin/VistaControlador/Menu.class b/bin/VistaControlador/Menu.class new file mode 100644 index 0000000..9c21b1f Binary files /dev/null and b/bin/VistaControlador/Menu.class differ diff --git a/bin/VistaControlador/ModeloInformes.class b/bin/VistaControlador/ModeloInformes.class new file mode 100644 index 0000000..3f3373b Binary files /dev/null and b/bin/VistaControlador/ModeloInformes.class differ diff --git a/bin/VistaControlador/MostrarTodo.class b/bin/VistaControlador/MostrarTodo.class new file mode 100644 index 0000000..acc67e0 Binary files /dev/null and b/bin/VistaControlador/MostrarTodo.class differ diff --git a/bin/VistaControlador/VistaAniadirVisualizar.class b/bin/VistaControlador/VistaAniadirVisualizar.class new file mode 100644 index 0000000..9bc7c1d Binary files /dev/null and b/bin/VistaControlador/VistaAniadirVisualizar.class differ diff --git a/bin/VistaControlador/VistaInformes.class b/bin/VistaControlador/VistaInformes.class new file mode 100644 index 0000000..514b3ef Binary files /dev/null and b/bin/VistaControlador/VistaInformes.class differ diff --git a/bin/VistaControlador/VistaPanel.class b/bin/VistaControlador/VistaPanel.class new file mode 100644 index 0000000..f97c3dc Binary files /dev/null and b/bin/VistaControlador/VistaPanel.class differ diff --git a/bin/VistaControlador/VistaPanelGestion.class b/bin/VistaControlador/VistaPanelGestion.class new file mode 100644 index 0000000..f3e66f1 Binary files /dev/null and b/bin/VistaControlador/VistaPanelGestion.class differ diff --git a/bin/VistaControlador/VistaPanelInterfaz.class b/bin/VistaControlador/VistaPanelInterfaz.class new file mode 100644 index 0000000..147a806 Binary files /dev/null and b/bin/VistaControlador/VistaPanelInterfaz.class differ diff --git a/bin/VistaControlador/VistaPanelModificar.class b/bin/VistaControlador/VistaPanelModificar.class new file mode 100644 index 0000000..64f975d Binary files /dev/null and b/bin/VistaControlador/VistaPanelModificar.class differ diff --git a/cherry.jpg b/cherry.jpg new file mode 100644 index 0000000..9d1aa77 Binary files /dev/null and b/cherry.jpg differ diff --git a/crearDB.sql b/crearDB.sql new file mode 100644 index 0000000..fc1436a --- /dev/null +++ b/crearDB.sql @@ -0,0 +1,55 @@ +drop database informes; +create database if not exists informes; +use informes; + +create table if not exists usuarios( +id int not null auto_increment, +usuario varchar(30) not null, +primary key(id, usuario), +pass varchar(30) not null); + +insert into usuarios(usuario, pass) values +("pepe", "pass"), +("juan", "1234"), +("roberto", "asdgg"); + +create table if not exists gestiones( +id int not null primary key auto_increment, +descripcion varchar(30), +idUsuario int not null, +foreign key (idUsuario) references usuarios(id) +); + +insert into gestiones(descripcion, idUsuario)values +("vicio", 1), +("comida", 1), +("escuela", 1), +("colegio", 2), +("super", 2), +("pc", 2), +("cosa1", 3), +("cosa2", 3), +("cosa3", 3); + +create table if not exists transacciones( +id int not null primary key auto_increment, +precio float, +descripcion varchar(30), +fecha date, +idGestion int not null, +foreign key (idGestion) references gestiones(id) +); + +insert into transacciones(precio, descripcion, fecha, idGestion) values +(9, "juego1", '19-01-01',1), +(3, "jego2", '19-02-01',1), +(6, "cosas ilegales", '19-03-03', 1), +(8, "objeto prueba", '19-04-01', 2), +(9, "objeto peuba2", '19-02-02', 2), +(7, "otro objeto", '19-04-03', 3), +(8, "juego1", '19-01-01',4), +(4, "jego2", '19-02-02',4), +(5, "cosas ilegales", '19-03-03', 4), +(9, "objeto prueba", '19-01-01', 5), +(10, "objeto peuba2", '19-02-02', 5), +(2, "otro objeto", '19-03-03', 6); diff --git a/invoice_logo.png b/invoice_logo.png new file mode 100644 index 0000000..f0afaa8 Binary files /dev/null and b/invoice_logo.png differ diff --git a/leaf_banner_red.png b/leaf_banner_red.png new file mode 100644 index 0000000..913451e Binary files /dev/null and b/leaf_banner_red.png differ diff --git a/lib/com.lowagie.text-2.1.7.jar b/lib/com.lowagie.text-2.1.7.jar new file mode 100644 index 0000000..870adc4 Binary files /dev/null and b/lib/com.lowagie.text-2.1.7.jar differ diff --git a/lib/commons-beanutils-1.8.3.jar b/lib/commons-beanutils-1.8.3.jar new file mode 100644 index 0000000..218510b Binary files /dev/null and b/lib/commons-beanutils-1.8.3.jar differ diff --git a/lib/commons-digester-2.1.jar b/lib/commons-digester-2.1.jar new file mode 100644 index 0000000..a07cfa8 Binary files /dev/null and b/lib/commons-digester-2.1.jar differ diff --git a/lib/commons-javaflow.jar b/lib/commons-javaflow.jar new file mode 100644 index 0000000..6f8e8db Binary files /dev/null and b/lib/commons-javaflow.jar differ diff --git a/lib/commons-logging-1.1.jar b/lib/commons-logging-1.1.jar new file mode 100644 index 0000000..2ff9bbd Binary files /dev/null and b/lib/commons-logging-1.1.jar differ diff --git a/lib/commons.collections-3.2.1.jar b/lib/commons.collections-3.2.1.jar new file mode 100644 index 0000000..aee7281 Binary files /dev/null and b/lib/commons.collections-3.2.1.jar differ diff --git a/lib/jasperreports-6.6.0.jar b/lib/jasperreports-6.6.0.jar new file mode 100644 index 0000000..07b6c65 Binary files /dev/null and b/lib/jasperreports-6.6.0.jar differ diff --git a/lib/jasperreports-fonts-6.6.0.jar b/lib/jasperreports-fonts-6.6.0.jar new file mode 100644 index 0000000..25e8ba9 Binary files /dev/null and b/lib/jasperreports-fonts-6.6.0.jar differ diff --git a/lib/jasperreports-functions-6.11.0.jar b/lib/jasperreports-functions-6.11.0.jar new file mode 100644 index 0000000..e8c4dd9 Binary files /dev/null and b/lib/jasperreports-functions-6.11.0.jar differ diff --git a/lib/jcommon-1.0.23.jar b/lib/jcommon-1.0.23.jar new file mode 100644 index 0000000..4dbb094 Binary files /dev/null and b/lib/jcommon-1.0.23.jar differ diff --git a/lib/joda-time-2.10.5.jar b/lib/joda-time-2.10.5.jar new file mode 100644 index 0000000..3750fd2 Binary files /dev/null and b/lib/joda-time-2.10.5.jar differ diff --git a/lib/livingdoc-confluence5-plugin-1.1.2.jar b/lib/livingdoc-confluence5-plugin-1.1.2.jar new file mode 100644 index 0000000..b8f4663 Binary files /dev/null and b/lib/livingdoc-confluence5-plugin-1.1.2.jar differ diff --git a/lib/mariadb-java-client-2.5.3-javadoc.jar b/lib/mariadb-java-client-2.5.3-javadoc.jar new file mode 100644 index 0000000..f3be52b Binary files /dev/null and b/lib/mariadb-java-client-2.5.3-javadoc.jar differ diff --git a/lib/mariadb-java-client-2.5.3.jar b/lib/mariadb-java-client-2.5.3.jar new file mode 100644 index 0000000..6d7006f Binary files /dev/null and b/lib/mariadb-java-client-2.5.3.jar differ diff --git a/src/VistaControlador/BarraOpciones.java b/src/VistaControlador/BarraOpciones.java index ed0e213..bfc2424 100644 --- a/src/VistaControlador/BarraOpciones.java +++ b/src/VistaControlador/BarraOpciones.java @@ -22,6 +22,7 @@ public class BarraOpciones extends JMenuBar{ JMenuItem gestion; JMenuItem modificacion; JMenuItem menuInterfaz; + JMenuItem menuInforme; JMenu administracion; JMenuItem aniadirUsuario; @@ -59,6 +60,8 @@ public class BarraOpciones extends JMenuBar{ this.vistas.add(this.modificacion); this.menuInterfaz = new JMenuItem("Gestion tema"); this.vistas.add(this.menuInterfaz); + this.menuInforme = new JMenuItem("Crear Informes"); + this.vistas.add(this.menuInforme); this.administracion = new JMenu("Administracion"); this.add(this.administracion); this.aniadirUsuario = new JMenuItem("Aniadir usuario"); diff --git a/src/VistaControlador/ControladorBarra.java b/src/VistaControlador/ControladorBarra.java index 5f7e9af..f2ab3ce 100644 --- a/src/VistaControlador/ControladorBarra.java +++ b/src/VistaControlador/ControladorBarra.java @@ -94,6 +94,10 @@ public class ControladorBarra implements ActionListener{ this.menu.cambiarVista(this.menu.VISTA_INTERFAZ); break; } + case "Informes":{ + this.menu.cambiarVista(this.menu.VISTA_INFORMES); + break; + } case "Aniadir usuario":{ Vista loggin = new Vista(Vista.Guardar); break; @@ -129,6 +133,8 @@ public class ControladorBarra implements ActionListener{ this.barra.modificacion.setActionCommand("Cambiar Modificar"); this.barra.menuInterfaz.addActionListener(this); this.barra.menuInterfaz.setActionCommand("Ajustar tema"); + this.barra.menuInforme.addActionListener(this); + this.barra.menuInforme.setActionCommand("Informes"); this.barra.aniadirUsuario.addActionListener(this); this.barra.aniadirUsuario.setActionCommand("Aniadir usuario"); } diff --git a/src/VistaControlador/ControladorInforme.java b/src/VistaControlador/ControladorInforme.java new file mode 100644 index 0000000..5ba536f --- /dev/null +++ b/src/VistaControlador/ControladorInforme.java @@ -0,0 +1,115 @@ +package VistaControlador; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.export.JRPdfExporter; +import net.sf.jasperreports.export.SimpleExporterInput; +import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput; +import net.sf.jasperreports.export.SimplePdfExporterConfiguration; +import net.sf.jasperreports.view.JasperViewer; + +public class ControladorInforme implements ActionListener{ + VistaInformes vista; + ModeloInformes modelo; + + public ControladorInforme(VistaInformes vista, ModeloInformes modelo) { + this.vista = vista; + this.modelo = modelo; + for(String anios:this.modelo.anios()) { + this.vista.opciones1_2.addItem(anios); + } + this.iniciarControlador(); + } + + private void iniciarControlador() { + this.vista.exportarInforme1.addActionListener(this); + this.vista.exportarInforme1.setActionCommand("exportar informe 1"); + this.vista.mostrarInforme1.addActionListener(this); + this.vista.mostrarInforme1.setActionCommand("mostrar informe 1"); + this.vista.exportarInforme2.addActionListener(this); + this.vista.exportarInforme2.setActionCommand("exportar informe 2"); + this.vista.mostrarInforme2.addActionListener(this); + this.vista.mostrarInforme2.setActionCommand("mostrar informe 2"); + } + + @Override + public void actionPerformed(ActionEvent ev) { + switch(ev.getActionCommand()) { + case "mostrar informe 1":{ + JasperPrint jasperPrint=null; + try { + Map params = new HashMap(); + params.put("Order", this.vista.opciones1_1.getSelectedItem()); + params.put("Year", this.vista.opciones1_2.getSelectedItem()); + jasperPrint=JasperFillManager.fillReport("Cherry.jasper",params,modelo.controlador); + JasperViewer jasperViewver=new JasperViewer(jasperPrint,false); + jasperViewver.setVisible(true); + } catch (JRException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + + case "exportar informe 1":{ + JasperPrint jasperPrint=null; + try { + Map params = new HashMap(); + params.put("Order", this.vista.opciones1_1.getSelectedItem()); + params.put("Year", this.vista.opciones1_2.getSelectedItem()); + jasperPrint=JasperFillManager.fillReport("Cherry.jasper",params,modelo.controlador); + JRPdfExporter exp=new JRPdfExporter(); + exp.setExporterInput(new SimpleExporterInput(jasperPrint)); + exp.setExporterOutput(new SimpleOutputStreamExporterOutput("Informe1.pdf")); + SimplePdfExporterConfiguration conf=new SimplePdfExporterConfiguration(); + exp.setConfiguration(conf); + exp.exportReport(); + } catch (JRException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + case "mostrar informe 2":{ + JasperPrint jasperPrint=null; + try { + Map params = new HashMap(); + params.put("Order",this.vista.opciones2.getSelectedItem()); + jasperPrint=JasperFillManager.fillReport("Graficos_gastos.jasper",params,modelo.controlador); + JasperViewer jasperViewver=new JasperViewer(jasperPrint,false); + jasperViewver.setVisible(true); + } catch (JRException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + + case "exportar informe 2":{ + JasperPrint jasperPrint=null; + try { + Map params = new HashMap(); + params.put("Order",this.vista.opciones2.getSelectedItem()); + jasperPrint=JasperFillManager.fillReport("Graficos_gastos.jasper",params,modelo.controlador); + JRPdfExporter exp=new JRPdfExporter(); + exp.setExporterInput(new SimpleExporterInput(jasperPrint)); + exp.setExporterOutput(new SimpleOutputStreamExporterOutput("Informe2.pdf")); + SimplePdfExporterConfiguration conf=new SimplePdfExporterConfiguration(); + exp.setConfiguration(conf); + exp.exportReport(); + } catch (JRException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + } + + } +} diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 12bb7fd..9ac0f57 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -31,7 +31,8 @@ import loggin.Vista; public class Menu extends JFrame{ static final int VISTA_MODIFICAR = 0; static final int VISTA_GESTION = 1; - static final int VISTA_INTERFAZ =2; + static final int VISTA_INTERFAZ = 2; + static final int VISTA_INFORMES = 3; JPanel panelCentral; JTabbedPane pestania; @@ -39,6 +40,7 @@ public class Menu extends JFrame{ VistaAniadirVisualizar gastos; VistaPanelGestion panelGestion; VistaPanelModificar panelModificar; + VistaInformes vista; VistaPanel panel; String rutaGuardado; int tema; @@ -84,6 +86,7 @@ public class Menu extends JFrame{ this.panelGestion = new VistaPanelGestion(this.meses); this.panelModificar = new VistaPanelModificar(); this.panelInterfaz = new VistaPanelInterfaz(); + this.vista = new VistaInformes(); this.panel = this.panelGestion; constrain.fill = GridBagConstraints.HORIZONTAL; @@ -107,6 +110,7 @@ public class Menu extends JFrame{ ControladorPanelGestion controlador3 = new ControladorPanelGestion(this.panelGestion, this); ControladorPanelModificar controlador4 = new ControladorPanelModificar(this.panelModificar, this); ControladorPanelInterfaz controlador5 = new ControladorPanelInterfaz(this.panelInterfaz, this); + ControladorInforme controlador6 = new ControladorInforme(this.vista, new ModeloInformes()); this.listenerPestania(); this.elegirMes = new DatePicker(); @@ -379,6 +383,9 @@ public class Menu extends JFrame{ this.panel = this.panelInterfaz; break; } + case Menu.VISTA_INFORMES:{ + this.panel = this.vista; + } } this.panelCentral.add(this.panel,constrain); this.panel.repaint(); diff --git a/src/VistaControlador/ModeloInformes.java b/src/VistaControlador/ModeloInformes.java new file mode 100644 index 0000000..fa0b293 --- /dev/null +++ b/src/VistaControlador/ModeloInformes.java @@ -0,0 +1,38 @@ +package VistaControlador; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Vector; + +public class ModeloInformes { + Connection controlador; + ModeloInformes(){ + String url="jdbc:mariadb://localhost:3306/informes?user=root&password=1234"; + try { + this.controlador=DriverManager.getConnection(url); + + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + Vector anios() { + Vector ret = new Vector(); + String query = "select distinct year(transacciones.fecha) from transacciones;"; + try { + PreparedStatement stmt = this.controlador.prepareStatement(query); + ResultSet resultado = stmt.executeQuery(); + while(resultado.next()) { + ret.add(resultado.getString(1)); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ret; + } +} diff --git a/src/VistaControlador/VistaInformes.java b/src/VistaControlador/VistaInformes.java new file mode 100644 index 0000000..a3fddbe --- /dev/null +++ b/src/VistaControlador/VistaInformes.java @@ -0,0 +1,65 @@ +package VistaControlador; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; + +public class VistaInformes extends VistaPanel{ + JButton mostrarInforme1; + JButton exportarInforme1; + JButton mostrarInforme2; + JButton exportarInforme2; + + JComboBox opciones1_1; + JComboBox opciones1_2; + JComboBox opciones2; + public VistaInformes() { + + + super(); + this.setLayout(new GridBagLayout()); + GridBagConstraints constrain = new GridBagConstraints(); + + constrain.gridx = 0; + constrain.gridy = 0; + this.mostrarInforme1 = new JButton("Mostrar 1"); + this.add(mostrarInforme1,constrain); + constrain.gridx = 0; + constrain.gridy = 1; + this.exportarInforme1 = new JButton("Exportar 1"); + this.add(exportarInforme1,constrain); + this.opciones1_1 = new JComboBox(); + constrain.gridx = 0; + constrain.gridy = 2; + this.add(opciones1_1, constrain); + this.opciones1_2 = new JComboBox(); + constrain.gridx = 0; + constrain.gridy = 3; + this.add(opciones1_2, constrain); + + constrain.gridx = 1; + constrain.gridy = 0; + this.mostrarInforme2 = new JButton("Mostrar 2"); + this.add(mostrarInforme2,constrain); + constrain.gridx = 1; + constrain.gridy = 1; + this.exportarInforme2 = new JButton("Exportar 2"); + this.add(exportarInforme2,constrain); + constrain.gridx = 1; + constrain.gridy = 2; + this.opciones2 = new JComboBox(); + this.add(opciones2, constrain); + + this.cargarComb(); + } + + private void cargarComb() { + this.opciones2.addItem("id"); + this.opciones2.addItem("usuario"); + this.opciones1_1.addItem("fecha"); + this.opciones1_1.addItem("usuario"); + } +}