PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/CRReports_Proj/UC/ReportViewer.ascx.cs

http://github.com/khaneh/Orders
C# | 64 lines | 60 code | 4 blank | 0 comment | 9 complexity | 8ef26668d7f6f5852c968706a88caf5e MD5 | raw file
 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Collections;
 5using System.Web;
 6using System.Web.Security;
 7using System.Web.UI;
 8using System.Web.UI.WebControls;
 9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class UC_ReportViewer : System.Web.UI.UserControl
13{
14    protected void Page_Load(object sender, EventArgs e)
15    {
16        CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
17        CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
18        CrystalReportViewer1.ReportSource = CrystalReportSource1;
19        if (Request.QueryString.Get("Id") != null)
20        {
21            SetParameters(Int32.Parse(Request.QueryString.Get("Id")));
22        }
23    }
24    protected void SetParameters(int sessionid)
25    {
26        try
27        {
28
29            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("Server=" + ConfigurationSettings.AppSettings["SqlServer"] + ";initial catalog=" + ConfigurationSettings.AppSettings["SqlDatabase"] + ";password=" + ConfigurationSettings.AppSettings["SqlPassword"] + ";user id=" + ConfigurationSettings.AppSettings["SqlUsername"] + ";");
30            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * From ReportLog Where Id=" + sessionid);
31            conn.Open();
32            cmd.Connection = conn;
33            System.Data.SqlClient.SqlDataReader red = cmd.ExecuteReader();
34            if (red.Read())
35            {
36                string filename = red.GetString(red.GetOrdinal("ReportFileName"));
37                string[] paramnames = red.GetString(red.GetOrdinal("ReportParameterNames")).Split((char)1);
38                string[] paramvalues = red.GetString(red.GetOrdinal("ReportParameterValues")).Split((char)1);
39                CrystalReportSource1.ReportDocument.Load(System.Configuration.ConfigurationSettings.AppSettings["ReportsRoot"] + filename);
40                CrystalReportSource1.ReportDocument.DataSourceConnections[0].SetLogon(System.Configuration.ConfigurationSettings.AppSettings["SqlUsername"], System.Configuration.ConfigurationSettings.AppSettings["SqlPassword"]);
41                CrystalReportSource1.ReportDocument.Refresh();
42                for (int j = 0; j < paramnames.Length; j++)
43                {
44                    if (CrystalReportSource1.ReportDocument.ParameterFields["@" + paramnames[j]] != null)
45                    {
46                        CrystalReportSource1.ReportDocument.ParameterFields["@" + paramnames[j]].CurrentValues.AddValue(paramvalues[j]);
47                    }
48                    else if (CrystalReportSource1.ReportDocument.ParameterFields[paramnames[j]] != null)
49                    {
50                        CrystalReportSource1.ReportDocument.ParameterFields[paramnames[j]].CurrentValues.AddValue(paramvalues[j]);
51                    }
52                }
53
54            }
55            conn.Close();
56            conn.Dispose();
57        }
58        catch (Exception e)
59        {
60            Response.Write(e.ToString());
61        }
62
63    }
64}