athira k

athira k

  • NA
  • 140
  • 53.5k

date range filter crystal report in mvc 5 razor

Jun 3 2017 1:15 AM
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 ??
 
 

Answers (2)