微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将datatable参数传递给我的Crystal报表的控制器,以便使用ASP.Net MVC中的表参数保存文件名?

如何解决如何将datatable参数传递给我的Crystal报表的控制器,以便使用ASP.Net MVC中的表参数保存文件名?

我想将我的javascript数据表数据传递给我的Crystal Report Controller,以保存我的文件名以及雇员名和日期。我怎样才能做到这一点?例如。我将使用名为

文件名保存它

工资单08292020-姓氏

这是我的数据表脚本。

  var dataTable;
    $(function () {
        dataTable = $('#payrollTable').DataTable({
            "ajax": "@Url.Action("getdata","payroll")","scrollX": true,"columns": [
                { "data": "EmployeeName" },{ "data": "ShiftName" },{
                    "data": "StartDate","render": function (value) {
                        if (value === null) return "";
                        return moment(value).format('DD/MM/YYYY');
                    }
                },{
                    "data": "EndDate",{
                    "data": "PayDate",{ "data": "MonthlyRate" },{ "data": "PerDay" },{ "data": "Cola" },{ "data": "RegularPayDaysWork" },{ "data": "RegularPayTotal" },{ "data": "RegHolidayDaysWork" },{ "data": "RegHolidayPercent" },{ "data": "RegHolidayTotal" },{ "data": "SpecialNWHolidayDaysWork" },{ "data": "SpecialNWHolidayPercent" },{ "data": "SpecialNWHolidayTotal" },{ "data": "DoubleHolidayDaysWork" },{ "data": "DoubleHolidayPercent" },{ "data": "DoubleHolidayTotal" },{ "data": "RestdayDaysWork" },{ "data": "RestdayPercent" },{ "data": "RestdayTotal" },{ "data": "RegOTDaysWork" },{ "data": "Regottotal" },{ "data": "RestdayOTDaysWork" },{ "data": "Restdayottotal" },{ "data": "SpecialHolidayOTDaysWork" },{ "data": "SpecialHolidayottotal" },{ "data": "SpecialWithRestdayOTDaysWork" },{ "data": "SpecialWithRestdayottotal" },{ "data": "RegularHolidayOTDaysWork" },{ "data": "RegularHolidayottotal" },{ "data": "RegularWithRestdayOTDaysWork" },{ "data": "RegularWithRestdayottotal" },{ "data": "DoubleHolidayOTDaysWork" },{ "data": "DoubleHolidayottotal" },{ "data": "DoubleWithRestdayOTDaysWork" },{ "data": "DoubleWithRestdayottotal" },{ "data": "AbsentDays" },{ "data": "AbsentTotal" },{ "data": "LateHrs" },{ "data": "Latetotal" },{ "data": "UndertimeHrs" },{ "data": "Undertimetotal" },{ "data": "Allowancetotal" },{ "data": "WitholdingTaxTotal" },{ "data": "PagibigContributionTotal" },{ "data": "PhilhealthContributionTotal" },{ "data": "SSSContributionTotal" },{ "data": "HDMFLoanTotal" },{ "data": "SSSLoan" },{ "data": "CashLoanTotal" },{ "data": "OtherDeductionsTotal" },{ "data": "LeaveDays" },{ "data": "Leavetotal" },{ "data": "GrossIncome" },{ "data": "TotalDeductions" },{ "data": "NetIncome" },{
                    "data": "Id","render": function (data) {
                        return "<a class='btn btn-default btn-sm' onclick=edit(" + data + ")><i class='fa fa-pencil'></i>Edit</a>&nbsp;<a class='btn btn-default btn-sm' onclick=printpreview(" + data + ")><i class='fa fa-print'></i>Print Payslip</a>"
                    },"orderable": false,"searchable": false,"width": "170px"
                }
            ],"language": {
                "emptyTable": "No data found"
            }
     });

这是我在数据表中触发printpreview的功能

   function printpreview(id)
    {
        window.location.href = "@Url.Action("export","payroll")?id=" + id;
    }

这是我的水晶报表控制器。

public ActionResult Export(int? id)
{
    ReportDocument rd = new ReportDocument();
    rd.Load(Path.Combine(Server.MapPath("~/Reports/CrystalReportPayroll.rpt")));
    rd.SetDataSource(db.Payrolls
    .Select(p => new
    {
        Id = p.Id,EmployeeId = p.Employees.FirstName + " " + p.Employees.MiddleName + " " + p.Employees.LastName,StartDate = DbFunctions.TruncateTime(p.StartDate).Value,EndDate = DbFunctions.TruncateTime(p.EndDate).Value,PayDate = DbFunctions.TruncateTime(p.PayDate).Value,Cola = p.Cola.Value,MonthlyRate = p.MonthlyRate,PerDay = p.PerDay,RegularPayDaysWork = p.RegularPayDaysWork,RegularPayTotal = p.RegularPayTotal,RegHolidayDaysWork = p.RegHolidayDaysWork,RegHolidayTotal = p.RegHolidayTotal,SpecialNWHolidayDaysWork = p.SpecialNWHolidayDaysWork,SpecialNWHolidayTotal = p.SpecialNWHolidayTotal,DoubleHolidayDaysWork = p.DoubleHolidayDaysWork,DoubleHolidayTotal = p.DoubleHolidayTotal,RestdayDaysWork = p.RestdayDaysWork,RestdayTotal = p.RestdayTotal,RegOTDaysWork = p.RegOTDaysWork == null ? 0 : p.RegOTDaysWork.Value,Regottotal = p.Regottotal == null ? 0 : p.Regottotal.Value,RestdayOTDaysWork = p.RestdayOTDaysWork == null ? 0 : p.RestdayOTDaysWork.Value,Restdayottotal = p.Restdayottotal == null ? 0 : p.Restdayottotal.Value,SpecialHolidayOTDaysWork = p.SpecialHolidayOTDaysWork == null ? 0 : p.SpecialHolidayOTDaysWork.Value,SpecialHolidayottotal = p.SpecialHolidayottotal == null ? 0 : p.SpecialHolidayottotal.Value,SpecialWithRestdayOTDaysWork = p.SpecialWithRestdayOTDaysWork == null ? 0 : p.SpecialWithRestdayOTDaysWork.Value,SpecialWithRestdayottotal = p.SpecialWithRestdayottotal == null ? 0 : p.SpecialWithRestdayottotal.Value,RegularHolidayOTDaysWork = p.RegularHolidayOTDaysWork == null ? 0 : p.RegularHolidayOTDaysWork.Value,RegularHolidayottotal = p.RegularHolidayottotal == null ? 0 : p.RegularHolidayottotal.Value,RegularWithRestdayOTDaysWork = p.RegularWithRestdayOTDaysWork == null ? 0 : p.RegularWithRestdayOTDaysWork.Value,RegularWithRestdayottotal = p.RegularWithRestdayottotal == null ? 0 : p.RegularWithRestdayottotal.Value,DoubleHolidayOTDaysWork = p.DoubleHolidayOTDaysWork == null ? 0 : p.DoubleHolidayOTDaysWork.Value,DoubleHolidayottotal = p.DoubleHolidayottotal == null ? 0 : p.DoubleHolidayottotal.Value,DoubleWithRestdayOTDaysWork = p.DoubleWithRestdayOTDaysWork == null ? 0 : p.DoubleWithRestdayOTDaysWork.Value,DoubleWithRestdayottotal = p.DoubleWithRestdayottotal == null ? 0 : p.DoubleWithRestdayottotal.Value,AbsentDays = p.AbsentDays == null ? 0 : p.AbsentDays.Value,AbsentTotal = p.AbsentTotal == null ? 0 : p.AbsentTotal.Value,LateHrs = p.LateHrs == null ? 0 : p.LateHrs.Value,Latetotal = p.Latetotal == null ? 0 : p.Latetotal.Value,UndertimeHrs = p.UndertimeHrs == null ? 0 : p.UndertimeHrs.Value,Undertimetotal = p.Undertimetotal == null ? 0 : p.Undertimetotal.Value,Allowancetotal = p.Allowancetotal == null ? 0 : p.Allowancetotal.Value,WitholdingTaxTotal = p.WitholdingTaxTotal == null ? 0 : p.WitholdingTaxTotal.Value,PagibigContributionTotal = p.PagibigContributionTotal == null ? 0 : p.PagibigContributionTotal.Value,PhilhealthContributionTotal = p.PhilhealthContributionTotal == null ? 0 : p.PhilhealthContributionTotal.Value,SSSContributionTotal = p.SSSContributionTotal == null ? 0 : p.SSSContributionTotal.Value,HDMFLoanTotal = p.HDMFLoanTotal == null ? 0 : p.HDMFLoanTotal.Value,SSSLoan = p.SSSLoan == null ? 0 : p.SSSLoan.Value,CashLoanTotal = p.CashLoanTotal == null ? 0 : p.CashLoanTotal.Value,OtherDeductionsTotal = p.OtherDeductionsTotal == null ? 0 : p.OtherDeductionsTotal.Value,LeaveDays = p.LeaveDays == null ? 0 : p.LeaveDays.Value,Leavetotal = p.Leavetotal == null ? 0 : p.Leavetotal.Value,GrossIncome = p.GrossIncome == null ? 0 : p.GrossIncome.Value,TotalDeductions = p.TotalDeductions == null ? 0 : p.TotalDeductions.Value,NetIncome = p.NetIncome == null ? 0 : p.NetIncome.Value,})
    .Where(p => id == p.Id).ToList());
    Response.Buffer = false;
    Response.ClearContent();
    Response.ClearHeaders();
    Stream stream = rd.ExportToStream
        (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    stream.Seek(0,SeekOrigin.Begin);
    return File(stream,"application/pdf","Payroll.pdf");
}

解决方法

尝试一下:

在您的视图中:

    <script>var url_reports = "@Url.Action("Export","Payroll")"</script>

在您的JS脚本中:

    <script>var url_reports = "@Url.Action("Export","Payroll")"</script>

在RouteConfig中,请确保您具有以下内容:

function printpreview(id)
    {
        window.open(url_reports + "/" + id);
    }
    

或为您的控制器创建自定义路线

function printpreview(id)
    {
        window.open(url_reports + "/" + id);
    }
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。