如何在水晶报表中设置参数 [英] how to set parameter in crystal report

查看:81
本文介绍了如何在水晶报表中设置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道如何使用mvc4在水晶报表中设置参数

这是视图

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
    {
        //
        // GET: /rptFbDailyTransacion/

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



这是WebFrom


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)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        //InitializeComponent();
        base.OnInit(e);
        oRpt = new PMIS.CrystalReports.rptFbDailyTransaction();
        //GenerateReport();
    }

    private void InitializeComponent()
    {

    }
    #endregion
    
</script>





当报告加载其询问参数值时

谢谢



when the report load its asking parameter value
thank you

推荐答案

请点击此链接使用webfrom在mvc 4中的结晶报告


这篇关于如何在水晶报表中设置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆