on 09-08-2008 12:53 PM
Hi all,
I've got my CR2008 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).
I have to questions:
1. Do you think I'll stomp into any limitation with this approach?
2. The Crystal Reports form is opening as a Modal form. How can I stop this from happening (the Modal property is read only)?
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
End Class
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
Hi Vitor,
For Q 1--
The problem u could face is that the Report files (.rpt) should be in place, if the files are moved by some user we can have a "File not found" exception. So better to expose the rpt files and embed them, But another disadvantage with embedding them is that if the user just wanted to change the logo or a simple aligment we have to change that in the code and again execute the code and pack the add on again. If we use a phusical file the user can make small desig modifications.
For Q 2--
For the modal form BUG u need to open the form in another thread. U can find the solution in the previous thread itself for that problem. If not just tell me. I'll help u.
Hope this helps.. and thanks for the new thread.. ,
Vasu Natari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vitor,
Instead of using rptCrystalForm.ShowDialog() us rptCrystalForm.Show().So u can access all other forms and reports with this report opened itself.
But u have to create a thread and show this report. then only the content of the report will be showned.
Create a testform:
In the testform u have do as follows:
-
Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Close()
Dim SampleRpt As New SampleRpt
SampleRpt.Show()
End Sub
Public Sub StartThread()
Try
Dim run As Boolean
run = True
Me.Show()
While (run)
Application.DoEvents()
Threading.Thread.Sleep(1)
End While
Catch ex As Exception
Throw ex
End Try
End Sub
-
then create another form containing the report viewer control :
ther u have to do as follows:
-
Private Sub FrmCrReportViewer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
LoadReport()
FViewer.Zoom(1)
FViewer.ResumeLayout(True)
Me.WindowState = FormWindowState.Maximized
Catch ex As Exception
Throw ex
End Try
End Sub
Private sub loadReport()
//ur code for loading the report
End sub
-
then while clicking the print button u vae to do as follows:
In the Item Event:
-
TestForm = New TestForm()
oThread = New Threading.Thread(AddressOf TestForm.StartThread)
oThread.Start()
I hope this will help u........:)
Kind regards
Mohana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi vitor,
u have to create a thread for generating a report.
Edited by: Raveendran N on Sep 8, 2008 2:25 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.