DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Zone-Free Angular: Unlocking High-Performance Change Detection With Signals and Modern Reactivity
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • Why Angular Performance Problems Are Often Backend Problems
  • Faster Releases With DevOps: Java Microservices and Angular UI in CI/CD

Trending

  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal
  • Code Quality Had 5 Pillars. AI Broke 3 and Created 2 We Can’t Measure
  • Real-Time AI Inference at Scale Using Cloud Run, GPUs, and Vertex AI
  1. DZone
  2. Coding
  3. Frameworks
  4. Learn MVC Using AngularJS and Crystal Report

Learn MVC Using AngularJS and Crystal Report

Looking for a better way to export data from your web application? Read on to learn how to leverage Angular for just such a task.

By 
Thiruppathi Rengasamy user avatar
Thiruppathi Rengasamy
·
Jun. 14, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
13.5K Views

Join the DZone community and get the full member experience.

Join For Free

introduction

in this article, we will learn mvc, using angularjs and crystal report to help us handle server side data, using visual studio 2015.

mvc


what is crystal report?

crystal report is a business intelligence application. crystal report is powered by sap . it is used to design and generate reports from a wide range of data sources.

why we are using sap crystal report

  • provides a powerful reporting tool.
  • creates a real-time operational report.
  • works with the web, windows, and mobile devices.
  • makes flexible and customizable reports.

tools installation

we will download the crystal report ide from this link . after registration, “exe” will be downloaded automatically.

mvc


after completing the installation, restart visual studio.

create an mvc project

open visual studio 2015.


mvc


go to menu >new > click project > it will open the new project popup.


mvc


select asp.net project and give to the solution name, and then click the ok button. again one popup should appear that's called 'new asp.net web application.'


mvc


select mvc template and click ok to start the project. configure angularjs in this mvc project.

create a new folder called report and right click on the folder. add crystal report into the solution explorer.

mvc

in this report folder, add one dataset for server-side data binding. this will be used to design the customizable reports.

mvc


use this dataset to export your data for the designing and developing of the report.


mvc


easy-to-use] drag-and-drop controls are used in the design, as shown.


mvc


write a method to access the data and bind to the data from the server to crystal report in the controller. i have written the code given below in my home controller file.

c# code

public actionresult exportexcel()  
        {  
            list<bookmodel> booklist = new list<bookmodel>();  
            datasetreport dsreport = new datasetreport();  
            using (var con = new sqlconnection(configurationmanager.connectionstrings["dbsqlcon"].connectionstring))  
            {  
                var cmd = new sqlcommand("bookmaster_sp", con);  
                cmd.commandtype = commandtype.storedprocedure;  
                cmd.parameters.add(new sqlparameter("@mode", sqldbtype.varchar)).value = "get";  
                con.open();  

                (new sqldataadapter(cmd)).fill(dsreport.tables["booklist"]);  
            }  

            reportdocument rd = new reportdocument();  
            rd.load(path.combine(server.mappath("~/report"), "reportbooklist.rpt"));  
            rd.setdatasource(dsreport.tables["booklist"]);  

            response.buffer = false;  
            response.clearcontent();  
            response.clearheaders();  


            stream stream = rd.exporttostream(crystaldecisions.shared.exportformattype.excelworkbook);  
            stream.seek(0, seekorigin.begin);  
            return file(stream, "application/pdf", "reportbooklist.xlsx");  
        }   

proceed, as shown below.

rd.load(path.combine(server.mappath("~/report"), "reportbooklist.rpt")); 

in this article, i have demonstrated only excel and pdf reports.

stream stream = rd.exporttostream(crystaldecisions.shared.exportformattype.excelworkbook);  

you can export 16 different types of report formats using crystal reports.

mvc


we have finished the server part of the work. now we can start writing the code to the html and angular js controller file.

javascript code

$scope.excelreport=function()  
    {  
        $window.open("home/exportexcel", "_blank");  
    }  
    $scope.pdfreport = function () {  
        $window.open("home/exportpdf", "_blank");  
    }   

before writing this code, you must inject the $window keyword into the angular controller.

uiroute.controller('bookcontroller', function ($scope, bookservice, $window)  

call the above javascript function in your html buttons.

<button class="btn btn-success " ng-click="excelreport()">excel report</button>  
<button class="btn btn-danger " ng-click="pdfreport()">pdf report</button>  

that's it! that's all the client side part of the work. now, you can run the application.

output 1

mvc

output 2

mvc

finally, we succeeded in exporting our data using crystal report in mvc angularjs.

source code download

  • link

conclusion

in this article, we learned mvc, using angularjs and crystal report. if you have any queries, please tell me through the comments section .

happy coding!

Crystal (programming language) AngularJS

Published at DZone with permission of Thiruppathi Rengasamy. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Zone-Free Angular: Unlocking High-Performance Change Detection With Signals and Modern Reactivity
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • Why Angular Performance Problems Are Often Backend Problems
  • Faster Releases With DevOps: Java Microservices and Angular UI in CI/CD

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook