This topic is locked

Crystal Report

9/21/2021 10:31:40 AM
ASPRunner.NET General questions
M
Mansour author

Hello

Is there anyway to use crystal report with Asprunner.net Enterprise version?

T
Tuong Do 9/21/2021

Hi Mansour,

I use Asprunner.Net Enterprise and i can integrate SAP Crystal Report Server 2016

I can help you if you have problem

M
Mansour author 10/5/2021

Hi Tuong,

I hope that, and i will appreciate that for you if you teach me how integrate SAP Crystal Report with Asprunner.Net Enterprise edition.
i need one or two example to how pass parameter from asprynner.net to crystal report becuse as you know the build in report in the
Asprunner.net does not profissional report.

T
Tuong Do 10/29/2021

Hi Mansour,

Let create a button to process the report then display the report as pdf to the sreen

In the Server event of the button

//Report has 2 parameters

byte[] oFile ;
String vFileName = " Statement.pdf" ;
Int32 vStatementID = 1 ;

Coverforce.CrystalReport oStatement = new CompanyName.CrystalReport(@"\Reports\Premium\Statement\Statement.rpt");
oStatement.SetParameter(0, vStatementID) ;
oStatement.SetParameter(1, "screen") ;
oFile = oStatement.GetPdf();
oStatement.Done() ;
HttpContext.Current.Session["oFile"] = oFile ;
HttpContext.Current.Session["oFileName"] = vFileName ;

In the Client after

var vUrl = "/Reports/GetFile.cshtml" ;
window.location = vUrl ;

In the GetFile.cshtml

@using System.IO;
@using System.Web;

@{
String vFileName = (string)HttpContext.Current.Session["oFileName"] ;
if (!String.IsNullOrEmpty(vFileName))
{
byte[] oFile = (byte[])HttpContext.Current.Session["oFile"] ;

HttpContext.Current.Session.Remove("oFile") ;
HttpContext.Current.Session.Remove("oFileName") ;

System.Web.HttpContext.Current.Response.ContentType = "application/PDF";
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Buffer = true;
System.Web.HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment; filename=" + vFileName) ;

}
else
{
HttpContext.Current.Response.Write("File not exists") ;

}

}

// CrystalReport.cs - This file is save in the source folder or subfolder of the source folder and this only work for the SAP crystal Report server, Tested with SAP report server 2016

using System;
using System.Data;
using System.IO;
using System.Collections;

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

using Persits.Email;

namespace CompanyName
{
public class CrystalReport
{
private CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument oClientDoc = new ReportClientDocumentClass() ;

private CrystalDecisions.ReportAppServer.Controllers.PrintOutputController oPrintOutputController = new CrystalDecisions.ReportAppServer.Controllers.PrintOutputController() ;
private CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray oByteArray = new CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray() ;
private dynamic objFactory , rptAppSession ;
private bool ReportExported = false ;
private bool ReportSaved = false ;
private String ReportSavedPath;
private String ReportSavedFileName ;
private String ReportActions = "no" ;

private Byte[] Attachements;
private String AttachementFileName ;

private Byte[] Attachements2 ;
private String AttachementFileName2 ;

private Byte[] Attachements3 ;
private String AttachementFileName3 ;

private Byte[] Attachements4 ;
private String AttachementFileName4 ;

public String FromName = "Abc Pty Ltd" ;
public String FromEmail = "admin@abc.com.au" ;
public String BouncedEmail = "admin@abc.com.au" ;

private ArrayList EmailCC = new ArrayList();

private String vCustomHeader ;
private ArrayList vCustomHeaders = new ArrayList();

public void SetAttachment (Byte[] vAtt , String vFileName = "test.pdf")
{
Attachements = vAtt;
AttachementFileName = vFileName;
}

public void SetAttachment2 (Byte[] vAtt , String vFileName = "test.pdf")
{
Attachements2 = vAtt;
AttachementFileName2 = vFileName;
}

public void SetAttachment3 (Byte[] vAtt , String vFileName = "test.pdf")
{
Attachements3 = vAtt;
AttachementFileName3 = vFileName;
}

public void SetAttachment4 (Byte[] vAtt , String vFileName = "test.pdf")
{
Attachements4 = vAtt;
AttachementFileName4 = vFileName;
}

public void ClearAttachment()
{
Attachements = null;
Attachements2 = null;
Attachements3 = null;
Attachements4 = null;
}

public void SetEmailCC (ArrayList email )
{

EmailCC = email;
}

public void ClearEmailCC()
{ EmailCC.Clear() ;
}

public void AddCustomHeader(String pCustomHeader)
{ vCustomHeaders.Add(pCustomHeader) ;
}

public void Done()
{
oClientDoc.Close() ;
oClientDoc = null ;
objFactory = null ;
}

public void Logon(String userid , String password )
{
oClientDoc.DatabaseController.logon(userid, password) ;
}

public string ReportPath
{
get ;
set ;
}

public CrystalReport(String ReportName)
{

ReportPath = System.Web.HttpContext.Current.Server.MapPath(ReportName);
object PathObj = (object)ReportPath ;
oClientDoc.ReportAppServer = "localhost:1566" ;

oClientDoc.Open(PathObj, (int)(CdReportClientDocumentOpenOptionsEnum.cdReportClientDocumentOpenAsReadOnly)) ;
oClientDoc.RowsetController.Refresh();

Logon("sa", "test");

}

public void SetParameter( String param_name , dynamic param_value )
{
ParameterFieldDiscreteValue param_val = new ParameterFieldDiscreteValue();
param_val.Value = param_value ;
Values vals = new Values() ;
vals.Add(param_val) ;
oClientDoc.DataDefController.ParameterFieldController.SetCurrentValues("", param_name, vals) ;
}
public void SetParameter( int param_index , dynamic param_value )
{
SetParameter(oClientDoc.DataDefinition.ParameterFields[param_index].Name, param_value) ;
}

public void ExportReportPdf()
{
CrReportExportFormatEnum rasReportExportFormat ;

rasReportExportFormat = CrReportExportFormatEnum.crReportExportFormatPDF ;

oPrintOutputController = oClientDoc.PrintOutputController ;

oByteArray = oPrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatPDF) ;
ReportExported = true ;

}

public byte[] GetPdf()
{
if (!ReportExported)
{
ExportReportPdf() ;
}

byte[] oPdf = (byte[])oByteArray.ByteArray ;
return oPdf ;

}

public void ExportReportExcel()
{

oPrintOutputController = oClientDoc.PrintOutputController ;

//oByteArray = oPrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatPDF) ;
oByteArray = oPrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatXLSX) ;

ReportExported = true ;

}

public byte[] GetExcel()
{
if (!ReportExported)
{
ExportReportExcel() ;
}

byte[] oExcel = (byte[])oByteArray.ByteArray ;
return oExcel ;

}

public void DisplayReport(String pFileName)
{

if (!ReportExported)
{
ExportReportPdf() ;
}

System.Web.HttpContext.Current.Response.Clear() ;
System.Web.HttpContext.Current.Response.ContentType = "application/PDF" ;
System.Web.HttpContext.Current.Response.Expires = 0 ;
System.Web.HttpContext.Current.Response.Buffer = true ;

System.Web.HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment; filename=" + pFileName) ;
System.Web.HttpContext.Current.Response.BinaryWrite (oByteArray.ByteArray) ;
System.Web.HttpContext.Current.Response.Flush() ;

}

}

}

M
Mansour author 10/31/2021

Many thanks for Tuong Do i will try it and inform you with result,
and again many many thanks for your help

M
Mansour author 11/30/2021

Dear Mr. Tuong Do

kindly can i contact email if yes send me your email ID

thank you

T
Tuong Do 12/13/2021

Hi Mansour,

This forrum does not notify me when some one reply to my message

How do i send you a private message?