ActiveReports 3.0 in C#

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 15841 Views - Last Post: 14 September 2009 - 12:42 PM Rate Topic: -----

#1 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

ActiveReports 3.0 in C#

Posted 19 August 2009 - 05:45 AM

I made an ActiveReport in Visual Studio 2008 using C# but I made the report using the Report Designer by dragging and dropping the contents of the report, is there a way to create that same report by just using code and not the Designer?

I've been to the DataDynamics website but it doesn't specify where you have to put the code in

any assistance would be helpful
Is This A Good Question/Topic? 0
  • +

Replies To: ActiveReports 3.0 in C#

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 05:53 AM

Sure there is.

Something like this:

// forms constructor

public Form1() {
// first create new object
ActiveReport3 ar3 = new ActiveReport3(); // or was it ActiveReports3

// next add some headers and detail
ReportHeader rHeader = new ReportHeader();
rHeader.Name = "header";
rHeader.BackColor = Color.Blue;

ar3.Sections.Add(rHeader);

Detail d = new Detail();
d.Name = "detail";
ar3.Sections.Add(d);

// controls to detail
DataDynamics.ActiveReports.TextBox txt = new DataDynamics.ActiveReports.TextBox();

txt.Text = "hello wurld";
txt.Location = new PointF(0.0, 0.0);
txt.Name = "txtHello";
d.Controls.Add(txt);

// corresponding footers.
ReportFooter f = new ReportFooter();
f.Name = "footer";
ar3.Sections.Add(f);

// run report and set ti to the viewer to see the results.
ar3.Run();
ReportViewer v = new ReportViewer();
v.Report = ar3;

// finally add viewer to our form to see the results
Form1.Controls.Add(v);
}




And the code can be put anywhere. In form's constructor if you like to or create some methods/classes.
Was This Post Helpful? 0
  • +
  • -

#3 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 06:00 AM

this is what I have so far

Form1.cs - which is ur basic form
rptCustomers.cs - This file is where I have to report designer with the designer (but I don't wanna use the designer)
On the form I have 2 Buttons: Close and View Report

what I'm trying to do is when I click on the View Report button

it should connect to the database, create the report and display the report

my form code is like this


using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;
using DataDynamics.ActiveReports.Design;
using DataDynamics.ActiveReports.DataSources;
using DataDynamics.ActiveReports.Viewer;

namespace CustomerInfoReport
{
	public partial class Form1 : Form
	{
		// declare variables
		SqlDBDataSource myDataSource;
		
		public Form1()
		{
			InitializeComponent();

			// create connection
			myDataSource.ConnectionString = @"NED-CREATIVE;initial catalog=C:\\SQL SERVER 2000 SAMPLE DATABASES\\NORTHWND.MDF;integrated security=SSPI;persist security info=False";
		}
		
		private void btnReport_Click(object sender, EventArgs e)
		{
			myDataSource.SQL = @"Select * from Employees";
			
			//Fields.Add("LastName");
			//Fields.Add("FirstName");
			//Fields.Add("Address");
			//Fields.Add("City");
			//Fields.Add("Region");
			//DataDynamics.ActiveReports.Field
			
			// rptCustomers rpt = new rptCustomers();
			// rpt.Show();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}



Was This Post Helpful? 0
  • +
  • -

#4 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 06:14 AM

I don't have access to ActiveReports at home (where I'm at the moment) so I can't test the code snippet I provide but I'll try to give some tips and point the direction.

So, first we need to create a datasource, like you have been doing with the SqlDBDataSource. I'm not familiar with that datasource so I'll use DataTable in my example.

			// create DataTable with two columns
			DataTable dt = new DataTable();
			dt.Columns.Add(new DataColumn("Name", typeof(String)));
			dt.Columns.Add(new DataColumn("Age", typeof(Int32)));

			// and few rows:
			DataRow dr1 = dt.NewRow();
			dr1.ItemArray = new object[] { "my name", 30 };
			DataRow dr2 = dt.NewRow();
			dr2.ItemArray = new object[] { "other name", 40 };
			DataRow dr3 = dt.NewRow();
			dr3.ItemArray = new object[] { "third name", 50 };

			dt.Rows.Add(dr1);
			dt.Rows.Add(dr2);
			dt.Rows.Add(dr3);



Then, create a similar report like in my previous post but instead of the textbox, add these controls to the detail:

DataDynamics.ActiveReports.TextBox txtName = new DataDynamics.ActiveReports.TextBox();
txtName.DataField = "Name";
txtName.Name = "txtName";
txtName.Location = new PointF(0.0, 0.0);
d.Add(txtName);

DataDynamics.ActiveReports.TextBox txtAge = new DataDynamics.ActiveReports.TextBox();
txtAge.DataField = "Age";
txtName.Name = "txtAge";
txtAge.Location = new PointF(2.0, 0.0);
d.Add(txtName);



Next, bind set activereport's datasource to datatable, run it and show it in the viewer
ar3.DataSource = dt;
ar3.Run();

// set the report to designer just to see the results
rptCustomers rpt = new rptCustomers();
rpt.Designer.Report = ar3; // might also be Document property, cant remember which
rpt.Show();



Those code pieces should create a report which shows three rows of information on the designer.
Was This Post Helpful? 0
  • +
  • -

#5 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 08:51 AM

I have it setup like this but I get squiggles near the end

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;
using DataDynamics.ActiveReports.Design;
using DataDynamics.ActiveReports.DataSources;
using DataDynamics.ActiveReports.Viewer;

namespace CustomerInfoReport
{
	public partial class Form1 : Form
	{
		// declare variables
		SqlDBDataSource myDataSource;
		
		public Form1()
		{
			InitializeComponent();

			// create connection
			myDataSource.ConnectionString = @"NED-CREATIVE;initial catalog=C:\\SQL SERVER 2000 SAMPLE DATABASES\\NORTHWND.MDF;integrated security=SSPI;persist security info=False";
		}
	
		private void btnReport_Click(object sender, EventArgs e)
		{
			myDataSource.SQL = @"Select * from Employees";

			ActiveReport3 myActiveReport = new ActiveReport3();

			// header section
			ReportHeader rHeader = new ReportHeader();
			rHeader.Name = "pageHeader";
			rHeader.BackColor = Color.Transparent;

			myActiveReport.Sections.Add(rHeader);

			// add controls to header section
			
			// Title
			DataDynamics.ActiveReports.Label label1 = new DataDynamics.ActiveReports.Label();
			label1.Text = "Employees Address Report";
			label1.Style = "font-weight: bold; font-size: 15.75pt;";
			label1.Location = new PointF(2.31f, 0.13f);
			rHeader.Controls.Add(label1);
			
			// Date/Time
			DataDynamics.ActiveReports.ReportInfo reportInfo1 = new DataDynamics.ActiveReports.ReportInfo();
			reportInfo1.FormatString = "{RunDateTime:M/d/yyy}";
			reportInfo1.Location = new PointF(0.06f, 0.19f);
			rHeader.Controls.Add(reportInfo1);

			// Page Number
			DataDynamics.ActiveReports.ReportInfo reportInfo2 = new DataDynamics.ActiveReports.ReportInfo();
			reportInfo2.FormatString = "Page {PageNumber} of {PageCount}";
			reportInfo2.Location = new PointF(6.38f, 0.19f);
			rHeader.Controls.Add(reportInfo2);

			// Detail section
			Detail myDetails = new Detail();
			myDetails.Name = "pageDetail";
			myActiveReport.Sections.Add(myDetails);

			// add controls to detail section
			
			// Last Name label
			DataDynamics.ActiveReports.Label label2 = new DataDynamics.ActiveReports.Label();
			label2.Text = "Last Name";
			label2.Location = new PointF(0.06f, 0.06f);
			myDetails.Controls.Add(label2);
			
			// First Name label
			DataDynamics.ActiveReports.Label label3 = new DataDynamics.ActiveReports.Label();
			label3.Text = "First Name";
			label3.Location = new PointF(1.13f, 0.06f);
			myDetails.Controls.Add(label3);

			// Address label
			DataDynamics.ActiveReports.Label label4 = new DataDynamics.ActiveReports.Label();
			label4.Text = "Address";
			label4.Location = new PointF(2.44f, 0.06f);
			myDetails.Controls.Add(label4);

			// City label
			DataDynamics.ActiveReports.Label label5 = new DataDynamics.ActiveReports.Label();
			label5.Text = "City";
			label5.Location = new PointF(4.56f, 0.06f);
			myDetails.Controls.Add(label5);

			// State label
			DataDynamics.ActiveReports.Label label6 = new DataDynamics.ActiveReports.Label();
			label6.Text = "State";
			label6.Location = new PointF(5.69f, 0.06f);
			myDetails.Controls.Add(label6);
			
			//Last Name textbox
			DataDynamics.ActiveReports.TextBox txtLastName1 = new DataDynamics.ActiveReports.TextBox();
			txtLastName1.DataField = "LastName";
			txtLastName1.Text = "txtLastName1";
			txtLastName1.Location = new PointF(0.06f, 0.31f);
			txtLastName1.Name = "txtLastName1";
			myDetails.Controls.Add(txtLastName1);

			DataDynamics.ActiveReports.TextBox txtFirstName1 = new DataDynamics.ActiveReports.TextBox();
			txtFirstName1.DataField = "FirstName";
			txtFirstName1.Text = "txtFirstName1";
			txtFirstName1.Location = new PointF(1.13f, 0.31f);
			txtFirstName1.Name = "txtFirstName1";
			myDetails.Controls.Add(txtFirstName1);

			DataDynamics.ActiveReports.TextBox txtAddress1 = new DataDynamics.ActiveReports.TextBox();
			txtAddress1.DataField = "Address";
			txtAddress1.Text = "txtAddress1";
			txtAddress1.Location = new PointF(2.44f, 0.31f);
			txtAddress1.Name = "txtAddress1";
			myDetails.Controls.Add(txtAddress1);

			DataDynamics.ActiveReports.TextBox txtCity1 = new DataDynamics.ActiveReports.TextBox();
			txtCity1.DataField = "City";
			txtCity1.Text = "txtCity1";
			txtCity1.Location = new PointF(4.56f, 0.31f);
			txtCity1.Name = "txtCity1";
			myDetails.Controls.Add(txtCity1);

			DataDynamics.ActiveReports.TextBox txtRegion1 = new DataDynamics.ActiveReports.TextBox();
			txtRegion1.DataField = "Region";
			txtRegion1.Text = "txtRegion1";
			txtRegion1.Location = new PointF(5.69f, 0.31f);
			txtRegion1.Name = "txtRegion1";
			myDetails.Controls.Add(txtRegion1);

			// corresponding footers.
			ReportFooter myFooter = new ReportFooter();
			myFooter.Name = "pageFooter";
			myActiveReport.Sections.Add(myFooter);
			
			// create DataTable with two columns
			DataTable myDataTable = new DataTable();
			myDataTable.Columns.Add(new DataColumn("Last Name", typeof(String)));
			myDataTable.Columns.Add(new DataColumn("First Name", typeof(String)));
			myDataTable.Columns.Add(new DataColumn("Address", typeof(String)));
			myDataTable.Columns.Add(new DataColumn("City", typeof(String)));
			myDataTable.Columns.Add(new DataColumn("State", typeof(String)));

			myActiveReport.DataSource = myDataTable;
			myActiveReport.Run();

			// set the report to designer just to see the results
			rptCustomers rpt = new rptCustomers();
			rpt.Designer.Report = myActiveReport; // might also be Document property, cant remember which
			rpt.Show();
			
			// run report and send it to the viewer to see the results.
			myActiveReport.Run();
			ReportViewer myViewer = new ReportViewer();
			myViewer.Report = myActiveReport;

			// finally add viewer to our form to see the results
			Form1.Controls.Add(myViewer);
		}
		
		private void btnClose_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#6 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 09:04 AM

ReportViewer class requires a reference to DataDynamics DLL (some dll with viewer in the name).

First try to comment out these lines:
			// run report and send it to the viewer to see the results.
			myActiveReport.Run();
			ReportViewer myViewer = new ReportViewer();
			myViewer.Report = myActiveReport;

			// finally add viewer to our form to see the results
			Form1.Controls.Add(myViewer);



And run your code. If it works as it's supposed to, then you add the reference and uncomment those lines.
Was This Post Helpful? 0
  • +
  • -

#7 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 09:50 AM


rpt.Designer.Report = myActiveReport;

error message: Error	1	'CustomerInfoReport.rptCustomers' does not contain a definition for 'Designer' and no extension method 'Designer' accepting a first argument of type 'CustomerInfoReport.rptCustomers' could be found (are you missing a using directive or an assembly reference?)



Was This Post Helpful? 0
  • +
  • -

#8 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 09:55 AM

With that "rpt.Designer" I meant the designer control you have in your other form, as you said before:

"rptCustomers.cs - This file is where I have to report designer with the designer (but I don't wanna use the designer)"

So, set that designer's modifier to public or internal and then call it with the "rpt.YourDesignersNameHere.Report"
Was This Post Helpful? 0
  • +
  • -

#9 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 09:58 AM

still nothing

// set the report to designer just to see the results
rptCustomers myReport = new rptCustomers();
myReport.rptCustomers.Report = myActiveReport;
myReport.Show();

// run report and send it to the viewer to see the results.
myActiveReport.Run();
ReportViewer myViewer = new ReportViewer();
myViewer.Report = myActiveReport;

// finally add viewer to our form to see the results
Form1.Controls.Add(myViewer);
Was This Post Helpful? 0
  • +
  • -

#10 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: ActiveReports 3.0 in C#

Posted 19 August 2009 - 10:24 AM

What do you mean with nothing?

Are you getting errors? At which lines? If it's the ReportViewer, comment out those lines I said in earlier post.
Was This Post Helpful? 0
  • +
  • -

#11 arliacne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 09

Re: ActiveReports 3.0 in C#

Posted 31 August 2009 - 08:21 AM

View Postjanne_panne, on 19 Aug, 2009 - 05:14 AM, said:

I don't have access to ActiveReports at home (where I'm at the moment) so I can't test the code snippet I provide but I'll try to give some tips and point the direction.

So, first we need to create a datasource, like you have been doing with the SqlDBDataSource. I'm not familiar with that datasource so I'll use DataTable in my example.

			// create DataTable with two columns
			DataTable dt = new DataTable();
			dt.Columns.Add(new DataColumn("Name", typeof(String)));
			dt.Columns.Add(new DataColumn("Age", typeof(Int32)));

			// and few rows:
			DataRow dr1 = dt.NewRow();
			dr1.ItemArray = new object[] { "my name", 30 };
			DataRow dr2 = dt.NewRow();
			dr2.ItemArray = new object[] { "other name", 40 };
			DataRow dr3 = dt.NewRow();
			dr3.ItemArray = new object[] { "third name", 50 };

			dt.Rows.Add(dr1);
			dt.Rows.Add(dr2);
			dt.Rows.Add(dr3);



Then, create a similar report like in my previous post but instead of the textbox, add these controls to the detail:

DataDynamics.ActiveReports.TextBox txtName = new DataDynamics.ActiveReports.TextBox();
txtName.DataField = "Name";
txtName.Name = "txtName";
txtName.Location = new PointF(0.0, 0.0);
d.Add(txtName);

DataDynamics.ActiveReports.TextBox txtAge = new DataDynamics.ActiveReports.TextBox();
txtAge.DataField = "Age";
txtName.Name = "txtAge";
txtAge.Location = new PointF(2.0, 0.0);
d.Add(txtName);



Next, bind set activereport's datasource to datatable, run it and show it in the viewer
ar3.DataSource = dt;
ar3.Run();

// set the report to designer just to see the results
rptCustomers rpt = new rptCustomers();
rpt.Designer.Report = ar3; // might also be Document property, cant remember which
rpt.Show();



Those code pieces should create a report which shows three rows of information on the designer.

Was This Post Helpful? 0
  • +
  • -

#12 arliacne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 09

Re: ActiveReports 3.0 in C#

Posted 31 August 2009 - 08:36 AM

Your walkthrough for programmatically working through adding and binding a datatable is the closest I've been able to come to success. Thank you.

I work with a product 25 years in the making. We have our own database, basically huge structure arrays (I'm coming from a assembly/C++ background into this C# world). It is not a "standard" database in any way, shape or form. So, I can access our database and grab values, i.e. strings, doubles, integers. but I can't connect to it.

Let's say I have a list of names and ages, "John", "Tom", "Mary", and I need to generate a detail section for each name. Your example helps to a point. I am currently slogging my way through learning ActiveReports 6. What I find with your example is I generate three detail sections, but what displays is:

txtName
txtAge

txtName
txtAge

txtName
txtAge

my code:
			DataTable dt = new DataTable();
			dt.Columns.Add(new DataColumn("Name", typeof(String)));
			dt.Columns.Add(new DataColumn("Age", typeof(Int32)));

			// and few rows:
			DataRow dr1 = dt.NewRow();
			dr1.ItemArray = new object[] { "John", 30 };
			DataRow dr2 = dt.NewRow();
			dr2.ItemArray = new object[] { "Tom", 40 };
			DataRow dr3 = dt.NewRow();
			dr3.ItemArray = new object[] { "Mary", 50 };

			dt.Rows.Add(dr1);
			dt.Rows.Add(dr2);
			dt.Rows.Add(dr3);

			rptReport rpt = new rptReport(); // or was it ActiveReports3
			rpt.DataSource = dt;
			rpt.Run();

			// run report and set ti to the viewer to see the results.
			viewer1.Document = rpt.Document;



Do you know why the names of the text box controls are displaying instead of the values?

And again, I can't emphasize enough how much I appreciate your simple, simple instructions - it's been hell trying to find a data binding example that doesn't first reference Northwind.

Al
Was This Post Helpful? 0
  • +
  • -

#13 arliacne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 09

Re: ActiveReports 3.0 in C#

Posted 31 August 2009 - 08:54 AM

Hmm ... looking at this I am realizing that there is no real connection betweem the datatable columns for Name and Age to the txtName and txtAge text boxes. Is there some other binding that has to go on? Perhaps in the code of the report itself?

Thanks.

Al
Was This Post Helpful? 0
  • +
  • -

#14 arliacne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 09

Re: ActiveReports 3.0 in C#

Posted 31 August 2009 - 02:56 PM

View Postarliacne, on 31 Aug, 2009 - 07:54 AM, said:

Hmm ... looking at this I am realizing that there is no real connection betweem the datatable columns for Name and Age to the txtName and txtAge text boxes. Is there some other binding that has to go on? Perhaps in the code of the report itself?

Thanks.

Al



Finally figured it out - perseverence and an overwhelming need to get it working has paid off:

		   rptReport rpt = new rptReport();
			rpt.DataSource = dt;
			rpt.txtName.DataField = "Name";
			rpt.txtAge.DataField = "Age";



Thanks,

Al
Was This Post Helpful? 0
  • +
  • -

#15 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: ActiveReports 3.0 in C#

Posted 02 September 2009 - 05:45 AM

go to my other post

http://www.dreaminco...h...=122362&hl=
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2