Skip to Content
0
Former Member
Dec 02, 2009 at 10:36 PM

Trying to switch from Eclipse to .net using J#

36 Views

I have a Java program that I developed in Eclipse and I manually run it every day. It works just fine. The goal was to create an executable and move that code to a server. That might be an easy task for an experienced Eclipse person, but that is not me.

I have available to me, here at work, Visual Studio 2005, so I installed it and moved my code into it. The original code was developed for Crystal Reports 2008.

I can not get the new drivers to load into the Visual Studio. I figure that there was probably older code that did the 3 steps I am trying to do.

Here is the current code;

/* EDIInvoice.java - Created on 08-12-2009 John Carrott

  • Stored at C:\Documents and Settings\jcarrott\workspace

  • \John\src\com.businessobjects.samples\

  • First-

  • This program opens and reads the file ghxInv.txt, which contains;

* 1. Company

* 2. Vendor

* 3. Invoice

*

  • Second -

  • Open CR8Invoice.rpt using parameters Company & po_number, then

  • export as (Invoice)<date>.pdf.

  • Loop until ghxInv.txt is empty

*/

package com.businessobjects.samples;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStreamReader;

import java.util.Calendar;

import java.util.GregorianCalendar;

import javax.swing.SwingUtilities;

import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;

import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;

import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;

public class EDIInvoice {

private static final String REPORT_NAME = "D:
Invoice
CR8Invoice.rpt";

public static void launchApplication() {

try

{

FileInputStream in = new FileInputStream("D:
Invoice
ghxInv.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

Calendar cal = new GregorianCalendar();

int month = cal.get(Calendar.MONTH);

int year = cal.get(Calendar.YEAR);

int day = cal.get(Calendar.DAY_OF_MONTH);

// String today = ("20091126-");

String today = (year + "" + (month + 1) + "" + day + "-");

// this will not work for Jan thru June

int length = today.length();

if (length < 9){

today = (year + "" + (month + 1) + "0" + day + "-");

}

System.out.println("Current date : " + today);

// Read the file one line at a time

while ((strLine = br.readLine()) != null)

{

String patternStr = ",";

String[] fields = strLine.split(patternStr);

String EXPORT_FILE = "D:
Invoice
report
Invoice" + today + fields[1] + ".pdf";

String Company = fields[0];

String Invoice = fields[1];

String PO_number = fields[2];

try {

//Open report.

ReportClientDocument reportClientDoc = new ReportClientDocument();

reportClientDoc.open(REPORT_NAME, 0);

//We will be using the ParameterFieldController quite a bit through-out the rest of this function.

reportClientDoc.getDatabaseController().logon("procure","procure90");

com.crystaldecisions.sdk.occa.report.application.ParameterFieldController paramFieldController = reportClientDoc.getDataDefController().getParameterFieldController();

//SINGLE VALUE DISCRETE PARAMETERS.

paramFieldController.setCurrentValue("", "Invoice", new String(fields[1]));

ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

//Release report.

reportClientDoc.close();

//Use the Java I/O libraries to write the exported content to the file system.

byte byteArray[] = new byte[byteArrayInputStream.available()];

//Create a new file that will contain the exported result.

File file = new File(EXPORT_FILE);

FileOutputStream fileOutputStream = new FileOutputStream(file);

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());

int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

byteArrayOutputStream.write(byteArray, 0, x);

byteArrayOutputStream.writeTo(fileOutputStream);

//Close streams.

byteArrayInputStream.close();

byteArrayOutputStream.close();

fileOutputStream.close();

System.out.println("Successfully exported report to " + EXPORT_FILE);

}

catch(ReportSDKException ex) {

ex.printStackTrace();

}

}

}

catch(Exception ex) {

System.out.println(ex);

}

}

}

Can anybody help me change this to work in Visual Studion 2005 or tell me how I can load the .jar files?

Thank you,