<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm4.aspx.vb" Inherits="Love.WebForm4" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
<script src='<%=ResolveUrl("~/crystalreportviewers/js/crviewer/crv.js")%>' type="text/javascript"></script>
<script src="assets/js/core/jquery.3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btnPreview').on("click", function () {
$.ajax({
type: 'POST',
url: "Handler.ashx",
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (r) {
},
error: function (r) {
alert(r.responseText);
}
})
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<button type="button" id="btnPreview" class="btn btn-primary btn-line">Preview Report</button>
</form>
</body>
</html>
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports System.Web.Services
Imports System.Web.Script.Services
Public Class WebForm4
Inherits System.Web.UI.Page
Private crystalReport As ReportDocument
<WebMethod()>
<ScriptMethod()>
Public Shared Sub Report()
Dim crystalReport As ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
crystalReport = New ReportDocument()
crystalReport.Load(HttpContext.Current.Server.MapPath("~/CrystalReport1.rpt"))
' crystalReport.SetParameterValue("mid", 1704)
Dim conStringReport As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim connStringBuilder As SqlConnectionStringBuilder = New SqlConnectionStringBuilder(conStringReport)
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
myConnectionInfo.ServerName = connStringBuilder.DataSource
myConnectionInfo.DatabaseName = connStringBuilder.InitialCatalog
myConnectionInfo.UserID = connStringBuilder.UserID
myConnectionInfo.Password = connStringBuilder.Password
CrTables = crystalReport.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = myConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Dim stream As New BinaryReader(crystalReport.ExportToStream(ExportFormatType.PortableDocFormat))
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.Close()
End Sub
End Class
Public Class Reports
Public Property TID() As String
End Class