使用VS自带的报表RDLC结合报表控件ReportViewer使用

1.新建一个报表,设置报表之后,使用强类型的DataSet  xsd 配置数据源,对报表中的使用最常用的是文本框和表格控件

2.新增WebForm窗体,拖一个ReportViewer控件,在WebForm中写入以下代码:

WebForm html:

<%@ Page Language="C#" MasterPageFile="~/Site_admin.Master" AutoEventWireup="true" CodeBehind="LotteryBill.aspx.cs" Inherits="XieYun.WebAdmin.ReportsALL.Organization.LotteryBill" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div>

                 &nbsp;&nbsp;&nbsp;     兑奖时间:
            <input id="searchStarTime" runat="server" name="searchStarTime" data-options="showSeconds:false" class="easyui-datetimebox" style="width: 140px" />
                --
            <input class="easyui-datetimebox" runat="server" id="searchEndTime" name="searchEndTime" data-options="showSeconds:false" style="width: 140px" />
        <span>
            <asp:Button ID="btnSearch" runat="server" Text="查询" OnClick="btnSearch_Click" />
        </span>
    </div>
    <div>
        <rsweb:ReportViewer ID="reportViewer2" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="629px" Width="851px">
        </rsweb:ReportViewer>
    </div>
</asp:Content>

使用ReportViewer时必须使用ScriptManager控件

后端代码

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string strWhere = string.Format(" LotteryStatusEnum={0} and IsVirtual=0", (int)LotteryStatusEnum.TransferSuc);
                LoadReportData(strWhere);
            }
        }

        /// <summary>
        /// 加载报表数据
        /// </summary>
        /// <param name="strWhere"></param>
        private void LoadReportData(string strWhere)
        {
            reportViewer2.ProcessingMode = ProcessingMode.Local;
            reportViewer2.LocalReport.ReportEmbeddedResource = "XieYun.WebAdmin.ReportsALL.rdlc.LotteryBillReport.rdlc";

            LotteryRecordManager lotteryRecordManager = new LotteryRecordManager();
            int recordCount = 0;
            List<LotteryRecordInfo> list = lotteryRecordManager.GetPageList(1, int.MaxValue / 3, strWhere, "", out recordCount, false);

            if (list != null && list.Count > 0)
            {
                foreach (var info in list)
                {
                    info.PrizeEnumStr = EnumValueNameDescriptionParse.GetEnumValueNameDescription(typeof(PrizeEnum), info.PrizeEnum).Description;
                    info.PayEnumStr = EnumValueNameDescriptionParse.GetEnumValueNameDescription(typeof(PayEnum), info.PayEnum).Description;
                    ;
                }
            }
            else
            {
                list = new List<LotteryRecordInfo>();
            }

            DataTable dt = lotteryRecordManager.ToDataTable2(list, "PrizeEnumStr", "PayEnumStr");
            if (dt == null)
            {
                dt = new DataTable();
            }
            ReportDataSource rds_shipperOrder = new ReportDataSource("DataSet1", dt);
            reportViewer2.LocalReport.DataSources.Clear();
            reportViewer2.LocalReport.DataSources.Add(rds_shipperOrder);

            reportViewer2.LocalReport.Refresh();
        }

        /// <summary>
        /// 单击搜索报表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string searchStarTime = this.searchStarTime.Value;
            string searchEndTime = this.searchEndTime.Value;
            DateTime dtSearchStartTime;
            DateTime dtSearchEndTime;
            string strWhere = string.Format(" LotteryStatusEnum={0} and IsVirtual=0 ", (int)LotteryStatusEnum.TransferSuc);
            if (!string.IsNullOrWhiteSpace(searchStarTime)&&DateTime.TryParse(searchStarTime.Trim(),out dtSearchStartTime))
            {
                strWhere += string.Format(" AND TransferTime >='{0}' ",dtSearchStartTime);
            }
            if (!string.IsNullOrWhiteSpace(searchEndTime) && DateTime.TryParse(searchEndTime.Trim(), out dtSearchEndTime))
            {
                strWhere += string.Format(" AND TransferTime <='{0}' ", dtSearchEndTime);
            }

            LoadReportData(strWhere);
            
        }

 

 

posted @ 2013-10-10 17:50  学亮  阅读(1995)  评论(0编辑  收藏  举报