Get Adobe Flash player

Tutorial: 3-tier ASP.NET / SSRS solution with PDF output, part 2. The User Interface Layer. 

Posted by Igor Saturday, July 31, 2010 10:21:41 AM
Rate this Content 6 Votes

As you remember, from the architectural point of view we should implement 3-tier solution with the User Interface, Business Logic and Data Access Layers.

Tutorial Part 2. User Interface layer implementation.

Please, use the code below as the Default.aspx page source:

    <form id="form1" runat="server">
    <div>
        <br />
        User Name:&nbsp;
        <asp:TextBox ID="_tb_UserName" runat="server">%Ivan%</asp:TextBox>
        <br />
        <br />
        <asp:Button ID="_btn_Run" runat="server" Text="Run Report"
            onclick="_btn_Run_Click" />
        <br />
        <br />
        <asp:Label ID="_l_Msg" runat="server" Text=""></asp:Label>
        <br />
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="979px"
            Height="636px" Font-Names="Verdana" Font-Size="8pt" Visible="False">
            <LocalReport ReportPath="report\Report1.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1"                      
                        Name="SSRSTutorial_DAL_dalReport" />                                                                    
                </DataSources>            
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
         SelectMethod="";
            TypeName="SSRSTutorial.DAL.dalReport"></asp:ObjectDataSource>      
    </div>
    </form>

As you may see, we use the form with one asp:TextBox control for the report parameter input. Also we use one asp:Button for report run.
And we use one asp:Label as the report error message output control.

Also, we use ASP.NET and SSRS controls: rsweb:ReportViewer is the standart ASP.NET SSRS reporting Viewer control which adjusted in turn to use the ObjectDataSource which will be generated thanks to our Business Logic Layer class.

Our form will looks like the screenshot below:

software outsourcing ukraine : Tutorial: 3-tier ASP.NET / SSRS solution with PDF output : SoftPilot2000

 

Default.aspx.cs Code Behind sources:

        protected void _btn_Run_Click(object sender, EventArgs e)
        {
            bool writeDateToFile = false;
            string outputMessage = "";
            string UserName = this._tb_UserName.Text;

            SSRSTutorial.blReport reportOutput = new SSRSTutorial.blReport(null);


            // the final production system will handle the gathering and validating of user
            // input
            byte[] rptData = reportOutput.RunReport(UserName, out outputMessage);

            if (rptData != null)
            {
                if (writeDateToFile)
                {
                    using (FileStream fs = new FileStream(@"c:\output.pdf", FileMode.Create))
                    {
                        fs.Write(rptData, 0, rptData.Length);
                    }
                }
                // write the resulting report back out to the browser
                Response.ContentType = "Application/pdf";
                Response.BinaryWrite(rptData);
                Response.Flush();
                Response.End();
            }
            else
            {
                if (outputMessage.Length > 0)
                {
                    _l_Msg.Text = outputMessage;
                }
            }
        }

As you may found above, we use the object's method reportOutput.RunReport  of our business layer class SSRSTutorial.blReport in turn to generate the report's PDF output for the browser. One paramer with the UserName template adjusted for use with LIKE SQL syntax passed to the RunReport method. If some errors been handled during report's business logic processing, we will get back the exception description at the outputMessage out variable.

As you may see, the only User Interface duties been handled at our User Interface Layer implementation method. We've got the input data from the form, instantiate the Business Layer object named reportOutput and call the RunReport method of the object. Also, we've passed the report's PDF data for the browser.

That's all for the UI layer of our tutorial.

End of Part 2.

To be continued.

(c) SoftPilot2000 Software Outsourcing Ukraine. All rights reserved.
Comments are closed on this post.