Report Integration

Now the existing report should be integrated into the application.

Select the application form (Form1) in design view and drag ReportViewer icon from the toolbox onto the form.

Select the ReportViewer control, and open the smart tags panel by clicking the triangle on the top right corner. Click the "Choose Report" drop-down list and select the PilotReport. A BindingSource (PilotBindingSource) is automatically created corresponding to the Pilot data source used in the report.

Open the code view for the Form1. Find Form1_Load function and add the following code:

Form1.cs: Form1_Load
1private void Form1_Load(object sender, EventArgs e) 2 { 3 // Add data to the database 4 Db4oManager.FillUpDB(); 5 // Bind the Pilot list to the report DataSource 6 this.PilotBindingSource.DataSource = Db4oManager.GetAllPilots(); 7 this.reportViewer1.RefreshReport(); 8 }

Form1.vb: Form1_Load
1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 2 ' Add data to the database 3 Db4oManager.FillUpDB() 4 ' Bind the Pilot list to the report DataSource 5 Me.PilotBindingSource.DataSource = Db4oManager.GetAllPilots() 6 Me.ReportViewer1.RefreshReport() 7 Me.ReportViewer1.RefreshReport() 8 End Sub

Db4oManager takes care of opening db4o connection on the first request. However the connection should be closed manually on the application termination:

Form1.cs: Form1_FormClosed
1private void Form1_FormClosed(object sender, FormClosedEventArgs e) 2 { 3 Db4oManager.CloseDb(); 4 }

Form1.vb: Form1_FormClosed
1Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed 2 Db4oManager.CloseDb() 3 End Sub