如何在mvc4中以编程方式将FromDate和ToDate传递给crystal报表?

时间:2016-04-26 11:39:21

标签: c# asp.net-mvc-4 crystal-reports

我在我的应用程序中生成了一个摘要报告。我正在使用mvc4。我使用Crystal报告生成了该报告。现在我有一个观点。在该视图中,我有两个名为FromDateToDate的字段。如果我选择FromDateToDate并点击确定按钮,则会根据这两个日期条件生成报告并显示报告。

我的报告

my report

现在运作良好。我想要的是将FromDateTodate保留在我在下面的报告中标记的位置。我怎么做?如何将日期传递给水晶报告?有任何帮助来解决这个问题吗?

我的控制器代码

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");
}

0 个答案:

没有答案