मेरे पास साझा करने के लिए कुछ दृष्टिकोण है। मैंने सरल सीआर रैपर विकसित किया जो क्रिस्टल रिपोर्ट प्रस्तुत करने में मदद कर सकता है। इस कोड का प्रयोग इस प्रकार करें। कृपया कोड के किसी भी हिस्से को संशोधित करने के लिए स्वतंत्र महसूस करें। लिंक डाउनलोड करें https://1drv.ms/u/s!AlTLBrnU_bLUiaoUxcxNiRCZRQjWng
और नमूना सीआर रैपर वर्ग का उपयोग करके रैपर का उपयोग कैसे करें enter code here
IDISposable इंटरफ़ेस लागू करता है।Page_Init में रिपोर्ट स्रोत सेट करें और पेज_लोड ईवेंट में पैरामीटर रिपोर्ट करें और पेज_उन्लोड ईवेंट में रिपोर्ट दस्तावेज़ का निपटान करें।
दूसरी विधि स्थिर वर्ग का उपयोग करती है और अंत में रिपोर्ट दस्तावेज़ का निपटान करते हुए रिपोर्ट प्रस्तुत करती है। रिपोर्ट स्रोत सत्र चर में सहेजा जाना चाहिए। कृपया ध्यान रखें कि स्थिर विधि का उपयोग करते हुए दूसरी विधि उच्च ट्रैफ़िक वेब एप्लिकेशन में वास्तव में उपयुक्त नहीं है। टकराव तब होगा जब दो उपयोगकर्ता एक ही समय में कोई रिपोर्ट चलाएंगे।
विधि 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();
}
}
}
विधि 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;
}
}
}
}
स्रोत
2016-10-04 16:17:43
पोस्ट अपने ReportViewer कोड-पीछे उपयोगी मदद पाने के लिए! –