mvc3动态报告

时间:2012-11-11 22:13:58

标签: asp.net-mvc-3 razor

使用MVC3和razor以及NuGet Doddle Report,我已经构建了一个很好的报告,可以在Excel中打开视图模型。我想允许用户在将报表导出到Excel之前提供过滤器并对视图进行排序。 是否有建议的方法来执行此操作或我可以查看的资源?

谢谢!

修改

创建报告的控制器代码:

public ReportResult CaseReport()
        {
        var viewModel = new CasesReportViewModel();


        var query = (from c in db.Cases
                     join customer in db.Customers on c.CustomerID equals customer.CustomerID
                     join category in db.CaseCategories on c.CaseCategoryID equals category.CaseCategoryID
                     join tech in db.Technicians on c.TechnicianID equals tech.TechnicianID
                     join engine in db.EngineModels on c.EngineModelID equals engine.EngineModelID
                     select new CasesReportViewModel()
                        {
                            CustomerName = c.Customer.CustomerName,
                            UserName = c.UserName,
                            PromoID = tech.PromoID,
                            EngineModelName = engine.EngineModelName,
                            CaseNumber = c.CaseNumber,
                            BMSWorkorder = c.BMSWorkorder,
                            CaseStatus = c.CaseStatus,
                            OpenedBy = c.OpenedBy,
                            OpenedDate = c.OpenedDate,
                            ClosedBy = c.ClosedBy,
                            ClosedDate = c.ClosedDate,
                            CategoryName = category.CategoryName,
                            CallerFirstName = c.CallerFirstName,
                            CallerLastName = c.CallerLastName,
                            AdditionalContact = c.AdditionalContact,
                            Qualified = c.Qualified,
                            Description = c.Description,
                            ESN = c.ESN,
                            Mileage = c.Mileage,
                            DateInService = c.DateInService,
                            ESTR = c.ESTR,
                            EDS = c.EDS
                        });


        var report = new Report(query.ToReportSource());

        //customize fields
        report.TextFields.Title = "Case Report";
        AppHelpers app = new AppHelpers();
        report.TextFields.Header = "Report Date = " + Convert.ToString(app.GetEasternTime());
        report.TextFields.Footer = "Copyright 2012";

        //data fields
        report.RenderHints.BooleanCheckboxes = true;

        report.DataFields["CustomerName"].DataFormatString = "{0:c}";
        report.DataFields["UserName"].DataFormatString = "{0:c}";
        report.DataFields["EngineModelName"].DataFormatString = "{0:c}";
        report.DataFields["CaseNumber"].DataFormatString = "{0:c}";
        report.DataFields["BMSWorkorder"].DataFormatString = "{0:c}";
        report.DataFields["CategoryName"].DataFormatString = "{0:c}";
        report.DataFields["CaseStatus"].DataFormatString = "{0:c}";
        report.DataFields["OpenedBy"].DataFormatString = "{0:c}";
        report.DataFields["OpenedDate"].DataFormatString = "{0:d}";
        report.DataFields["ClosedBy"].DataFormatString = "{0:c}";
        report.DataFields["ClosedDate"].DataFormatString = "{0:d}";
        report.DataFields["CallerFirstName"].DataFormatString = "{0:c}";
        report.DataFields["CallerLastName"].DataFormatString = "{0:c}";
        report.DataFields["AdditionalContact"].DataFormatString = "{0:c}";
        report.DataFields["Qualified"].DataFormatString = "{0:c}";
        report.DataFields["Description"].DataFormatString = "{0:c}";
        report.DataFields["ESN"].DataFormatString = "{0:c}";
        report.DataFields["Mileage"].DataFormatString = "{0:c}";
        report.DataFields["DateInService"].DataFormatString = "{0:d}";
        report.DataFields["ESTR"].DataFormatString = "{0:c}";
        report.DataFields["EDS"].DataFormatString = "{0:c}";

        return new ReportResult(report, new ExcelReportWriter(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileName = "CaseReport" };

        }

0 个答案:

没有答案