Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Imports CrystalDecisions.CrystalReports.Engine
Imports Microsoft.VisualBasic
Imports System
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Globalization
Partial Class crs_fullcyl
    Inherits System.Web.UI.Page
  
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        CrystalReportViewer1.Visible = False
        TxtToDt.Text = Format(Now, "yyyy-MM-dd")
        TxtToDt0.Text = Format(Now, "yyyy-MM-dd")
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = False
        Else
            CrystalReportViewer1.Visible = False
        End If
        Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))

        Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        'Set login info
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim RptDocument As New ReportDocument
        Dim myTable As Table
        For Each myTable In RptDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.ServerName = "JPM"
            myLogin.ConnectionInfo.DatabaseName = "JPMDB"
            myLogin.ConnectionInfo.UserID = "vbreports"
            myLogin.ConnectionInfo.Password = ""
            myTable.ApplyLogOnInfo(myLogin)
            myTable.Location = myTable.Location
        Next
        CrystalReportViewer1.ReportSource = RptDocument
        
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))

        'Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        RptDocument.SetParameterValue(0, TxtToDt.Text)
        RptDocument.SetParameterValue(1, TxtToDt0.Text)
        RptDocument.SetParameterValue(2, flag)

        Dim ms As New System.IO.MemoryStream
        ms = RptDocument.ExportToStream(ExportFormatType.PortableDocFormat)
        HttpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.ClearHeaders()
        HttpContext.Current.Response.ContentType = "application/pdf"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=cylinderreport.pdf")
        HttpContext.Current.Response.BinaryWrite(ms.ToArray())
        HttpContext.Current.Response.End()

    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = False
        Else
            CrystalReportViewer1.Visible = False
        End If
        Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))

        Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        'Set login info
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim RptDocument As New ReportDocument
        Dim myTable As Table
        For Each myTable In RptDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.ServerName = "JPM"
            myLogin.ConnectionInfo.DatabaseName = "JPMDB"
            myLogin.ConnectionInfo.UserID = "vbreports"
            myLogin.ConnectionInfo.Password = ""
            myTable.ApplyLogOnInfo(myLogin)
            myTable.Location = myTable.Location
        Next
        CrystalReportViewer1.ReportSource = RptDocument
       
        RptDocument.Load(Server.MapPath("reports\cyl1.rpt"))

        'Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Issued Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        RptDocument.SetParameterValue(0, TxtToDt.Text)
        RptDocument.SetParameterValue(1, TxtToDt0.Text)
        RptDocument.SetParameterValue(2, flag)


        Dim ms As New System.IO.MemoryStream
        ms = RptDocument.ExportToStream(ExportFormatType.ExcelRecord)
        HttpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.ClearHeaders()
        HttpContext.Current.Response.ContentType = "application/excel"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=cylinderreport.xls")
        HttpContext.Current.Response.BinaryWrite(ms.ToArray())
        HttpContext.Current.Response.End()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack = True Then
            TxtToDt.Text = Format(Now, "yyyy-MM-dd")
            TxtToDt0.Text = Format(Now, "yyyy-MM-dd")
        End If
    End Sub

End Class
Posted
Updated 19-Jun-14 16:13pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900