Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

Generating Crystal Report Using Entity Framework in MVC5

$
0
0

Please I have an application that I have built and am trying to integrate crystal report using what i have query from my controller

this is the report generator Controller

public ActionResult ExportReport(int CategoryId, string DateFrom, string DateTo)
        {

            DateTime StartDate = Convert.ToDateTime(DateFrom);
            DateTime EndDate = Convert.ToDateTime(DateTo);
            ReportDocument read = new ReportDocument();
            

            if (CategoryId == 1)
            {
                var dailyReport = _routineService.GetAllRoutines().Where(x => x.LaodingDate >= StartDate && x.LaodingDate <= EndDate && x.CategoryId == CategoryId).ToList();
                read.Load(Path.Combine(Server.MapPath("~/Reports"), "DailyReport.rpt"));
                read.SetDataSource(dailyReport);
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();

                try
                {
                    Stream stream = read.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "application/pdf", "Enugu_Local_DailySalesReport.pdf");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else if (CategoryId == 2)
            {
                var bridgReport = _routineService.GetAllRoutinesByCategory(CategoryId).Where(x => x.LaodingDate >= StartDate && x.LaodingDate <= EndDate).ToList();
                read.Load(Path.Combine(Server.MapPath("~/Reports"), "BridgingDailyReport.rpt"));
                read.SetDataSource(bridgReport);
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();

                try
                {
                    Stream stream = read.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "application/pdf", "Enugu_Bridging_DailySalesReport.pdf");
                }
                catch (Exception ex)
                {
                    throw ex;
                } 
            }

            return RedirectToAction("DailyReport");
        }

The problem now is when the database is query with that specific data, instead of the Crystal report template to print what has been queried  from database, it now bring every record from database irrespective of the  date and category... I don't want every record from database, I want to print daily, monthly, Quarterly and yearly report.

I think some how that it because am connecting my crystal report directly to database like this .\sqlexpress. How can i make it work with my query please?

Please I need some help on how to export what I query from database to crystal report thank you for your help

am new to crystal report please help me out thank you


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>