using System.Data; using System; using System.Collections.Generic; using System.Linq; using System.Web; using Payroll.BO; using Microsoft.Reporting.NETCore; namespace HRM.UI.Controllers.MobileAPI.Components { public static class RDLCGenerator { private static DataSet _oSubreportDataset; public static byte[] GetBytes(string ReportName, DataSet _dSet, List reportparameters = null, DataSet SubreportDataset = null) { LocalReport oLocalReport = new LocalReport(); oLocalReport.DataSources.Clear(); _dSet.DataSetName = "rptDataSet"; foreach (DataTable oDT in _dSet.Tables) { oLocalReport.DataSources.Add(new ReportDataSource(oDT.DataSet.DataSetName + "_" + oDT.TableName, oDT)); } _oSubreportDataset = SubreportDataset; if (_oSubreportDataset != null) { oLocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing); } oLocalReport.EnableExternalImages = true; oLocalReport.ReportPath = ReportName; if (reportparameters != null) oLocalReport.SetParameters(reportparameters); return RenderReport(oLocalReport); } private static byte[] RenderReport(LocalReport pLocalReport) { return pLocalReport.Render("PDF", null, out string mimeType, out string encoding, out string filenameExtension, out string[] streamids, out Warning[] warnings); } private static void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e) { LocalReport lReport = sender as LocalReport; if (lReport != null) { string sederReportName = lReport.ReportPath.Split('\\').Last(); if (sederReportName == "NewPaySlip.rdlc") { if (e.ReportPath == "NewPaySlipAllowance") { e.DataSources.Add(new ReportDataSource("rptDataSet_dtNewPayslipAllowance", _oSubreportDataset.Tables["dtNewPayslipAllowance"])); } else { e.DataSources.Add(new ReportDataSource("rptDataSet_dtNewPayslipDeduction", _oSubreportDataset.Tables["dtNewPayslipDeduction"])); } } else if (sederReportName == "PaySlipNew.rdlc") { if (e.ReportPath == "PayslipGross") { e.DataSources.Add(new ReportDataSource("rptDataSet_SalaryMonthlysGross", _oSubreportDataset.Tables["SalaryMonthlysGross"])); } else if (e.ReportPath == "PayslipLoanRemaining") { e.DataSources.Add(new ReportDataSource("rptDataSet_RemainingLoanforPayslip", _oSubreportDataset.Tables["RemainingLoanforPayslip"])); } } else if (sederReportName == "PaySlipForAnwar.rdlc") { if (e.ReportPath == "PayslipGrossForAnwar") { e.DataSources.Add(new ReportDataSource("rptDataSet_Payslip", _oSubreportDataset.Tables["Payslip"])); } else if (e.ReportPath == "PayslipLoanRemaining") { e.DataSources.Add(new ReportDataSource("rptDataSet_RemainingLoanforPayslip", _oSubreportDataset.Tables["RemainingLoanforPayslip"])); } } else if (sederReportName == "PaySlipNewNMGT.rdlc") { e.DataSources.Add(new ReportDataSource("rptDataSet_Payslip", _oSubreportDataset.Tables["Payslip"])); e.DataSources.Add(new ReportDataSource("rptDataSet_RemainingLoanforPayslip", _oSubreportDataset.Tables["RemainingLoanforPayslip"])); //if (e.ReportPath == "PayslipGross") //{ // e.DataSources.Add(new ReportDataSource("rptDataSet_Payslip", _oSubReportDataSet.Tables["Payslip"])); //} //else if (e.ReportPath == "PayslipLoanRemaining") //{ // e.DataSources.Add(new ReportDataSource("rptDataSet_RemainingLoanforPayslip", _oSubReportDataSet.Tables["RemainingLoanforPayslip"])); //} } } } } }