简体   繁体   English

如何在 stimulsoft 报告中将数据传递给 BusinessObject?

[英]How to pass data to BusinessObject in stimulsoft report?

I need to pass data for stimulsoft report file via code.我需要通过代码为 stimulsoft 报告文件传递数据。

public ActionResult PackageCommandPrint(string startDate, string endDate, int profileId)
    {
        try
        {
            List<PackageCommand> commands = new List<PackageCommand>();
            StiReport report = new StiReport();
            report.Load(Server.MapPath("~/Content/Reports/PackageCommand.mrt"));
            if (HttpContext.Cache["PackageCommands"] == null)
            {
                using (SPMSEntities db = new SPMSEntities())
                {
                    commands = db.PackageCommands.ToList();
                    HttpContext.Cache.Insert("PackageCommands", commands, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration);
                }
            }
            else
            {
                commands = HttpContext.Cache["PackageCommands"] as List<PackageCommand>;
            }
            string userFullName;
            using (SPMSEntities db = new SPMSEntities())
            {
                Profile profile = db.Profiles.Find(profileId);
                userFullName = profile.FirstName + " " + profile.LastName;
            }
            report.Dictionary.Variables.Add(new StiVariable("Params", "TodayPersianDate", Convertor.ToPersianDate(DateTime.Now)));
            report.Dictionary.Variables.Add(new StiVariable("Params", "UserFullName", userFullName));
            report.RegBusinessObject("Data", commands);                                                                                                      
            report.Compile();
            return StiMvcViewer.GetReportSnapshotResult(report);
        }
        catch (Exception e)
        {
            HelperStoreSqlLog.WriteError(e, "PackageCommand");
            return View();
        }
    }

Report file: https://drive.google.com/file/d/1A8CLRYAoIQNXPVJkqNucrxJeW1yxJFg1/view?usp=sharing报告文件: https://drive.google.com/file/d/1A8CLRYAoIQNXPVJkqNucrxJeW1yxJFg1/view?usp=sharing

When i try to get report get me error that:当我尝试获取报告时,会出现以下错误:

System.ArgumentNullException: Value cannot be null. System.ArgumentNullException:值不能为 null。 Parameter name: value at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult) at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase) at Stimulsoft.Report.Mvc.StiMvcViewer.SaveReportObjec t(HttpContextBase httpContext, StiReport report) at Stimulsoft.Report.Mvc.StiMvcViewer.GetReportSnapsh otResult(StiReport report) at SPMS.Controllers.ReportController.PackageCommandPr int(String startDate, String endDate, Int32 profileId) in D:\Projects\SPMS\SPMS\Controllers\ReportController.cs:line 83 Parameter name: value at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult) at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase) at Stimulsoft.Report.Mvc.StiMvcViewer.SaveReportObjec t (HttpContextBase httpContext, StiReport 报告) 在 Stimulsoft.Report.Mvc.StiMvcViewer.GetReportSnapsh otResult(StiReport 报告) 在 SPMS.Controllers.ReportController.PackageCommandPr int(String startDate, String endDate, Int32 profileId) 在 D:\Projects\SPMS\SPMS \Controllers\ReportController.cs:第 83 行

line 83: return StiMvcViewer.GetReportSnapshotResult(report);第 83 行: return StiMvcViewer.GetReportSnapshotResult(report);

What is problem?什么是问题? I try to test this code by empty report file but get up error again.我尝试通过空报告文件测试此代码,但再次出现错误。 在此处输入图像描述

Razor: Razor:

@using Stimulsoft.Report.Mvc  
@{
    Layout = null;
}
@Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
    Localization = "~/Content/Reports/Localization/fa.xml",
    Theme = StiTheme.Office2013,
    ActionGetReportSnapshot = "PackageCommandPrint",
    ActionViewerEvent = "PackageCommandViewer",
    ServerCacheMode = StiCacheMode.None 
})

Add new Business Object (your model 'Data') without Category .添加没有 Category的新业务 Object(您的 model '数据')。 在此处输入图像描述

在此处输入图像描述

if you want to keep the category you should use this code如果要保留类别,则应使用此代码

  //report.RegBusinessObject("category", "name", businessObject);
  report.RegBusinessObject("Data", "Data", commands);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM