Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: Vb dot net and CR


Message #1 by "Shaneil Narayan" <SNarayan@e...> on Mon, 10 Feb 2003 16:21:16 +1200
I have approached this in a slightly different manner.

Create a stored procedure (or SQL Statement etc.)
Build a dataset based on the results of the sp (this can usually be done by
dragging the sp from explorer on to a new dataset)
rebuild your project
Create a report and use the dataset as the data source

You can now write a form to capture the requied parameters  and call the
stored procedure to return a dataset (this is filtered)
Now bind the dataset to the report

so you get something like below - All LoadReportList does is call a stored
procedure with the required parameter (in this case depot)

	Dim Invoices As New MscContainerControlBr.Invoices()
            ds = Invoices.LoadReportList(Depot)
            Dim rpt As New rptContainerReleases()
            rpt.SetDataSource(ds)

            CrystalReportViewer.ReportSource = rpt
            CrystalReportViewer.Visible = True



-----Original Message-----
From: Eileen Harcar [mailto:empcrh@c...]
Sent: 11 February 2003 01:52
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] RE: Vb dot net and CR


Hello, I'm not sure what database you are trying to pass parameters to, or
if it really matters.   I found the answer on Crystal Decision website.   Do
a search for passing parameters vb.net to crystal report.   Sorry I do not
have the code available or I would paste it in.   Hope this helps.

-----Original Message-----
From: Shaneil Narayan [mailto:SNarayan@e...] 
Sent: Monday, February 10, 2003 2:50 PM
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] RE: Vb dot net and CR
Importance: High

Thanks a lot Gavin for your reply......isn't there anything less complicated
than that.

Cheers,
Shaneil

-----Original Message-----
From: Gavin Wu [mailto:gavin@m...]
Sent: Tuesday, 11 February 2003 2:43 AM
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] RE: Vb dot net and CR


Hi, Shaneil

Here is my class for crystal report. In this class, we use crystal report to
access btrieve database. Some parts are not useful if you use other kind of
databases. But for passing parameters, I think it is the same. And also we
use xml file to store default values for the parameters. The output can be
pdf and xml (and a set of functions to parse the xml file should be ignored
for your purpose. Several xml access methods are used in this class and I
think they are useful.). You need to modify it if you want to use it:
    Public Class CPowerFaxReport

        Public Enum PowerFaxOutputType
            PDF = 1
            XML = 2
        End Enum

        Public Enum PowerFaxReportType
            REPORT_INVOICE = 1
            REPORT_STATEMENT = 2
            REPORT_PURCHASEORDER = 3
            REPORT_ORDERCONFIRMATION = 4
            REPORT_ARSUMMARY = 5
            REPORT_ARDETAILS = 6
        End Enum

        Private parameters() As typeParameter
        Private mFieldMaps() As FieldMap

        Private m_ParamCount As Integer
        Private m_sParamFileName As String

        Private locationData As CBVSettings

        ' Declare an application object
        Private crxApplication As New CRAXDRT.Application()

        ' Declare report object
        Private CrxReport As CRAXDRT.Report
        Private CrxSubreport As CRAXDRT.Report

        Private m_bReportOpened As Boolean

        Private m_sReport As String
        Private m_sSubreports() As String
        Private m_SubreportCount As Integer

        Private m_OutputFile As String

        Private m_OutputType As PowerFaxOutputType

        Private m_ReportType As PowerFaxReportType

        Private m_nReportParams As Integer

        Private m_MapFileXML As String
        Private m_MapFileXSD As String

        Private m_ReportParameters(10) As String

        Private HeaderRecord As String

        Private m_BVVersion As String

        Private m_sFooterHeading As String
        Private m_sFooterTailing As String
        Private m_sHeaderHeading As String
        Private m_sHeaderTailing As String
        Private m_sDetailsHeading As String
        Private m_sDetailsTailing As String

        Private m_nPreSectionNo As Integer

        Public Property LocationObject() As CBVSettings
            Get
                Return locationData
            End Get
            Set(ByVal Value As CBVSettings)
                locationData = New CBVSettings()
                locationData = Value
            End Set
        End Property

        Public Property ReportOpened() As Boolean
            Get
                Return m_bReportOpened
            End Get
            Set(ByVal Value As Boolean)
                m_bReportOpened = Value
            End Set
        End Property

        Public Property OutputType() As PowerFaxOutputType
            Get
                Return m_OutputType
            End Get
            Set(ByVal Value As PowerFaxOutputType)
                m_OutputType = Value
            End Set
        End Property

        Public Property ReportType() As PowerFaxReportType
            Get
                Return m_ReportType
            End Get
            Set(ByVal Value As PowerFaxReportType)
                m_ReportType = Value
            End Set
        End Property

        Public Property MapFileXML() As String
            Get
                Return m_MapFileXML
            End Get
            Set(ByVal Value As String)
                m_MapFileXML = Value
            End Set
        End Property

        Public Property MapFileXSD() As String
            Get
                Return m_MapFileXSD
            End Get
            Set(ByVal Value As String)
                m_MapFileXSD = Value
            End Set
        End Property

        Public Property OutputFile() As String
            Get
                Return m_OutputFile
            End Get
            Set(ByVal Value As String)
                m_OutputFile = Value
            End Set
        End Property

        Public Property ParamFileName() As String
            Get
                ParamFileName = m_sParamFileName
            End Get
            Set(ByVal Value As String)
                m_sParamFileName = Value
                'Call InitializeParamArray(m_sParamFileName)
            End Set
        End Property

        Public Property ReportName() As String
            Get
                Return m_sReport
            End Get
            Set(ByVal Value As String)
                m_sReport = Value
                'Try
                '    InitializeReport()
                'Catch ex As Exception
                '    Throw ex
                'End Try
            End Set
        End Property

        Public Sub New()
            m_bReportOpened = False
            m_sReport = ""
            m_SubreportCount = 0
            m_OutputFile = ""
            m_OutputType = PowerFaxOutputType.PDF
            m_ReportType = PowerFaxReportType.REPORT_STATEMENT
            m_nReportParams = 0
            m_MapFileXML = ""
            m_MapFileXSD = ""
            ' m_sDBPath = ""
            ' m_strDicPath = ""
            ' m_BVFileCount = 0
            m_sParamFileName = ""
            m_BVVersion = "400"
        End Sub

        Public Sub LoadParameters()
            Try
                InitializeParamArray(m_sParamFileName)
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub LoadMap()
            Try
                MapFields(m_MapFileXML, m_MapFileXSD)
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        ' read XML file for settings
        Private Sub InitializeParamArray(ByVal ParamFileName As String)
            Dim doc As XmlDocument = New XmlDocument()
            Dim currNode As XmlNode
            Dim currSubNode As XmlNode
            Dim objNodeList As XmlNodeList

            Dim i As Integer
            Dim j As Integer

            doc.Load(ParamFileName)

            objNodeList = doc.GetElementsByTagName("ReportName")
            currNode = objNodeList.Item(0)
            ' m_sReport = currNode.InnerXml            ' .Value

            objNodeList = doc.GetElementsByTagName("ReportParams")
            currNode = objNodeList.Item(0)
            m_nReportParams = CInt(currNode.InnerXml)


            objNodeList = doc.GetElementsByTagName("SubReport")
            m_SubreportCount = objNodeList.Count
            If m_SubreportCount > 0 Then
                ReDim m_sSubreports(m_SubreportCount)
                For i = 0 To (m_SubreportCount - 1)
                    currNode = objNodeList.Item(i)
                    m_sSubreports(i) = currNode.InnerXml        ' .Value
                Next i
            End If

            objNodeList = doc.GetElementsByTagName("Parameter")
            m_ParamCount = objNodeList.Count
            ReDim parameters(m_ParamCount)
            For i = 0 To (m_ParamCount - 1)
                currNode = objNodeList.Item(i)
                If currNode.HasChildNodes Then
                    For j = 0 To (currNode.ChildNodes.Count - 1)
                        currSubNode = currNode.ChildNodes(j)
                        Select Case currSubNode.Name
                            Case "FromX"
                                parameters(i).FromX 
CSng(currSubNode.InnerXml)
                            Case "ToX"
                                parameters(i).ToX 
CSng(currSubNode.InnerXml)
                            Case "FromY"
                                parameters(i).FromY 
CSng(currSubNode.InnerXml)
                            Case "ToY"
                                parameters(i).ToY 
CSng(currSubNode.InnerXml)
                            Case "ParamName"
                                parameters(i).ParamName 
currSubNode.InnerXml
                            Case "ParamDisplay"
                                parameters(i).ParamDisplay 
currSubNode.InnerXml
                            Case "ParamValue"
                                parameters(i).ParamValue 
currSubNode.InnerXml
                            Case "ParamType"
                                parameters(i).ParamType 
currSubNode.InnerXml
                        End Select
                        currSubNode = Nothing
                    Next j
                End If
                currNode = Nothing
            Next
            objNodeList = Nothing

            doc = Nothing
        End Sub

        Public Sub SetParamValue(ByVal ParamName As String, ByVal ParamValue
As String)
            Dim l As Integer

            For l = 0 To m_ParamCount - 1
                If parameters(l).ParamName = ParamName Then
                    parameters(l).ParamValue = ParamValue
                    'm_bValueChanged = True
                    Exit For
                End If
            Next l
            Return
        End Sub

        Public Sub CreateReport()

            Try
                Dim i As Integer

                '  Use the DiscardSavedData method to ensure that your
report hits the Database and refreshes the data
                CrxReport.DiscardSavedData()

                Dim ParamCollection As CRAXDRT.ParameterFieldDefinitions
                Dim param As CRAXDRT.ParameterFieldDefinition
                Dim nParam As Integer
                Dim pName As String
                Dim pValue As String

                '
****************************************************************************
********
                '  Set the Parameters for the Main Report

                ' report-specific parameters
                ParamCollection = CrxReport.ParameterFields
                nParam = ParamCollection.Count
                For i = 1 To nParam
                    param = ParamCollection(i)
                    pName = param.ParameterFieldName
                    Select Case m_ReportType
                        Case PowerFaxReportType.REPORT_ARDETAILS
                            If pName = "BV20DT01AsOf" Then
                                pValue = m_ReportParameters(1)
                            ElseIf pName = "BV30TC01FromTerritory" Then
' start territory code
                                pValue = m_ReportParameters(2)
                            ElseIf pName = "BV35TC02ToTerritory" Then
' end territory ode
                                pValue = m_ReportParameters(3)
                            ElseIf pName = "BV40CS03FromSearchKey" Or pName
= "BV40CS01FromCustomer" Then                ' start customer No
                                pValue = m_ReportParameters(4)
'
                            ElseIf pName = "BV45CS04ToSearchKey" Or pName 
"BV45CS02ToCustomer" Then                ' end customer No
                                pValue = m_ReportParameters(5)
'
                            Else
                                pValue 
locationData.GetParameterValue(pName)      ' .  GetDefaultParamValue(pName)
                            End If
                        Case PowerFaxReportType.REPORT_ARSUMMARY
                            If pName = "BV20DT01AsOf" Then
                                pValue = m_ReportParameters(1)
                            ElseIf pName = "BV30TC01FromTerritory" Then
' start territory code
                                pValue = m_ReportParameters(2)
                            ElseIf pName = "BV35TC02ToTerritory" Then
' end territory ode
                                pValue = m_ReportParameters(3)
                            ElseIf pName = "BV40CS03FromSearchKey" Or pName
= "BV40CS01FromCustomer" Then                ' start customer No
                                pValue = m_ReportParameters(4)
'
                            ElseIf pName = "BV45CS04ToSearchKey" Or pName 
"BV45CS02ToCustomer" Then                ' end customer No
                                pValue = m_ReportParameters(5)
'
                            Else
                                pValue 
locationData.GetParameterValue(pName)      ' .  GetDefaultParamValue(pName)
                            End If
                        Case PowerFaxReportType.REPORT_INVOICE
                            Select Case pName
                                Case "BV10SA01FromInvoice"
                                    pValue = m_ReportParameters(1)
                                Case "BV15SA02ToInvoice"
                                    pValue = m_ReportParameters(2)
                                Case "BV99LT01Literal"
                                    pValue = locationData.LiteralText1
                                Case "BV99LT02Literal"
                                    pValue = locationData.LiteralText2
                                Case "BV99LT03Literal"
                                    pValue = locationData.LiteralText3
                                Case "BV99LT04Literal"
                                    pValue = locationData.LiteralText4
                                Case "BV99LT05Literal"
                                    pValue = locationData.LiteralText5
                                Case "BV99LT06Literal"
                                    pValue = locationData.LiteralText6
                                Case "BV99LT07Literal"
                                    pValue = locationData.LiteralText7
                                Case "BV99LT08Literal"
                                    pValue = locationData.LiteralText8
                                Case Else
                                    pValue 
locationData.GetParameterValue(pName)      ' .  GetDefaultParamValue(pName)
                            End Select
                        Case PowerFaxReportType.REPORT_ORDERCONFIRMATION
                            pValue = locationData.GetParameterValue(pName)
' .  GetDefaultParamValue(pName)
                        Case PowerFaxReportType.REPORT_PURCHASEORDER
                            Select Case pName
                                Case "BV99PO01ForPO"
                                    pValue = m_ReportParameters(1)
                                Case "BV99LT01Literal"
                                    pValue = locationData.POLiteral1
                                Case "BV99LT02Literal"
                                    pValue = locationData.POLiteral2
                                Case "BV99LT03Literal"
                                    pValue = locationData.POLiteral3
                                Case "BV99LT04Literal"
                                    pValue = locationData.POLiteral4
                                Case "BV99LT05Literal"
                                    pValue = locationData.POLiteral5
                                Case "BV99LT06Literal"
                                    pValue = locationData.POLiteral6
                                Case "BV99LT07Literal"
                                    pValue = locationData.POLiteral7
                                Case "BV99LT08Literal"
                                    pValue = locationData.POLiteral8
                                Case Else
                                    pValue 
locationData.GetParameterValue(pName)      ' .  GetDefaultParamValue(pName)
                            End Select
                        Case PowerFaxReportType.REPORT_STATEMENT
                            Select Case pName
                                Case "BV30CS01FromCustomer"
                                    pValue = m_ReportParameters(1)
                                Case "BV35CS02ToCustomer"
                                    pValue = m_ReportParameters(2)
                                Case "BV99LT01"
                                    pValue = locationData.StatementLiteral1
                                Case "BV99LT02"
                                    pValue = locationData.StatementLiteral2
                                Case "BV99LT03"
                                    pValue = locationData.StatementLiteral3
                                Case "BV99LT04"
                                    pValue = locationData.StatementLiteral4
                                Case "BV99LT05"
                                    pValue = locationData.StatementLiteral5
                                Case "BV99LT06"
                                    pValue = locationData.StatementLiteral6
                                Case "BV99LT07"
                                    pValue = locationData.StatementLiteral7
                                Case "BV99LT08"
                                    pValue = locationData.StatementLiteral8
                                Case Else
                                    pValue 
locationData.GetParameterValue(pName)      ' .  GetDefaultParamValue(pName)
                            End Select
                    End Select

                    ' 12 = string, 9 = bool
                    If param.ValueType 
CRAXDRT.__MIDL___MIDL_itf_crvb60r_0230_0001.crStringField Then
                        ParamCollection(i).SetCurrentValue(CStr(pValue))
                    ElseIf param.ValueType 
CRAXDRT.__MIDL___MIDL_itf_crvb60r_0230_0001.crBooleanField Then
                        ParamCollection(i).SetCurrentValue(CBool(pValue))
                    ElseIf param.ValueType 
CRAXDRT.__MIDL___MIDL_itf_crvb60r_0230_0001.crDateField Then
                        ParamCollection(i).SetCurrentValue(CDate(pValue))
                    End If
                Next i

                m_BVVersion = locationData.BVDataVersion

                CrxReport.DisplayProgressDialog = False
                If m_OutputType = PowerFaxOutputType.PDF Then
                    '+
                    '   Report is exported as PDF format
                    '-
                    ' CrxReport.ExportOptions.PromptForExportOptions False
                    CrxReport.ExportOptions.CharFieldDelimiter = ""
                    CrxReport.ExportOptions.CharStringDelimiter = ""
                    CrxReport.ExportOptions.DestinationType 
CRAXDRT.CRExportDestinationType.crEDTDiskFile
                    CrxReport.ExportOptions.FormatType 
CRAXDRT.CRExportFormatType.crEFTPortableDocFormat ' crEFTWordForWindows
                    CrxReport.ExportOptions.DiskFileName = m_OutputFile
                ElseIf m_OutputType = PowerFaxOutputType.XML Then
                    '+
                    ' output to xml
                    '-
                    CrxReport.DisplayProgressDialog = False
                    CrxReport.ExportOptions.XMLFileName = m_OutputFile
                    CrxReport.ExportOptions.DestinationType 
CRAXDRT.CRExportDestinationType.crEDTDiskFile
                    CrxReport.ExportOptions.FormatType 
CRAXDRT.CRExportFormatType.crEFTXML        ' .crEFTPortableDocFormat '
crEFTWordForWindows
                End If
                CrxReport.Export(False)
            Catch ex As Exception
                Debug.WriteLine(ex.ToString)
                Throw ex
            End Try

            Return
        End Sub

        Public Sub OpenReport()
            InitializeReport()
            m_bReportOpened = True
        End Sub

        Public Sub CloseReport()
            CrxReport = Nothing
        End Sub

        Private Sub InitializeReport()
            Try
                '  Use the .OpenReport method of the Application object to
set your Report object to a RPT file
                Dim i As Integer
                Dim sReportName As String
                sReportName = m_sReport

                CrxReport = crxApplication.OpenReport(sReportName)
                CrxReport.EnableParameterPrompting = False

                ' set locations for this report
                Dim tbl As CRAXDRT.DatabaseTable

                For Each tbl In CrxReport.Database.Tables
                    tbl.SetTableLocation(locationData.GetLocation(tbl.Name),
tbl.Name, "")
                    System.Diagnostics.Debug.WriteLine(tbl.Location & "
" & locationData.GetLocation(tbl.Name))
                Next tbl

                If m_SubreportCount > 0 Then
                    For i = 0 To m_SubreportCount - 1
                        CrxSubreport 
CrxReport.OpenSubreport(m_sSubreports(i))
                        For Each tbl In CrxSubreport.Database.Tables

tbl.SetTableLocation(locationData.GetLocation(tbl.Name), tbl.Name, "")
                            System.Diagnostics.Debug.WriteLine(tbl.Location
& "     " & locationData.GetLocation(tbl.Name))
                        Next tbl
                    Next i
                End If

            Catch ex As Exception
                Debug.WriteLine(ex.ToString)
                ' Throw ex
            End Try
        End Sub

        Private Function GetDefaultParamValue(ByVal sParamName As String) As
String
            Dim i As Integer
            Dim s As String

            s = ""
            For i = 0 To (m_ParamCount - 1)
                If (parameters(i).ParamName = sParamName) Then
                    s = parameters(i).ParamValue
                    Exit For
                End If
            Next i

            GetDefaultParamValue = s
        End Function

        Public Sub AddParameters(ByVal index As Integer, ByVal vValue As
String)
            If index < 1 Or index > 10 Then
                Return
            End If
            m_ReportParameters(index) = vValue
        End Sub

        ' xmlout is a xml file which stores the formatted output
        Public Function FormatOutput(ByVal xmlout As String) As Boolean

            Dim b As Boolean

            m_sFooterHeading = ""
            m_sFooterTailing = ""
            m_sHeaderHeading = ""
            m_sHeaderTailing = ""
            m_sDetailsHeading = ""
            m_sDetailsTailing = ""

            Dim xw As New StreamWriter(xmlout, False)
            Dim xr As New Xml.XmlTextReader(m_OutputFile)

            Dim s As String
            b = True
            Try
                xw.WriteLine("<?xml version=""1.0"" ?>")
                ' xw.WriteLine("<?xml-stylesheet type=""text/xsl""
href=""ARAging.xsl"" ?>")

                Select Case m_ReportType
                    Case PowerFaxReportType.REPORT_ARSUMMARY
                        m_sFooterHeading 
"<Fax>false</Fax><Email>false</Email><Print>false</Print>"
                        m_sFooterTailing = "<Contact_WB /><FaxNo_WB
/><Email_WB /><Contact_D /><Email_D /><Fax_D />"
                        xw.WriteLine("<Root
xmlns=""http://www.mksoftware.com/statsum.xsd"">")
                    Case PowerFaxReportType.REPORT_ARDETAILS
                        xw.WriteLine("<Root
xmlns=""http://www.mksoftware.com/statdet.xsd"">")
                End Select
                s = GetNode(xr, xw)
                xw.WriteLine("</Root>")
            Catch ex As Exception
                b = False
                Throw ex
            Finally
                xr.Close()
                xw.Close()
            End Try

            Return b
        End Function

        Public Function FormatOutput(ByVal xmlout As String, ByVal xmlout1
As String) As Boolean

            Dim b As Boolean

            m_sFooterHeading = ""
            m_sFooterTailing = ""
            m_sHeaderHeading = ""
            m_sHeaderTailing = ""
            m_sDetailsHeading = ""
            m_sDetailsTailing = ""

            Dim xw As New StreamWriter(xmlout, False)
            Dim xw1 As New StreamWriter(xmlout1, False)
            Dim xr As New Xml.XmlTextReader(m_OutputFile)

            Dim s As String
            b = True
            Try
                xw.WriteLine("<?xml version=""1.0"" ?>")
                xw1.WriteLine("<?xml version=""1.0"" ?>")
                ' xw.WriteLine("<?xml-stylesheet type=""text/xsl""
href=""ARAging.xsl"" ?>")
                If m_ReportType = PowerFaxReportType.REPORT_INVOICE_ALL Then
                    m_sFooterHeading 
"<Fax>false</Fax><Email>false</Email><Print>false</Print>"
                    m_sFooterTailing = "<Contact_WB /><FaxNo_WB /><Email_WB
/><Contact_D /><Email_D /><Fax_D />"
                    xw.WriteLine("<Root
xmlns=""http://www.mksoftware.com/invodet.xsd"">")
                    xw1.WriteLine("<Root
xmlns=""http://www.mksoftware.com/invosum.xsd"">")
                End If
                s = GetNode(xr, xw, xw1)
                xw.WriteLine("</Root>")
                xw1.WriteLine("</Root>")
            Catch ex As Exception
                b = False
                Throw ex
            Finally
                xr.Close()
                xw.Close()
                xw1.Close()
            End Try

            Return b
        End Function

        Private Function GetNode(ByVal xr As Xml.XmlTextReader, ByVal xw As
StreamWriter) As String

            Select Case m_ReportType
                Case PowerFaxReportType.REPORT_ARDETAILS
                    Return ARDetails(xr, xw)
                Case PowerFaxReportType.REPORT_ARSUMMARY
                    Return ARSummary(xr, xw)
                Case Else
                    Return ""
            End Select
        End Function

        Private Function GetNode(ByVal xr As Xml.XmlTextReader, ByVal xw As
StreamWriter, ByVal xw1 As StreamWriter) As String

            Select Case m_ReportType
                Case PowerFaxReportType.REPORT_INVOICE_ALL
                    Return InvoiceList(xr, xw, xw1)
                Case Else
                    Return ""
            End Select
        End Function

        Private Function ARSummary(ByVal xr As Xml.XmlTextReader, ByVal xw
As StreamWriter) As String
            Try
                Dim s As String
                xr.Read()
                xr.ReadStartElement("FormattedReport")
                'Do While (True)
                Do While (True)
                    xr.Read()
                    If xr.EOF Then Return ""
                    If xr.Name = "FormattedArea" AndAlso xr.HasAttributes
Then
                        ' xr.ReadStartElement("FormattedArea")
                        ' get all attributes
                        Try
                            xr.MoveToAttribute("Type")
                            s = xr.Value
                            Debug.WriteLine(xr.Name + "-->" + s)
                        Catch ex1 As Exception
                            Debug.WriteLine(ex1.Message)
                            s = ""
                        End Try

                        Select Case s
                            Case "Header"
                                'GetDetails(s, xr, xw)
                            Case "Details"
                                'GetDetailStatement(s, xr, xw)
                            Case "Footer"
                                GetFooterStatement(s, xr, xw)
                                'GetDetails(s, xr, xw)
                        End Select
                        ' xr.ReadEndElement()
                    End If
                Loop
                xr.ReadEndElement()
            Catch ex As Exception
                Debug.WriteLine(ex.ToString())
            End Try

            xr.Close()
            Return ""
        End Function

        Private Function ARDetails(ByVal xr As Xml.XmlTextReader, ByVal xw
As StreamWriter) As String
            Try
                Dim s As String
                xr.Read()
                xr.ReadStartElement("FormattedReport")
                'Do While (True)
                Do While (True)
                    xr.Read()
                    If xr.EOF Then Return ""
                    If xr.Name = "FormattedArea" AndAlso xr.HasAttributes
Then
                        ' xr.ReadStartElement("FormattedArea")
                        ' get all attributes
                        Try
                            xr.MoveToAttribute("Type")
                            s = xr.Value
                            Debug.WriteLine(xr.Name + "-->" + s)
                        Catch ex1 As Exception
                            Debug.WriteLine(ex1.Message)
                            s = ""
                        End Try

                        Select Case s
                            Case "Header"
                                'GetDetails(s, xr, xw)
                            Case "Details"
                                GetDetailStatement(s, xr, xw)
                            Case "Footer"
                                'GetDetails(s, xr, xw)
                        End Select
                        ' xr.ReadEndElement()
                    End If
                Loop
                xr.ReadEndElement()
            Catch ex As Exception
                Debug.WriteLine(ex.ToString())
            End Try

            xr.Close()
            Return ""
        End Function


        Private Function GetRealName(ByVal s As String) As String
            Dim i As Integer
            For i = 0 To mFieldMaps.GetUpperBound(0)
                If s = mFieldMaps(i).ReportField Then Return
mFieldMaps(i).MappedName
            Next

            Return ""
        End Function

        Private Sub GetDetails(ByVal Tag As String, ByVal reader As
Xml.XmlTextReader, ByVal writer As StreamWriter)
            Dim ObjectName As String
            Dim FormattedValue As String
            Dim Value As String
            Dim s As String

            Try
                ' loop to the record part
                Do While (True)
                    reader.Read()
                    If reader.Name = "FormattedReportObjects" Then
                        Exit Do
                    End If
                Loop

                reader.ReadStartElement("FormattedReportObjects")
                s = ""
                Do While (True)
                    reader.ReadStartElement("FormattedReportObject")

                    ObjectName = GetRealName(reader.ReadElementString())
                    FormattedValue = reader.ReadElementString()
                    Value = reader.ReadElementString()
                    If ObjectName <> "" Then s += "<" + ObjectName + ">" +
Value + "</" + ObjectName + ">"

                    reader.ReadEndElement()

                    reader.Read()
                    If (reader.Name <> "FormattedReportObject") Then
                        Exit Do
                    End If
                Loop

                reader.ReadEndElement()         ' end of
FormattedReportObjects

                If Tag = "Header" Then
                    HeaderRecord = s
                ElseIf Tag = "Details" Then
                    ' s = "<Record>" + HeaderRecord + s + "</Record>"
                    writer.WriteLine("<Detail>" + s.Replace("&", "&amp;") +
"</Detail>")
                    'ElseIf Tag = "Footer" Then
                    'writer.WriteLine("<Total>" + s.Replace("&", "&amp;") +
s.Replace("&", "&amp;") + "</Total>")
                Else
                    ' nothing
                    ' s = "<Record><CustNo>" + HeaderRecord + "</CustNo>" +
s + "</Record>"
                End If
            Catch ex As Exception
                Throw ex
            End Try
            Return
        End Sub

        Private Sub GetDetailStatement(ByVal Tag As String, ByVal reader As
Xml.XmlTextReader, ByVal writer As StreamWriter)
            Dim ObjectName As String
            Dim FormattedValue As String
            Dim Value As String
            Dim s As String

            Try
                ' loop to the record part
                s = ""
                Do While (True)
                    reader.Read()
                    If reader.EOF Then Return
                    If reader.Name = "FormattedSection" AndAlso
reader.HasAttributes Then
                        ' xr.ReadStartElement("FormattedArea")
                        ' get all attributes
                        Try
                            reader.MoveToAttribute("SectionNumber")
                            s = reader.Value
                            Debug.WriteLine(reader.Name + "-->" + s)
                            If IsNumeric(s) Then
                                If (CType(s, Integer) = 0) Then
                                    Exit Do
                                Else
                                    Return
                                End If
                            End If
                        Catch ex1 As Exception
                            Debug.WriteLine(ex1.Message)
                            s = ""
                        End Try
                    End If
                Loop

                Do While (True)
                    reader.Read()
                    If reader.EOF Then Return
                    If reader.Name = "FormattedReportObjects" Then
                        Exit Do
                    End If
                Loop

                reader.ReadStartElement("FormattedReportObjects")
                s = ""
                Do While (True)
                    reader.ReadStartElement("FormattedReportObject")

                    ObjectName = GetRealName(reader.ReadElementString())
                    If ObjectName <> "" Then
                        FormattedValue = reader.ReadElementString()
                        Value = reader.ReadElementString()
                        s += "<" + ObjectName + ">" + Value + "</" +
ObjectName + ">"
                    Else
                        Value = reader.ReadElementString()
                    End If

                    reader.ReadEndElement()

                    reader.Read()
                    If (reader.Name <> "FormattedReportObject") Then
                        Exit Do
                    End If
                Loop

                reader.ReadEndElement()         ' end of
FormattedReportObjects

                If s <> "" Then writer.WriteLine("<Detail>" + s.Replace("&",
"&amp;") + "</Detail>")

            Catch ex As Exception
                Throw ex
            End Try
            Return
        End Sub

        Private Sub MapFields(ByVal xmlfile As String, ByVal xsdfile As
String)
            Dim m_XmlDataDocument As XmlDataDocument

            Try
                Debug.WriteLine("Creating an XmlDataDocument ...")
                m_XmlDataDocument = New XmlDataDocument()

                ' Parse Schema here, use args(1), xsd file
                Dim myStreamReader As StreamReader = Nothing

                myStreamReader = New StreamReader(xsdfile)
                Debug.WriteLine("Reading Schema file ...")
                m_XmlDataDocument.DataSet.ReadXmlSchema(myStreamReader)
                myStreamReader.Close()

                ' fill the dataset, use args(0), xml file
                m_XmlDataDocument.Load(xmlfile)

            Catch e As Exception
                Debug.WriteLine("Exception: " & e.ToString())
                Throw (e)
                Return
            End Try

            ' read data
            Try
                ' read dataset and initialize the location property
                Dim myTable As New DataTable()
                Dim FieldName As String
                Dim MapName As String

                myTable = m_XmlDataDocument.DataSet.Tables("Field")

                Dim ex As Exception
                If myTable.Rows.Count = 0 Then
                    ex = New Exception("There is no location defined.")
                    Throw ex
                    Return
                End If

                Dim mCount As Integer = myTable.Rows.Count
                Debug.WriteLine(mCount.ToString)
                ReDim Preserve mFieldMaps(mCount - 1)
                Debug.WriteLine((mFieldMaps.GetUpperBound(0)).ToString)

                Dim myColumn As DataColumn
                For Each myColumn In myTable.Columns
                    Debug.WriteLine(myColumn.ToString())
                Next

                Dim myRow As DataRow
                Dim i As Integer = 0
                For Each myRow In myTable.Rows
                    With myRow
                        FieldName = .Item("FName")
                        MapName = .Item("Map")
                    End With
                    mFieldMaps(i).ReportField = FieldName
                    mFieldMaps(i).MappedName = MapName
                    i += 1
                Next
            Catch e As Exception
                Throw e
            End Try
            Return
        End Sub

    End Class

Gavin

-----Original Message-----
From: Shaneil Narayan [mailto:SNarayan@e...]
Sent: Sunday, February 09, 2003 11:21 PM
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] Vb dot net and CR
Importance: High

How do we pass variables from VB dotnet to Crystal reports. I have 2
parameters that need to be entered from VB. 1) Report Date  2) Period

How can i do that?

I am able to pass the report date to the dataadapter through parameterized
query by entering the data on VB form.i generated a dataset. But when I run
the report...I get all the data in the table instead of those for that
particular date. When I enter the date through the dataadapter (Right click
on dataadapter > Preview data) I can query properly.

what I am doing is ....I have created a global variable in a module. I pass
the user entered date from the textbox to the Variable. Here is the code
that passes the parameter to the dataadapter.

OleDbDataAdapter1.SelectCommand.Parameters("WORKDATE").Value = MyDate
'MyDate is a variable.
DataSet31.Clear()
OleDbDataAdapter1.Fill(DataSet31)

This somehow doesn't do what its supposed to...

Can someone help please.

Thanks in advance.


---
VB.NET Handbooks Library Special Offer

Get a massive 40% off this complete library
of books (US residents only at the moment).
Free ground shipping on this 10 book bundle!

http://www.wroxdirect.com/proddescription.asp?Bookselect=BUN10E004

---
VB.NET Handbooks Library Special Offer

Get a massive 40% off this complete library
of books (US residents only at the moment).
Free ground shipping on this 10 book bundle!

http://www.wroxdirect.com/proddescription.asp?Bookselect=BUN10E004


---
VB.NET Handbooks Library Special Offer

Get a massive 40% off this complete library
of books (US residents only at the moment).
Free ground shipping on this 10 book bundle!

http://www.wroxdirect.com/proddescription.asp?Bookselect=BUN10E004



---
VB.NET Handbooks Library Special Offer

Get a massive 40% off this complete library
of books (US residents only at the moment).
Free ground shipping on this 10 book bundle!

http://www.wroxdirect.com/proddescription.asp?Bookselect=BUN10E004
****************************************************************************
Medite Shipping Co (UK) Ltd act as agents for MSC for all services within
the scope of the relevant MSC bill of lading. Services provided outside of
the scope of the bill of lading are performed as agent for the
shipper/consignee. Those services outside the MSC B/L are transacted under
the Standard Trading Conditions of the British International Freight
Association (BIFA STCs) a current edition of which is available upon
request.********************************************************************
******** This message may contain information which is legally privileged
and/or confidential. If you are not the intended recipient, you are hereby
notified that any unauthorised disclosure, copying, distribution or use of
this information is strictly prohibited. Such notification not withstanding,
any comments or opinions expressed are those of the originator, not of
Medite Shipping Co (UK) Ltd., unless otherwise explicity stated.
****************************************************************************

  Return to Index