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 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());
      }
    }
  }
Example #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"}
  };
}
  /**
   * 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.");
    }
  }
Example #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);
   }
 }
Example #10
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();
   }
 }
  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");
  }
 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;
 }
Example #13
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");
      }
    }
  /**
   * 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);
      }
    }
  }
Example #15
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;
  }
 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 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;
 }
Example #19
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);
        }

    }
Example #20
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();
    }
  }
Example #21
0
 /**
  * Tell the VM to run the finalize() method on every single Object before it exits. Note that the
  * JVM may still exit abnormally and not perform this, so you still don't have a guarantee. And
  * besides that, this is inherently unsafe in multi-threaded code, as it may result in deadlock as
  * multiple threads compete to manipulate objects. This value defaults to <code>false</code>.
  * There is a security check, <code>checkExit(0)</code>.
  *
  * @param finalizeOnExit whether to finalize all Objects on exit
  * @throws SecurityException if permission is denied
  * @see #exit(int)
  * @see #gc()
  * @since 1.1
  * @deprecated never rely on finalizers to do a clean, thread-safe, mop-up from your code
  */
 public static void runFinalizersOnExit(boolean finalizeOnExit) {
   SecurityManager sm = SecurityManager.current; // Be thread-safe!
   if (sm != null) sm.checkExit(0);
   current.finalizeOnExit = finalizeOnExit;
 }
Example #22
0
 /** See {@link Runtime#loadLibrary}. */
 public static void loadLibrary(String libName) {
   Runtime.getRuntime().loadLibrary(libName);
 }
  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/");
    }
  }
  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;
  }
Example #25
0
 /** See {@link Runtime#load}. */
 public static void load(String pathName) {
   Runtime.getRuntime().load(pathName);
 }
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());
    }
  }
}
Example #27
0
 // Accessor to avoid adding a vtable slot.
 static void exitNoChecksAccessor(int status) {
   current.exitNoChecks(status);
 }
  /**
   * 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());
    }
  }
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());
    }
  }
}