|
|
@@ -1,9 +1,13 @@
|
|
|
package com.uas.report.crystal;
|
|
|
|
|
|
+import com.crystaldecisions.sdk.occa.report.application.DatabaseController;
|
|
|
import com.crystaldecisions.sdk.occa.report.application.OpenReportOptions;
|
|
|
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
|
|
|
import com.crystaldecisions.sdk.occa.report.application.ReportSaveAsOptions;
|
|
|
-import com.crystaldecisions.sdk.occa.report.data.*;
|
|
|
+import com.crystaldecisions.sdk.occa.report.data.IDatabase;
|
|
|
+import com.crystaldecisions.sdk.occa.report.data.ITable;
|
|
|
+import com.crystaldecisions.sdk.occa.report.data.Tables;
|
|
|
+import com.crystaldecisions.sdk.occa.report.document.ReportDocument;
|
|
|
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -17,7 +21,7 @@ import java.io.IOException;
|
|
|
public class Application {
|
|
|
private static Logger logger = LoggerFactory.getLogger(Application.class);
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws ClassNotFoundException {
|
|
|
ReportClientDocument client = new ReportClientDocument();
|
|
|
try {
|
|
|
String reportName = "bjd_price.rpt";
|
|
|
@@ -41,19 +45,37 @@ public class Application {
|
|
|
// connections.removeConnection(iConnection);
|
|
|
// connections.add(i, newConnection);
|
|
|
// }
|
|
|
- IDataDefinition dataDefinition = client.getDataDefinition();
|
|
|
- Fields<IField> resultFields = dataDefinition.getResultFields();
|
|
|
- client.getDataDefinition().getResultFields().remove(0);
|
|
|
- System.out.println(resultFields.size());
|
|
|
- Tables tables = (Tables) client.getDatabase().getTables().clone(true);
|
|
|
+// IDataDefinition dataDefinition = client.getDataDefinition();
|
|
|
+// Fields<IField> resultFields = dataDefinition.getResultFields();
|
|
|
+// client.getDataDefinition().getResultFields().remove(0);
|
|
|
+// System.out.println(resultFields.size());
|
|
|
+// Tables tables = (Tables) client.getDatabase().getTables().clone(true);
|
|
|
+// for (int j = 0; j < tables.size(); j++) {
|
|
|
+// ITable iTable = (ITable) tables.get(j).clone(true);
|
|
|
+// logger.info(iTable.getName());
|
|
|
+// iTable.setName("1_QUOTATION_VIEW");
|
|
|
+// logger.info(iTable.getName());
|
|
|
+// client.getDatabase().getTables().remove(j);
|
|
|
+// client.getDatabase().getTables().add(j, iTable);
|
|
|
+// }
|
|
|
+
|
|
|
+ DatabaseController databaseController = client.getDatabaseController();
|
|
|
+ IDatabase database = databaseController.getDatabase();
|
|
|
+ Tables tables = database.getTables();
|
|
|
for (int j = 0; j < tables.size(); j++) {
|
|
|
- ITable iTable = (ITable) tables.get(j).clone(true);
|
|
|
+ ITable iTable = (ITable) tables.get(j).clone(false);
|
|
|
logger.info(iTable.getName());
|
|
|
- iTable.setName("1_QUOTATION_VIEW");
|
|
|
- logger.info(iTable.getName());
|
|
|
- client.getDatabase().getTables().remove(j);
|
|
|
- client.getDatabase().getTables().add(j, iTable);
|
|
|
+ logger.info(iTable.getAlias());
|
|
|
+// iTable.setName("1_QUOTATION_VIEW");
|
|
|
+// iTable.setAlias("1_QUOTATION_VIEW");
|
|
|
+// logger.info(iTable.getName());
|
|
|
+ databaseController.modifyTableAlias(iTable, "1_QUOTATION_VIEW");
|
|
|
+// tables.set(j, iTable);
|
|
|
+// databaseController.getDatabase().getTables().remove(j);
|
|
|
+// databaseController.getDatabase().getTables().set(j, iTable);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
// for (IConnection iConnection : connections) {
|
|
|
// Tables tables = iConnection.getTables();
|
|
|
// for (ITable iTable : tables) {
|
|
|
@@ -63,11 +85,31 @@ public class Application {
|
|
|
// }
|
|
|
// database.setConnections(null);
|
|
|
System.out.println(client.isReadOnly());
|
|
|
- client.refreshReportDocument();
|
|
|
+// client.refreshReportDocument();
|
|
|
// client.save();
|
|
|
- client.flushRequests();
|
|
|
+// client.flushRequests();
|
|
|
client.saveAs(reportName, "C:\\sunyj\\project\\report-parent\\crystal-replace-view",
|
|
|
ReportSaveAsOptions._overwriteExisting);
|
|
|
+ ReportDocument reportDocument=client.getReportDocument();
|
|
|
+
|
|
|
+// InputStream lis;
|
|
|
+// PrintOutputController lpoc;
|
|
|
+// lpoc = client.getPrintOutputController();
|
|
|
+// lis = lpoc.export(ReportExportFormat.from_int(ReportExportFormat._crystalReports));
|
|
|
+//
|
|
|
+// try {
|
|
|
+// FileOutputStream out = new FileOutputStream("C:\\sunyj\\project\\report-parent\\crystal-replace-view\\"+reportName);
|
|
|
+// byte[] buf = new byte[4096];
|
|
|
+// int len;
|
|
|
+// while ((len = lis.read(buf)) > 0) {
|
|
|
+// out.write(buf, 0, len);
|
|
|
+// }
|
|
|
+// out.close();
|
|
|
+// lis.close();
|
|
|
+// } catch (IOException e) {
|
|
|
+// System.err.println(e.toString());
|
|
|
+// }
|
|
|
+// reportDocument.save();
|
|
|
} catch (ReportSDKException e) {
|
|
|
logger.error("报表读取失败", e);
|
|
|
} catch (IOException e) {
|