ReportViewer 使用DataSet 结构 与 linQ 填充 DataSet数据

(一)

1.          Linq 映射文件

 

 

2.          


 

3.          

 

 

 

4.         浏览打印页面

 

 

5 运行效果

 

 

 

(二)

5.         实现代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

 

using OTPrintDialog.EMS_OT;

using OTPrintDialog.DataSet;

using System.Data.Common;

 

namespace OTPrintDialog.EMS_OT

{

    public partial class OTPrintDialog : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if(!IsPostBack)

            {

                LoadData();

            }

        }

 

        private void LoadData()

        {

 

            this.ReportViewer1.LocalReport.ReportPath = "EMS_OT_OT.rdlc";

 

            String flowNo = Request["flowNo"];

            if (String.IsNullOrEmpty(flowNo))

            {

                return;

            }

 

 

            using (EMS_OTDataContext myContext = new EMS_OTDataContext())

            {

 

                EMS_OT_OT myOt = myContext.EMS_OT_OT.FirstOrDefault(p => p.flowNo == flowNo);

 

                if(myOt==null)

                {

                    return ;

                }

 

                ///填充DataSet的数据

                OTMain myOTmain = new OTMain();

                OTMain.dtMainRow myRow = myOTmain.dtMain.NewdtMainRow();

                myRow.oTNo = myOt.oTNo;

                myOTmain.dtMain.AdddtMainRow(myRow);

 

               

 

               

                Microsoft.Reporting.WebForms.ReportDataSource rs1 = new Microsoft.Reporting.WebForms.ReportDataSource();

 

                ///Name 相当重要,它可以查看 rdlc 文件的xml 中找出 Table 的名字

                rs1.Name = "OTMain_dtMain";

 

                ///实际的填充过数据的表

                rs1.Value = myOTmain.dtMain;

 

                this.ReportViewer1.LocalReport.DataSources.Add(rs1);

 

 

                this.ReportViewer1.DataBind();

             

            }

          

        }

    }

}

 

(1-1)           Rdlc 文件

<?xml version="1.0" encoding="utf-8"?>

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

 <DataSources>

    <DataSource Name="DummyDataSource">

      <rd:DataSourceID>8cb5ebf6-1dc6-4963-b5e5-5c1b405686a4</rd:DataSourceID>

      <ConnectionProperties>

        <DataProvider>SQL</DataProvider>

        <ConnectString />

      </ConnectionProperties>

    </DataSource>

 </DataSources>

 <InteractiveHeight>29.7cm</InteractiveHeight>

 <rd:DrawGrid>true</rd:DrawGrid>

 <InteractiveWidth>21cm</InteractiveWidth>

 <rd:GridSpacing>0.25cm</rd:GridSpacing>

 <rd:SnapToGrid>true</rd:SnapToGrid>

 <RightMargin>2.5cm</RightMargin>

 <LeftMargin>2.5cm</LeftMargin>

 <BottomMargin>2.5cm</BottomMargin>

 <rd:ReportID>9064650f-f95a-434e-bd13-42d8c8801e0f</rd:ReportID>

 <PageWidth>21cm</PageWidth>

 <DataSets>

    <DataSet Name="OTMain_dtMain">

      <Fields>

        <Field Name="oTNo">

          <DataField>oTNo</DataField>

          <rd:TypeName>System.String</rd:TypeName>

        </Field>

      </Fields>

      <Query>

        <DataSourceName>DummyDataSource</DataSourceName>

        <CommandText />

        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>

      </Query>

      <rd:DataSetInfo>

        <rd:DataSetName>OTMain</rd:DataSetName>

        <rd:TableName>dtMain</rd:TableName>

      </rd:DataSetInfo>

    </DataSet>

 </DataSets>

 <Width>16cm</Width>

 <Body>

    <ColumnSpacing>1cm</ColumnSpacing>

    <ReportItems>

      <Textbox Name="oTNo">

        <rd:DefaultName>oTNo</rd:DefaultName>

        <Top>2cm</Top>

        <Width>5.5cm</Width>

        <Style>

          <FontFamily>宋体</FontFamily>

          <PaddingLeft>2pt</PaddingLeft>

          <PaddingRight>2pt</PaddingRight>

          <PaddingTop>2pt</PaddingTop>

          <PaddingBottom>2pt</PaddingBottom>

        </Style>

        <CanGrow>true</CanGrow>

        <Left>5.75cm</Left>

        <Height>0.63492cm</Height>

        <Value>=First(Fields!oTNo.Value)</Value>

      </Textbox>

    </ReportItems>

    <Height>5cm</Height>

 </Body>

 <Language>zh-CN</Language>

 <TopMargin>2.5cm</TopMargin>

 <PageHeight>29.7cm</PageHeight>

</Report>

 

 

posted @ 2009-01-14 09:46  b0b0  阅读(1081)  评论(0编辑  收藏  举报