Sneha K

Sneha K

  • 1.1k
  • 527
  • 190.1k

How to pass FromDate and ToDate to crystal report in MVC4?

May 20 2016 8:21 AM

I generated one summary report in my application. I am working with mvc4. I generated that report using Crystal report. Now I have one view. In that view I have two fields called FromDate, ToDate. If I select FromDate and ToDate and click the ok button it will generate the report as per that two dates criteria and display the report.

My Report

                      

Now that is working well. What I want is to keep FromDate and Todate in the place which I marked in the report above. How do I do that? How do I pass the dates to crystal report? Any help to resolve this issue?

My Controller code

 
public ActionResult GetOrderComplaintsValues(VisitorsViewModel vvm)
{
var ObjFromDate = Convert.ToDateTime(vvm.FromDate);
var ObjTodate = Convert.ToDateTime(vvm.ToDate);
var objpovisitID = vvm.POVisitID;
var objText = "Order";
if(objpovisitID == new Guid("DB7FE0EA-8444-4F6B-9961-4F54E7C4F0FD"))
{
var PurchaseOrderCount = (from v in db.View_VisitorsForm where v.POVisitID == objpovisitID && v.VisitingDate >= ObjFromDate && v.VisitingDate <= ObjTodate select v).ToList();
}
SqlConnection con = new SqlConnection(@"Data Source=192.168.0.73\SQLEXPRESS,14330;Initial Catalog=WafeERP_NEW;User ID=sa;Password=wafewin;");
DataTable dt = new DataTable();
try
{
con.Open();
if (objpovisitID == new Guid("DB7FE0EA-8444-4F6B-9961-4F54E7C4F0FD"))
{
SqlCommand cmd = new SqlCommand("Select * from View_VisitorsForm where POVisitID= '" + objpovisitID + "' and VisitingDate >='" + ObjFromDate + "'and VisitingDate <= '" + ObjTodate + "'", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
else if (objpovisitID == new Guid("283462E7-665D-44D1-A469-B8AF2D913B8B"))
{
SqlCommand cmd = new SqlCommand("Select * from View_VisitorsForm where POVisitID= '" + objpovisitID + "' and VisitingDate >='" + ObjFromDate + "'and VisitingDate <= '" + ObjTodate + "'", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
else if (objpovisitID == new Guid("00000000-0000-0000-0000-000000000000"))
{
SqlCommand cmd = new SqlCommand("Select * from View_VisitorsForm where VisitingDate >='" + ObjFromDate + "'and VisitingDate <= '" + ObjTodate + "'", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
}
catch (Exception ex)
{
throw;
}
ReportClass rc = new ReportClass();
rc.FileName = Server.MapPath("/Reports/rpt_OrderComplaintsSummaryReport.rpt");
rc.Load();
rc.SetDataSource(dt);
Stream stream = rc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
 
Thank you in advance. 
 
 

Answers (2)