如何使用Session构建Crystal Report? [英] How to build a Crystal Report by using a Session?

查看:62
本文介绍了如何使用Session构建Crystal Report?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将数据保存到数据库的Web项目。用户由会话控制。当用户登录会话时启动。会话正在使用用户ID号。如何根据会话ID和用户提交到数据库的数据构建水晶报告?



 使用 System.Linq; 
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用 CrystalDecisions.Web;
使用 System.Web.UI.WebControls.WebParts;
使用 CrystalDecisions.CrystalReports.Engine;
使用 CrystalDecisions.Shared;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Xml.Linq;
使用 System.Web.SessionState;


命名空间 SACSCOCLogin1._1
{
public partial class ReportFormA:System.Web.UI.Page
{
受保护 void Page_Load( object sender ,EventArgs e)
{
if (!IsPostBack)
{
string SelectFormula = {COCINST.inst_id}> 10000
+ 中({COCINST.LongName},1,1)= \A \;
}

CrystalReportViewer1.Visible = true ;
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath( 〜/ Reports / ReportA.rpt) );
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.SelectionFormula = {COCINST.inst_id} =' + Session [ inst_id]。ToString()+ ';
// CrystalReportViewer1.SelectionFormula ={FIN2013.inst_id} ='+ Session [inst_id] .ToString()+';
}

protected 覆盖 void OnPreRender(EventArgs e)
{
Session [ inst_id] = inst_id;
CrystalReportViewer1.Visible = true ;
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath( 〜/ Reports / ReportA.rpt) );
crystalReport.SetDatabaseLogon
Admin master22 @ SQL Hot);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.SelectionFormula = {COCINST.inst_id} =' + Session [ inst_id]。ToString()+ ';
// CrystalReportViewer1.SelectionFormula ={FIN2013.inst_id} ='+ Session [inst_id] .ToString()+';
}

}
}

解决方案

使用 Selectionformula

使用选择公式创建报告 [ ^ ]

示例公式应该是这样的(将会话值分配给选择公式的字段)

 crystalReportViewer.SelectionFormula =   {Table.inst_id} =  ' + Session [inst_id]。ToString()+' < span class =code-string> ; < /跨度> 


I have a web project that saves data to a database. The user is controlled by a session. When a user logs in a session starts. The session is using the users ID number. How can I build a crystal report based on the session ID and the data the user submitted into the database?

using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;


namespace SACSCOCLogin1._1
{
    public partial class ReportFormA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string SelectFormula = "{COCINST.inst_id} > 10000 "
                + "AND Mid({COCINST.LongName}, 1, 1) = \"A\"";
            }

            CrystalReportViewer1.Visible = true;
            ReportDocument crystalReport = new ReportDocument();
            crystalReport.Load(Server.MapPath("~/Reports/ReportA.rpt"));
            CrystalReportViewer1.ReportSource = crystalReport;
            CrystalReportViewer1.SelectionFormula = "{COCINST.inst_id} = '" + Session["inst_id"].ToString() + "'";
            //CrystalReportViewer1.SelectionFormula = "{FIN2013.inst_id} = '" + Session["inst_id"].ToString() + "'";
        }

        protected override void OnPreRender(EventArgs e)
        {
            Session["inst_id"] = "inst_id";
            CrystalReportViewer1.Visible = true;
            ReportDocument crystalReport = new ReportDocument();
            crystalReport.Load(Server.MapPath("~/Reports/ReportA.rpt"));
            crystalReport.SetDatabaseLogon
            ("Admin", "master22", @"SQL", "Hot");
            CrystalReportViewer1.ReportSource = crystalReport;
            CrystalReportViewer1.SelectionFormula = "{COCINST.inst_id} = '" + Session["inst_id"].ToString() + "'";
            //CrystalReportViewer1.SelectionFormula = "{FIN2013.inst_id} = '" + Session["inst_id"].ToString() + "'";
        }
        
    }
}

解决方案

Use the Selectionformula
Creating a Report with a Selection Formula[^]
Sample formula should be like this(Assign the session value to selection formula's field)

crystalReportViewer.SelectionFormula = "{Table.inst_id} = "'" + Session["inst_id"].ToString() + "'";


这篇关于如何使用Session构建Crystal Report?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆