Paylaşmak için bazı yaklaşımlarım var. Crystal Reports oluşturmaya yardımcı olabilecek basit CR sarmalayıcıyı geliştirdim. Bu kodu olduğu gibi kullanın. Lütfen kodun herhangi bir bölümünü değiştirmek, değiştirmek için çekinmeyin. İndirme bağlantısı https://1drv.ms/u/s!AlTLBrnU_bLUiaoUxcxNiRCZRQjWng
Ve örnek, sarıcıyı, enter code here
kimlik doğrulaması arabirimini uygulayan CR sarıcı sınıfını kullanarak nasıl kullanacağını gösterir.Page_Load olaylarda page_ınit rapor kaynağını ve rapor parametrelerini ayarlayın ve Page_Unload olay raporu belgesini imha edin.
İkinci yöntem statik sınıfını kullanır ve sonunda rapor belgesini imha, olanları rapor oluşturma. Rapor kaynağı oturum değişkenine kaydedilmelidir. Statik sınıfın kullanılması nedeniyle ikinci yöntemin yüksek trafikli web uygulamasında gerçekten uygun olmadığını lütfen unutmayın. İki kullanıcı aynı anda herhangi bir rapor çalıştırırsa, çarpışma gerçekleşir.
Yöntem 1
using System;
using System.Linq;
using CrystalDecisions.Shared;
using System.Configuration;
using System.Web.Configuration;
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
namespace YourNamespace
{
public partial class ReportForm : System.Web.UI.Page
{
protected string _serverName;
protected string _databaseName;
protected string _schemaName;
protected string _userId;
protected string _userPassword;
protected bool _integratedSecurity;
protected string _databaseType;
//Wrapper Report Document
protected CReportDocument _reportDocument;
/// <summary>
/// Load report
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Init(object sender, EventArgs e)
{
//Wrapper object
this._reportDocument = new CReportDocument();
//These settings should be initialized from i.e. web.config in Page_PreInit
this._reportDocument.ServerName = this._serverName;
this._reportDocument.DatabaseName = String.Empty;
this._reportDocument.SchemaName = this._schemaName;
this._reportDocument.DatabaseType = CReportDatabaseType.ORACLE;
this._reportDocument.UserId = this._userId;
this._reportDocument.UserPassword = this._userPassword;
this._reportDocument.IntegratedSecurity = false;
//Get report name from query string. Define Your own method to get report name
var parReportName = Request.QueryString["reportname"];
if (String.IsNullOrEmpty(parReportName))
{
lblConfigError.Text = "Crystal Report name is not being provided.";
return;
}
//Set Report file
this._reportDocument.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
//Set Report documant
this._reportDocument.SetReportDocument();
//Get Report Document
crViewer.ReportSource = this._reportDocument.GetReportDocument();
}
protected void Page_Load(object sender, EventArgs e)
{
CReportParameter reportParameter;
//Get parameters Your own method to provide report parameters
var parFimYear = RouteData.Values["par1"];
var parFimCityCode = RouteData.Values["par2"];
if (par1 == null || par2 == null)
{
lblConfigError.Text = "Crystal Report parameters are not being provided.";
return;
}
//Define Report Parameter
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parYear";
reportParameter.ParameterValue = parFimYear;
reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
_reportDocument.AddCReportParameter(reportParameter);
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parCityCode";
reportParameter.ParameterValue = parFimCityCode;
reportParameter.crParameterValueKind = ParameterValueKind.StringParameter;
_reportDocument.AddCReportParameter(reportParameter);
//Set report parameters
this._reportDocument.SetReportParameters();
}
protected void Page_Unload(object sender, EventArgs e)
{
this._reportDocument.Dispose();
}
}
}
Yöntem 2
using System;
using System.Linq;
using CrystalDecisions.Shared;
using System.Configuration;
using System.Web.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper
namespace YourNamespace
{
public partial class ReportForm : System.Web.UI.Page
{
protected string _serverName;
protected string _databaseName;
protected string _schemaName;
protected string _userId;
protected string _userPassword;
protected bool _integratedSecurity;
protected string _databaseType;
/// <summary>
/// Load report
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Init(object sender, EventArgs e)
{
CReportParameter reportParameter;
//These settings should be initialized from i.e. web.config in Page_PreInit
if (!IsPostBack)
{
if (this._databaseType == CReportDatabaseType.ORACLE.ToString())
{
//static wrapper class
CReportDocumentManager.ServerName = this._serverName;
CReportDocumentManager.DatabaseName = String.Empty;
CReportDocumentManager.SchemaName = this._schemaName;
CReportDocumentManager.DatabaseType = CReportDatabaseType.ORACLE;
CReportDocumentManager.UserId = this._userId;
CReportDocumentManager.UserPassword = this._userPassword;
CReportDocumentManager.IntegratedSecurity = false;
//Get report name from query string. Define Your own method to get report name
var parReportName = Request.QueryString["reportname"];
if (String.IsNullOrEmpty(parReportName))
{
lblConfigError.Text = "Crystal Report name is not being provided.";
return;
}
//get par1. Your own method to provide report parameters. This is from MVC application
var par1 = RouteData.Values["par1"];
//get par2
var par2 = RouteData.Values["par2"];
if (par1 == null || par2 == null)
{
lblConfigError.Text = "Crystal Report parameters are not being provided.";
return;
}
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parYear";
reportParameter.ParameterValue = par1;
reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
CReportDocumentManager.AddCReportParameter(reportParameter);
reportParameter = new CReportParameter();
reportParameter.ParameterName = "@parCityCode";
reportParameter.ParameterValue = par2;
reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter;
CReportDocumentManager.AddCReportParameter(reportParameter);
CReportDocumentManager.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName;
ReportDocument doc = CReportDocumentManager.GetCReportDocument();
crViewer.ReportSource = doc;
Session[parReportName] = doc;
}
}
else
{
var parReportName = Request.QueryString["reportname"];
ReportDocument doc = (ReportDocument)Session[parReportName];
crViewer.ReportSource = doc;
}
}
}
}
Post ReportViewer kod arkasında kullanışlı yardım almak için! –