hi everyone,
i want to know how to set parameter in crystal report using mvc4
this is the view
@{
ViewBag.Title = "Facility Booking Daily Transaction Report";
}
<h3>Facility Booking Daily Transaction Report</h3>
@using (Html.BeginForm("Report", "rptFbDailyTransacion", FormMethod.Post, new { target = "_blank" }))
{
<table>
<tr>
<td>
Select Date :
</td>
<td>
@Html.Telerik().DatePicker().Name("dateBook").Value(System.DateTime.Now)
</td>
</tr>
<tr align="right">
<td></td>
<td></td>
<td colspan ="5"><input type="submit" id="submit1" class = "btn" value="Show Report" />
</td>
</tr>
</table>
}
this is the controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using PMIS.Models;
namespace PMIS.Controllers.Report
{
public class rptFbDailyTransacionController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Report(DateTime dateBook)
{
PMIS_DBContext db = new PMIS_DBContext();
PMIS_DBDataSet ds = new PMIS_DBDataSet();
System.Data.DataTable dt = ds.Tables.Add("FbdailyTransaction_Items");
dt.Columns.Add("BookingNo", Type.GetType("System.String"));
dt.Columns.Add("BookingDate", Type.GetType("System.DateTime"));
dt.Columns.Add("FacilityType", Type.GetType("System.String"));
dt.Columns.Add("CName", Type.GetType("System.String"));
dt.Columns.Add("TaxAmount", Type.GetType("System.Decimal"));
dt.Columns.Add("TotalAmount", Type.GetType("System.Decimal"));
dt.Columns.Add("BalanceAmount", Type.GetType("System.Decimal"));
dt.Columns.Add("UserP", Type.GetType("System.String"));
dt.Columns.Add("Company", Type.GetType("System.String"));
DataRow nr;
var rec = from t1 in db.fbtbook1
join t2 in db.fbmfacilitytypes on t1.FacilityTypeId equals t2.ID
where t1.RecordStatus == "A" && t1.BookingDate==dateBook
select new
{
t1.BookingNo,
t1.BookingDate,
t2.FacilityType,
t1.Name,
t1.TaxAmount,
t1.TotalAmount,
t1.BalanceAmount
};
string mcompany = "";
var compRec = from mcompRec in db.mcompanies
select new
{
mcompRec.CompanyName
};
foreach (var compRecitem in compRec)
{
mcompany = compRecitem.CompanyName;
}
foreach (var item in rec)
{
nr = dt.NewRow();
nr["BookingNo"] = item.BookingNo;
nr["BookingDate"] = item.BookingDate;
nr["FacilityType"] = item.FacilityType;
nr["CName"] = item.Name;
nr["TaxAmount"] = item.TaxAmount;
nr["TotalAmount"] = item.TotalAmount;
nr["BalanceAmount"] = item.BalanceAmount;
nr["UserP"] = User.Identity.Name.ToString();
nr["Company"] = mcompany;
dt.Rows.Add(nr);
}
Session["Reportdata"] = dt;
Session["date"] = dateBook.ToShortDateString();
return RedirectToAction("../ReportWebForms/rptFbDailyTransaction.aspx");
}
}
}
this is the WebFrom
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>Facility Booking Daily Transaction</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<CR:CrystalReportViewer ID="FbDailyTransaction" runat="server"
AutoDataBind="true" />
</div>
</form>
</body>
</html>
<script runat="server">
public PMIS.CrystalReports.rptFbDailyTransaction oRpt = null;
protected void Page_Load(object sender, EventArgs e)
{
String strReportName = System.Web.HttpContext.Current.Session["date"].toString();
oRpt.SetDataSource(Session["Reportdata"]);
oRpt.ParameterFields("company",strReportName);
FbDailyTransaction.ReportSource = oRpt;
FbDailyTransaction.RefreshReport();
}
protected void Page_Unload(object sender, EventArgs e)
{
if (this.oRpt != null)
{
this.oRpt.Close();
this.oRpt.Dispose();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
oRpt = new PMIS.CrystalReports.rptFbDailyTransaction();
}
private void InitializeComponent()
{
}
#endregion
</script>
when the report load its asking parameter value
thank you