Skip to Content
0
Former Member
Dec 16, 2013 at 04:54 PM

Always that run the Crystal Reports in Visual Studio 2012 I have to pass the parameters and database conection again

47 Views

Hello friends!


First, I'm so sorry because my English is very poor. I'm learning English still.


I have problems with Visual Studio 2012 and Crystal Reports, because, Always that run my Reports I need to inform the parameters and database conection again, everytime.


Below I'm putting my code.


Aspx:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rel_orcamento.aspx.cs" Inherits="projeto_orcamento.Rel_orcamento" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div id="div_banner_itens">

<asp:TextBox ID="txt_codigo_orca" runat="server" ></asp:TextBox>

<asp:TextBox ID="txt_param_capa" runat="server" ></asp:TextBox>

<asp:TextBox ID="txt_param_carta" runat="server" ></asp:TextBox>

<asp:TextBox ID="txt_param_espec" runat="server" ></asp:TextBox>

<asp:TextBox ID="txt_param_arquivo" runat="server" ></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

</div>

<div id="div_relatorio">

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" ReuseParameterValuesOnRefresh="True" HasCrystalLogo="False" ToolPanelView="None" />

<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">

<Report FileName="Relatorios\orcamentooficial.rpt">

</Report>

</CR:CrystalReportSource>

</div>

</form>

</body>

</html>

Code Behind:

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using CrystalDecisions.Web;

using CrystalDecisions.Reporting;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace projeto_orcamento

{

public partial class Rel_orcamento : System.Web.UI.Page

{

private ReportDocument Report;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

txt_codigo_orca.Text = Request.QueryString["cod"];

txt_param_capa.Text = Request.QueryString["capa"];

txt_param_carta.Text = Request.QueryString["carta"];

txt_param_espec.Text = Request.QueryString["esp"];

txt_param_arquivo.Text = Request.QueryString["arquivo"];

}

}

private void ConfiguraCrystalReports(string orcacodigo, string capa, string carta, string arquivo, string espefica)

{

ReportDocument rpt = new ReportDocument();

string reportPath = Server.MapPath("~/Relatorios/orcamentooficial.rpt");

rpt.Load(reportPath);

rpt.SetParameterValue("codigoorca", orcacodigo);

rpt.SetParameterValue("abre_capa", capa);

rpt.SetParameterValue("abre_carta", carta);

rpt.SetParameterValue("abre_arquivo", arquivo);

rpt.SetParameterValue("abre_especificacao", espefica);

rpt.SetParameterValue("codigoorca", orcacodigo, rpt.Subreports[0].Name.ToString());

rpt.SetParameterValue("codigoorca", orcacodigo, rpt.Subreports[1].Name.ToString());

ConnectionInfo myConnectionInfo = new ConnectionInfo();

myConnectionInfo.ServerName = "xxxxxx";

myConnectionInfo.DatabaseName = "xxxxxx";

myConnectionInfo.UserID = "xxxxxxx";

myConnectionInfo.Password = "xxxxxxx";

SetDBLogonForReport(myConnectionInfo, rpt);

CrystalReportViewer1.ReportSource = rpt;

}

}

private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument ArquivoReport)

{

Tables tables = ArquivoReport.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)

{

TableLogOnInfo tableLogonInfo = table.LogOnInfo;

tableLogonInfo.ConnectionInfo = connectionInfo;

table.ApplyLogOnInfo(tableLogonInfo);

}

}

protected void Button1_Click(object sender, EventArgs e)

{

ConfiguraCrystalReports(txt_codigo_orca.Text, txt_param_capa.Text, txt_param_carta.Text, txt_param_arquivo.Text, txt_param_espec.Text);

}

}

}

My friends a need a lot to help with this problem. I'm to 5 days trying solution for my problem. I liked to not inform more the parameters and databse connction.

Thanks a lot...

Lucas Zanardi