CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Crystal Reports and CCS

Print topic Send  topic

Author Message
jormah

Posts: 10
Posted: 05/26/2004, 11:32 PM

Have anyone try to use Crystal Reports with CCS? How can I call Crystal *.rpt file inside CCS code, or use Crystal Java API with CCS?
WinXP, Linux, JSP/Java/Servlet/Templates environment.

R- JormaH
_________________
Jorma Hytonen
Mipro Oy, Finland
View profile  Send private message
Jeff Turkington
Posted: 05/28/2004, 3:04 PM

I have developed a simple integration technique that you can use to intergate Crystal Reports (using RAS or CE) into any web application and have used this with good success with CCS apps. Give me a shout and I can share techniques and sample code.

-jeff
LV
Posted: 05/28/2004, 6:57 PM

Jeff,

Can you shed some instructions on how to link Crystal Reports with CCS here in this forum.

Thanks in advance.
Jeff Turkington
Posted: 05/28/2004, 9:14 PM

It's not that difficult but you do have to create a bunch of code on your own outside CCS.

1. Get Crystal RAS or CE working first... and test that the samples display.

2. Create a standalone web app using whatever language you like (start wth the CR examples) to display a report when passed a report target parameter.

3a. Modify this code above to accept another parameter that is a hash (MD5 or other) of the concatnation of the report target and a time/date value.

3b. Extract this "key" in the report display code and compare to one that is generated at runtime... this prevents URL spoofing by someone at a later time.

4. SImply add a link control to your CCS code that passes the MD5 parameter of the report and time/date to the report display code.

What this achieves is a way to integrate the two application envirinments with the least amount of grief and maximum amount of flexibility without sacrificing security.

I will post the CCS and CR RAS code in subsequent posts.
Jeff Turkington
Posted: 05/28/2004, 9:16 PM

//Control Label1 Event BeforeShow. Action Custom Code @5-2A29BDB7

//
// Genrate request for report and access key from URL report_id parameter passed
//

string s;
string Report_ID = System.Web.HttpContext.Current.Request.QueryString["Report_ID"];

// get report name and parameters from report_id
string sReport = Settings.CMSDataAccessObject.ExecuteScalar("SELECT Report_Target FROM tbl_reports WHERE report_id=" + Report_ID).ToString();
string sParams = Settings.CMSDataAccessObject.ExecuteScalar("SELECT Report_Parameters FROM tbl_reports WHERE report_id=" + Report_ID).ToString();

// generate request
string sRequest = sReport;

// add parameters
//if (instr(sParams, "c")) sRequest += "," + System.Web.HttpContext.Current.Request.QueryString["Case_ID"];
//if (instr(sParams, "e")) sRequest += "," + System.Web.HttpContext.Current.Request.QueryString["Event_ID"];

// encode request into key
string str;
string ts = DateTime.Now.ToShortDateString();
str = sRequest + ts;

// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);

// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i=0;i<result.Length;i++) {
sb.Append(result.ToString("X2"));
}

// get result
string sKey = sb.ToString();

// do report
string sURL = "./reports/DoReport.aspx?request=" + sRequest + "&key=" + sKey;
s = "<SCRIPT LANGUAGE=\"JScript\">";
s += "window.open ('" + sURL + "', '_blank', 'status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');";
s += "</SCRIPT>";
Response.Write(s);

// refresh report listing
s = "<SCRIPT LANGUAGE=\"JScript\">";
s += "history.go(-1)";
s += "</SCRIPT>";
Response.Write (s);
Jeff Turkignton
Posted: 05/28/2004, 9:16 PM

** THIS IS THE CR RAS CODE **

using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// for MD5 encoding
using System.Security.Cryptography;
using System.Text;


namespace CMSReporting
{
/// <summary>
/// Summary description for DoReport
/// </summary>
public class DoReport : System.Web.UI.Page
{

// Global Variables
ReportClientDocument rcDoc;
string sRequest;
string sKey;

protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;


Boolean ValidRequest()
{
// get request and key from URL
sRequest = System.Web.HttpContext.Current.Request.QueryString["Request"];
sKey = System.Web.HttpContext.Current.Request.QueryString["Key"];

// encode request into key
string str;
string ts = DateTime.Now.ToShortDateString();
str = sRequest + ts;

// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);

// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int j=0; j<result.Length; j++) {
sb.Append(result[j].ToString("X2"));
}

// get result
string smyKey = sb.ToString();

return (sKey == smyKey);
}

void DisplayError ()
{
Response.Write ("Invalid report request or timeout, please retry.");
}




void CreateReport()
{

// create report client document
rcDoc = new ReportClientDocument();

// set location of RAS server
rcDoc.ReportAppServer = "localhost";

// decode request
// request -> target.crp, DB, P0, P1, P2, P3

// open a report
string Path = Request.ServerVariables["PATH_TRANSLATED"];
Path = Path.Substring(0, Path.LastIndexOf("\\"));
Path += "\\" + sRequest;
object objPath = Path;
rcDoc.Open(ref objPath, 0);

// set datasource location
ConnectionInfo myCI;
myCI = rcDoc.DatabaseController.GetConnectionInfos(null)[0].Clone(true);

myCI.UserName = "sa";
myCI.Password = "spudz!";

// get database connection attributes
PropertyBag myPB;
PropertyBag myLI;
myPB = myCI.Attributes;

myLI = (PropertyBag)myPB["QE_LogonProperties"];

// set server and database name
myLI["Data Source"] = "tal3.tal.nat";
myLI["Initial Catalog"] = "CMS_DEVL";


//update table
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableOld;
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableNew;
myTableOld = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];

int i;
i = 0;
foreach (object o in rcDoc.Database.Tables) {
myTableOld = (CrystalDecisions.ReportAppServer.DataDefModel.Table) rcDoc.Database.Tables;
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
myTableNew.Name = myTableOld.Name;
myTableNew.ConnectionInfo = myCI;
rcDoc.DatabaseController.SetTableLocation(myTableOld, myTableNew);
i++;
}
//possibly pass a parameter?
//PassParameter(0, "1");

// view the report
CrystalReportViewer1.ReportSource = rcDoc;
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}


void PassParameter(int param_index, string param_value)
{
ParameterFieldDiscreteValue crParameterValue; // discrete parameter value
ParameterField crParameterOld; // parameter field in the report
ParameterField crParameterNew; // parameter field that will replace old parameter

// create a discrete value
crParameterValue = new ParameterFieldDiscreteValue();

// set parameter value
crParameterValue.Value = param_value;

// get parameter in the report
crParameterOld = (ParameterField)rcDoc.DataDefinition.ParameterFields[param_index];

// create a new parameter field
crParameterNew = new ParameterField();

// copy properties of old parameter to new parameter
crParameterOld.CopyTo(crParameterNew, true);

// add discrete value to this new parameter field
crParameterNew.CurrentValues.Add(crParameterValue);

// modify parameter
rcDoc.DataDefController.ParameterFieldController.Modify(crParameterOld, crParameterNew);

// clean up
crParameterValue = null;
crParameterNew = null;
}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

// Create Report
if (ValidRequest())
CreateReport();
else
DisplayError();
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
LV
Posted: 06/01/2004, 9:04 AM

Thank you for sharing! :-)
jormah

Posts: 10
Posted: 06/09/2004, 3:23 AM

Yes! Thanks a lot. Crystal(9) is running and stand-alone reports working. CCS is online too.
In my past life I use CR with C++ API, little bit confused this huge amount of code. Is that needed only with CCS?

R- Jorma

_________________
Jorma Hytonen
Mipro Oy, Finland
View profile  Send private message
turkington

Posts: 2
Posted: 06/09/2004, 10:30 AM

Hi Jorma,

First of all, this is for use with Crystal Report Application Server (RAS) or Crystal Enterprise. You can't just integrate Crystal into a web app as you would in VB6. Not sure if that's your true question though...

After a lot of messing about, I chose to not directly include the code in CCS as there are a lot of dependant references needed and it was just too messy.

-Jeff
_________________
-jeff
View profile  Send private message
waseem
Posted: 07/05/2004, 10:14 AM

Quote Jeff Turkignton:
** THIS IS THE CR RAS CODE **

using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// for MD5 encoding
using System.Security.Cryptography;
using System.Text;


namespace CMSReporting
{
/// <summary>
/// Summary description for DoReport
/// </summary>
public class DoReport : System.Web.UI.Page
{

// Global Variables
ReportClientDocument rcDoc;
string sRequest;
string sKey;

protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;


Boolean ValidRequest()
{
// get request and key from URL
sRequest = System.Web.HttpContext.Current.Request.QueryString["Request"];
sKey = System.Web.HttpContext.Current.Request.QueryString["Key"];

// encode request into key
string str;
string ts = DateTime.Now.ToShortDateString();
str = sRequest + ts;

// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);

// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int j=0; j<result.Length; j++) {
sb.Append(result[j].ToString("X2"));
}

// get result
string smyKey = sb.ToString();

return (sKey == smyKey);
}

void DisplayError ()
{
Response.Write ("Invalid report request or timeout, please retry.");
}




void CreateReport()
{

// create report client document
rcDoc = new ReportClientDocument();

// set location of RAS server
rcDoc.ReportAppServer = "localhost";

// decode request
// request -> target.crp, DB, P0, P1, P2, P3

// open a report
string Path = Request.ServerVariables["PATH_TRANSLATED"];
Path = Path.Substring(0, Path.LastIndexOf("\\"));
Path += "\\" + sRequest;
object objPath = Path;
rcDoc.Open(ref objPath, 0);

// set datasource location
ConnectionInfo myCI;
myCI = rcDoc.DatabaseController.GetConnectionInfos(null)[0].Clone(true);

myCI.UserName = "sa";
myCI.Password = "spudz!";

// get database connection attributes
PropertyBag myPB;
PropertyBag myLI;
myPB = myCI.Attributes;

myLI = (PropertyBag)myPB["QE_LogonProperties"];

// set server and database name
myLI["Data Source"] = "tal3.tal.nat";
myLI["Initial Catalog"] = "CMS_DEVL";


//update table
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableOld;
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableNew;
myTableOld = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];

int i;
i = 0;
foreach (object o in rcDoc.Database.Tables) {
myTableOld = (CrystalDecisions.ReportAppServer.DataDefModel.Table) rcDoc.Database.Tables;
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
myTableNew.Name = myTableOld.Name;
myTableNew.ConnectionInfo = myCI;
rcDoc.DatabaseController.SetTableLocation(myTableOld, myTableNew);
i++;
}
//possibly pass a parameter?
//PassParameter(0, "1");

// view the report
CrystalReportViewer1.ReportSource = rcDoc;
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}


void PassParameter(int param_index, string param_value)
{
ParameterFieldDiscreteValue crParameterValue; // discrete parameter value
ParameterField crParameterOld; // parameter field in the report
ParameterField crParameterNew; // parameter field that will replace old parameter

// create a discrete value
crParameterValue = new ParameterFieldDiscreteValue();

// set parameter value
crParameterValue.Value = param_value;

// get parameter in the report
crParameterOld = (ParameterField)rcDoc.DataDefinition.ParameterFields[param_index];

// create a new parameter field
crParameterNew = new ParameterField();

// copy properties of old parameter to new parameter
crParameterOld.CopyTo(crParameterNew, true);

// add discrete value to this new parameter field
crParameterNew.CurrentValues.Add(crParameterValue);

// modify parameter
rcDoc.DataDefController.ParameterFieldController.Modify(crParameterOld, crParameterNew);

// clean up
crParameterValue = null;
crParameterNew = null;
}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

// Create Report
if (ValidRequest())
CreateReport();
else
DisplayError();
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

waseem
Posted: 07/05/2004, 10:17 AM

i include all merge modules for crystal report 9 but when i run applicaiton on client system error accoured "load crpe32.dl failed"
please help me if you have solution for this problem.....
Rich
Posted: 09/20/2004, 8:39 AM

Jeff,
You may have helped me a great deal.

Rich
turkington

Posts: 2
Posted: 09/20/2004, 1:10 PM

Rich,

I will be taking anoter peek at this cdoe later this week and enhancing it some... give me a shout atjeff@turkington.net if you like.

-Jeff
_________________
-jeff
View profile  Send private message
jorma_hytonen
Posted: 09/20/2004, 7:08 PM

Have anybody try to use JasperReports to create report with CCS?
I have, but I have some problems to call and send parameters to report servlet.

R- Jormah
balaji
Posted: 10/13/2004, 5:31 AM

Quote Jeff Turkignton:
** THIS IS THE CR RAS CODE **

using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// for MD5 encoding
using System.Security.Cryptography;
using System.Text;


namespace CMSReporting
{
/// <summary>
/// Summary description for DoReport
/// </summary>
public class DoReport : System.Web.UI.Page
{

// Global Variables
ReportClientDocument rcDoc;
string sRequest;
string sKey;

protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;


Boolean ValidRequest()
{
// get request and key from URL
sRequest = System.Web.HttpContext.Current.Request.QueryString["Request"];
sKey = System.Web.HttpContext.Current.Request.QueryString["Key"];

// encode request into key
string str;
string ts = DateTime.Now.ToShortDateString();
str = sRequest + ts;

// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);

// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int j=0; j<result.Length; j++) {
sb.Append(result[j].ToString("X2"));
}

// get result
string smyKey = sb.ToString();

return (sKey == smyKey);
}

void DisplayError ()
{
Response.Write ("Invalid report request or timeout, please retry.");
}




void CreateReport()
{

// create report client document
rcDoc = new ReportClientDocument();

// set location of RAS server
rcDoc.ReportAppServer = "localhost";

// decode request
// request -> target.crp, DB, P0, P1, P2, P3

// open a report
string Path = Request.ServerVariables["PATH_TRANSLATED"];
Path = Path.Substring(0, Path.LastIndexOf("\\"));
Path += "\\" + sRequest;
object objPath = Path;
rcDoc.Open(ref objPath, 0);

// set datasource location
ConnectionInfo myCI;
myCI = rcDoc.DatabaseController.GetConnectionInfos(null)[0].Clone(true);

myCI.UserName = "sa";
myCI.Password = "spudz!";

// get database connection attributes
PropertyBag myPB;
PropertyBag myLI;
myPB = myCI.Attributes;

myLI = (PropertyBag)myPB["QE_LogonProperties"];

// set server and database name
myLI["Data Source"] = "tal3.tal.nat";
myLI["Initial Catalog"] = "CMS_DEVL";


//update table
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableOld;
CrystalDecisions.ReportAppServer.DataDefModel.Table[] myTableNew;
myTableOld = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table[10];

int i;
i = 0;
foreach (object o in rcDoc.Database.Tables) {
myTableOld = (CrystalDecisions.ReportAppServer.DataDefModel.Table) rcDoc.Database.Tables;
myTableNew = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
myTableNew.Name = myTableOld.Name;
myTableNew.ConnectionInfo = myCI;
rcDoc.DatabaseController.SetTableLocation(myTableOld, myTableNew);
i++;
}
//possibly pass a parameter?
//PassParameter(0, "1");

// view the report
CrystalReportViewer1.ReportSource = rcDoc;
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}


void PassParameter(int param_index, string param_value)
{
ParameterFieldDiscreteValue crParameterValue; // discrete parameter value
ParameterField crParameterOld; // parameter field in the report
ParameterField crParameterNew; // parameter field that will replace old parameter

// create a discrete value
crParameterValue = new ParameterFieldDiscreteValue();

// set parameter value
crParameterValue.Value = param_value;

// get parameter in the report
crParameterOld = (ParameterField)rcDoc.DataDefinition.ParameterFields[param_index];

// create a new parameter field
crParameterNew = new ParameterField();

// copy properties of old parameter to new parameter
crParameterOld.CopyTo(crParameterNew, true);

// add discrete value to this new parameter field
crParameterNew.CurrentValues.Add(crParameterValue);

// modify parameter
rcDoc.DataDefController.ParameterFieldController.Modify(crParameterOld, crParameterNew);

// clean up
crParameterValue = null;
crParameterNew = null;
}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

// Create Report
if (ValidRequest())
CreateReport();
else
DisplayError();
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

Praveen
Posted: 04/20/2005, 9:01 AM

Hi ,

Can someone tell me why Crystal Reports always puts a .00 after decimal its not even rounding off the figure, while running reports for employee salary.The database does not have any issues as the same report is being run on different machine with crystal reports and the figres are coming correct, example
1235.87, but on naother machine with same report it always gives output as 1235.00 .
I have changed the formatting also for the decimal places but still the output comes like that .

Please help asap
Praveen
Oper


Posts: 1195
Posted: 04/22/2005, 12:32 PM

we are using Report manager awesome product generated PDF and is free, you wont regret.

but need a learning curve, we have a CCS application wrokign for like 90 users, data entry, report etc, and we using that tool.
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.