天天看点

Mvc调用Reporting Service

1、aspx页面

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<script runat="server">

    void Page_Load(object sender, EventArgs e)

    {

        if (ViewData["ReportData"] != null)

        {

            Dictionary<string, string> dic = ViewData["ReportData"] as Dictionary<string, string>;

            ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://" + dic["IPstr"] + "/reportserver");

            ReportViewer1.ServerReport.ReportPath = "/MerchantManagerReports/V_DeviceInMerchant";

            ReportViewer1.ProcessingMode = ProcessingMode.Remote;

            ServerReport serverReport = ReportViewer1.ServerReport;

            List<ReportParameter> list = new List<ReportParameter>();

            list.Add(new ReportParameter("OrgID", dic["orgId"] == MerchantManagerApp.MmaPermissions.OrgManager.YadaOrgId ? null : dic["orgId"]));

            list.Add(new ReportParameter("MerchantNo", dic["MerchantNo"] == "" ? null : dic["MerchantNo"]));

            list.Add(new ReportParameter("TerminalID", dic["TerminalID"] == "" ? null : dic["TerminalID"]));

            list.Add(new ReportParameter("Contact", dic["Contact"] == "" ? null : dic["Contact"]));

            serverReport.SetParameters(list);

        }

    }

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

    Index

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script src="<%=VirtualPathUtility.ToAbsolute("~/Scripts/jquery-1.4.1.js") %>" type="text/javascript"></script>

    <script src="<%=VirtualPathUtility.ToAbsolute("~/Scripts/jquery.validate.js") %>"

        type="text/javascript"></script>

    <script src="<%=VirtualPathUtility.ToAbsolute("~/Scripts/MvcReportViewStyle.js") %>"

        type="text/javascript"></script>//去掉webForm 调用Reporting Service时,出现的三层滚动条

    <table id="reportCondition">

        <tr>

            <td valign="top">

                <%  Dictionary<string, string> dic = ViewData["ReportData"] as Dictionary<string, string>;

                    string merchantNo = "", terminalID = "", Contact = "";

                    if (dic != null)

                    {

                        merchantNo = dic["MerchantNo"];

                        terminalID = dic["TerminalID"];

                        Contact = dic["Contact"];

                    }

                    using (Html.BeginForm("DeviceInMerchant", "ReportView"))

                    {%>

                <table>

                    <tr>

                        <td>

                            机构:

                        </td>

                        <td>

                            <select name="Orgs" id="Orgs" >

                                <% string orgStr = ""; string orgId = dic == null ? "" : dic["orgId"];

                                   IEnumerable<CommOrganization> orgs = ViewData["orgs"] as IEnumerable<CommOrganization>;

                                   foreach (var item in orgs)

                                   {

                                       orgStr += "<option value=/"" + item.ID + "/" ";

                                       if (orgId == item.ID.ToString())

                                           orgStr += "selected=/"selected/"";

                                       orgStr += ">" + item.Name + "</option>";

                                   } %>

                                <%= orgStr%>

                            </select>

                        </td>

                        <td>

                            商户号

                        </td>

                        <td>

                            <%=Html.TextBox("MerchantNo", merchantNo)%>

                        </td>

                        <td>

                            终端号

                        </td>

                        <td>

                            <%=Html.TextBox("TerminalID", terminalID)%>

                        </td>

                        <td>

                            联系人

                        </td>

                        <td>

                            <%=Html.TextBox("Contact", Contact)%>

                        </td>

                        <td>

                            <input type="submit" value="查询" />

                        </td>

                    </tr>

                </table>

                <%} %>

            </td>

        </tr>

    </table>

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

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"

        SizeToReportContent="True" ProcessingMode="Remote" Width="100%" BackColor="#eaf6fc"

        ShowFindControls="False" ToolTip="商户档案" ShowBackButton="true" ShowZoomControl="true"

        AsyncRendering="true" ZoomMode="percent" ShowRefreshButton="true" Height="500px">

    </rsweb:ReportViewer>

    </form>

</asp:Content>

2、cs

 public ActionResult DeviceInMerchant()

        {

            ViewData["orgs"] = GetOrgList();

            return View();

        }

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult DeviceInMerchant(FormCollection collection)

        {

            Dictionary<string, string> dic = new Dictionary<string, string>();

            dic.Add("IPstr", reportServerIp);

            dic.Add("MerchantNo", collection["MerchantNo"]);

            dic.Add("TerminalID", collection["TerminalID"]);

            dic.Add("Contact", collection["Contact"]);

            dic.Add("orgId", collection["Orgs"]);

            ViewData["orgs"] = GetOrgList();

            ViewData["ReportData"] = dic;

            return View();

        }

运行页面时,调整窗口适当大小,你最多会内外三层滚动条,如何去掉多余滚动条,参见调用 Reporting Service 时,怎么去掉滚动条