public ArrayList<Empleado> listarEmpleado() {
   ArrayList<Empleado> emple = new ArrayList<Empleado>();
   try {
     cn = Conexion.realizarConexion();
     st = cn.createStatement();
     String sql = "select * from empleado";
     rs = st.executeQuery(sql);
     while (rs.next()) {
       emple.add(
           new Empleado(
               rs.getString(1),
               rs.getString(2),
               rs.getString(3),
               rs.getString(4),
               rs.getString(5),
               rs.getString(6),
               rs.getString(7),
               rs.getString(8)));
     }
   } catch (ClassNotFoundException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } catch (SQLException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } finally {
     try {
       rs.close();
       st.close();
       cn.close();
     } catch (Exception ex) {
       showMessageDialog(null, ex.getMessage(), "Excepción", 0);
     }
   }
   return emple;
 }
 public String buscarEmpleado(String codigo) {
   try {
     cn = Conexion.realizarConexion();
     st = cn.createStatement();
     String sql =
         "select chr_emplcodigo from empleado " + " where chr_emplcodigo = '" + codigo + "'";
     rs = st.executeQuery(sql);
     while (rs.next()) {
       return rs.getString("chr_emplcodigo");
     }
   } catch (ClassNotFoundException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } catch (SQLException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } finally {
     try {
       rs.close();
       st.close();
       cn.close();
     } catch (Exception ex) {
       showMessageDialog(null, ex.getMessage(), "Excepción", 0);
     }
   }
   return null;
 }
 public String insertarEmpleado(Empleado empleado) {
   String mensaje = null;
   try {
     cn = Conexion.realizarConexion();
     String sql = "insert into empleado values(?,?,?,?,?,?,?,?)";
     ps = cn.prepareStatement(sql);
     ps.setString(1, empleado.getCodigo());
     ps.setString(2, empleado.getPaterno());
     ps.setString(3, empleado.getMaterno());
     ps.setString(4, empleado.getNombre());
     ps.setString(5, empleado.getCiudad());
     ps.setString(6, empleado.getDireccion());
     ps.setString(7, empleado.getUsuario());
     ps.setString(8, empleado.getClave());
     ps.executeUpdate();
   } catch (ClassNotFoundException ex) {
     mensaje = ex.getMessage();
   } catch (SQLException ex) {
     mensaje = ex.getMessage();
   } finally {
     try {
       ps.close();
       cn.close();
     } catch (Exception ex) {
       mensaje = ex.getMessage();
     }
   }
   return mensaje;
 }
  public void ejecutarReporte(String codigo) {
    try {
      cn = Conexion.realizarConexion();
      String master = System.getProperty("user.dir") + "\\src\\reportes\\reporteEmpleado.jasper";
      System.out.println("master: " + master);
      if (master == null) {
        showMessageDialog(null, "No se encontro el archivo", "Error", 0);
        System.exit(2);
      }

      JasperReport masterReport = null;
      try {
        masterReport = (JasperReport) JRLoader.loadObject(master);
      } catch (JRException ex) {
        showMessageDialog(null, "MasterReport:" + ex.getMessage(), "Error", 0);
        System.exit(3);
      }

      Map parametro = new HashMap();
      parametro.put("chr_emplcodigo", codigo);

      JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, parametro, cn);

      JasperViewer jviewer = new JasperViewer(jasperPrint, false);
      jviewer.setTitle("Reporte");
      jviewer.setVisible(true);
    } catch (ClassNotFoundException ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } catch (SQLException ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } catch (Exception ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } finally {
      try {
        cn.close();
      } catch (Exception ex) {
        showMessageDialog(null, ex.getMessage(), "Error", 0);
      }
    }
  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      Locales.setCurrent(request);
      if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP
        Users.setCurrent((String) request.getSession().getAttribute("xava.user"));
      }
      request.getParameter("application"); // for a bug in websphere 5.1
      request.getParameter("module"); // for a bug in websphere 5.1
      Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
      int[] selectedRowsNumber =
          (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab");
      Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab");
      int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab);
      request.getSession().removeAttribute("xava_selectedRowsReportTab");
      Integer columnCountLimit =
          (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab");
      request.getSession().removeAttribute("xava_columnCountLimitReportTab");

      setDefaultSchema(request);
      String user = (String) request.getSession().getAttribute("xava_user");
      request.getSession().removeAttribute("xava_user");
      Users.setCurrent(user);
      String uri = request.getRequestURI();
      if (uri.endsWith(".pdf")) {
        InputStream is;
        JRDataSource ds;
        Map parameters = new HashMap();
        synchronized (tab) {
          tab.setRequest(request);
          parameters.put("Title", tab.getTitle());
          parameters.put("Organization", getOrganization());
          parameters.put("Date", getCurrentDate());
          for (String totalProperty : tab.getTotalPropertiesNames()) {
            parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty));
          }
          TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null);
          tableModel.getValueAt(0, 0);
          if (tableModel.getRowCount() == 0) {
            generateNoRowsPage(response);
            return;
          }
          is = getReport(request, response, tab, tableModel, columnCountLimit);
          ds = new JRTableModelDataSource(tableModel);
        }
        JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds);
        response.setContentType("application/pdf");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\"");
        JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream());
      } else if (uri.endsWith(".csv")) {
        String csvEncoding = XavaPreferences.getInstance().getCSVEncoding();
        if (!Is.emptyString(csvEncoding)) {
          response.setCharacterEncoding(csvEncoding);
        }
        response.setContentType("text/x-csv");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\"");
        synchronized (tab) {
          tab.setRequest(request);
          response
              .getWriter()
              .print(
                  TableModels.toCSV(
                      getTableModel(request, tab, selectedRows, true, false, columnCountLimit)));
        }
      } else {
        throw new ServletException(
            XavaResources.getString("report_type_not_supported", "", ".pdf .csv"));
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new ServletException(XavaResources.getString("report_error"));
    } finally {
      request.getSession().removeAttribute("xava_reportTab");
    }
  }
Ejemplo n.º 6
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ServletOutputStream servletOutputStream = response.getOutputStream();
    JasperReport jasperReport;
    JasperPrint jasperPrint;

    Connection conn = null;

    try {

      Context ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:jboss/datasources/BuffaloDS");
      conn = ds.getConnection();

      if (conn != null) {
        System.out.println("Conexion Exitosa JDBC com.edb.Driver...");
      } else {
        System.out.println("Error Conexion JDBC com.edb.Driver...");
      }

    } catch (Exception e) {
      // TODO: handle exception
      System.out.println("Error al conectar JDBC: " + e.getMessage());
    }

    try {
      String pUsuario = request.getParameter("pUsuario");
      String pSucursal = request.getParameter("pSucursal");
      String pId = request.getParameter("pId");

      System.out.println("Parametros Reporte: ......");
      System.out.println("pUsuario: " + pUsuario);
      System.out.println("pSucursal: " + pSucursal);
      System.out.println("pId : " + pId);

      System.out.println("Conexion em: " + em.isOpen());

      @SuppressWarnings("deprecation")
      String realPath = request.getRealPath("/");
      System.out.println("Real Path: " + realPath);

      // load JasperDesign from XML and compile it into JasperReport
      System.out.println(
          "Context getServletContext: " + request.getServletContext().getContextPath());
      System.out.println("Context getServletPath: " + request.getServletPath());
      System.out.println(
          "Context getSession().getServletContext(): "
              + request.getSession().getServletContext().getRealPath("/"));

      String urlPath = request.getRequestURL().toString();
      urlPath =
          urlPath.substring(0, urlPath.length() - request.getRequestURI().length())
              + request.getContextPath()
              + "/";
      System.out.println("URL ::::: " + urlPath);

      String rutaReporte =
          urlPath + "resources/report/OrdenesIngreso/reporteTraspasoMateriaPrima.jasper";
      System.out.println("rutaReporte: " + rutaReporte);

      String rutaImagen = urlPath + "resources/gfx/Medipiel-Logo.jpg";
      System.out.println("RutaImagen: " + rutaImagen);
      String SUBREPORT_DIR = urlPath + "resources/report/OrdenesIngreso/";
      System.out.println("SUBREPORT_DIR: " + SUBREPORT_DIR);

      // create a map of parameters to pass to the report.
      Map parameters = new HashMap();
      parameters.put("SUBREPORT_DIR", SUBREPORT_DIR);
      parameters.put("usuario", pUsuario);
      /*parameters.put("pSucursal", new Integer(pSucursal));*/
      parameters.put("ID", new Integer(pId));
      // parameters.put("pRutaImagen", rutaImagen);

      // find file .jasper
      jasperReport = (JasperReport) JRLoader.loadObject(new URL(rutaReporte));

      // fill JasperPrint using fillReport() method
      jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

      // save report to path
      // JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/etiquetas/Etiqueta+"+pCodigoPre+"-"+pNombreElaborado+".pdf");
      response.setContentType("application/pdf");
      JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);

      servletOutputStream.flush();
      servletOutputStream.close();

    } catch (Exception e) {
      // display stack trace in the browser
      e.printStackTrace();
      System.out.println("Error al ingresar RerpoteVentas: " + e.getMessage());
      StringWriter stringWriter = new StringWriter();
      PrintWriter printWriter = new PrintWriter(stringWriter);
      e.printStackTrace(printWriter);
      response.setContentType("text/plain");
      response.getOutputStream().print(stringWriter.toString());
    }
  }
Ejemplo n.º 7
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ServletOutputStream servletOutputStream = response.getOutputStream();
    JasperReport jasperReport;
    JasperPrint jasperPrint;

    Connection conn = null;

    Properties props = new Properties();

    //        FacesContext.getCurrentInstance().responseComplete();
    try {
      Context ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:jboss/datasources/BuffaloDS");
      conn = ds.getConnection();

      if (conn != null) {
        System.out.println("Conexion Exitosa JDBC com.edb.Driver...");
      } else {
        System.out.println("Error Conexion JDBC com.edb.Driver...");
      }

    } catch (Exception e) {
      // TODO: handle exception
      System.out.println("Error al conectar JDBC: " + e.getMessage());
    }

    try {
      String pPaciente = request.getParameter("pPaciente");
      String pCodigoPre = request.getParameter("pCodigoPre");
      String pNombreElaborado = request.getParameter("pNombreElaborado");
      String pPresentacion = request.getParameter("pPresentacion");
      String pMedico = request.getParameter("pMedico");
      String pUso = request.getParameter("pUso");
      String pConservacion = request.getParameter("pConservacion");
      String pFechaElaboracion = request.getParameter("pFechaElaboracion");
      String pFechaVencimiento = request.getParameter("pFechaVencimiento");

      System.out.println("Parametros Reporte: ......");
      System.out.println("pPaciente: " + pPaciente);
      System.out.println("pCodigoPre: " + pCodigoPre);
      System.out.println("pNombreElaborado: " + pNombreElaborado);
      System.out.println("pPresentacion: " + pPresentacion);
      System.out.println("pMedico: " + pMedico);
      System.out.println("pUso: " + pUso);
      System.out.println("pConservacion: " + pConservacion);
      System.out.println("pFechaElaboracion: " + pFechaElaboracion);
      System.out.println("pFechaVencimiento: " + pFechaVencimiento);

      System.out.println("Conexion em: " + em.isOpen());

      @SuppressWarnings("deprecation")
      String realPath = request.getRealPath("/");
      System.out.println("Real Path: " + realPath);

      // load JasperDesign from XML and compile it into JasperReport
      System.out.println(
          "Context getServletContext: " + request.getServletContext().getContextPath());
      System.out.println("Context getServletPath: " + request.getServletPath());
      System.out.println(
          "Context getSession().getServletContext(): "
              + request.getSession().getServletContext().getRealPath("/"));

      String urlPath = request.getRequestURL().toString();
      urlPath =
          urlPath.substring(0, urlPath.length() - request.getRequestURI().length())
              + request.getContextPath()
              + "/";
      System.out.println("URL ::::: " + urlPath);

      // create a map of parameters to pass to the report.
      Map parameters = new HashMap();
      parameters.put("pPaciente", pPaciente);
      parameters.put("pCodigoPre", pCodigoPre);
      parameters.put("pNombreElaborado", pNombreElaborado);
      parameters.put("pPresentacion", pPresentacion);
      parameters.put("pMedico", pMedico);
      parameters.put("pUso", pUso);
      parameters.put("pConservacion", pConservacion);
      parameters.put("pFechaElaboracion", pFechaElaboracion);
      parameters.put("pFechaVencimiento", pFechaVencimiento);

      String rutaReporte = urlPath + "resources/report/EtiquetaGrande.jasper";
      System.out.println("rutaReporte: " + rutaReporte);

      // find file .jasper
      jasperReport = (JasperReport) JRLoader.loadObject(new URL(rutaReporte));

      // fill JasperPrint using fillReport() method
      jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

      //        		//save report to path
      //
      //	JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/etiquetas/Etiqueta+"+pCodigoPre+"-"+pNombreElaborado+".pdf");
      response.setContentType("application/pdf");
      JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);

      servletOutputStream.flush();
      servletOutputStream.close();

    } catch (Exception e) {
      // display stack trace in the browser
      e.printStackTrace();
      System.out.println("Error al ingresar ReporteEtiquetaGrande: " + e.getMessage());
      StringWriter stringWriter = new StringWriter();
      PrintWriter printWriter = new PrintWriter(stringWriter);
      e.printStackTrace(printWriter);
      response.setContentType("text/plain");
      response.getOutputStream().print(stringWriter.toString());
    }
  }