Sunday, March 11, 2012

CR from only code(VS 2005)

Hey gurus

I need to create a crystal report entirely from code

i have a form where a customer will add table(s) to a list box, depending on the added tables, a list of fields applicable to the respective table can be added to another list. On selection of each of these fields, values may be entered so as to filter the data displayed on the report.

From each of the availble fields that can be "Parametized", a group can be created, with ascending/descending order

Finally summaries can be added such as the sum of all amounts(total,VAT etc) to the end of the report
Report options like drill-down will need to be able to be set dynamically also.

so far everything above here is basicly how to generate my SQL statement, which won'y be that difficult.

But i have no idea how to make my report document show information the way i have described above.

left list < > right list (Panel with combobox, textbox , checkbox(enable/disable))

tables,field, groups are added/removed as depicted above
fields and groups have a panel next to each rightlistbox where parameters can be set like (< = > between like <> asc desc)

at the bottom of the form there are 3 buttons
Preview report data --> shows datagrid of Data retrieved via generated SQL statement
Preview Report --> shows a itempanel with items for each field/group/summary field
Create report - Creates crystal report and shows in report viewer on a tab created before the report begins creation

At this point, i am not very close to being far from completion
any help will be greatly appreciated
Thanks
Jsee attached file of GUI so you can get a better idea of what i am trying to do, sorry bout bad quality 100kb is not alot but sufficient|||I have made some progress on this

The code below shows the population of a dataset and subsequently binding it to a report, then showing that report in a report viewer control on a new tab created here also.

The report is completely blank. There is however data in the TRDS dataset



Private Sub MakeReport()

Dim TRDS As New DataSet

Dim ConString As String = ""

Dim CON As OleDb.OleDbConnection

Dim DA As OleDb.OleDbDataAdapter

Dim NewTabPanel As New DevComponents.DotNetBar.TabControlPanel

Dim RptUC As New ReportOnTab ' Usercontrol with crystal reportviewer on a panel

'Get Data

Try

TRDS = New Report1DataSet

If My.Settings.User_Claims_ManagementConnection_String = "" Then

ConString = My.Settings.Claims_Management_SystemConnectionString.ToString

Else

ConString = My.Settings.User_Claims_ManagementConnection_String.ToString

End If

CON = New OleDb.OleDbConnection(ConString)

DA = New OleDb.OleDbDataAdapter(FullSQL, CON)

'Fill the dataset

DA.Fill(TRDS, "Client")

'Make report on new tab

NewTabPanel.Name = "NewTab_Panel"

NewTabPanel.Text = "This is the new reports panel"

'Report creation

Report = New Report1

'Settings for the report

'Set datasource to the generated dataset

Report.SetDataSource(TRDS)

'At this point there is a blank report, with a dataset attached to it containing, one table and rows filtered by where in FULLSQL

'Set groups

'Add fields that will be shown to detail section

'Add summaries

'Apply formatting

'End of report creation

'Create tab on tab control

ReportTab.CreateTab("Name of this report", -1)

'Attach usercontrol to tab panel and make dock fill

ReportTab.Tabs.Item(ReportTab.Tabs.Count - 1).AttachedControl.Controls.Add(RptUC)

ReportTab.Tabs.Item(ReportTab.Tabs.Count - 1).AttachedControl.Controls.Item(0).Dock = DockStyle.Fill

'Reset the report creation form

ReportDefinitionsClear()

'Select the newly created tab

ReportTab.SelectedTab = ReportTab.Tabs.Item(ReportTab.Tabs.Count - 1)

'Set source of the usercontrol report viewer to this report

RptUC.ReportViewer.ReportSource = Report

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub



now the FULLSQL variable is rather dynamic and is generated through use of the above picture's gui, thats 2000 lines, shud i post that to?

anyway, it works, all i need to do now is...

1.! create fields from the SELECT statement on the report

2.! create groups via the ORDERBY statement on the report

3.! Finally add any other summaries,special fields, and so on to the report

My question is how do i achieve such a feat,

How do i add groups via code to the detail section?
How do i add fields via code to my blank reports detail section?
Is it even possible?

So far have discovered that most things within the report1 class are readonly.

I have looked everywhere online, searched for 2 days and found nothing like this

Please help
Thanks
J

No comments:

Post a Comment