cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports 2008

Former Member
0 Kudos

Hi,

How to create a Crystal Report for user AddOn.How to load the report through coding when i click a print button.

Regards

Mohana

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

See B1 Application menu bar is there Launch Application Click first,Click New button and give application name,path name(ur exe name-report) and run.

Regards..

billa 2007

Former Member
0 Kudos

Mohana,

Just see the following links,

Crystal Reports Integration for SAP Business One

https://www.sdn.sap.com/irj/sdn/businessone?rid=/webcontent/uuid/807d22cb-cb1d-2b10-8794-fb76d7feca8...

Hope it helps,

Vasu Natari.

Former Member
0 Kudos

Hi Vasu,

I have created a report for the user form and saved.How to load the report through coding for the user form.For CR2008,it is adding a default folder(CrystalReports) for all the module.How to bring this default folder to my addon.

Thanx in advance

Mohana

Former Member
0 Kudos

Mohana,

R u using VS 2008..?

Vasu Natari.

Former Member
0 Kudos

Hi Vasu,

I am using VS2005...

Regards

Mohana

Former Member
0 Kudos

Then in VS 2005 how are u using CR 2008...??

R u using the embedded version on CR..??

Generally for these kindi of req i add a Crystal report file and a windows forms and using the report viewer control i pass the report to the form.

And on the print button click i show this form with the report.

Vasu Natari.

Edited by: vasu natari on Sep 1, 2008 11:27 AM

Former Member
0 Kudos

Hi Vasu,

Give some sample for generating a report which u specified.

It will be useful for me.

Regards

Mohana

Former Member
0 Kudos

Hi Mohana,

Plz check the following code..

Public Sub DisplayReport()
        Dim objRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument

        Dim dstemp, dstemp2 As DataSet
        dstemp = dsReportData
        dstemp2 = dsReportData

        objRep.Load(System.Windows.Forms.Application.StartupPath & "\CrystalReports\rptDocumentProdTypeB.rpt")
        Dim frmRepDisp As New frmReportDisplay ' This is the windows form added to my code.
        frmRepDisp.WindowState = FormWindowState.Maximized
        objRep.SetDataSource(dsReportData) 'I'm passing the data to my report in the form of a data source.
        frmRepDisp.CrystalReportViewer1.ReportSource = objRep 'Here i am setting the report for the report viewer control in the Windows form.
        frmRepDisp.CrystalReportViewer1.Refresh()
        frmRepDisp.ShowDialog()
     
        dsReportData.Clear()

     End Sub

In the above case as i have many reports to display i am sending the path of the report file u can do it without that also.

And i call the above prcedure in the Item pressed event after loadng my dataset with data.

Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                        If pVal.ItemUID = "11" Then
                            LoadDatatoReport(aForm) 'Fill the data in the data sets. 
                            DisplayReport() 'Display the report.
                        End If

Hope its Helpful,

Regards,

Vasu Natari.

Edited by: vasu natari on Sep 1, 2008 12:18 PM

Former Member
0 Kudos

Hi vasu,

While using showdialog i can't able to access other forms.Is there any alternate solution for this?I u use show() the report content will not be displayed.

Regards

Mohana

Former Member
0 Kudos

Nope i did'nt find any solution i just use it like that....

Vasu Natari.

Former Member
0 Kudos

Hi vasu,

I'm fairly new to CrystalReports, so can you suggest some reading material? or can post some sample code of your LoadDatatoReport(aForm) function?

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi Vitor,

Plz check the following code for the method.

Public Sub LoadDatatoReport(ByVal bForm As SAPbouiCOM.Form)
        oDtable = bForm.DataSources.DataTables.Item("oDtable")

        For intRecCount As Integer = 0 To oDtable.Rows.Count - 1
            oDRow = dsReportData.Tables.Item("DataTable1").NewRow()
            oDRow.Item("CustName") = oDtable.GetValue("CustName", intRecCount) 'objDelDoc.CardCode
            oDRow.Item("ClientOrderNo") = oDtable.GetValue("ClientOrderNo", intRecCount)
            oDRow.Item("NumAtCard") = oDtable.GetValue("NumAtCard", intRecCount)
            oDRow.Item("DocDueDate") = oDtable.GetValue("DocDueDate", intRecCount)
            oDRow.Item("CustomerAddress") = oDtable.GetValue("CustomerAddress", intRecCount)
            oDRow.Item("ClientSalesPerson") = oDtable.GetValue("ClientSalesPerson", intRecCount)
            oDRow.Item("CustContactPerson") = oDtable.GetValue("CustContactPerson", intRecCount)
            oDRow.Item("U_Installation") = oDtable.GetValue("U_Installation", intRecCount)
            oDRow.Item("ClientItemNo") = oDtable.GetValue("ClientItemNo", intRecCount)
            oDRow.Item("ItemDesc") = oDtable.GetValue("ItemDesc", intRecCount)
            oDRow.Item("GAno") = oDtable.GetValue("GAno", intRecCount)
            oDRow.Item("MaterialQualityNo") = oDtable.GetValue("MaterialQualityNo", intRecCount)
            'MsgBox(oDtable.GetValue("BatchNo", intRecCount))
            oDRow.Item("BatchNo") = oDtable.GetValue("BatchNo", intRecCount)
            oDRow.Item("LineNo") = oDtable.GetValue("LineNo", intRecCount)
            oDRow.Item("U_ProdNo") = oDtable.GetValue("U_ProdNo", intRecCount)
            oDRow.Item("Equipment") = oDtable.GetValue("Equipment", intRecCount)
            oDRow.Item("BondraGrpNo") = oDtable.GetValue("BondraGrpNo", intRecCount)
            oDRow.Item("ItemSpecialNo") = oDtable.GetValue("ItemSpecialNo", intRecCount)
            dsReportData.Tables.Item("DataTable1").Rows.Add(oDRow)
        Next


    End Sub

I'll be having a data set or an XSD file associated with my Crystal report and i'll be filling that data set and passing to the report.

For the general info abt crystals u can try google.

Hope it helps.

Regards,

Vasu Natari.

Former Member
0 Kudos

Hi Vasu,

I found a solution by creating a thread.this is working fine for me.

Regards

Mohana

Former Member
0 Kudos

Mohana,

Thats gr8, can u please post the code sample.

Thanks,

Vasu Natari.

Former Member
0 Kudos

Vasu,

Thanks.It helps and I'll also do has you suggested: use google.

Sorry I can't give you points...

Best Regards,

Vítor Vieira

Former Member
0 Kudos

Its ok Vitor...

I'm Happy to help u...

Vasu Natari

Former Member
0 Kudos

Vasu,

I've got my reporting system up and running, but I'm not using DataSets or XSD files.

I created a Windows form with a CrystalReportViewer control, and in run time I just have to set the report filename, the title and formulas (if any).

My question is, do you think I'll stomp into any limitation with this approach?

I'm using the following code:


Public Class ADAT_Crystal

    Private DBUserid As String = "sa"
    Private DBPassword As String = "XXYYZZ"
    Private rptPath As String = ""
    Private rptConnectionInfo As ConnectionInfo
    Private rptDocument As ReportDocument
    Private rptCrystalForm As CrystalForm
    Private SelectionString As String = ""


    Public Function LoadCrystal(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, _
            ByRef Titulo As String, ByRef ReportName As String, ByRef Parametros As String, ByRef Formulas As String) As Boolean
        LoadCrystal = False

        Try
            rptPath = sPath & "reports" & ReportName

            SelectionString = Formulas

            SetDBConnection(oApplication, oCompany)

            SetReportDocument(oApplication)

            SetDBLogonForReport(oApplication)

            SetCrystalForm(oApplication, Titulo)

            LoadCrystal = True
        Catch ex As Exception

        End Try
    End Function


    Private Sub SetDBConnection(ByRef oApplication As SAPbouiCOM.Application, ByRef oCompany As SAPbobsCOM.Company)
        Try
            rptConnectionInfo = New ConnectionInfo()

            rptConnectionInfo.DatabaseName = oCompany.CompanyDB
            rptConnectionInfo.UserID = DBUserid         ' GetDBUserdID()
            rptConnectionInfo.Password = DBPassword     ' GetDBUserPassword()
            rptConnectionInfo.ServerName = oCompany.Server

        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub


    Private Sub SetReportDocument(ByRef oApplication As SAPbouiCOM.Application)
        Try
            rptDocument = New ReportDocument
            rptDocument.Load(rptPath)
            rptDocument.DataDefinition.RecordSelectionFormula = SelectionString

        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub


    Private Sub SetDBLogonForReport(ByRef oApplication As SAPbouiCOM.Application)
        Try
            Dim myTables As Tables = rptDocument.Database.Tables

            For Each myTable As Table In myTables
                Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
                myTableLogonInfo.ConnectionInfo = rptConnectionInfo
                myTable.ApplyLogOnInfo(myTableLogonInfo)
            Next
        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub


    Private Sub SetCrystalForm(ByRef oApplication As SAPbouiCOM.Application, ByRef Titulo As String)
        Try
            rptCrystalForm = New CrystalForm()

            rptCrystalForm.Text = Titulo


            rptCrystalForm.oCrystalReportViewer.ReportSource = rptDocument
            rptCrystalForm.oCrystalReportViewer.Refresh()
            rptCrystalForm.ShowDialog()

        Catch ex As Exception
            oApplication.StatusBar.SetText(TranslateStr(oApplication, Error_) & ex.Message)
        End Try
    End Sub

Handling the PrintPreview click



                    Case "519"
                        Dim SelectionString As String = "{ONP.DocNum} = " & Trim(oForm.Items.Item("DocNum").Specific.Value) & ""
                        Dim oCrystal As New ADAT_Crystal
                        oCrystal.LoadCrystal(oCompany, oApplication, "Nota de Produção", "rptNotaProd.rpt", "", SelectionString)
                        Return False

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi Vitor,

If u have opened a new thread i could have got some points but anyways.... i'll share..

The problem with the above approach is that we need to have the Physical .RPT file at the system in the default folder. So if we miss the file we get a file not found error.

Hope its helpful.

Vasu Natari.

Former Member
0 Kudos

Vasu,

Sorry. Don't worry, I going to open a new thread just 4 you

Regards,

Vítor Vieira