Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am doing a website and a option for taking report. And a trail I have retrieve all the data from a table called booking and given a link to download the report. this works which I need. Here what I need is that is need to filter the date that is, from date and to date want to give as dynamically and in between these ranges I need to print the details. For this is have written a stored procedure in sql and when passing two dates it works correctly.
Actually the data is taken from two tables and in stored procedure it is inner joined with condition. My problem is that how can I filter dates and print ony data between these ranges??

controller part

public ActionResult ExportCustomers()
       {

           ReportDocument rd = new ReportDocument();
           rd.Load(Path.Combine(Server.MapPath("~/CrystalReports/Report.rpt")));

           rd.SetDataSource(db.ItemBookings.Select(p => new
           {

               name = p.CustID,
               status = p.Status,
               bookingTime = p.Bookingtime,
               Post = p.TotalAmount,
           }).ToList());

           Response.Buffer = false;
           Response.ClearContent();
           Response.ClearHeaders();


           Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
           stream.Seek(0, SeekOrigin.Begin);
           return File(stream, "application/pdf", "CollectionHistory.pdf");
       }


in view page

<div><a href="@Url.Action("ExportCustomers")"> Report PDF </a></div>  


stored procedure

CREATE procedure [dbo].[spItemBookingDateFilter]
	    @FomDate AS VARCHAR(20),
		@ToDate AS VARCHAR(20)
AS
Begin
SELECT        IB.ID, IB.CustID, IB.DeviceID, IB.Bookingtime, IB.RouteID, IB.IsCollected, IB.IsAllocated, IB.Status, IB.TotalAmount, IB.TotalWeight, AD.Id AS Expr1, AD.Name, AD.MobNo, AD.Location, AD.Address, AD.Post, 
                         AD.PostalCode
FROM            dbo.ItemBooking AS IB INNER JOIN
                         dbo.CustomerAddressDetail AS AD ON IB.AddressID = AD.Id 
						 AND  convert(VARCHAR(50),@FomDate,105) <= IB.BookingTime AND convert(VARCHAR(50),@ToDate,105) >= IB.BookingTime

						 end

GO


by giving a table it is just downloading as pdf file but how can I give stored procedure with parameter to filter date range and to print these data ??
somebody please guid me how to get to the correct result ??

What I have tried:

I have searched in many ways but only for c# windows application but don't know how to implement in mvc razor with stored procedure or data table?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900