Ejemplo n.º 1
1
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      // com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Orders - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(7);

            int headerwidths[] = {12, 10, 30, 30, 8, 8, 12};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(5);

            Phrase phrase = new Phrase("Orders list as at: " + endDate, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
            table.getDefaultCell().setColspan(2);
            phrase = new Phrase("Printed on : " + date, pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
            phrase = new Phrase("Order No", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Date Due", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Supplier", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Item", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Units", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Qty", pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
            phrase = new Phrase("Net Value", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.lang.Object[] listofAct = this.getListofActivities();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();

              for (int i = 0; i < listofAct.length; i++) {
                int w = 0;
                java.sql.ResultSet rset3 =
                    st3.executeQuery(
                        "SELECT DISTINCT order_no,date_due AS date,supplier from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY date");

                java.sql.ResultSet rset =
                    st.executeQuery(
                        "SELECT item,units,quantity,net_value from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY item");
                java.sql.ResultSet rsetTotals =
                    st2.executeQuery(
                        "SELECT SUM(net_value) from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "'  AND order_no = '"
                            + listofAct[i].toString()
                            + "'");

                while (rset3.next()) {
                  while (rset.next()) {
                    w = w + 1;

                    if (w == 1) {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(2).toString(), pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(3).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);

                    } else {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);
                    }
                  }
                }
                // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                // table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

                while (rsetTotals.next()) {

                  table.getDefaultCell().setColspan(5);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  phrase = new Phrase("Total", pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                  phrase = new Phrase((""), pFontHeader);

                  table.addCell(phrase);

                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rsetTotals.getString(1)),
                          pFontHeader);

                  table.addCell(phrase);
                }
              }
              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Ejemplo n.º 2
1
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          try {

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();
            java.sql.Statement st2x = connectDB.createStatement();

            java.sql.ResultSet rset2x =
                st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
            while (rset2x.next()) {
              ks = rset2x.getObject(1).toString();
            }
            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Price List - Page: "),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(5);

            int headerwidths[] = {20, 50, 30, 30, 30};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            // table.setHeaderRows(2);

            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

            Phrase phrase = new Phrase(" ");
            //  table.addCell(phrase);

            try {
              table.getDefaultCell().setColspan(5);
              phrase = new Phrase("Departmental Price List ");
              table.addCell(phrase);
              table.getDefaultCell().setColspan(4);
              java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset3 =
                  st2.executeQuery(
                      "SELECT DISTINCT activity FROM pb_activity WHERE code ILIKE  '" + bank + "'");

              while (rset3.next()) {
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                phrase =
                    new Phrase(
                        rset3.getString(1).toUpperCase()
                            + " - "
                            + bank
                            + " Price List as at : "
                            + date,
                        pFontHeader);

                table.addCell(phrase);
              }
              //  Phrase phrase = new Phrase(bank +"    Balance Report"    +"  as at : "  +endDate,
              // pFontHeader);

              //  table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase = new Phrase("Printed on : " + date, pFontHeader);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("CODE", pFontHeader);
              table.addCell(phrase);

              //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase("DESCRIPTION", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              // phrase = new Phrase("",pFontHeader);
              // table.addCell(phrase);

              phrase = new Phrase("Norminal Rate (E.A) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("Special Rate (PRIVATE) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("NON E.A " + ks, pFontHeader);
              table.addCell(phrase);

              // phrase = new Phrase("Credit KShs.",pFontHeader);
              // table.addCell(phrase);

              // table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
              // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              double osBalance = 0.00;

              //  java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              java.sql.Statement st = connectDB.createStatement();

              //  java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "SELECT code, upper(service_type), rate, anaesthetist_rate,other_prices FROM pb_operating_parameters WHERE gl_account ilike  '"
                          + bank
                          + "' order by service_type");

              while (rset.next()) {
                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                table.addCell(phrase);

                //  table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(3)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(4)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);
              }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  processDNSForWindowsIpv6(String dnsone, String dnstwo) throws SocketException, IOException {
    System.out.println("This is Windows");
    // change ip configuration using netsh command
    if (uddhavcombobox.getSelectedItem().equals("wlan0")) {
      nameinterface = "Wireless Network Connection";
      //                            netsh interface ip set dns "Local Area Connection" static
      // 192.168.0.200
      //                            netsh dnsclient add dnsserver "Local Area Connection"
      // 192.168.137.202 1
      //                            netsh dnsclient add dnsserver "Local Area Connection"
      // 192.168.137.200 2
      //                            netsh interface ipv6 add dnsserver "Local Area Connection"
      // 2001:db8::99:4acd::8
      //                            netsh interface ipv6 add dns "Ethernet" 2401:ddc0:60::1
      //                            2620:0:ccc::2
      //                            2620:0:ccd::2
      //                            google-public-dns-a.google.com has IPv6 address
      // 2001:4860:4860::8888
      command1 = "netsh interface ipv6 add dns  \"" + nameinterface + "\" " + dnsone + " index=1";
      command2 = "netsh interface ipv6 add dns  \"" + nameinterface + "\" " + dnstwo + " index=2";

      try {
        Runtime r = java.lang.Runtime.getRuntime();
        Process p1 = r.exec(command1);
        Process p2 = r.exec(command2);
        System.out.println(command1);
        System.out.println(command2);
      } catch (IOException e1) {
        System.out.println(e1.getMessage());
      }
    }
    if (uddhavcombobox.getSelectedItem().equals("eth0")) {
      nameinterface = "Local Area Connection";
      //                            netsh interface ip set dns "Local Area Connection" static
      // 192.168.0.200
      //                            netsh dnsclient add dnsserver "Local Area Connection"
      // 192.168.137.202 1
      //                            netsh dnsclient add dnsserver "Local Area Connection"
      // 192.168.137.200 2
      command1 = "netsh interface ipv6 add dns  \"" + nameinterface + "\" " + dnsone + " index=1";
      command2 = "netsh interface ipv6 add dns  \"" + nameinterface + "\" " + dnstwo + " index=2";

      try {
        Runtime r = java.lang.Runtime.getRuntime();
        Process p1 = r.exec(command1);
        Process p2 = r.exec(command2);
        System.out.println(command1);
        System.out.println(command2);
      } catch (IOException e1) {
        System.out.println(e1.getMessage());
      }
    }
  }
Ejemplo n.º 4
0
  public static void main(String argv[]) {

    BMDriver bmt = new BMDriver();
    boolean dbstatus;

    dbstatus = bmt.runTests();

    if (dbstatus != true) {
      System.err.println("Error encountered during buffer manager tests:\n");
      Runtime.getRuntime().exit(1);
    }

    Runtime.getRuntime().exit(0);
  }
  // Java Client for GeoNames Webservices
  private String getPhysicalPlaceOnGeonames(double lat, double lng) {
    String sPlaceName = "";
    String sGeoNameId = "";
    String hostname = "www.geonames.org";
    try {
      Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 " + hostname);
      int returnVal = p1.waitFor();
      boolean reachable = (returnVal == 0);

      if (reachable) {
        WebService.setUserName("betaas");

        PostalCodeSearchCriteria postalCodeSearchCriteria = new PostalCodeSearchCriteria();
        postalCodeSearchCriteria.setLatitude(lat);
        postalCodeSearchCriteria.setLongitude(lng);
        List<Toponym> placeNames = WebService.findNearbyPlaceName(lat, lng);
        for (int i = 0; i < placeNames.size(); i++) {
          sGeoNameId = String.valueOf(placeNames.get(i).getGeoNameId());
          sPlaceName = "<" + PREFIX_GEONAMES + sGeoNameId + ">";
        }
      }
      //      else
      //        mLogger.info("[CM] Adaptation Context Manager, Geonames function. Service " +
      // hostname + " unavailable.");
    } catch (Exception e) {
      //      mLogger
      //          .error("[CM] Adaptation Context Manager, Geonames function. It has not been
      // executed correctly. Probably there is not Internet connection.");
    }
    return sPlaceName;
  }
 /**
  * @param maximumNumberOfIteration the maximum number of iteration
  * @param writeStepNumber flag that indicates whether the step number has to written to the
  *     simulation input file (<CODE>true</CODE>) or not <CODE>false</CODE>
  * @param unitsOfExecution the maximum number of units of executions to be used
  */
 public OptimizationSettings(
     int maximumNumberOfIteration, boolean writeStepNumber, int unitsOfExecution) {
   maxIteration = maximumNumberOfIteration;
   wriSteNum = writeStepNumber;
   uniOfExe = unitsOfExecution;
   if (uniOfExe < 1) uniOfExe = java.lang.Runtime.getRuntime().availableProcessors();
 }
/** Default values for main parameters */
public class DefaultConfigIRValues {

  /** Constant for test status passed */
  public static final String R_PASSED = "104";
  /** Constant for test status failed */
  public static final String R_FAILED = "105";
  /** Constant for test status error */
  public static final String R_ERROR = "106";
  /** Constant for test status skipped */
  public static final String R_SKIPPED = "107";

  public static final String REPORTER_PLUGIN_NAME = "Reporter";
  public static final String REPORTER_PLUGIN_CLASS = "org.apache.harmony.harness.plugins.Reporter";
  public static final String[][] DEFAULT_EXEC_STATUSES = {
    {"passed", R_PASSED}, {"failed", R_FAILED}, {"error", R_ERROR}, {"moderror", R_SKIPPED}
  };

  /** Constant for default logging level */
  public static final Level DEFAULT_LOG_LEVEL = Level.INFO;
  /** Constant for default timeout (in seconds) */
  public static final int DEFAULT_TIMEOUT = 600;
  /** Constant for default execution mode (each test in new vm) */
  public static final boolean DEFAULT_EXEC_MODE = Main.OTHER;
  /** Constant for default execution location (on current computer) */
  public static final boolean DEFAULT_EXEC_LOCATION = Main.LOCAL;
  /** Constant for default competition rate (number of test which can be run simultaneously) */
  public static final int DEFAULT_COMPETITION =
      java.lang.Runtime.getRuntime().availableProcessors();

  /** Constant for test suite root */
  public static final String DEFAULT_TEST_SUITE_ROOT = System.getProperty("user.dir");
  /** Constant for temporary directory */
  public static final String DEFAULT_TMP_DIR =
      System.getProperty("user.dir") + File.separator + "toDelete";
  /** Constant for results root */
  public static final String RESULT_DIR =
      System.getProperty("user.dir") + File.separator + "results";
  /** Constant for tested runtime */
  public static final String TESTED_RUNTIME = "java";
  /** Constant for tested compile */
  public static final String TESTED_COMPILE = "javac";
  /** Constant for reference runtime */
  public static final String REFERENCE_RUNTIME = "java";

  public static final String EUNIT_PLUGIN_CLASS = "ExecUnit";
  public static final String EUNIT_CLASS_NAME = "org.apache.harmony.harness.ExecUnit";
  public static final String[][] RUNNERS_MAP = {
    {"Runtime", "org.apache.harmony.harness.plugins.Run"},
    {"RuntimeNegative", "org.apache.harmony.harness.plugins.RunNeg"},
    {"CompileNegative", "org.apache.harmony.harness.plugins.Comp"},
    {"CompileRuntime", "org.apache.harmony.harness.plugins.CompRun"},
    {"ExecuteNegative", "org.apache.harmony.harness.plugins.Exec"},
    {"Execute", "org.apache.harmony.harness.plugins.ExecRun"},
    {"MultiCase", "org.apache.harmony.harness.plugins.MultiCase"},
    {"JPDARunner", "org.apache.harmony.harness.plugins.JPDARunner"},
    {"DistributedRunner", "org.apache.harmony.harness.plugins.DistributedRunner"},
    {"JUExec", "org.apache.harmony.harness.plugins.JUExec"},
    {"GroupRunner", "org.apache.harmony.harness.plugins.RunGroupInThreads"}
  };
}
Ejemplo n.º 8
0
  /**
   * 1. destroy java process then Process.exitValue 2. waitFor java process then Process.exitValue,
   * Process.exitValue 3. destroy "java -version" process then Process.exitValue, Process.exitValue
   */
  public void test_3() {
    System.out.println("==test_3===");
    if (RuntimeAdditionalTest0.os.equals("Unk")) {
      fail("WARNING (test_3): unknown operating system.");
    }
    Process pi3 = null;
    try {

      String cmnd = RuntimeAdditionalTest0.javaStarter;
      pi3 = Runtime.getRuntime().exec(cmnd);
      pi3.destroy();
      /*System.out.println(*/ pi3.exitValue() /*)*/;
    } catch (Exception eeee) {
      // eeee.printStackTrace();
      while (true) {
        try {
          /*System.out.println(=ntln("XXX: " + */ pi3.exitValue() /*)*/;
          break;
        } catch (IllegalThreadStateException e) {
          continue;
        }
      }
    }
    /*System.out.println("YYY: " + */ pi3.exitValue() /*)*/;
    try {

      String cmnd = RuntimeAdditionalTest0.javaStarter;
      pi3 = Runtime.getRuntime().exec(cmnd);
      /*System.out.println(*/ pi3.waitFor() /*)*/;
      /*System.out.println(*/ pi3.exitValue() /*)*/;
      /*System.out.println(*/ pi3.exitValue() /*)*/;
    } catch (Exception eeee) {
      eeee.printStackTrace();
      fail("ERROR (test_3): unexpected exception.");
    }
    try {

      String cmnd = RuntimeAdditionalTest0.javaStarter + " -version";
      pi3 = Runtime.getRuntime().exec(cmnd);
      /*System.out.println(*/ pi3.waitFor() /*)*/;
      /*System.out.println(*/ pi3.exitValue() /*)*/;
      /*System.out.println(*/ pi3.exitValue() /*)*/;
    } catch (Exception eeee) {
      eeee.printStackTrace();
      fail("ERROR (test_3): unexpected exception.");
    }
  }
Ejemplo n.º 9
0
 private static void abortAllSlaves() {
   try {
     java.lang.Runtime.getRuntime().exec(PerfConf.get().DFS_PERF_HOME + "/bin/dfs-perf-abort");
   } catch (IOException e) {
     e.printStackTrace();
     LOG.error(e);
   }
 }
Ejemplo n.º 10
0
  public static void main(String[] args) throws Exception {

    FirefoxDriver driver = new FirefoxDriver();
    driver.get("http://docs.seleniumhq.org/");
    driver.findElement(By.linkText("Download")).click();
    driver.findElement(By.linkText("2.47.1")).click();
    Thread.sleep(3000);
    java.lang.Runtime.getRuntime().exec("f:\\seleniumhq.exe");
  }
Ejemplo n.º 11
0
 public static void execution() {
   try {
     Runtime.getRuntime().exec("bash  BotsBall/caml/lancer.sh " + getCheminFichier());
   } catch (IOException e) {
     System.out.println("errrrreur");
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Ejemplo n.º 12
0
  /**
   * Load the the versioned libs
   *
   * @return void
   */
  private void createLibsAliases() {
    // fill this array with the name of the lib and the needed versioned
    // name
    String[][] libraries = {{"libproj.so", "libproj.so.0"}
      // ,{"libgdal.so","libgdal.so.2"}
    };

    for (int i = 0; i < libraries.length; i++) {
      File lib = new File("/data/data/org.qgis.qgis/lib/" + libraries[i][0]);
      String aliasName = libraries[i][1];
      String aliasPath = getFilesDir() + "/" + aliasName;

      try {
        File alias = new File(aliasPath);
        if (!alias.exists()) {
          try {
            String str = "ln -s " + lib.getAbsolutePath() + " " + aliasPath;
            Process process = Runtime.getRuntime().exec(str);
            int res = process.waitFor();
            process.destroy();
            if (res != 0) {
              Log.i(QtTAG, "Can't use symlinks, copying '" + aliasName + " to " + aliasPath);
              try {

                BufferedOutputStream out =
                    new BufferedOutputStream(openFileOutput(aliasName, MODE_PRIVATE));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(lib));
                byte[] buff = new byte[32 * 1024];
                int len;
                while ((len = in.read(buff)) > 0) {
                  out.write(buff, 0, len);
                }
                out.flush();
                out.close();
              } catch (IOException e) {
                Log.w("ExternalStorage", "Error writing " + aliasPath, e);
              }
            } else {
              Log.i(QtTAG, "Symlinked '" + lib.getAbsolutePath() + "' to '" + aliasPath + "'");
            }

          } catch (SecurityException e) {
            Log.i(QtTAG, "Can't symlink '" + aliasName + "'", e);
          }
        }
        Log.i(QtTAG, "Loading '" + aliasPath + "'");
        System.load(aliasPath);
      } catch (SecurityException e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      } catch (Exception e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      }
    }
  }
Ejemplo n.º 13
0
 public Boolean isOnline() {
   try {
     Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
     int returnVal = p1.waitFor();
     boolean reachable = (returnVal == 0);
     return reachable;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
Ejemplo n.º 14
0
 /**
  * print profiling information, i.e. do a restart and print the last elapsed time if not in quiet
  * mode
  */
 public void profile(String s) {
   restart();
   if (Global.PROFILE > 0)
     System.out.println(
         s
             + " "
             + ts_elapsed
             + " ms"
             + ((Global.PROFILE > 1)
                 ? " [mem free " + Runtime.getRuntime().freeMemory() + "]"
                 : ""));
 };
  /* sets the parts of speech for each node in the graph */
  public void addPOS() {
    System.out.println("Running POS tagger...");
    /* parameters for exec command */
    File dir = new File("/home/josh/Desktop/Artificial_Intelligence/POS_Tagger");
    /* where we are placing the file to parse */
    File result = new File(file.toString() + ".pos");
    int i = 1;
    String s = null, data = "";
    try {
      /* command to run the POS tagger */
      String command =
          "java -mx300m -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/"
              + "bidirectional-distsim-wsj-0-18.tagger -textFile "
              + file.toString();

      /* run the process */
      Process p = Runtime.getRuntime().exec(command, null, dir);
      i = p.waitFor();

      BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

      /* extract the data from the command */

      while ((s = stdInput.readLine()) != null) {
        /* copy the data into one string */
        data += s;
      }
      /* place the data in a .pos text file */
      byte[] buffer = data.getBytes();
      FileOutputStream fout = new FileOutputStream(result, false);
      fout.write(buffer);
      fout.close();

      /* read any errors from the attempted command */
      while ((s = stdError.readLine()) != null) {
        System.out.println(s);
      }

    } catch (Exception e) {
      System.out.println("Exception happened - here's what I know: ");
      e.printStackTrace();
      System.exit(-1);
    }
    /* wait for the above process to complete */
    while (i == 1) ;
    /* update our file to include the POS tags */
    this.file = result;
  }
 public static int basic_system_execute_command(Object system_command_line) {
   String scl = SmartEiffelRuntime.NullTerminatedBytesToString(system_command_line);
   Process process;
   try {
     process = Runtime.getRuntime().exec(scl);
     process.waitFor();
   } catch (Exception e) {
     System.err.print("SmartEiffelRuntime: basic_system_execute_command(\"");
     System.err.print(scl);
     System.err.println("\") failed.");
     SmartEiffelRuntime.print_run_time_stack();
     System.err.println("Try to continue execution.");
   }
   return 0;
 }
Ejemplo n.º 17
0
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub
      // erzeuge hier mir dem exec command einene neuen prozess der den editor mit Manual.txt öffnet
      // System.out.println(mpath3);
      try {
        Runtime runtime = Runtime.getRuntime();
        @SuppressWarnings("unused")
        Process process = runtime.exec(cmdstring);

      } catch (SecurityException err) {
        System.out.println("security fail");
      } catch (IOException io) {
        System.out.println("io-fail");
      } catch (NullPointerException ne) {
        System.out.println("iwas war null");
      } catch (IllegalArgumentException ie) {
        System.out.println("illegales command");
      }
    }
Ejemplo n.º 18
0
    /*
     * (non-Javadoc)
     * 
     * @see
     * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        InputStream input = getClass().getResourceAsStream(
            "/de/aidger/res/pdf/Handbuch.pdf");
        try {
            File tempFile = File.createTempFile("manual", ".pdf");
            tempFile.deleteOnExit();

            FileOutputStream out = new FileOutputStream(tempFile);
            byte buffer[] = new byte[1024];
            int len;
            while ((len = input.read(buffer)) > 0) {
                out.write(buffer, 0, len);
            }

            out.close();
            input.close();

            /*
             * Open the manual in the specified pdf viewer or try the default
             * one.
             */
            try {
                java.lang.Runtime.getRuntime().exec(
                    new String[] {
                            Runtime.getInstance().getOption("pdf-viewer"),
                            tempFile.getAbsolutePath() });
            } catch (IOException ex) {
                try {
                    Desktop.getDesktop().open(tempFile);
                } catch (IOException e1) {
                    UI.displayError(_("No pdf viewer could be found!"));
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(HelpAction.class.getName()).log(Level.SEVERE,
                null, ex);
        }

    }
Ejemplo n.º 19
0
  public static void main(String[] args) throws IOException {
    System.out.println("Max Heap memory" + java.lang.Runtime.getRuntime().maxMemory());
    System.out.println("args[0] " + args[0]);
    try {
      int newGUID = Integer.parseInt(args[2]);

      mss = new MServerSocket("ProxyloadServer" + newGUID, new NoProxyPolicy(), null, 0);

      for (int i = 0; true; i++) {
        System.out.println("Waiting for connections");
        MSocket ms = mss.accept();
        System.out.println("Accepted new connection " + (i + 1));

        TestServerConnection tsc = new TestServerConnection(ms);
        (new Thread(tsc)).start();
      }
    } catch (IOException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 20
0
 void dumpDatabase(String password, String filename) {
   // From:
   // http://www.jvmhost.com/articles/mysql-postgresql-dump-restore-java-jsp-code#sthash.6M0ty78M.dpuf
   String program = constructProgramPath(bc.mysqlPath, "mysqldump");
   System.out.println("MySQL path from config.properties: *" + program + "*");
   // 'destructive' dump, resulting in exact copy of DB:
   String[] executeCmd =
       new String[] {
         program, "-h" + bc.mysqlHost, "-ukassenadmin", "-p" + password, "kasse", "-r", filename
       };
   // 'non-destructive' (incremental) dump using replace:
   // String[] executeCmd = new String[] {program, "--no-create-info", "--replace",
   //    "-ukassenadmin", "-p"+password, "kasse", "-r", filename};
   try {
     Runtime shell = Runtime.getRuntime();
     Process proc = shell.exec(executeCmd);
     int processComplete = proc.waitFor();
     if (processComplete == 0) {
       System.out.println("Dump created successfully");
       JOptionPane.showMessageDialog(
           this,
           "Datenbank-Dump '" + filename + "' wurde erfolgreich angelegt.",
           "Info",
           JOptionPane.INFORMATION_MESSAGE);
     } else {
       System.out.println("Could not create the dump");
       JOptionPane.showMessageDialog(
           this,
           "Fehler: Dump-Datei " + filename + " konnte nicht erstellt werden.",
           "Fehler",
           JOptionPane.ERROR_MESSAGE);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
public class JournalsIndvPdf implements java.lang.Runnable {

  java.util.Date beginDate = null;

  java.util.Date endDate = null;

  java.lang.String Jno = null;

  java.lang.String Jno1 = null;

  public static java.sql.Connection connectDB = null;

  public java.lang.String dbUserName = null;

  org.netbeans.lib.sql.pool.PooledConnectionSource pConnDB = null;

  boolean threadCheck = true;

  java.lang.Thread threadSample;

  com.lowagie.text.Font pFontHeader = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
  com.lowagie.text.Font pFontHeader1 = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);

  //   com.lowagie.text.ParagraphFont pgraph = Paragraph();

  java.lang.Runtime rtThreadSample = java.lang.Runtime.getRuntime();

  java.lang.Process prThread;

  public void JournalsIndvPdf(
      java.sql.Connection connDb, java.lang.String jno, java.lang.String jno1) {

    connectDB = connDb;

    //  beginDate = begindate;

    //  endDate = endate;

    Jno = jno;

    Jno1 = jno1;

    threadSample = new java.lang.Thread(this, "SampleThread");

    System.out.println("threadSample created");

    threadSample.start();

    System.out.println("threadSample fired");
  }

  public static void main(java.lang.String[] args) {

    //		new TransactionsListPdf().TransactionsListPdf();

  }

  public void run() {

    System.out.println("System has entered running mode");

    while (threadCheck) {

      System.out.println("O.K. see how we execute target program");

      this.generatePdf();

      try {

        System.out.println("Right, let's wait for task to complete of fail");

        java.lang.Thread.currentThread().sleep(200);

        System.out.println("It's time for us threads to get back to work after the nap");

      } catch (java.lang.InterruptedException IntExec) {

        System.out.println(IntExec.getMessage());
      }

      threadCheck = false;

      System.out.println("We shall be lucky to get back to start in one piece");
    }

    if (!threadCheck) {

      Thread.currentThread().stop();
    }
  }

  public java.lang.String getDateLable() {

    java.lang.String date_label = null;

    java.lang.String month_now_strs = null;

    java.lang.String date_now_strs = null;

    java.lang.String year_now_strs = null;

    java.lang.String minute_now_strs = null;

    java.lang.String hour_now_strs = null;

    java.lang.Runtime rt = java.lang.Runtime.getRuntime();

    java.util.Calendar calinst = java.util.Calendar.getInstance();

    java.util.Date date_now = calinst.getTime();

    int date_now_str = date_now.getDate();

    int month_now_str = date_now.getMonth();

    int year_now_str = date_now.getYear();

    int hour_now_str = date_now.getHours();

    int minute_now_str = date_now.getMinutes();

    int year_now_abs = year_now_str - 100;

    if (year_now_abs < 10) {

      year_now_strs = "200" + year_now_abs;

    } else {

      year_now_strs = "20" + year_now_abs;
    }

    switch (month_now_str) {
      case 0:
        month_now_strs = "JAN";

        break;

      case 1:
        month_now_strs = "FEB";

        break;

      case 2:
        month_now_strs = "MAR";

        break;

      case 3:
        month_now_strs = "APR";

        break;

      case 4:
        month_now_strs = "MAY";

        break;

      case 5:
        month_now_strs = "JUN";

        break;

      case 6:
        month_now_strs = "JUL";

        break;

      case 7:
        month_now_strs = "AUG";

        break;

      case 8:
        month_now_strs = "SEP";

        break;

      case 9:
        month_now_strs = "OCT";

        break;

      case 10:
        month_now_strs = "NOV";

        break;

      case 11:
        month_now_strs = "DEC";

        break;

      default:
        if (month_now_str < 10) {

          month_now_strs = "0" + month_now_str;

        } else {

          month_now_strs = "" + month_now_str;
        }
    }

    if (date_now_str < 10) {

      date_now_strs = "0" + date_now_str;

    } else {

      date_now_strs = "" + date_now_str;
    }

    if (minute_now_str < 10) {

      minute_now_strs = "0" + minute_now_str;

    } else {

      minute_now_strs = "" + minute_now_str;
    }

    if (hour_now_str < 10) {

      hour_now_strs = "0" + hour_now_str;

    } else {

      hour_now_strs = "" + hour_now_str;
    }

    date_label =
        date_now_strs + month_now_strs + year_now_strs + "@" + hour_now_strs + minute_now_strs;

    return date_label;
  }

  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) compName = rset2.getObject(1).toString();

            while (rset4.next()) date = rset4.getObject(1).toString();

            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName + "", pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Journal List - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

            int headerwidths[] = {10, 10, 8, 25, 15, 15};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(6);

            Phrase phrase = new Phrase("", pFontHeader);
            double osBalance = 0;
            double osBalance1 = 0;
            //  try {
            //      java.text.DateFormat dateFormat =
            // java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);//MEDIUM);
            //

            //                            java.util.Date endDate1 =
            // dateFormat.parse(endDate.toLocaleString());//dateInstance.toLocaleString());
            //                            java.util.Date endDate11 =
            // dateFormat.parse(beginDate.toLocaleString());//dateInstance.toLocaleString());

            //                            System.out.println(""+endDate1);
            //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
            // pFontHeader);

            //  table.addCell(phrase);
            table.getDefaultCell().setColspan(4);

            phrase = new Phrase("Journal  No : " + Jno, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setColspan(2);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Printed On  : " + date, pFontHeader);

            table.addCell(phrase);
            // } catch(java.text.ParseException psExec) {

            //     javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
            // psExec.getMessage());
            //
            //  }
            // Phrase phrase = new Phrase("Patients List As At:" +endDate, pFontHeader);

            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);

            phrase = new Phrase("Date", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Activity Code", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("journal No.", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("Description", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Debit KShs", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Credit KShs", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              java.sql.Statement st = connectDB.createStatement();

              java.sql.Statement st2 = connectDB.createStatement();

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "select input_date,activity_code ,journal_no,description,debit,credit from ac_journal WHERE journal_no BETWEEN '"
                          + Jno
                          + "' AND '"
                          + Jno1
                          + "' ORDER BY journal_no"); // tn,debit_note db WHERE tn.policy_no != ''
                                                      // and tn.policy_no = db.policy_no GROUP BY
                                                      // tn.policy_no,db.policy_class");

              while (rset.next()) {

                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);

                table.addCell(phrase);
                phrase = new Phrase(rset.getObject(3).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getString(4).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader1);
                osBalance = osBalance + rset.getDouble(5);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(6)),
                        pFontHeader1);
                osBalance1 = osBalance1 + rset.getDouble(6);
                table.addCell(phrase);
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              table.getDefaultCell().setColspan(4);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance)),
                      pFontHeader1);

              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance1)),
                      pFontHeader1);

              table.addCell(phrase);

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("kghostview " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
}
  public static void main(String[] args) throws Exception {

    // args[] needs to be the input raw data which will go through cleaning phase followed by Mahout
    // classification
    if (args.length != 1) {
      System.err.println("ClassificationAutomator::main(): Not supplied raw data file to process");
    }

    String inputFile = args[0];
    String outputDir = "data/";

    // This will be relative to HDFS system path
    String mahoutSeqOutput = "data/";

    // We first take the data and split it into required number of columns, here we choose 4 -->
    // [Product, Complaint ID, Issue, State]. Second input
    // to ColumnReducer's method will need to be hardcoded, i.e. reduceColumn(inputFile, "data")
    ColumnReducer reducer = new ColumnReducer();
    reducer.reduceColumn(inputFile, outputDir);

    // Now call Nachiket's class to obtain the state wise sorted and bank wise sorted data. Note
    // that state sorted data goes into data/states
    // and banks sorted data goes into data/banks
    StatewiseSorter stateSorter = new StatewiseSorter();
    File stateDir = new File("data/states");
    if (!stateDir.exists()) {
      stateDir.mkdir();
    }
    File classificationDir = new File("data/classification");
    if (!stateDir.exists()) {
      classificationDir.mkdir();
    }
    stateSorter.sortState(outputDir, outputDir + "states/");

    ColumnReducerBank bankReducer = new ColumnReducerBank();
    bankReducer.reduceColumn(inputFile, outputDir);
    File bankDir = new File("data/banks");
    if (!bankDir.exists()) {
      bankDir.mkdir();
    }
    BankwiseSorter bankSorter = new BankwiseSorter();
    bankSorter.sortBank(outputDir, outputDir + "banks/");

    // We convert every CSV file into a sequence file by calling ComplaintsCSVtoSeq. We will also
    // iterate over every file under data/states and call
    // the method convertToSeq(). Before that we need to strip the first column i.e. state of each
    // csv file.
    ComplaintsCSVtoSeq allComplaints = new ComplaintsCSVtoSeq();
    StripColumn allColumns = new StripColumn();
    File[] directoryList = stateDir.listFiles();

    for (File everyFile : directoryList) {
      if (everyFile.exists()) {

        // Note that the file name is the same as temp_stateName
        String fileName = everyFile.getName();
        System.out.println(fileName);
        String[] tempFileName = fileName.split("_", 2);
        String[] targetFileName = tempFileName[1].split("\\.", 2);
        File dirStateCreate = new File("data/classification/" + targetFileName[0]);
        System.out.println(
            "ClassificationAutomator::main(): Created directory "
                + "data/classification/"
                + targetFileName[0]);
        if (!dirStateCreate.exists()) {
          dirStateCreate.mkdir();
        }
        allColumns.deleteColumn(fileName);
      }
    }
    // We also need to push these files into hadoop as the convertToSeq() call will execute on HDFS
    Process p = Runtime.getRuntime().exec("hdfs dfs -mkdir /data");
    p = Runtime.getRuntime().exec("hdfs dfs -put data/states data/");
    p = Runtime.getRuntime().exec("hdfs dfs -put data/classification data/");
    p = Runtime.getRuntime().exec("hdfs dfs -put data/banks data/");
    File[] newDirectoryList = stateDir.listFiles();
    for (File everyFile : newDirectoryList) {
      if (everyFile.exists()) {

        // Note that the file name is the same as temp_stateName
        String fileName = everyFile.getName();
        String[] targetFileName = fileName.split("\\.", 2);
        allComplaints.convertToSeq(
            "data/states/" + fileName, mahoutSeqOutput + "classification/" + targetFileName[0]);
      }
      allComplaints.convertToSeq("data/banks/Equifax.csv", mahoutSeqOutput + "classification/");
    }
  }
Ejemplo n.º 23
0
 /** See {@link Runtime#loadLibrary}. */
 public static void loadLibrary(String libName) {
   Runtime.getRuntime().loadLibrary(libName);
 }
Ejemplo n.º 24
0
 /** See {@link Runtime#load}. */
 public static void load(String pathName) {
   Runtime.getRuntime().load(pathName);
 }
Ejemplo n.º 25
0
  public java.lang.String getDateLable() {

    java.lang.String date_label = null;

    java.lang.String month_now_strs = null;

    java.lang.String date_now_strs = null;

    java.lang.String year_now_strs = null;

    java.lang.String minute_now_strs = null;

    java.lang.String hour_now_strs = null;

    java.lang.Runtime rt = java.lang.Runtime.getRuntime();

    java.util.Calendar calinst = java.util.Calendar.getInstance();

    java.util.Date date_now = calinst.getTime();

    int date_now_str = date_now.getDate();

    int month_now_str = date_now.getMonth();

    int year_now_str = date_now.getYear();

    int hour_now_str = date_now.getHours();

    int minute_now_str = date_now.getMinutes();

    int year_now_abs = year_now_str - 100;

    if (year_now_abs < 10) {

      year_now_strs = "200" + year_now_abs;

    } else {

      year_now_strs = "20" + year_now_abs;
    }

    switch (month_now_str) {
      case 0:
        month_now_strs = "JAN";

        break;

      case 1:
        month_now_strs = "FEB";

        break;

      case 2:
        month_now_strs = "MAR";

        break;

      case 3:
        month_now_strs = "APR";

        break;

      case 4:
        month_now_strs = "MAY";

        break;

      case 5:
        month_now_strs = "JUN";

        break;

      case 6:
        month_now_strs = "JUL";

        break;

      case 7:
        month_now_strs = "AUG";

        break;

      case 8:
        month_now_strs = "SEP";

        break;

      case 9:
        month_now_strs = "OCT";

        break;

      case 10:
        month_now_strs = "NOV";

        break;

      case 11:
        month_now_strs = "DEC";

        break;

      default:
        if (month_now_str < 10) {

          month_now_strs = "0" + month_now_str;

        } else {

          month_now_strs = "" + month_now_str;
        }
    }

    if (date_now_str < 10) {

      date_now_strs = "0" + date_now_str;

    } else {

      date_now_strs = "" + date_now_str;
    }

    if (minute_now_str < 10) {

      minute_now_strs = "0" + minute_now_str;

    } else {

      minute_now_strs = "" + minute_now_str;
    }

    if (hour_now_str < 10) {

      hour_now_strs = "0" + hour_now_str;

    } else {

      hour_now_strs = "" + hour_now_str;
    }

    date_label =
        date_now_strs + month_now_strs + year_now_strs + "@" + hour_now_strs + minute_now_strs;

    return date_label;
  }
Ejemplo n.º 26
0
public class RevenuePriceListPdf implements java.lang.Runnable {

  public static java.sql.Connection connectDB = null;
  java.lang.String bank = null;
  java.util.Date beginDate = null;
  com.afrisoftech.lib.DBObject dbObject;
  java.util.Date endDate = null;
  public java.lang.String dbUserName = null;
  org.netbeans.lib.sql.pool.PooledConnectionSource pConnDB = null;
  String ks;
  boolean threadCheck = true;
  java.lang.Thread threadSample;
  com.lowagie.text.Font pFontHeader = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
  com.lowagie.text.Font pFontHeader1 = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL);
  //   com.lowagie.text.ParagraphFont pgraph = Paragraph();
  java.lang.Runtime rtThreadSample = java.lang.Runtime.getRuntime();
  java.lang.Process prThread;

  public void RevenuePriceListPdf(
      java.sql.Connection connDb,
      java.util.Date begindate,
      java.util.Date endate,
      java.lang.String combox) {
    // public void StoresBalPdf(java.sql.Connection connDb) {

    dbObject = new com.afrisoftech.lib.DBObject();

    bank = combox;

    connectDB = connDb;

    // beginDate = begindate;

    // endDate = endate;

    threadSample = new java.lang.Thread(this, "SampleThread");

    System.out.println("threadSample created");

    threadSample.start();

    System.out.println("threadSample fired");
  }

  public static void main(java.lang.String[] args) {
    //	new CashBookListPdf().CashBookListPdf();
  }

  public void run() {

    System.out.println("System has entered running mode");

    while (threadCheck) {

      System.out.println("O.K. see how we execute target program");

      this.generatePdf();

      try {

        System.out.println("Right, let's wait for task to complete of fail");

        java.lang.Thread.currentThread().sleep(200);

        System.out.println("It's time for us threads to get back to work after the nap");

      } catch (java.lang.InterruptedException IntExec) {

        System.out.println(IntExec.getMessage());
      }

      threadCheck = false;

      System.out.println("We shall be lucky to get back to start in one piece");
    }

    if (!threadCheck) {

      Thread.currentThread().stop();
    }
  }

  public java.lang.String getDateLable() {

    java.lang.String date_label = null;

    java.lang.String month_now_strs = null;

    java.lang.String date_now_strs = null;

    java.lang.String year_now_strs = null;

    java.lang.String minute_now_strs = null;

    java.lang.String hour_now_strs = null;

    java.lang.Runtime rt = java.lang.Runtime.getRuntime();

    java.util.Calendar calinst = java.util.Calendar.getInstance();

    java.util.Date date_now = calinst.getTime();

    int date_now_str = date_now.getDate();

    int month_now_str = date_now.getMonth();

    int year_now_str = date_now.getYear();

    int hour_now_str = date_now.getHours();

    int minute_now_str = date_now.getMinutes();

    int year_now_abs = year_now_str - 100;

    if (year_now_abs < 10) {

      year_now_strs = "200" + year_now_abs;

    } else {

      year_now_strs = "20" + year_now_abs;
    }

    switch (month_now_str) {
      case 0:
        month_now_strs = "JAN";

        break;

      case 1:
        month_now_strs = "FEB";

        break;

      case 2:
        month_now_strs = "MAR";

        break;

      case 3:
        month_now_strs = "APR";

        break;

      case 4:
        month_now_strs = "MAY";

        break;

      case 5:
        month_now_strs = "JUN";

        break;

      case 6:
        month_now_strs = "JUL";

        break;

      case 7:
        month_now_strs = "AUG";

        break;

      case 8:
        month_now_strs = "SEP";

        break;

      case 9:
        month_now_strs = "OCT";

        break;

      case 10:
        month_now_strs = "NOV";

        break;

      case 11:
        month_now_strs = "DEC";

        break;

      default:
        if (month_now_str < 10) {

          month_now_strs = "0" + month_now_str;

        } else {

          month_now_strs = "" + month_now_str;
        }
    }

    if (date_now_str < 10) {

      date_now_strs = "0" + date_now_str;

    } else {

      date_now_strs = "" + date_now_str;
    }

    if (minute_now_str < 10) {

      minute_now_strs = "0" + minute_now_str;

    } else {

      minute_now_strs = "" + minute_now_str;
    }

    if (hour_now_str < 10) {

      hour_now_strs = "0" + hour_now_str;

    } else {

      hour_now_strs = "" + hour_now_str;
    }

    date_label =
        date_now_strs + month_now_strs + year_now_strs + "@" + hour_now_strs + minute_now_strs;

    return date_label;
  }

  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          try {

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();
            java.sql.Statement st2x = connectDB.createStatement();

            java.sql.ResultSet rset2x =
                st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
            while (rset2x.next()) {
              ks = rset2x.getObject(1).toString();
            }
            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Price List - Page: "),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(5);

            int headerwidths[] = {20, 50, 30, 30, 30};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            // table.setHeaderRows(2);

            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

            Phrase phrase = new Phrase(" ");
            //  table.addCell(phrase);

            try {
              table.getDefaultCell().setColspan(5);
              phrase = new Phrase("Departmental Price List ");
              table.addCell(phrase);
              table.getDefaultCell().setColspan(4);
              java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset3 =
                  st2.executeQuery(
                      "SELECT DISTINCT activity FROM pb_activity WHERE code ILIKE  '" + bank + "'");

              while (rset3.next()) {
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                phrase =
                    new Phrase(
                        rset3.getString(1).toUpperCase()
                            + " - "
                            + bank
                            + " Price List as at : "
                            + date,
                        pFontHeader);

                table.addCell(phrase);
              }
              //  Phrase phrase = new Phrase(bank +"    Balance Report"    +"  as at : "  +endDate,
              // pFontHeader);

              //  table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase = new Phrase("Printed on : " + date, pFontHeader);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("CODE", pFontHeader);
              table.addCell(phrase);

              //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase("DESCRIPTION", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              // phrase = new Phrase("",pFontHeader);
              // table.addCell(phrase);

              phrase = new Phrase("Norminal Rate (E.A) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("Special Rate (PRIVATE) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("NON E.A " + ks, pFontHeader);
              table.addCell(phrase);

              // phrase = new Phrase("Credit KShs.",pFontHeader);
              // table.addCell(phrase);

              // table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
              // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              double osBalance = 0.00;

              //  java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              java.sql.Statement st = connectDB.createStatement();

              //  java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "SELECT code, upper(service_type), rate, anaesthetist_rate,other_prices FROM pb_operating_parameters WHERE gl_account ilike  '"
                          + bank
                          + "' order by service_type");

              while (rset.next()) {
                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                table.addCell(phrase);

                //  table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(3)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(4)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);
              }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
}
  public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      // com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());
      double osBalance1 = 0.00;
      double osBalance = 0.00;
      double current = 0.00;
      double osBalancebf = 0.00;
      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          String Messg = null;

          docPdf.open();

          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(7);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {15, 15, 30, 15, 15, 15, 15};

            table1.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            //  table1.setHeaderRows(4);
            //  }
            table1.setWidthPercentage((100));

            table1.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table1.getDefaultCell().setColspan(7);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table1.getDefaultCell().setColspan(1);
            table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st2x = connectDB.createStatement();

              java.sql.ResultSet rset2x =
                  st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
              while (rset2x.next()) {
                ks = rset2x.getObject(1).toString();
              }
              java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header");
              while (rset3.next()) {
                table1.getDefaultCell().setColspan(7);

                table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11);
                table1.addCell(phrase);
              }

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }
            docPdf.add(table1);
          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

          //  } catch(java.io.FileNotFoundException fnfExec) {

          //  javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
          // fnfExec.getMessage());

          /// }
          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {12, 10, 28, 11, 14, 12, 14, 14, 15};

            table.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            table.setHeaderRows(8);
            //  }
            table.setWidthPercentage((100));

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(9);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table.getDefaultCell().setColspan(1);
            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              double Debit = 0.00;
              double Credit = 0.00;
              java.sql.Statement st22 = connectDB.createStatement();
              java.sql.Statement st11 = connectDB.createStatement();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st1 = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st4 = connectDB.createStatement();
              java.sql.Statement st41 = connectDB.createStatement();
              java.sql.Statement st5 = connectDB.createStatement();
              java.sql.Statement st22D = connectDB.createStatement();
              java.sql.ResultSet rset3 =
                  st3.executeQuery(
                      "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile");
              java.sql.ResultSet rset4 =
                  st4.executeQuery(
                      "select scheme_name,account_no,tel_main,address from ac_schemes where account_no = '"
                          + memNo
                          + "'");
              java.sql.ResultSet rset41 =
                  st41.executeQuery(
                      "select payer_name from ac_schemes where account_no = '" + memNo + "'");
              //      java.sql.ResultSet rset1 = st1.executeQuery("select date,admission_no||'
              // '||cheque_no, upper(item),invoice_no ||'
              // '||receipt_no,debit,credit,credit_bal,balance from ac_debtors where account_no = '"
              // + memNo + "' AND date::date BETWEEN '" + beginDate + "' AND '" + endDate + "' group
              // by 1, 2, 3order by date,invoice_no");// UNION select
              // pd.date::date,initcap(pd.scheme_staff_no), (sh.first_name||' '||sh.second_name||'
              // '||sh.last_name) as name,pd.reference,sum(pd.credit),pd.patient_no from
              // hp_patient_card pd,hp_inpatient_register sh where pd.patient_no = sh.patient_no and
              // pd.isurer = '"+memNo+"' AND pd.date::date BETWEEN '"+beginDate+"' AND '"+endDate+"'
              // and pd.credit > 0 group by pd.date::date,pd.scheme_staff_no,
              // name,pd.reference,pd.invoice_no,pd.patient_no order by pd.invoice_no");
              java.sql.ResultSet rsetTotals2 =
                  st22.executeQuery(
                      "select sum(debit - credit) from ac_debtors where account_no = '"
                          + memNo
                          + "' AND date::date < '"
                          + beginDate
                          + "'");
              java.sql.ResultSet rsetTotals =
                  st2.executeQuery(
                      "select sum(debit),sum(credit) from ac_debtors where account_no = '"
                          + memNo
                          + "' AND date::date BETWEEN '"
                          + beginDate
                          + "' AND '"
                          + endDate
                          + "'");

              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP | Rectangle.BOTTOM);

              table.getDefaultCell().setColspan(9);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase("Statement of Account", pFontHeader11);
              table.addCell(phrase);

              while (rset4.next()) {
                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                table.getDefaultCell().setColspan(9);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);

                while (rset41.next()) {
                  table.getDefaultCell().setColspan(9);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset41.getString(1), pFontHeader1);
                  table.addCell(phrase);
                }
                table.getDefaultCell().setColspan(9);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase =
                    new Phrase(
                        "Account No : " + rset4.getObject(2).toString().toUpperCase(),
                        pFontHeader1);
                table.addCell(phrase);

                phrase =
                    new Phrase(
                        dbObject.getDBObject("Tel : " + rset4.getObject(3), "-"), pFontHeader1);
                table.addCell(phrase);
                phrase = new Phrase(dbObject.getDBObject(rset4.getObject(4), "-"), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setColspan(6);
              }
              try {
                java.text.DateFormat dateFormat =
                    java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

                java.util.Date endDate1 =
                    dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());
                java.util.Date endDate11 =
                    dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

                System.out.println("" + endDate1);
                //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
                // pFontHeader);

                //  table.addCell(phrase);

                phrase =
                    new Phrase(
                        "Period : "
                            + dateFormat.format(endDate11)
                            + " - "
                            + dateFormat.format(endDate1),
                        pFontHeader1);

                table.addCell(phrase);
              } catch (java.text.ParseException psExec) {

                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), psExec.getMessage());
              }
              // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1);
              // table.addCell(phrase);

              table.getDefaultCell().setColspan(3);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Date " + datenowSql, pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP);
              table.getDefaultCell().setColspan(1);
              // phrase = new Phrase("Date", pFontHeader1);
              // table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Staff No.", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase = new Phrase(" Staff Name", pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              phrase = new Phrase("Debit Bal. ", pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Running Amt. " + ks, pFontHeader1);
              table.addCell(phrase);

              while (rsetTotals2.next()) {
                table.getDefaultCell().setColspan(5);

                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("BAL/BF", pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                table.getDefaultCell().setColspan(4);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rsetTotals2.getString(1)),
                        pFontHeader1);
                osBalancebf = osBalancebf + rsetTotals2.getDouble(1);
                table.addCell(phrase);
              }
              for (int i = 0; i < listofStaffNos.length; i++) {
                java.sql.ResultSet rset1 =
                    st1.executeQuery(
                        "select admission_no, upper(item), sum(debit - credit) from ac_debtors where account_no = '"
                            + memNo
                            + "' and admission_no = '"
                            + listofStaffNos[i]
                            + "' AND date::date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' GROUP BY 1, 2");
                while (rset1.next()) {
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(6);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"),
                  // pFontHeader);

                  // table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(4), "-"),
                  // pFontHeader);

                  // table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(5)),
                  // pFontHeader);
                  // Debit = Debit + rset1.getDouble(5);
                  // table.addCell(phrase);
                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)),
                  // pFontHeader);
                  // Credit = Credit + rset1.getDouble(6);
                  // table.addCell(phrase);

                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)),
                  // pFontHeader);
                  // osBalance1 = osBalance1 + rset1.getDouble(6);
                  // table.addCell(phrase);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rset1.getString(3)),
                          pFontHeader);
                  osBalancebf = osBalancebf + rset1.getDouble(3);
                  // osBalancebf = osBalance1;
                  table.addCell(phrase);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)),
                          pFontHeader);

                  table.addCell(phrase);
                }
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              //  while (rsetTotals.next()) {

              table.getDefaultCell().setColspan(4);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)),
                      pFontHeader);

              table.addCell(phrase);

              // phrase = new Phrase(" ");

              //     }
              try {

                java.sql.Statement st31 = connectDB.createStatement();
                // java.sql.Statement st4 = connectDB.createStatement();
                java.sql.ResultSet rset2 = st31.executeQuery("select name from pb_notice");

                // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from
                // pb_hospitalprofile");
                //   java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                while (rset2.next()) {
                  Messg = rset2.getString(1);
                }
                com.lowagie.text.HeaderFooter footer =
                    new com.lowagie.text.HeaderFooter(
                        new Phrase("" + Messg + ""),
                        false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                // Font.BOLDITALIC,java.awt.Color.blue)));

                //  com.lowagie.text.HeaderFooter headerFoter = new
                // com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);//
                // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                // Font.BOLDITALIC,java.awt.Color.blue)));
                //  headerFoter.ALIGN_CENTER;
                //  headerFoter.setRight(5);
                docPdf.setFooter(footer);

              } catch (java.sql.SQLException SqlExec) {

                SqlExec.printStackTrace();
                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), SqlExec.getMessage());
              }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              SqlExec.printStackTrace();
              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

            // }  // }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("xpdf " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  /**
   * checks a TPTP proof obligation with VAMPIRE
   *
   * @param poContent
   * @return boolean (matchmaking result)
   */
  public boolean check(String poContent) {

    boolean result = false;

    long startTime;
    long stopTime;

    File poFile = new File(PO_DIR + "poTest.p");

    try {
      FileWriter fw = new FileWriter(poFile);
      fw.write(poContent);
      fw.close();

    } catch (IOException io) {
      //	    	System.out.println("cannot write poFile");
      io.printStackTrace();
    }

    proofObligationFile = poFile.getAbsolutePath();

    if (proofObligationFile == null) {
      //    	System.out.println("proofObligationFile == null");
      return false;
    }

    Runtime runt = java.lang.Runtime.getRuntime();
    StringBuffer proverOutputBuffer = new StringBuffer();
    Process newProver;

    try {
      startTime = System.currentTimeMillis();
      newProver = runt.exec(START_PROVER_COMMAND + " " + proofObligationFile);

      stopTime = startTime;

      try {

        InputStream is = newProver.getInputStream();
        InputStreamReader sr = new java.io.InputStreamReader(is);

        boolean stop = false;

        while (!stop) {
          int c;
          c = sr.read();
          if (c != -1) {
            proverOutputBuffer.append((char) c);
          } else {
            stop = true;
          }
        }

        stopTime = System.currentTimeMillis();

        System.err.println("PROVER CALL OUTPUT: " + proverOutputBuffer.toString());
        result =
            (proverOutputBuffer.toString().toLowerCase().indexOf(this.SUCCESSFUL_PATTERN) != -1);

      } catch (IOException e) {
        e.printStackTrace();
        result = false;
      }

      long duration = (stopTime - startTime); // in ms.

      System.err.println("PROVER CALL OUTPUT: " + proverOutputBuffer.toString());
      result = (proverOutputBuffer.toString().toLowerCase().indexOf(this.SUCCESSFUL_PATTERN) != -1);

      System.err.println(
          " -- Done Checking PO: "
              + " [ "
              + (result ? "match" : "no match")
              + " in ("
              + duration
              + " ms) ]");

    } catch (IOException e1) {
      e1.printStackTrace();
    }

    poFile.delete();

    return result;
  }
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) compName = rset2.getObject(1).toString();

            while (rset4.next()) date = rset4.getObject(1).toString();

            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName + "", pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Journal List - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

            int headerwidths[] = {10, 10, 8, 25, 15, 15};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(6);

            Phrase phrase = new Phrase("", pFontHeader);
            double osBalance = 0;
            double osBalance1 = 0;
            //  try {
            //      java.text.DateFormat dateFormat =
            // java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);//MEDIUM);
            //

            //                            java.util.Date endDate1 =
            // dateFormat.parse(endDate.toLocaleString());//dateInstance.toLocaleString());
            //                            java.util.Date endDate11 =
            // dateFormat.parse(beginDate.toLocaleString());//dateInstance.toLocaleString());

            //                            System.out.println(""+endDate1);
            //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
            // pFontHeader);

            //  table.addCell(phrase);
            table.getDefaultCell().setColspan(4);

            phrase = new Phrase("Journal  No : " + Jno, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setColspan(2);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Printed On  : " + date, pFontHeader);

            table.addCell(phrase);
            // } catch(java.text.ParseException psExec) {

            //     javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
            // psExec.getMessage());
            //
            //  }
            // Phrase phrase = new Phrase("Patients List As At:" +endDate, pFontHeader);

            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);

            phrase = new Phrase("Date", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Activity Code", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("journal No.", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("Description", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Debit KShs", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Credit KShs", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              java.sql.Statement st = connectDB.createStatement();

              java.sql.Statement st2 = connectDB.createStatement();

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "select input_date,activity_code ,journal_no,description,debit,credit from ac_journal WHERE journal_no BETWEEN '"
                          + Jno
                          + "' AND '"
                          + Jno1
                          + "' ORDER BY journal_no"); // tn,debit_note db WHERE tn.policy_no != ''
                                                      // and tn.policy_no = db.policy_no GROUP BY
                                                      // tn.policy_no,db.policy_class");

              while (rset.next()) {

                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);

                table.addCell(phrase);
                phrase = new Phrase(rset.getObject(3).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getString(4).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader1);
                osBalance = osBalance + rset.getDouble(5);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(6)),
                        pFontHeader1);
                osBalance1 = osBalance1 + rset.getDouble(6);
                table.addCell(phrase);
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              table.getDefaultCell().setColspan(4);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance)),
                      pFontHeader1);

              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance1)),
                      pFontHeader1);

              table.addCell(phrase);

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("kghostview " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Ejemplo n.º 30
0
public class OrderedItemsPdf implements java.lang.Runnable {
  //// java.awt.Desktop deskTop = Desktop.getDesktop();
  java.util.Date beginDate = null;
  java.util.Date endDate = null;
  public static java.sql.Connection connectDB = null;
  public java.lang.String dbUserName = null;
  org.netbeans.lib.sql.pool.PooledConnectionSource pConnDB = null;
  boolean threadCheck = true;
  java.lang.Thread threadSample;
  com.lowagie.text.Font pFontHeader = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
  com.lowagie.text.Font pFontHeader1 = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
  //   com.lowagie.text.ParagraphFont pgraph = Paragraph();
  java.lang.Runtime rtThreadSample = java.lang.Runtime.getRuntime();
  java.lang.Process prThread;

  public void OrderedItemsPdf(
      java.sql.Connection connDb, java.util.Date begindate, java.util.Date endate) {
    // public void OrderedItemsPdf(java.sql.Connection connDb) {

    connectDB = connDb;
    beginDate = begindate;
    endDate = endate;

    threadSample = new java.lang.Thread(this, "SampleThread");

    System.out.println("threadSample created");

    threadSample.start();

    System.out.println("threadSample fired");
  }

  public static void main(java.lang.String[] args) {
    //		new TransactionsListPdf().TransactionsListPdf();
  }

  public void run() {

    System.out.println("System has entered running mode");

    while (threadCheck) {

      System.out.println("O.K. see how we execute target program");

      this.generatePdf();

      try {

        System.out.println("Right, let's wait for task to complete of fail");

        java.lang.Thread.currentThread().sleep(2000);

        System.out.println("It's time for us threads to get back to work after the nap");

      } catch (java.lang.InterruptedException IntExec) {

        System.out.println(IntExec.getMessage());
      }

      threadCheck = false;

      System.out.println("We shall be lucky to get back to start in one piece");
    }

    if (!threadCheck) {

      Thread.currentThread().stop();
    }
  }

  public java.lang.String getDateLable() {

    java.lang.String date_label = null;

    java.lang.String month_now_strs = null;

    java.lang.String date_now_strs = null;

    java.lang.String year_now_strs = null;

    java.lang.String minute_now_strs = null;

    java.lang.String hour_now_strs = null;

    java.lang.Runtime rt = java.lang.Runtime.getRuntime();

    java.util.Calendar calinst = java.util.Calendar.getInstance();

    java.util.Date date_now = calinst.getTime();

    int date_now_str = date_now.getDate();

    int month_now_str = date_now.getMonth();

    int year_now_str = date_now.getYear();

    int hour_now_str = date_now.getHours();

    int minute_now_str = date_now.getMinutes();

    int year_now_abs = year_now_str - 100;

    if (year_now_abs < 10) {

      year_now_strs = "200" + year_now_abs;

    } else {

      year_now_strs = "20" + year_now_abs;
    }

    switch (month_now_str) {
      case 0:
        month_now_strs = "JAN";

        break;

      case 1:
        month_now_strs = "FEB";

        break;

      case 2:
        month_now_strs = "MAR";

        break;

      case 3:
        month_now_strs = "APR";

        break;

      case 4:
        month_now_strs = "MAY";

        break;

      case 5:
        month_now_strs = "JUN";

        break;

      case 6:
        month_now_strs = "JUL";

        break;

      case 7:
        month_now_strs = "AUG";

        break;

      case 8:
        month_now_strs = "SEP";

        break;

      case 9:
        month_now_strs = "OCT";

        break;

      case 10:
        month_now_strs = "NOV";

        break;

      case 11:
        month_now_strs = "DEC";

        break;

      default:
        if (month_now_str < 10) {

          month_now_strs = "0" + month_now_str;

        } else {

          month_now_strs = "" + month_now_str;
        }
    }

    if (date_now_str < 10) {

      date_now_strs = "0" + date_now_str;

    } else {

      date_now_strs = "" + date_now_str;
    }

    if (minute_now_str < 10) {

      minute_now_strs = "0" + minute_now_str;

    } else {

      minute_now_strs = "" + minute_now_str;
    }

    if (hour_now_str < 10) {

      hour_now_strs = "0" + hour_now_str;

    } else {

      hour_now_strs = "" + hour_now_str;
    }

    date_label =
        date_now_strs + month_now_strs + year_now_strs + "@" + hour_now_strs + minute_now_strs;

    return date_label;
  }

  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      // com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Orders - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(7);

            int headerwidths[] = {12, 10, 30, 30, 8, 8, 12};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(5);

            Phrase phrase = new Phrase("Orders list as at: " + endDate, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
            table.getDefaultCell().setColspan(2);
            phrase = new Phrase("Printed on : " + date, pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
            phrase = new Phrase("Order No", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Date Due", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Supplier", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Item", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Units", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Qty", pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
            phrase = new Phrase("Net Value", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.lang.Object[] listofAct = this.getListofActivities();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();

              for (int i = 0; i < listofAct.length; i++) {
                int w = 0;
                java.sql.ResultSet rset3 =
                    st3.executeQuery(
                        "SELECT DISTINCT order_no,date_due AS date,supplier from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY date");

                java.sql.ResultSet rset =
                    st.executeQuery(
                        "SELECT item,units,quantity,net_value from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY item");
                java.sql.ResultSet rsetTotals =
                    st2.executeQuery(
                        "SELECT SUM(net_value) from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "'  AND order_no = '"
                            + listofAct[i].toString()
                            + "'");

                while (rset3.next()) {
                  while (rset.next()) {
                    w = w + 1;

                    if (w == 1) {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(2).toString(), pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(3).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);

                    } else {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);
                    }
                  }
                }
                // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                // table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

                while (rsetTotals.next()) {

                  table.getDefaultCell().setColspan(5);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  phrase = new Phrase("Total", pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                  phrase = new Phrase((""), pFontHeader);

                  table.addCell(phrase);

                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rsetTotals.getString(1)),
                          pFontHeader);

                  table.addCell(phrase);
                }
              }
              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }

  public java.lang.Object[] getListofActivities() {

    java.lang.Object[] listofActivities = null;

    java.util.Vector listActVector = new java.util.Vector(1, 1);

    try {

      java.sql.Statement stmt1 = connectDB.createStatement();

      java.sql.ResultSet rSet1 =
          stmt1.executeQuery(
              "SELECT DISTINCT order_no FROM st_orders WHERE date BETWEEN '"
                  + beginDate
                  + "' AND '"
                  + endDate
                  + "' ORDER BY order_no");

      while (rSet1.next()) {

        listActVector.addElement(rSet1.getObject(1).toString().toUpperCase());
      }

    } catch (java.sql.SQLException sqlExec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), sqlExec.getMessage());
    }

    listofActivities = listActVector.toArray();
    System.out.println("Done list of activities ...");
    return listofActivities;
  }
}