// set adb wifi service public static boolean setAdbWifiStatus(boolean status) { Process p; try { p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes("setprop service.adb.tcp.port " + String.valueOf(getPort()) + "\n"); os.writeBytes("stop adbd\n"); if (status) { os.writeBytes("start adbd\n"); } os.writeBytes("exit\n"); os.flush(); p.waitFor(); if (p.exitValue() != 255) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } }
public boolean checkSetDevicePermissions() { java.lang.Process process = null; DataOutputStream os = null; try { File f = new File(MSM_DEVICE); if (f.canRead() && f.canWrite() /* && f1.canRead() && f1.canWrite() */) { return true; } process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.flush(); os.writeBytes("chmod 0666 " + MSM_DEVICE + "\n"); os.flush(); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (os != null) os.close(); process.destroy(); } catch (Exception e) { } } return true; }
/** * Check if the process is alive. * * @param name The process name to be checked. * @return Returns true if this process is alive, else retur false */ private boolean isProcessAlive(String name) { String cmd; String line; StringBuffer sb = new StringBuffer(); sb.append("ps "); sb.append(name); cmd = sb.toString(); try { java.lang.Process p = Runtime.getRuntime().exec(cmd); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { String[] tokens = line.split("\\s+"); if (tokens[7].equals("S")) { if (tokens[8].indexOf(name) >= 0) { Slog.w(TAG, line); return true; } } } input.close(); } catch (Exception ex) { Slog.w(TAG, ex); } return false; }
public void execMethodReadPrivateFileSystem(String path) { String line = ""; String args[] = new String[3]; args[0] = "chmod"; args[1] = "777"; args[2] = "/data/data/com.eoemobile/databases/webviewCache.db"; try { java.lang.Process process = Runtime.getRuntime().exec(args); InputStream stderr = process.getErrorStream(); InputStreamReader isrerr = new InputStreamReader(stderr); BufferedReader brerr = new BufferedReader(isrerr); InputStream outs = process.getInputStream(); InputStreamReader isrout = new InputStreamReader(outs); BufferedReader brout = new BufferedReader(isrout); String errline = null; String result = ""; while ((line = brerr.readLine()) != null) { result += line; result += "\n"; } if (result != "") { errline = result; System.out.println(errline); } while ((line = brout.readLine()) != null) { result += line; result += "\n"; } if (result != "") { System.out.println(result); } } catch (Throwable t) { t.printStackTrace(); } }
@Override public void executeShellCommand(String command, ParcelFileDescriptor sink) throws RemoteException { synchronized (mLock) { throwIfCalledByNotTrustedUidLocked(); throwIfShutdownLocked(); throwIfNotConnectedLocked(); } InputStream in = null; OutputStream out = null; try { java.lang.Process process = Runtime.getRuntime().exec(command); in = process.getInputStream(); out = new FileOutputStream(sink.getFileDescriptor()); final byte[] buffer = new byte[8192]; while (true) { final int readByteCount = in.read(buffer); if (readByteCount < 0) { break; } out.write(buffer, 0, readByteCount); } } catch (IOException ioe) { throw new RuntimeException("Error running shell command", ioe); } finally { IoUtils.closeQuietly(in); IoUtils.closeQuietly(out); IoUtils.closeQuietly(sink); } }
public static void __hx_ctor( sys.io.Process __temp_me13, java.lang.String cmd, haxe.root.Array<java.lang.String> args) { java.lang.String[] pargs = new java.lang.String[((int) ((args.length + 1)))]; pargs[0] = cmd; { int _g1 = 0; int _g = args.length; while ((_g1 < _g)) { int i = _g1++; pargs[(i + 1)] = args.__get(i); } } try { __temp_me13.proc = new java.lang.ProcessBuilder(((java.lang.String[]) (pargs))).start(); } catch (java.lang.Throwable __temp_catchallException113) { java.lang.Object __temp_catchall114 = __temp_catchallException113; if ((__temp_catchall114 instanceof haxe.lang.HaxeException)) { __temp_catchall114 = ((haxe.lang.HaxeException) (__temp_catchallException113)).obj; } { java.lang.Object e = __temp_catchall114; throw haxe.lang.HaxeException.wrap(e); } } java.lang.Process p = __temp_me13.proc; __temp_me13.stderr = new sys.io._Process.ProcessInput(((java.io.InputStream) (p.getErrorStream()))); __temp_me13.stdout = new sys.io._Process.ProcessInput(((java.io.InputStream) (p.getInputStream()))); __temp_me13.stdin = new haxe.java.io.NativeOutput(((java.io.OutputStream) (p.getOutputStream()))); }
/** * Create tombstones for the list of processes. * * @param ProcList The list of processes with ',' as a delimiter. */ private void createTombstone(String procList) { String cmd = "ps"; List<String> procList4Tombstones = new ArrayList<String>(); String line; StringBuffer sb = new StringBuffer(); sb.append(","); sb.append(procList); sb.append(","); procList = sb.toString(); try { java.lang.Process p = Runtime.getRuntime().exec(cmd); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { String[] tokens = line.split("\\s+"); if (tokens.length == 9) { String delimiter1 = "/"; String[] procname = tokens[8].split(delimiter1); StringBuffer sb1 = new StringBuffer(); sb1.append(","); sb1.append(procname[procname.length - 1]); sb1.append(","); String pn = sb1.toString(); if (procList.indexOf(pn) >= 0) { procList4Tombstones.add(tokens[1]); procList4Tombstones.add(procname[procname.length - 1]); } } } input.close(); } catch (Exception ex) { Slog.w(TAG, ex); } Iterator<String> it = procList4Tombstones.iterator(); while (it.hasNext()) { /* * Sometimes the debuggerd will exit after the tombstones creation which * will not allow the next tombstones generation. * Wait till the debuggerd is back. */ Slog.w(TAG, "Waiting for the debuggerd process..."); while (false == isProcessAlive("debuggerd")) { SystemClock.sleep(500); } String pid = it.next(); Slog.w(TAG, "Creating tombstone file for process[" + it.next() + "]"); SystemClock.sleep(1000); Process.sendSignal(Integer.parseInt(pid), 6); SystemClock.sleep(1000); Process.sendSignal(Integer.parseInt(pid), 6); SystemClock.sleep(2000); } }
// save log to file and return warning messages private String logToFile() { if (getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, getPackageName()) != 0) { return null; } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd.HH'h'mm'm'ss's'"); String logfilename = AdPreviewer.ADPREVIEWER_DIR + this.getIntent().getExtras().getString("originalFilename") + "." + dateFormat.format(new Date()); File logfile = new File(logfilename + ".log"); File warningsLogfile = new File(logfilename + ".WARNING.log"); String pidString = null; try { Log.i(CLASSTAG, "creating log file: " + logfilename); logfile.createNewFile(); Process process = Runtime.getRuntime().exec("logcat -v time -d"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuilder log = new StringBuilder(); StringBuilder warningsLog = new StringBuilder(); String line; int warningsCount = 0; while ((line = bufferedReader.readLine()) != null) { if (pidString == null && line.indexOf("AdContext") > 0) { pidString = line.substring(line.indexOf("("), line.indexOf(")") + 1); } if (pidString != null && line.indexOf(pidString) > 0) { log.append(line + "\n"); if (line.indexOf("W/") >= 0 || line.indexOf("E/") >= 0) { warningsLog.append(line + "\n"); warningsCount++; } } } BufferedWriter out = new BufferedWriter(new FileWriter(logfile)); out.write(log.toString()); out.close(); if (warningsCount > 0) { warningsLogfile.createNewFile(); BufferedWriter out2 = new BufferedWriter(new FileWriter(warningsLogfile)); out2.write(warningsLog.toString()); out2.close(); return warningsLog.toString(); } } catch (IOException e) { e.printStackTrace(); } return null; }
/** * 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); } } }
/* sets the parts of speech for each node in the graph */ public void addPOS() { System.out.println("Running POS tagger..."); /* parameters for exec command */ File dir = new File("/home/josh/Desktop/Artificial_Intelligence/POS_Tagger"); /* where we are placing the file to parse */ File result = new File(file.toString() + ".pos"); int i = 1; String s = null, data = ""; try { /* command to run the POS tagger */ String command = "java -mx300m -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/" + "bidirectional-distsim-wsj-0-18.tagger -textFile " + file.toString(); /* run the process */ Process p = Runtime.getRuntime().exec(command, null, dir); i = p.waitFor(); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); /* extract the data from the command */ while ((s = stdInput.readLine()) != null) { /* copy the data into one string */ data += s; } /* place the data in a .pos text file */ byte[] buffer = data.getBytes(); FileOutputStream fout = new FileOutputStream(result, false); fout.write(buffer); fout.close(); /* read any errors from the attempted command */ while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (Exception e) { System.out.println("Exception happened - here's what I know: "); e.printStackTrace(); System.exit(-1); } /* wait for the above process to complete */ while (i == 1) ; /* update our file to include the POS tags */ this.file = result; }
public static int basic_system_execute_command(Object system_command_line) { String scl = SmartEiffelRuntime.NullTerminatedBytesToString(system_command_line); Process process; try { process = Runtime.getRuntime().exec(scl); process.waitFor(); } catch (Exception e) { System.err.print("SmartEiffelRuntime: basic_system_execute_command(\""); System.err.print(scl); System.err.println("\") failed."); SmartEiffelRuntime.print_run_time_stack(); System.err.println("Try to continue execution."); } return 0; }
/** * Print report from a single command line. * * <p>TODO: Use ProcessBuilder & redirectErrorStream(true) to capture both streams (might be * important for some command lines) * * @param reportName Simple tag that will print before the report and in various annotations. * @param command Command line to execute. */ private void commandLineReport(String reportName, String command) { if (mVerbose > 0) { System.err.println(reportName + ":"); Runtime rt = Runtime.getRuntime(); Writer logOutput = null; try { // Process must be fully qualified here because android.os.Process // is used elsewhere java.lang.Process p = Runtime.getRuntime().exec(command); if (mRequestBugreport) { logOutput = new BufferedWriter( new FileWriter( new File(Environment.getExternalStorageDirectory(), reportName), true)); } // pipe everything from process stdout -> System.err InputStream inStream = p.getInputStream(); InputStreamReader inReader = new InputStreamReader(inStream); BufferedReader inBuffer = new BufferedReader(inReader); String s; while ((s = inBuffer.readLine()) != null) { if (mRequestBugreport) { logOutput.write(s); logOutput.write("\n"); } else { System.err.println(s); } } int status = p.waitFor(); System.err.println("// " + reportName + " status was " + status); if (logOutput != null) { logOutput.close(); } } catch (Exception e) { System.err.println("// Exception from " + reportName + ":"); System.err.println(e.toString()); } } }
// detect if adbd is running public static boolean getAdbdStatus() { int lineCount = 0; try { Process process = Runtime.getRuntime().exec("ps | grep adbd"); InputStreamReader ir = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberReader(ir); String str = input.readLine(); while (str != null) { lineCount++; str = input.readLine(); } if (lineCount >= 2) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
public void run() { BufferedReader lsofBufferedReader = initialize(); if (lsofBufferedReader != null) { while (!shutdown) { scanList(lsofBufferedReader); } process.destroy(); } }
@Override protected void onDestroy() { QtApplication.setMainActivity(null); super.onDestroy(); if (m_quitApp) { Log.i(QtApplication.QtTAG, "onDestroy"); if (m_debuggerProcess != null) m_debuggerProcess.destroy(); System.exit(0); // FIXME remove it or find a better way } QtApplication.setMainActivity(null); }
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(); } }
BufferedReader initialize() { BufferedReader lsofBufferedReader = null; try { process = Runtime.getRuntime().exec("lsof -F pn -i -r 1"); InputStream inputStream = process.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); lsofBufferedReader = new BufferedReader(inputStreamReader); } catch (Exception exception) { exception.printStackTrace(errorStream); } return lsofBufferedReader; }
/** * Pipes a list of <code>Process</code> objects together like a shell pipe. * * @param proc list of processes * @return InputStream - final output */ public static java.io.InputStream pipe(java.lang.Process... proc) throws java.lang.InterruptedException { // Start Piper between all processes java.lang.Process p1; java.lang.Process p2; for (int i = 0; i < proc.length; i++) { p1 = proc[i]; // If there's one more process if (i + 1 < proc.length) { p2 = proc[i + 1]; // Start piper new Thread(new Piper(p1.getInputStream(), p2.getOutputStream())).start(); } } java.lang.Process last = proc[proc.length - 1]; // Wait for last process in chain; may throw InterruptedException last.waitFor(); // Return its InputStream return last.getInputStream(); }
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); String compName = null; String date = null; String Messg = null; try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st3.executeQuery("select name from interim_footer"); // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from // pb_hospitalprofile"); // java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) Messg = rset2.getObject(1).toString(); // while(rset4.next()) // date = rset4.getObject(1).toString(); com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase("" + Messg + ""), false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); // com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new // Phrase(""+compName+""),false);// // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); // headerFoter.ALIGN_CENTER; // headerFoter.setRight(5); docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.open(); try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = {25, 25, 20, 15, 15, 15}; table.setWidths(headerwidths); // table..setWidths(headerwidths); table.setWidthPercentage((100)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(6); Phrase phrase = new Phrase(); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement stc = connectDB.createStatement(); java.sql.Statement stb = connectDB.createStatement(); java.sql.Statement sta = connectDB.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st21 = connectDB.createStatement(); java.sql.Statement st22 = connectDB.createStatement(); java.sql.Statement st = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st32 = connectDB.createStatement(); java.sql.ResultSet rsetc = stc.executeQuery( "select discharge from hp_admission where patient_no = '" + memNo + "' order by date_admitted desc LIMIT 1"); java.sql.ResultSet rsetb = stb.executeQuery( "select (discharge_date - adm_date) from hp_inpatient_register where patient_no = '" + memNo + "'"); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile"); java.sql.ResultSet rset22 = st32.executeQuery("SELECT header_name from pb_header"); java.sql.ResultSet rseta = sta.executeQuery( "select ad.ward,ad.bed_no,ad.doctor ,pr.adm_date,pr.discharge_date from hp_admission ad,hp_inpatient_register pr where pr.patient_no = '" + memNo + "' and pr.patient_no = ad.patient_no"); // java.sql.ResultSet rset = st.executeQuery("select DISTINCT member_code, // member_name,date from shares_transactions order by member_code"); java.sql.ResultSet rset = st.executeQuery( "select patient_no,initcap(second_name||' '||first_name||' '||last_name),address,residence,tel_no,payer,description,category from hp_inpatient_register where patient_no = '" + memNo + "'"); java.sql.ResultSet rset1 = st1.executeQuery( " select date::date,initcap(service) as service,dosage,reference,debit-credit from hp_patient_card where patient_no = '" + memNo + "' AND date::date >= '" + beginDate + "' AND (reference IS NULL OR reference != '') and service != 'N.H.I.F' AND service != 'Receipt' order by date::date"); // union select date::date,initcap(service) as service,dosage,reference,credit from hp_patient_card where patient_no = '"+memNo+"' and credit > 0 order by date"); java.sql.ResultSet rsetTotals = st2.executeQuery( "select sum(debit - credit) from hp_patient_card where patient_no = '" + memNo + "' AND date::date >= '" + beginDate + "' and service != 'N.H.I.F' and service != 'Receipt'"); java.sql.ResultSet rset11 = st11.executeQuery( " select date::date,initcap(service) as service,dosage,reference,credit-debit from hp_patient_card where patient_no = '" + memNo + "' AND date::date >= '" + beginDate + "' AND (service = 'N.H.I.F' OR service = 'Receipt') AND invoice_no NOT LIKE 'I%' AND invoice_no NOT LIKE 'O%' order by date::date"); // union select date::date,initcap(service) as service,dosage,reference,credit from hp_patient_card where patient_no = '"+memNo+"' and credit > 0 order by date"); java.sql.ResultSet rsetTotals1 = st21.executeQuery( "select sum(credit-debit) from hp_patient_card where patient_no = '" + memNo + "' AND date::date >= '" + beginDate + "' and (service = 'N.H.I.F' OR service = 'Receipt') AND invoice_no NOT LIKE 'I%' AND invoice_no NOT LIKE 'O%'"); while (rset22.next()) // { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(dbObject.getDBObject(rset22.getObject(1), "-"), pFontHeader11); table.addCell(phrase); /* table.getDefaultCell().setColspan(6); table.getDefaultCell().setBorderColor(java.awt.Color.white); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Address:"+"\t"+dbObject.getDBObject(rset3.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Tel:"+"\t"+dbObject.getDBObject(rset3.getObject(3), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Fax:"+"\t"+ dbObject.getDBObject(rset3.getObject(5), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorderColor(java.awt.Color.white); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Email:"+"\t"+dbObject.getDBObject(rset3.getObject(6), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Website:"+"\t" +dbObject.getDBObject(rset3.getObject(7), "-"), pFontHeader); table.addCell(phrase); /// table.addCell(" "); } */ table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("Interim Invoice", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); while (rset.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Patient No: " + memNo, pFontHeader1); table.addCell(phrase); while (rseta.next()) table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Ward: " + dbObject.getDBObject(rseta.getObject(1), "-"), pFontHeader1); table.addCell(phrase); while (rset.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Patient Name: " + dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1); table.addCell(phrase); while (rseta.next()) table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Bed No: " + dbObject.getDBObject(rseta.getObject(2), "-"), pFontHeader1); table.addCell(phrase); while (rset.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Address: " + dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1); table.addCell(phrase); while (rseta.next()) table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Doctor: " + dbObject.getDBObject(rseta.getObject(3), "-"), pFontHeader1); table.addCell(phrase); while (rset.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Town " + dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1); table.addCell(phrase); while (rseta.next()) table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Adm Date: " + dbObject.getDBObject(rseta.getObject(4), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "TEl No. " + dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1); table.addCell(phrase); while (rseta.next()) table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Discharge Date: " + dbObject.getDBObject(rseta.getObject(5), "-"), pFontHeader1); table.addCell(phrase); while (rset.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Payer : " + dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Patient Category : " + dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Scheme Name : " + dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1); table.addCell(phrase); // if(rsetc.getBoolean(1) == true){ while (rsetb.next()) table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "No.of Days : " + dbObject.getDBObject(rsetb.getObject(1), "-"), pFontHeader1); table.addCell(phrase); // } table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorderWidth(Rectangle.TOP); table.getDefaultCell().setColspan(1); phrase = new Phrase("Date", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Description", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Qty", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Ref", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("Amt. KShs", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Bal. KShs", pFontHeader1); table.addCell(phrase); while (rset1.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(4), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(5)), pFontHeader); table.addCell(phrase); osBalance = osBalance + rset1.getDouble(5); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance)), pFontHeader); // current = current + osBalance; table.addCell(phrase); } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); while (rsetTotals.next()) { table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Invoice Amount", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rsetTotals.getString(1)), pFontHeader); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance)), pFontHeader1); table.addCell(phrase); // phrase = new Phrase(" "); } while (rset11.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset11.getObject(1), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset11.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset11.getObject(4), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset11.getString(5)), pFontHeader); table.addCell(phrase); osBalance1 = osBalance1 + rset11.getDouble(5); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance1)), pFontHeader); // current = current + osBalance; table.addCell(phrase); } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); while (rsetTotals1.next()) { table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total Receipts", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rsetTotals1.getString(1)), pFontHeader); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance1)), pFontHeader1); table.addCell(phrase); // phrase = new Phrase(" "); } // while (rsetTotals.next()) { table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Net Amount", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),pFontHeader); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance - osBalance1)), pFontHeader1); table.addCell(phrase); // phrase = new 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 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 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()); } double osBalancet = 0.00; String compName = null; String date = null; double osBalancebf = 0.00; double price = 0.00; double qty = 0.00; 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 TO_CHAR(current_timestamp(0),'FMDay FMDD/ MM/ YY HH12:MI')"); 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("Stocks By Dep. Cost - 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(5); int headerwidths[] = {25, 10, 10, 15, 10}; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.setHeaderRows(2); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(5); Phrase phrase = new Phrase("", pFontHeader); 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(3); phrase = new Phrase( "Items cost Report " + StoreName + ": Period : From " + dateFormat.format(endDate11) + " To " + dateFormat.format(endDate1), 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); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("ITEM", pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("Units", pFontHeader); table.addCell(phrase); phrase = new Phrase("Bp", pFontHeader); table.addCell(phrase); phrase = new Phrase("qty", pFontHeader); table.addCell(phrase); phrase = new Phrase("Cost", pFontHeader); table.addCell(phrase); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase("AMOUNT",pFontHeader); // table.addCell(phrase); // phrase = new Phrase("TOTAL KShs",pFontHeader); // table.addCell(phrase); // phrase = new Phrase("PROFIT",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.Connection conDb1 = // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner"); System.out.println(listofAct.length); // java.sql.Statement pSet1 = connectDB.createStatement(); java.sql.Statement st = connectDB.createStatement(); // java.sql.ResultSet rsetTotals = st.executeQuery("select sum((ph.quantity * // st.transfer_price)::numeric(10,2)), sum(amount)::numeric(10,2),sum(amount - // ph.quantity * st.transfer_price)::numeric(10,2) from hp_pharmacy ph,st_stock_prices // st WHERE st.department = 'Pharmacy' AND ph.date_prescribed BETWEEN '"+beginDate+"' // AND '"+endDate+"' AND ph.description = st.product"); for (int i = 0; i < listofAct.length; i++) { System.out.println("item" + listofAct[i]); /* double opStock = 0.00; double supplies = 0.00; double sales = 0.00; double closing = 0.00; */ java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st21 = connectDB.createStatement(); java.sql.Statement st31 = connectDB.createStatement(); java.sql.Statement st41 = connectDB.createStatement(); java.sql.Statement st32 = connectDB.createStatement(); java.sql.Statement st2e = connectDB.createStatement(); java.sql.ResultSet rset = st21.executeQuery( "select sp.product,sp.units,sp.transfer_price from st_stock_prices sp where sp.product ILIKE '" + listofAct[i] + "%' AND sp.department ILIKE '" + StoreName + "%'"); java.sql.ResultSet rset31 = st31.executeQuery( "select SUM(ph.quantity) from hp_pharmacy ph where ph.description ILIKE '" + listofAct[i] + "%' AND ph.main_service ILIKE '" + StoreName + "%' and ph.date_prescribed BETWEEN '" + beginDate + "' AND '" + endDate + "'"); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1); table.getDefaultCell().setColspan(1); phrase = new Phrase(listofAct[i].toString().toUpperCase(), pFontHeader1); table.addCell(phrase); while (rset.next()) { table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(3)), pFontHeader1); price = rset.getDouble(3); table.addCell(phrase); } while (rset31.next()) { phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset31.getString(1)), pFontHeader1); qty = rset31.getDouble(1); table.addCell(phrase); osBalancebf = qty * price; phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancebf)), pFontHeader); osBalancet = osBalancebf + osBalancet; table.addCell(phrase); } } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancet)), 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()); } 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 void generatePdf() { java.sql.ResultSet rsetTotals1 = null; 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.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("Un Finalised Invoices List - Page: ", pFontHeader1), true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, // Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); double balance = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(4); int headerwidths[] = {15, 30, 25, 15}; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.setHeaderRows(2); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setColspan(2); Phrase phrase = new Phrase( "In Patient Unfinalised Inv : ", com.lowagie.text.FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10)); table.addCell(phrase); table.getDefaultCell().setColspan(2); phrase = new Phrase( "Printed On : " + date, com.lowagie.text.FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10)); table.addCell(phrase); table.getDefaultCell().setColspan(1); // phrase = new Phrase("Name", pFontHeader); // table.addCell(phrase); phrase = new Phrase("Date", pFontHeader); table.addCell(phrase); phrase = new Phrase("No.", pFontHeader); table.addCell(phrase); phrase = new Phrase("Name", pFontHeader); table.addCell(phrase); phrase = new Phrase("Amount", 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.lang.Object[] listofAct1 = this.getListofActivities1(); java.sql.Statement st21 = connectDB.createStatement(); // java.sql.ResultSet rsetTotals = st21.executeQuery("SELECT sum(amount) from // op_unfinalised_inv where trans_date BETWEEN '"+beginDate+"' AND '"+endDate+"'"); // java.sql.Connection conDb1 = // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner"); // System.out.println(listofAct.length); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st22 = connectDB.createStatement(); for (int k = 0; k < listofAct1.length; k++) { java.sql.ResultSet rset1 = st2.executeQuery( "SELECT patient_no,sum(debit-credit) from hp_patient_card WHERE patient_no ILIKE '" + listofAct1[k].toString() + "%' and invoice_no NOT iLike 'O%' OR invoice_no NOT iLike 'I%' AND date BETWEEN '" + beginDate + "' AND '" + endDate + "' group by patient_no"); java.sql.ResultSet rset2 = st22.executeQuery( "SELECT patient_name from hp_admission WHERE patient_no ILIKE '" + listofAct1[k].toString() + "%'"); /* table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ",pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase(listofAct1[k].toString(),pFontHeader); // table.addCell(phrase); phrase = new Phrase("",pFontHeader); table.addCell(phrase); */ while (rset1.next()) { while (rset2.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontNum); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontNum); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset2.getString(1), pFontNum); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(2)), pFontHeader1); table.addCell(phrase); balance = balance + rset1.getDouble(2); } } } // while (rsetTotals.next()) { table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)), // pFontHeader); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(balance)), 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(); 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 void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; // com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate()); double osBalance1 = 0.00; double osBalance = 0.00; double current = 0.00; double osBalancebf = 0.00; try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); String compName = null; String date = null; String Messg = null; docPdf.open(); try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(7); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = {15, 15, 30, 15, 15, 15, 15}; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st2x = connectDB.createStatement(); java.sql.ResultSet rset2x = st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile"); while (rset2x.next()) { ks = rset2x.getObject(1).toString(); } java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header"); while (rset3.next()) { table1.getDefaultCell().setColspan(7); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), BadElExec.getMessage()); } // } catch(java.io.FileNotFoundException fnfExec) { // javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), // fnfExec.getMessage()); /// } try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = {12, 10, 28, 11, 14, 12, 14, 14, 15}; table.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { table.setHeaderRows(8); // } table.setWidthPercentage((100)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase(); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { double Debit = 0.00; double Credit = 0.00; java.sql.Statement st22 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st41 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.Statement st22D = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery( "select scheme_name,account_no,tel_main,address from ac_schemes where account_no = '" + memNo + "'"); java.sql.ResultSet rset41 = st41.executeQuery( "select payer_name from ac_schemes where account_no = '" + memNo + "'"); // java.sql.ResultSet rset1 = st1.executeQuery("select date,admission_no||' // '||cheque_no, upper(item),invoice_no ||' // '||receipt_no,debit,credit,credit_bal,balance from ac_debtors where account_no = '" // + memNo + "' AND date::date BETWEEN '" + beginDate + "' AND '" + endDate + "' group // by 1, 2, 3order by date,invoice_no");// UNION select // pd.date::date,initcap(pd.scheme_staff_no), (sh.first_name||' '||sh.second_name||' // '||sh.last_name) as name,pd.reference,sum(pd.credit),pd.patient_no from // hp_patient_card pd,hp_inpatient_register sh where pd.patient_no = sh.patient_no and // pd.isurer = '"+memNo+"' AND pd.date::date BETWEEN '"+beginDate+"' AND '"+endDate+"' // and pd.credit > 0 group by pd.date::date,pd.scheme_staff_no, // name,pd.reference,pd.invoice_no,pd.patient_no order by pd.invoice_no"); java.sql.ResultSet rsetTotals2 = st22.executeQuery( "select sum(debit - credit) from ac_debtors where account_no = '" + memNo + "' AND date::date < '" + beginDate + "'"); java.sql.ResultSet rsetTotals = st2.executeQuery( "select sum(debit),sum(credit) from ac_debtors where account_no = '" + memNo + "' AND date::date BETWEEN '" + beginDate + "' AND '" + endDate + "'"); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorderWidth(Rectangle.TOP | Rectangle.BOTTOM); table.getDefaultCell().setColspan(9); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("Statement of Account", pFontHeader11); table.addCell(phrase); while (rset4.next()) { table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(9); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1); table.addCell(phrase); while (rset41.next()) { table.getDefaultCell().setColspan(9); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset41.getString(1), pFontHeader1); table.addCell(phrase); } table.getDefaultCell().setColspan(9); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Account No : " + rset4.getObject(2).toString().toUpperCase(), pFontHeader1); table.addCell(phrase); phrase = new Phrase( dbObject.getDBObject("Tel : " + rset4.getObject(3), "-"), pFontHeader1); table.addCell(phrase); phrase = new Phrase(dbObject.getDBObject(rset4.getObject(4), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(6); } try { java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM); java.util.Date endDate1 = dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString()); java.util.Date endDate11 = dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString()); System.out.println("" + endDate1); // phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate), // pFontHeader); // table.addCell(phrase); phrase = new Phrase( "Period : " + dateFormat.format(endDate11) + " - " + dateFormat.format(endDate1), pFontHeader1); table.addCell(phrase); } catch (java.text.ParseException psExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), psExec.getMessage()); } // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1); // table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Date " + datenowSql, pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorderWidth(Rectangle.TOP); table.getDefaultCell().setColspan(1); // phrase = new Phrase("Date", pFontHeader1); // table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Staff No.", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(2); phrase = new Phrase(" Staff Name", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("", pFontHeader1); table.addCell(phrase); phrase = new Phrase("", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Debit Bal. ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Running Amt. " + ks, pFontHeader1); table.addCell(phrase); while (rsetTotals2.next()) { table.getDefaultCell().setColspan(5); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("BAL/BF", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(4); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rsetTotals2.getString(1)), pFontHeader1); osBalancebf = osBalancebf + rsetTotals2.getDouble(1); table.addCell(phrase); } for (int i = 0; i < listofStaffNos.length; i++) { java.sql.ResultSet rset1 = st1.executeQuery( "select admission_no, upper(item), sum(debit - credit) from ac_debtors where account_no = '" + memNo + "' and admission_no = '" + listofStaffNos[i] + "' AND date::date BETWEEN '" + beginDate + "' AND '" + endDate + "' GROUP BY 1, 2"); while (rset1.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"), // pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(4), "-"), // pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(5)), // pFontHeader); // Debit = Debit + rset1.getDouble(5); // table.addCell(phrase); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), // pFontHeader); // Credit = Credit + rset1.getDouble(6); // table.addCell(phrase); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), // pFontHeader); // osBalance1 = osBalance1 + rset1.getDouble(6); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(3)), pFontHeader); osBalancebf = osBalancebf + rset1.getDouble(3); // osBalancebf = osBalance1; table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)), pFontHeader); table.addCell(phrase); } } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); // while (rsetTotals.next()) { table.getDefaultCell().setColspan(4); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("", pFontHeader); table.addCell(phrase); phrase = new Phrase("", pFontHeader); table.addCell(phrase); phrase = new Phrase("", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)), pFontHeader); table.addCell(phrase); // phrase = new Phrase(" "); // } try { java.sql.Statement st31 = connectDB.createStatement(); // java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st31.executeQuery("select name from pb_notice"); // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from // pb_hospitalprofile"); // java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) { Messg = rset2.getString(1); } com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase("" + Messg + ""), false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); // com.lowagie.text.HeaderFooter headerFoter = new // com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); // headerFoter.ALIGN_CENTER; // headerFoter.setRight(5); docPdf.setFooter(footer); } catch (java.sql.SQLException SqlExec) { SqlExec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table); } catch (java.sql.SQLException SqlExec) { SqlExec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } // } // } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } try { if (System.getProperty("os.name").equalsIgnoreCase("Linux")) { System.out.println(tempFile); wait_for_Pdf2Show = rt.exec("xpdf " + tempFile + ""); wait_for_Pdf2Show.waitFor(); } else { wait_for_Pdf2Show = rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile); wait_for_Pdf2Show.waitFor(); } } catch (java.lang.InterruptedException intrExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage()); } } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
/** * Executes a process script with the desired environment, current working directory, and * input/output streams * * <p>This implements the following CGI specification recommedations: * * <UL> * <LI>Servers SHOULD provide the "<code>query</code>" component of the script-URI as * command-line arguments to scripts if it does not contain any unencoded "=" characters and * the command-line arguments can be generated in an unambiguous manner. * <LI>Servers SHOULD set the AUTH_TYPE metavariable to the value of the "<code>auth-scheme * </code>" token of the "<code>Authorization</code>" if it was supplied as part of the * request header. See <code>getCGIEnvironment</code> method. * <LI>Where applicable, servers SHOULD set the current working directory to the directory in * which the script is located before invoking it. * <LI>Server implementations SHOULD define their behavior for the following cases: * <ul> * <LI><u>Allowed characters in pathInfo</u>: This implementation does not allow ASCII NUL * nor any character which cannot be URL-encoded according to internet standards; * <LI><u>Allowed characters in path segments</u>: This implementation does not allow * non-terminal NULL segments in the the path -- IOExceptions may be thrown; * <LI><u>"<code>.</code>" and "<code>..</code>" path segments</u>: This implementation * does not allow "<code>.</code>" and "<code>..</code>" in the the path, and such * characters will result in an IOException being thrown; * <LI><u>Implementation limitations</u>: This implementation does not impose any * limitations except as documented above. This implementation may be limited by the * servlet container used to house this implementation. In particular, all the primary * CGI variable values are derived either directly or indirectly from the container's * implementation of the Servlet API methods. * </ul> * </UL> * * For more information, see java.lang.Runtime#exec(String command, String[] envp, File dir) * * @exception IOException if problems during reading/writing occur */ public void run() throws IOException { /* * REMIND: this method feels too big; should it be re-written? */ if (!isReady()) { throw new IOException(this.getClass().getName() + ": not ready to run."); } if (debug >= 1) { log("runCGI(envp=[" + env + "], command=" + command + ")"); } if ((command.indexOf(File.separator + "." + File.separator) >= 0) || (command.indexOf(File.separator + "..") >= 0) || (command.indexOf(".." + File.separator) >= 0)) { throw new IOException( this.getClass().getName() + "Illegal Character in CGI command " + "path ('.' or '..') detected. Not " + "running CGI [" + command + "]."); } /* original content/structure of this section taken from * http://developer.java.sun.com/developer/ * bugParade/bugs/4216884.html * with major modifications by Martin Dengler */ Runtime rt = null; BufferedReader commandsStdOut = null; BufferedReader commandsStdErr = null; BufferedOutputStream commandsStdIn = null; Process proc = null; byte[] bBuf = new byte[1024]; char[] cBuf = new char[1024]; int bufRead = -1; // create query arguments Enumeration paramNames = params.keys(); StringBuffer cmdAndArgs = new StringBuffer(command); if (paramNames != null && paramNames.hasMoreElements()) { cmdAndArgs.append(" "); while (paramNames.hasMoreElements()) { String k = (String) paramNames.nextElement(); String v = params.get(k).toString(); if ((k.indexOf("=") < 0) && (v.indexOf("=") < 0)) { cmdAndArgs.append(k); cmdAndArgs.append("="); v = java.net.URLEncoder.encode(v); cmdAndArgs.append(v); cmdAndArgs.append(" "); } } } String postIn = getPostInput(params); int contentLength = (postIn.length() + System.getProperty("line.separator").length()); if ("POST".equals(env.get("REQUEST_METHOD"))) { env.put("CONTENT_LENGTH", new Integer(contentLength)); } rt = Runtime.getRuntime(); proc = rt.exec(cmdAndArgs.toString(), hashToStringArray(env), wd); /* * provide input to cgi * First -- parameters * Second -- any remaining input */ commandsStdIn = new BufferedOutputStream(proc.getOutputStream()); if (debug >= 2) { log("runCGI stdin=[" + stdin + "], qs=" + env.get("QUERY_STRING")); } if ("POST".equals(env.get("REQUEST_METHOD"))) { if (debug >= 2) { log("runCGI: writing ---------------\n"); log(postIn); log("runCGI: new content_length=" + contentLength + "---------------\n"); } commandsStdIn.write(postIn.getBytes()); } if (stdin != null) { // REMIND: document this /* assume if nothing is available after a time, that nothing is * coming... */ if (stdin.available() <= 0) { if (debug >= 2) { log("runCGI stdin is NOT available [" + stdin.available() + "]"); } try { Thread.currentThread().sleep(iClientInputTimeout); } catch (InterruptedException ignored) { } } if (stdin.available() > 0) { if (debug >= 2) { log("runCGI stdin IS available [" + stdin.available() + "]"); } bBuf = new byte[1024]; bufRead = -1; try { while ((bufRead = stdin.read(bBuf)) != -1) { if (debug >= 2) { log("runCGI: read [" + bufRead + "] bytes from stdin"); } commandsStdIn.write(bBuf, 0, bufRead); } if (debug >= 2) { log("runCGI: DONE READING from stdin"); } } catch (IOException ioe) { // REMIND: replace with logging // REMIND: should I throw this exception? log("runCGI: couldn't write all bytes."); ioe.printStackTrace(); } } } commandsStdIn.flush(); commandsStdIn.close(); /* we want to wait for the process to exit, Process.waitFor() * is useless in our situation; see * http://developer.java.sun.com/developer/ * bugParade/bugs/4223650.html */ boolean isRunning = true; commandsStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream())); commandsStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream())); BufferedWriter servletContainerStdout = null; try { if (response.getOutputStream() != null) { servletContainerStdout = new BufferedWriter(new OutputStreamWriter(response.getOutputStream())); } } catch (IOException ignored) { // NOOP: no output will be written } while (isRunning) { try { // read stderr first cBuf = new char[1024]; while ((bufRead = commandsStdErr.read(cBuf)) != -1) { if (servletContainerStdout != null) { servletContainerStdout.write(cBuf, 0, bufRead); } } // set headers String line = null; while (((line = commandsStdOut.readLine()) != null) && !("".equals(line))) { if (debug >= 2) { log("runCGI: addHeader(\"" + line + "\")"); } if (line.startsWith("HTTP")) { // TODO: should set status codes (NPH support) /* * response.setStatus(getStatusCode(line)); */ } else { response.addHeader( line.substring(0, line.indexOf(":")).trim(), line.substring(line.indexOf(":") + 1).trim()); } } // write output cBuf = new char[1024]; while ((bufRead = commandsStdOut.read(cBuf)) != -1) { if (servletContainerStdout != null) { if (debug >= 4) { log("runCGI: write(\"" + cBuf + "\")"); } servletContainerStdout.write(cBuf, 0, bufRead); } } if (servletContainerStdout != null) { servletContainerStdout.flush(); } proc.exitValue(); // Throws exception if alive isRunning = false; } catch (IllegalThreadStateException e) { try { Thread.currentThread().sleep(500); } catch (InterruptedException ignored) { } } } // replacement for Process.waitFor() }
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); 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.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("FINAL VOUCHER"), 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.setRight(5); docPdf.setHeader(headerFoter); docPdf.open(); try { java.lang.Object listofStaffNos[] = this.getListofStaffNos(); for (int j = 0; j < listofStaffNos.length; j++) { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = {25, 25, 20, 15, 15, 15}; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(6); Phrase phrase = new Phrase(); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement st = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery( "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery("select dealer,description from ac.cash_book"); // java.sql.ResultSet rset = st.executeQuery("select DISTINCT member_code, // member_name,date from shares_transactions order by member_code"); java.sql.ResultSet rset = st.executeQuery( "select patient_no,initcap(first_name||' '||second_name||' '||last_name),address,residence,tel_no from hp_patient_register where patient_no = '" + listofStaffNos[j] + "'"); java.sql.ResultSet rset5 = st5.executeQuery( "select staff_no,staff_name from hp_schemestaff sh, hp_patient_card pc where pc.patient_no = '" + listofStaffNos[j] + "' AND pc.scheme_staff_no = sh.staff_no"); java.sql.ResultSet rset1 = st1.executeQuery( "select date::date,initcap(service) as service,dosage,reference,debit from hp_patient_card where patient_no = '" + listofStaffNos[j] + "' AND paid = true order by date"); java.sql.ResultSet rsetTotals = st2.executeQuery( "select sum(debit) from hp_patient_card where patient_no = '" + listofStaffNos[j] + "' AND paid = true"); while (rset3.next()) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setBorderColor(java.awt.Color.white); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Address:" + "\t" + rset3.getObject(2).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Tel:" + "\t" + rset3.getObject(3).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Fax:" + "\t" + rset3.getObject(5).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setBorderColor(java.awt.Color.white); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Email:" + "\t" + rset3.getObject(6).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Website:" + "\t" + rset3.getObject(7).toString(), pFontHeader); table.addCell(phrase); /// table.addCell(" "); } table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("Voucher", pFontHeader1); table.addCell(phrase); while (rset4.next()) table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Address: " + rset4.getObject(2).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Tel: " + rset4.getObject(3).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Fax: " + rset4.getObject(4).toString(), pFontHeader); table.addCell(phrase); /* table.getDefaultCell().setBorderColor(java.awt.Color.white); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Email:"+"\t"+rset3.getObject(6).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Website:"+"\t" +rset3.getObject(7).toString(), pFontHeader); table.addCell(phrase); /// table.addCell(" "); */ while (rset5.next()) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Member No. " + rset5.getObject(1).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Member Name " + rset5.getObject(2).toString(), pFontHeader); table.addCell(phrase); } while (rset.next()) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Patient No. " + rset.getObject(1).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Patient Name " + rset.getObject(2).toString(), pFontHeader); table.addCell(phrase); /* table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Address "+rset.getObject(3).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Town "+rset.getObject(4).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("TEl No. "+rset.getObject(5).toString(), pFontHeader); table.addCell(phrase); */ } table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorderWidth(Rectangle.TOP); table.getDefaultCell().setColspan(1); phrase = new Phrase("Date", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(2); phrase = new Phrase("Description", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Qty", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Ref", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("Amount KShs", pFontHeader1); table.addCell(phrase); while (rset1.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(3).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(5)), pFontHeader); table.addCell(phrase); } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); while (rsetTotals.next()) { table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rsetTotals.getString(1)), pFontHeader); table.addCell(phrase); // phrase = new 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 void generatePdf() { java.lang.Object[][] rangeDates = ageingSeries.getAgeingDateSeries(); // ageingDates = ageingSeries.getAgeingDateSeries(); double columnTotals[] = new double[rangeDates.length]; 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(); int interval = 0; 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(); java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); 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, pFontHeader2), 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("Ageing Page: ", pFontHeader), true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, // Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); double Totals = 0.00; double OS = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(rangeDates.length + 3); String headerWidths = null; java.util.Vector headerVector = new java.util.Vector(1, 1); int z = rangeDates.length; int headerwidths[] = {35, 15, 15, 10, 10}; table.setWidths(headerwidths); table.setWidthPercentage((107)); table.setHeaderRows(2); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(5); Phrase phrase = new Phrase(""); table.getDefaultCell().setColspan(3); try { java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM); java.util.Date endDate2 = dateFormat.parse(endDate.toLocaleString()); phrase = new Phrase("Weekly Sales Comparison " + dateFormat.format(endDate2), pFontHeader); table.addCell(phrase); } catch (java.text.ParseException psExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), psExec.getMessage()); } 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().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("DESCRIPTION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); for (int x = 0; x < rangeDates.length; x++) { int days = 1; try { // Date parser java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); com.afrisoftech.lib.DateFormatter dateFormatter = new com.afrisoftech.lib.DateFormatter( dateFormat.parse(rangeDates[x][0].toString().trim()), "w"); com.afrisoftech.lib.DateFormatter yearFormatterCurrent = new com.afrisoftech.lib.DateFormatter(endDate, "yy"); java.lang.String monthString = dateFormatter.getDateString(); java.lang.String yearStringCurrent = yearFormatterCurrent.getDateString(); // int days = 1; // if (x < 1) { com.afrisoftech.lib.DateFormatter dateFormatterCurrent = new com.afrisoftech.lib.DateFormatter(endDate, "w"); com.afrisoftech.lib.DateFormatter yearFormatterCurrent1 = new com.afrisoftech.lib.DateFormatter(endDate, "yy"); java.lang.String monthStringCurrent = dateFormatterCurrent.getDateString(); java.lang.String yearStringCurrent1 = yearFormatterCurrent1.getDateString(); // phrase = new Phrase("Week ["+monthStringCurrent+"/"+yearStringCurrent1+"]" // ,pFontHeader); // } else { // phrase = new Phrase("Week ["+monthString+"/"+yearStringCurrent+"]", // pFontHeader); // phrase = new Phrase("+ "+x*days +" // Month",pFontHeader); interval = x; // } table.addCell(phrase); // Catch java.text.parse exception. } catch (java.text.ParseException prs) { prs.printStackTrace(); } } // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Change % (+/-)", pFontHeader); table.addCell(phrase); phrase = new Phrase("Change In Reporting Rate", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { double GrandTotal = 0.00; double Over120Total = 0.00; double TurnOver = 0.00; java.lang.Object[] listofAct = this.getListofActivities(); // java.sql.Connection conDb1 = // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner"); System.out.println(listofAct.length); double Over120 = 0.00; for (int i = 0; i < listofAct.length; i++) { double TotalCount = 0.00; table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setColspan(1); java.sql.Statement stmta1 = connectDB.createStatement(); java.sql.PreparedStatement pSeta1 = connectDB.prepareStatement( "SELECT count(activity_code) FROM ac_ledger where activity_code = '" + listofAct[i] + "'"); java.sql.PreparedStatement pset22 = connectDB.prepareStatement( "select activity from pb_activity WHERE code = ?"); // < '"+endDate+"'::date // and date > // '"+endDate+"'::date - // 30 group by dealer"); // java.sql.PreparedStatement pset22 = connectDB.prepareStatement("select // description from ac_ledger WHERE activity_code = ?");//< '"+endDate+"'::date and // date > '"+endDate+"'::date - 30 group by dealer"); pset22.setString(1, listofAct[i].toString().toUpperCase()); java.sql.ResultSet rSeta1 = pSeta1.executeQuery(); while (rSeta1.next()) { name = rSeta1.getInt(1); } if (name > 0) { java.sql.ResultSet rset22 = pset22.executeQuery(); while (rset22.next()) { table.getDefaultCell().setColspan(1); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( dbObject.getDBObject(rset22.getObject(1).toString().toUpperCase(), "-"), pFontHeader1); table.addCell(phrase); } java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st21 = connectDB.createStatement(); java.sql.Statement st22 = connectDB.createStatement(); java.sql.Statement st23 = connectDB.createStatement(); java.sql.Statement st211 = connectDB.createStatement(); java.sql.Statement st221 = connectDB.createStatement(); java.sql.Statement st231 = connectDB.createStatement(); java.sql.Statement st2A = connectDB.createStatement(); java.sql.Statement st2B = connectDB.createStatement(); java.sql.Statement st2C = connectDB.createStatement(); java.sql.Statement stc = connectDB.createStatement(); System.out.println("Dealer Is : [" + listofAct[i] + "]."); java.sql.PreparedStatement pset1 = connectDB.prepareStatement( "select sum(credit-debit) from ac_ledger WHERE activity_code = ? AND date = '" + rangeDates[rangeDates.length - 1][0] + "'"); // AND '"+rangeDates[rangeDates.length - 1][1]+"'");//< // '"+endDate+"'::date and date > '"+endDate+"'::date - 30 // group by dealer"); pset1.setString(1, listofAct[i].toString()); java.sql.ResultSet rset1 = pset1.executeQuery(); // java.sql.PreparedStatement pset111 = connectDB.prepareStatement("select // sum(credit-debit) from ac_ledger WHERE activity_code = ? AND date < // '"+endDate+"'");//< '"+endDate+"'::date and date > '"+endDate+"'::date - 30 // group by dealer"); // pset111.setString(1,listofAct[i].toString()); // java.sql.ResultSet rset111 = pset111.executeQuery(); // java.sql.Statement st02 = connectDB.createStatement(); // java.sql.PreparedStatement pset112 = connectDB.prepareStatement("select // sum(credit-debit) from ac_ledger WHERE activity_code = ? AND date < // '"+endDate+"'");//< '"+endDate+"'::date and date > '"+endDate+"'::date - 30 // group by dealer"); // pset112.setString(1,listofAct[i].toString()); // java.sql.ResultSet rset112 = pset112.executeQuery(); for (int t = 0; t < rangeDates.length; t++) { java.sql.Statement st01 = connectDB.createStatement(); java.sql.PreparedStatement pset = connectDB.prepareStatement( "select sum(credit-debit) from ac_ledger WHERE activity_code = ? AND date between '" + rangeDates[t][0] + "' AND '" + rangeDates[t][1] + "'"); // < '"+endDate+"'::date and date > '"+endDate+"'::date - 30 // group by dealer"); pset.setString(1, listofAct[i].toString().toUpperCase()); java.sql.ResultSet rset = pset.executeQuery(); while (rset.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(1)), pFontHeader1); table.addCell(phrase); columnTotals[t] = columnTotals[t] + rset.getDouble(1); TotalCount = TotalCount + rset.getDouble(1); TurnOver = rset.getDouble(1); } } // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(TotalCount)), pFontHeader); // table.addCell(phrase); while (rset1.next()) { Over120 = rset1.getDouble(1); if (Over120 > 0) { phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency( java.lang.String.valueOf((Over120 / TurnOver) * 100)), pFontHeader); table.addCell(phrase); phrase = new Phrase("+", pFontHeader); table.addCell(phrase); } else { phrase = new Phrase(java.lang.String.valueOf(0.00), pFontHeader); table.addCell(phrase); phrase = new Phrase("", pFontHeader); table.addCell(phrase); } } /* }else{ if (TotalCount <= 0 && Over120 > 0){ phrase = new Phrase(java.lang.String.valueOf((Over120/TurnOver)*100), pFontHeader); table.addCell(phrase); phrase = new Phrase("+", pFontHeader); table.addCell(phrase); }else{ if (TotalCount > 0 && Over120 < 0){ phrase = new Phrase(java.lang.String.valueOf((Over120/TurnOver)*100), pFontHeader); table.addCell(phrase); phrase = new Phrase("-", pFontHeader); table.addCell(phrase); }else{ if (TotalCount > 0 && Over120 == 0){ phrase = new Phrase(java.lang.String.valueOf((Over120/TurnOver)*100), pFontHeader); table.addCell(phrase); phrase = new Phrase("-", pFontHeader); table.addCell(phrase); }else{ if (TotalCount < 0 && Over120 < 0){ phrase = new Phrase(java.lang.String.valueOf((Over120/TurnOver)*100), pFontHeader); table.addCell(phrase); phrase = new Phrase("-", pFontHeader); table.addCell(phrase); }else{ phrase = new Phrase(java.lang.String.valueOf(0.00), pFontHeader); table.addCell(phrase); phrase = new Phrase("", pFontHeader); table.addCell(phrase); } } } } }*/ // } } } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); // while (rsetTotals.next()) { table.getDefaultCell().setColspan(1); 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(rsetTotals.getString(1)), // pFontHeader); for (int x = 0; x < rangeDates.length; x++) { // phrase = new Phrase("Current"+2*x,pFontHeader); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(columnTotals[x])), pFontHeader); table.addCell(phrase); } phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(Over120Total)), pFontHeader); // table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(OS)), pFontHeader); // table.addCell(phrase); docPdf.add(table); } catch (java.sql.SQLException SqlExec) { SqlExec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { // Bad 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()); } }
/** * Performs file compression into a certain file or directory and have it inside the specified * destination file path. * * @param forarchive Directory or file to compress * @param destination Output file destination. * @return File information of the output file. */ public java.io.File archive(java.io.File forarchive, String destination) { java.io.File _file = null; String _batchfilename = Application.startUpPath() + "\\archiver.bat"; String _zip = mime.Mime.resources.sevenZip().getPath(); if (_zip.startsWith("/")) _zip = mime.Mime.resources.sevenZip().getPath().substring(1); String _path = forarchive.getPath(); if (_path.startsWith("/")) _path = forarchive.getPath().substring(1); String _contents = "\"" + _zip + "\" a \"" + destination + "\" " + _path + "\""; java.io.File _batchfile = null; StreamWriter _sw = new StreamWriter(_batchfilename); try { _sw.write(_contents); _batchfile = new java.io.File(_batchfilename); } catch (Exception ex) { _batchfile = null; ex.printStackTrace(); } finally { _sw.close(); _sw.dispose(); } if (_batchfile != null) { java.lang.Process p = null; try { p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", _batchfilename}); p.waitFor(); InputStream _errorstream = p.getErrorStream(); String _error = ""; if (_errorstream != null) { int _bytecount = _errorstream.available(); if (_bytecount > 0) { StringWriter _writer = new StringWriter(); try { byte[] _bytes = new byte[_bytecount]; _errorstream.read(_bytes); _error = new String(_bytes); } catch (Exception ex) { ex.printStackTrace(); } finally { _writer.close(); _writer = null; System.gc(); } } } _file = new java.io.File(destination); if (!_file.exists()) { _file = null; System.gc(); } } catch (Exception ex) { _file = null; ex.printStackTrace(); } finally { if (p != null) p.destroy(); p = null; System.gc(); } try { _batchfile.delete(); } catch (Exception ex) { } finally { _batchfile = null; System.gc(); } } return _file; }
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(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); double osBalancebf = 0.00; double osBalance = 0.00; double osBalanceb1 = 0.00; String compName = null; String date = null; docPdf.open(); try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); // java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(7); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = {15, 15, 30, 15, 15, 15, 15}; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header"); while (rset3.next()) table1.getDefaultCell().setColspan(7); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1); table1.addCell(phrase); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), BadElExec.getMessage()); } com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase("Debtors Statement - Page: ", pFontHeader), true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, // Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = {10, 30, 15, 15, 15, 20}; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.setHeaderRows(2); table.getDefaultCell().setBorder(Rectangle.BOTTOM); Phrase phrase = new Phrase(); // table.getDefaultCell().setColspan(8); table.getDefaultCell().setColspan(4); try { java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM); java.util.Date endDate1 = dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString()); java.util.Date endDate11 = dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString()); System.out.println("" + endDate1); // phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate), // pFontHeader); // table.addCell(phrase); phrase = new Phrase( Debtor + " Period : " + dateFormat.format(endDate11) + " - " + dateFormat.format(endDate1), pFontHeader1); table.addCell(phrase); } catch (java.text.ParseException psExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), psExec.getMessage()); } // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1); // table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Date " + datenowSql, pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setColspan(1); // table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("Acc No", pFontHeader); table.addCell(phrase); phrase = new Phrase("Scheme", pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("Debit", pFontHeader); table.addCell(phrase); phrase = new Phrase("Credit", pFontHeader); table.addCell(phrase); phrase = new Phrase("Balance ", pFontHeader); table.addCell(phrase); phrase = new Phrase("Running Total", 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 st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.ResultSet rset = st.executeQuery( "select db.account_no,db.payee,sum(db.debit),sum(credit),SUM(db.balance) from ac_debtors db WHERE db.date BETWEEN '" + beginDate + "' AND '" + endDate + "' AND db.dealer ILIKE '" + Debtor + "' GROUP BY db.payee,db.account_no ORDER BY db.payee"); java.sql.ResultSet rset1 = st1.executeQuery( "select SUM(db.balance) from ac_debtors db WHERE db.date < '" + beginDate + "' AND db.dealer ILIKE '" + Debtor + "' GROUP BY db.account_no"); while (rset1.next()) { bfwd = rset1.getDouble(1); bfcd = bfcd + rset1.getDouble(1); } while (rset.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(3)), pFontHeader1); osBalance = osBalance + rset.getDouble(3); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(4)), pFontHeader1); osBalanceb1 = osBalanceb1 + rset.getDouble(4); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(5)), pFontHeader); osBalancebf = osBalancebf + rset.getDouble(5); // osBalancebf = osBalance1; table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancebf)), pFontHeader); table.addCell(phrase); } // } table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); // while (rsetTotals.next()) { table.getDefaultCell().setColspan(2); 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)), pFontHeader); table.addCell(phrase); // table.getDefaultCell().setColspan(2); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalanceb1)), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalancebf)), 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(); try { if (System.getProperty("os.name").equalsIgnoreCase("Linux")) { System.out.println(tempFile); // wait_for_Pdf2Show = rt.exec("kghostview "+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()); } }
@Override public void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters) throws IOException, InterruptedException { Map<String, Path> input = portBindings.getInput(); Map<String, Path> output = portBindings.getOutput(); FileSystem fs = FileSystem.get(conf); java.lang.Process process = Runtime.getRuntime() .exec( "python scripts/madis/mexec.py -d scripts/base_projects.db -f scripts/buildprojectdb.sql"); BufferedOutputStream stdin = new BufferedOutputStream(process.getOutputStream()); InputStream errorStream = process.getErrorStream(); Iterator<Project> projects = DataStore.getReader(new FileSystemPath(fs, input.get(projectPort))); JsonStreamWriter<Project> writer = new JsonStreamWriter<Project>(Project.SCHEMA$, stdin); try { while (projects.hasNext()) { writer.write(projects.next()); } writer.close(); process.waitFor(); } catch (Exception e) { // providing error details from Madis error stream BufferedReader stderr = new BufferedReader(new InputStreamReader(errorStream)); StringBuilder errorBuilder = new StringBuilder(); String line; while ((line = stderr.readLine()) != null) { errorBuilder.append(line); } stderr.close(); throw new IOException( "got error while writing to Madis stream: " + errorBuilder.toString(), e); } if (process.exitValue() != 0) { BufferedReader stderr = new BufferedReader(new InputStreamReader(errorStream)); StringBuilder errorBuilder = new StringBuilder(); String line; while ((line = stderr.readLine()) != null) { errorBuilder.append(line); } stderr.close(); throw new RuntimeException("MadIS execution failed with error: " + errorBuilder.toString()); } InputStream inStream = null; OutputStream outStream = null; try { inStream = new FileInputStream(new File("scripts/base_projects.db")); outStream = fs.create(new FileSystemPath(fs, output.get(projectDBPort)).getPath()); IOUtils.copyStream(inStream, outStream); } finally { if (inStream != null) { inStream.close(); } if (outStream != null) { outStream.close(); } } }
public void generatePdf(java.lang.String memNo) { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); double osBalance1 = 0.00; double osBalance = 0.00; double current = 0.00; double osBalancebf = 0.00; try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); String compName = null; String date = null; String Messg = null; com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase("Allocation - Page: ", pFontHeader), true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, // Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = {15, 15, 30, 15, 15, 15}; table1.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { // table1.setHeaderRows(4); // } table1.setWidthPercentage((100)); table1.getDefaultCell().setBorder(Rectangle.BOTTOM); table1.getDefaultCell().setColspan(7); Phrase phrase = new Phrase(); // table.addCell(phrase); table1.getDefaultCell().setColspan(1); table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header"); while (rset3.next()) table1.getDefaultCell().setColspan(6); table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11); table1.addCell(phrase); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } docPdf.add(table1); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), BadElExec.getMessage()); } // } catch(java.io.FileNotFoundException fnfExec) { // javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), // fnfExec.getMessage()); /// } try { java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); java.lang.Object listofStaffNos[] = this.getListofStaffNos(); com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10); // com.lowagie.text.Table table = new com.lowagie.text.Table(7); // table.endHeaders(); int headerwidths[] = {12, 10, 23, 10, 12, 13, 8, 11, 10, 8}; table.setWidths(headerwidths); // if (docPdf.getPageNumber() > 1) { table.setHeaderRows(10); // } table.setWidthPercentage((100)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(10); Phrase phrase = new Phrase(); // table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { java.sql.Statement st22 = connectDB.createStatement(); java.sql.Statement st11 = connectDB.createStatement(); java.sql.Statement st = connectDB.createStatement(); java.sql.Statement st1 = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st41 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); // java.sql.ResultSet rset3 = st3.executeQuery("select hospital_name,postal_code||' // '||box_no||' '||town,main_telno||' // '||other_telno,initcap(street),main_faxno,email,website,room_no from // pb_hospitalprofile"); // java.sql.ResultSet rset4 = st4.executeQuery("select scheme_manager from // ac_scheme_providers where scheme_manager = '"+memNo+"'"); java.sql.ResultSet rset4 = st4.executeQuery( "select scheme_name,account_no from ac_schemes where account_no = '" + memNo + "'"); java.sql.ResultSet rset41 = st41.executeQuery( "select payer_name from ac_schemes where account_no = '" + memNo + "'"); // java.sql.ResultSet rset1 = st1.executeQuery("select ac.date,pc.scheme_staff_no, // ac.payee,ac.reference_no,sum(ac.debit),ac.admission_no from hp_patient_card // pc,ac_debtors ac where pc.patient_no = ac.admission_no and ac.dealer = '"+memNo+"' // and ac.dealer = pc.scheme AND ac.date::date BETWEEN '"+beginDate+"' AND // '"+endDate+"' and ac.debit > 0 group by ac.date,pc.scheme_staff_no, // ac.payee,ac.reference_no,ac.admission_no");// UNION select // pd.date::date,initcap(pd.scheme_staff_no), (sh.first_name||' '||sh.second_name||' // '||sh.last_name) as name,pd.reference,sum(pd.credit),pd.patient_no from // hp_patient_card pd,hp_inpatient_register sh where pd.patient_no = sh.patient_no and // pd.isurer = '"+memNo+"' AND pd.date::date BETWEEN '"+beginDate+"' AND '"+endDate+"' // and pd.credit > 0 group by pd.date::date,pd.scheme_staff_no, // name,pd.reference,pd.invoice_no,pd.patient_no order by pd.invoice_no"); java.sql.ResultSet rset1 = st1.executeQuery( "select al.date,db.admission_no,db.item,al.inv_no,al.inv_date,db.debit, al.cheque_no,al.amount,al.amount_alloc,(db.debit-al.amount_alloc) from db_allocation al,ac_debtors db where al.acc_no = '" + memNo + "' and al.inv_no = db.invoice_no AND al.date::date BETWEEN '" + beginDate + "' AND '" + endDate + "' order by al.date"); // UNION select // pd.date::date,initcap(pd.scheme_staff_no), // (sh.first_name||' '||sh.second_name||' // '||sh.last_name) as // name,pd.reference,sum(pd.credit),pd.patient_no // from hp_patient_card pd,hp_inpatient_register // sh where pd.patient_no = sh.patient_no and // pd.isurer = '"+memNo+"' AND pd.date::date // BETWEEN '"+beginDate+"' AND '"+endDate+"' and // pd.credit > 0 group by // pd.date::date,pd.scheme_staff_no, // name,pd.reference,pd.invoice_no,pd.patient_no // order by pd.invoice_no"); // java.sql.ResultSet rsetTotals2 = st22.executeQuery("select sum(debit),sum(balance) // from ac_debtors where account_no = '"+memNo+"' AND date::date < '"+beginDate+"'"); // java.sql.ResultSet rset1 = st1.executeQuery("select // pc.date::date,pc.scheme_staff_no, initcap(sh.first_name||' '||sh.second_name||' // '||sh.last_name) as name,pc.reference,sum(pc.credit),pc.patient_no from // hp_patient_card pc,hp_patient_register sh where pc.scheme_staff_no = sh.account_no // and pc.isurer = '"+memNo+"' AND pc.date::date BETWEEN '"+beginDate+"' AND // '"+endDate+"' and pc.credit > 0 group by pc.date::date,pc.scheme_staff_no, // name,pc.reference,pc.invoice_no,pc.patient_no");// UNION select // pd.date::date,initcap(pd.scheme_staff_no), (sh.first_name||' '||sh.second_name||' // '||sh.last_name) as name,pd.reference,sum(pd.credit),pd.patient_no from // hp_patient_card pd,hp_inpatient_register sh where pd.patient_no = sh.patient_no and // pd.isurer = '"+memNo+"' AND pd.date::date BETWEEN '"+beginDate+"' AND '"+endDate+"' // and pd.credit > 0 group by pd.date::date,pd.scheme_staff_no, // name,pd.reference,pd.invoice_no,pd.patient_no order by pd.invoice_no"); // java.sql.ResultSet rsetTotals = st2.executeQuery("select // sum(amount),sum(amount_alloc) from db_allocation where acc_no = '"+memNo+"' AND // date::date BETWEEN '"+beginDate+"' AND '"+endDate+"' and acc_no = '"+memNo+"'"); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorderWidth(Rectangle.TOP | Rectangle.BOTTOM); table.getDefaultCell().setColspan(10); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); phrase = new Phrase("Payment Allocation Report", pFontHeader11); table.addCell(phrase); while (rset4.next()) table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setColspan(10); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(10); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Account No : " + rset4.getObject(2).toString(), pFontHeader1); table.addCell(phrase); while (rset41.next()) table.getDefaultCell().setColspan(10); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(rset41.getString(1), pFontHeader1); table.addCell(phrase); // while (rset4.next()) table.getDefaultCell().setColspan(5); 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(6); phrase = new Phrase( "Period : " + dateFormat.format(endDate11) + " - " + dateFormat.format(endDate1), pFontHeader1); table.addCell(phrase); } catch (java.text.ParseException psExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), psExec.getMessage()); } // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1); // table.addCell(phrase); table.getDefaultCell().setColspan(4); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" Date Printed " + datenowSql, pFontHeader1); table.addCell(phrase); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setColspan(1); phrase = new Phrase("Date", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Patient No.", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Patient Name", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(1); phrase = new Phrase("Inv. No.", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Inv.Date", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Inv. Amt.", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Chq No. ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); table.getDefaultCell().setColspan(1); phrase = new Phrase("Chq. Amt. ", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Amt.Alloc ", pFontHeader1); table.addCell(phrase); phrase = new Phrase("Inv. Bal. ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setBorderWidth(Rectangle.BOTTOM); // table while (rset1.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(4), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(5), "-"), pFontHeader); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(6)), pFontHeader); // osBalance1 = osBalance1 + rset1.getDouble(5); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset1.getObject(7), "-"), pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(8)), pFontHeader); // osBalance1 = osBalance1 + rset1.getDouble(5); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(9)), pFontHeader); osBalancebf = osBalancebf + rset1.getDouble(9); // osBalancebf = osBalance1; table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset1.getString(10)), pFontHeader); osBalance1 = osBalance1 + rset1.getDouble(10); table.addCell(phrase); } table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("", pFontHeader); 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_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(osBalancebf)), pFontHeader); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(osBalance1)), pFontHeader); table.addCell(phrase); // phrase = new Phrase(" "); // } /* try { java.sql.Statement st31 = connectDB.createStatement(); // java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st31.executeQuery("select name from pb_notice"); // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile"); // java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while(rset2.next()) Messg = rset2.getString(1); com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase(""+Messg+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue))); // com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue))); // headerFoter.ALIGN_CENTER; // headerFoter.setRight(5); docPdf.setFooter(footer); } catch(java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage()); } */ 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()); } }