Using WebReport in asp.net WebAPI and JQuery
I'm trying to use fastreport.net as WebAPI and can be loaded via jquery. It works perfectly, as in asp.net webforms. But in multiple tabs of report, only first report is shown with data and the other tab is shown without data. Seems that the other tab is not registered well in FastReport.Export.axd. How to register data for tabs in report? Thanks.
Code in html page :
Code in ApiController :
Code in html page :
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "../api/webgl/FRCOALoad",
success: function (data) {
$("#fastreport").html(data);
},
error: function (xhr, status, error) {
alert(error);
}
});
});
</script>
<div id="fastreport"></div>
Code in ApiController :
<HttpPost>
Public Function FRCOALoad() As String
Dim retval As String = String.Empty
Try
Dim mySQLConnString As String = WebConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
Using cnn As New OleDbConnection(mySQLConnString)
cnn.Open()
Using cmd As New OleDbCommand
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
Dim selCompany As String = String.Empty
Dim selRE As Integer = 0
cmd.CommandText = "SELECT TOP 1 SetCompany, SetREBerjalan FROM tbSet"
Using dr As OleDbDataReader = cmd.ExecuteReader()
If dr.Read() Then
selCompany = dr.GetString(0)
selRE = dr.GetInt32(1)
Else
Throw New Exception("Record not found.")
End If
End Using
Using rpt1 As New FastReport.Report
Using rpt2 As New FastReport.Report
Using wr As New FastReport.Web.WebReport
wr.Width = System.Web.UI.WebControls.Unit.Percentage(100)
wr.Height = System.Web.UI.WebControls.Unit.Percentage(100)
wr.ShowExports = False
wr.ShowRefreshButton = False
Dim selJudul As String = selCompany + " - Kode Perkiraan"
cmd.CommandText = "SELECT * FROM qryRptListCOA"
Using dr As OleDbDataReader = cmd.ExecuteReader()
Using dt As New DataTable()
dt.Load(dr)
dt.TableName = "MainReport"
If dt.Rows.Count > 0 Then
wr.Report.Load(HttpContext.Current.Server.MapPath("~/App_Data/rptCOA.frx"))
wr.Report.SetParameterValue("Judul", selJudul)
wr.Report.RegisterData(dt, dt.TableName)
wr.Report.Prepare()
wr.CurrentTab.Name = "Kode Perkiraan"
End If
End Using
End Using
selJudul = selCompany + " - Cost Center"
cmd.CommandText = "SELECT * FROM qryRptListCC"
Using dr As OleDbDataReader = cmd.ExecuteReader()
Using dt As New DataTable()
dt.Load(dr)
dt.TableName = "MainReport"
If dt.Rows.Count > 0 Then
rpt1.Load(HttpContext.Current.Server.MapPath("~/App_Data/rptCC.frx"))
rpt1.SetParameterValue("Judul", selJudul)
rpt1.RegisterData(dt, dt.TableName)
Dim a As FastReport.Web.ReportTab = wr.AddTab(rpt1, "Cost Center", False)
a.Report.Prepare()
a.Properties.ShowExports = False
a.Properties.ShowRefreshButton = False
End If
End Using
End Using
selJudul = selCompany + " - Audit"
cmd.CommandText = "SELECT * FROM qryRptAudit"
cmd.Parameters.AddWithValue("selRE", selRE)
Using dr As OleDbDataReader = cmd.ExecuteReader()
Using dt As New DataTable()
dt.Load(dr)
dt.TableName = "MainReport"
If dt.Rows.Count > 0 Then
rpt2.Load(HttpContext.Current.Server.MapPath("~/App_Data/rptAudit.frx"))
rpt2.SetParameterValue("Judul", selJudul)
rpt2.RegisterData(dt, dt.TableName)
Dim b As FastReport.Web.ReportTab = wr.AddTab(rpt2, "Audit", False)
b.Report.Prepare()
b.Properties.ShowExports = False
b.Properties.ShowRefreshButton = False
End If
End Using
End Using
retval = wr.Scripts.ToHtmlString + wr.Styles.ToHtmlString + wr.GetHtml.ToHtmlString
End Using
End Using
End Using
End Using
End Using
Catch ex As Exception
'do nothing
End Try
Return retval
End Function
Comments