package br.dsc.upe.poli.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

import br.dsc.upe.poli.banco.ConexaoFactory;

public class ReportTest {

	public static void main(String[] args) throws Exception {
		relatorio();
		
		
	}

	public static void relatorio() throws ClassNotFoundException,
			SQLException, JRException {
		ConexaoFactory conexaoFactory = new ConexaoFactory();
		Connection conn= conexaoFactory.getConexao();
		String sql = "select distinct nome_aluno,resp.login,pergunta,resposta from resposta as resp,validacao_table as va, alunos_table as al where resp.login = va.login and identidade_aluno = va.identidade AND nome_aluno='Maria' ";
		ResultSet rs = conn.createStatement().executeQuery(sql);
		geraRelatorio(sql, conn, rs);
	}

	public static void geraRelatorio(String sql,Connection conn, ResultSet rs)
			throws JRException {
		JRResultSetDataSource jr = new JRResultSetDataSource(rs);
		System.out.println("JR RESULT");
		JasperPrint jp = JasperFillManager.fillReport("relatorios/alunos.jasper", null, jr);
		
		//JasperFillManager.fillReportToFile("relatorios/alunos.jrxml", null, jp);
		JasperViewer.viewReport(jp,false);
		System.out.println("View");
		//JasperExportManager.exportReportToHtmlFile(jp, "relatorios/alunos.html");
		JasperExportManager.exportReportToPdfFile(jp,"relatorios/alunosNovo.pdf");
	
		//JasperViewer.viewReport("relatorios/alunos.jrprint", false);
	}
}
