SSRS_NOTE

1.Computer -> Manage ->Server and Applications -> Services -> SQL Server Reporting Service(如果启动不了的话 右键属性 logon)


2.Start->Microsoft SQL Server 2008 R2 ->Configration Tools->Report Services Configration

 

aspx:

<rsweb:ReportViewer ID="rptViewer" ZoomMode="PageWidth" SizeToReportContent="True" runat="server" Height="100%" Width="100%">
</rsweb:ReportViewer>

 

cs:

1.服务器端

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptViewer.ShowParameterPrompts = false;
                rptViewer.ShowPromptAreaButton = false;
                
                string reportName = null;
                Dictionary<string, string> paramList = null;
                bool hasParam = false;
                if (this.Request.QueryString["ReportName"] != null)
                    reportName = this.Request.QueryString["ReportName"];

                if (Session["ParamList"] != null)
                    paramList = (Dictionary<string, string>)Session["ParamList"];
                if (this.Request.QueryString["HasParam"] != null)
                    hasParam = Convert.ToBoolean(this.Request.QueryString["HasParam"]);

                if (reportName != null)
                {
                    ShowReport(reportName, paramList, hasParam);
                }
            }
        }

        private void ShowReport(string ReportName, Dictionary<string, string> ParamList, bool HasParam)
        {

            try
            {
                rptViewer.Reset();
                rptViewer.ProcessingMode = ProcessingMode.Remote;
                string serverUrl = "http://" + ConfigurationManager.AppSettings["ReportServer"].ToString();
                rptViewer.ServerReport.ReportServerUrl = new Uri(serverUrl);

                if (ReportName == AppConstant.RPT_INVOICEJOURNAL || ReportName == AppConstant.RPT_INVOICE || ReportName == AppConstant.RPT_PAYMENTJOURNAL || ReportName == AppConstant.RPT_PAYMENTREMINDER)
                {
                    rptViewer.ServerReport.ReportPath = "/Billing/" + ReportName;
                }

                if (ReportName == AppConstant.RPT_PRINTALLHARBOURGAURDSCHEDULE || ReportName == AppConstant.RPT_HARBOURAGGREMENT || ReportName == AppConstant.RPT_HARBOURAGGREMENTLIST)
                {
                    rptViewer.ServerReport.ReportPath = "/Harbour/" + ReportName;
                }
                //Set report parameter
                if (ParamList != null && ParamList.Count > 0)
                {
                    ReportParameterCollection list = new ReportParameterCollection();
                    //every report has parameter SiteID
                    ReportParameter siteId = new ReportParameter();
                    siteId.Name = "SiteID";
                    siteId.Values.Add(CurrentSession.SiteID.ToString());
                    list.Add(siteId);
                    foreach (KeyValuePair<String, String> item in ParamList)
                    {
                        ReportParameter param = new ReportParameter();
                        param.Name = item.Key;
                        param.Values.Add(item.Value);
                        list.Add(param);
                    }
                    this.rptViewer.ServerReport.SetParameters(list);
                }

                rptViewer.ServerReport.Refresh();

            }
            catch (Exception ex)
            {

                WriteSystemLog(AppConstant.EXCEPTION + ex.Message, Convert.ToChar(AppEnum.LogType.E.ToString()));
            }
        }

 2.客户端

private void ShowReport(string ReportName, Dictionary<string, string> ParamList, bool HasParam)
        {

            InvoiceManager objInvocieManager;
            try
            {
                objInvocieManager = new InvoiceManager();
                //path for your reports
                string path = HttpContext.Current.Server.MapPath("~/Invoices/Reports/");
                rptViewer.Reset();
                rptViewer.ProcessingMode = ProcessingMode.Local;
                LocalReport localReport = rptViewer.LocalReport;
                localReport.ReportPath = path + ReportName + ".rdlc";// rptViewer.LocalReport.ReportPath = "Invoices\\Reports\\PrintInvoiceJournal.rdlc";
                ReportDataSource rptDataSource;

                //Set report parameter
                if (HasParam == true)
                {
                    if (ParamList != null && ParamList.Count > 0)
                    {
                        foreach (KeyValuePair<String, String> item in ParamList)
                        {
                            ReportParameter param = new ReportParameter();
                            param.Name = item.Key;
                            param.Values.Add(item.Value);
                            localReport.SetParameters(param);
                        }
                    }
                }

                if (ReportName == AppConstant.RPT_PRINTIVOICEJOURNAL)
                {
                    int invoiceJournalNo = 0;
                    if (ParamList != null && ParamList.Count > 0)
                    {
                        foreach (KeyValuePair<String, String> item in ParamList)
                        {
                            // if (item.Key == "")
                            invoiceJournalNo = Convert.ToInt16(item.Value);
                        }
                    }

                    //Bind report data source
                    rptDataSource = new ReportDataSource();
                    rptDataSource.Name = "dsPrintInvoiceJournal";
                    rptDataSource.Value = objInvocieManager.PrintInvoiceJournal(CurrentSession.SiteID, invoiceJournalNo);
                    localReport.DataSources.Add(rptDataSource);

                } 
                

                localReport.Refresh();

            }
            catch (Exception ex)
            {

                WriteSystemLog(AppConstant.EXCEPTION + ex.Message, Convert.ToChar(AppEnum.LogType.E.ToString()));
            }
            finally
            {
                objInvocieManager = null;
            }
        }

 

 

 sample reports of reporting services  http://msftrsprodsamples.codeplex.com/

posted on 2013-05-24 14:42  cw_volcano  阅读(188)  评论(0编辑  收藏  举报