Forums

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF ReportWriter for .NET (v4.x)  /  Report from objects

Forum Thread - Report from objects

 Oct 09 2007 3:44 AM
Is it possible to create report without database. I have collection ob objects which holds values I wish to have in report. There is no database. Below is a example of what I want.

public class Person
{
  public string FirstName;
  public string LastName;
}

public void GenerateReport()
{
  List<Person> list = GetListOfPersons...
 
  DocumentLayout report = new DocumentLayout("Document1.dplx");
  foreach (Person per in list)
  {
    Label labFirst = report.GetElementById("labFirst") as Label;
    labFirst.Text = per.FirstName;

    Label labLast = report.GetElementById("labLast") as Label;
    labLast.Text = per.LastName;
    //Create new line???
  }

  Document document = report.Run();
}
 Oct 09 2007 8:57 AM
Posted by a ceTe Software moderator
Hello,

It is not possible to create reports directly from the object's data however you can create reports using a DataTable without using any data base. You will have to create a DataTable using the data from the objects you have. You will have to create a dplx file and map the record boxes to the column names created in the DataTable. You can use this datatable in the OpeningRecordSet event of the Query object. Following is some sample code for this.

        //Declare the table globally to use in the event
        DataTable table = new DataTable();
        //Create the table using the data from your objects
        table.Columns.Add("FirstName");
        table.Columns.Add("LastName");
        for(int i=0; i<10; i++)
        {
                DataRow row = table.NewRow();
                row["FirstName"] = someObject.FirstName;
                row["LastName"] = someObject.LastName;
                table.Rows.Add(row);
        }
        //Create report
        DocumentLayout report = new DocumentLayout(@"C:\Temp\DataTable.dplx");
        Query query = (Query)report.GetElementById("Query");
        query.OpeningRecordSet +=new OpeningRecordSetEventHandler(query_OpeningRecordSet);
        Document doc = report.Run();
        doc.DrawToWeb();

This is the code for the OpeningRecordSet event.

        private void query_OpeningRecordSet(object sender, OpeningRecordSetEventArgs e)
        {
                e.RecordSet = new DataTableRecordSet(table);
        }

You can also use the Generator product to generate reports using the data from the objects where you will have more control on all the elements you are going to add to the PDF document.

Thanks,
ceTe Software Support Team.
 Oct 16 2007 7:17 AM
Thank you. How can I do the same with SubReport? (master/detail scenario)

DataTable table = new DataTable();
table.Columns.Add("ID"); 
table.Columns.Add("FirstName");
table.Columns.Add("LastName");
for(int i=0; i<10; i++)
{
        DataRow row = table.NewRow();
        row["ID"] = someObject.ID;
        row["FirstName"] = someObject.FirstName;
        row["LastName"] = someObject.LastName;
        table.Rows.Add(row);
}

DocumentLayout report = new DocumentLayout(@"C:\Temp\DataTable.dplx");

Query query = (Query)report.GetElementById("Query");
query.OpeningRecordSet +=new OpeningRecordSetEventHandler(query_OpeningRecordSet);

Query queryDetail = (Query)report.GetElementById("QueryDetail");
queryDetail.OpeningRecordSet +=new OpeningRecordSetEventHandler(queryDetail_OpeningRecordSet);

Document doc = report.Run();
doc.DrawToWeb();


private void query_OpeningRecordSet(object sender, OpeningRecordSetEventArgs e)
{
        e.RecordSet = new DataTableRecordSet(table);
}

private void queryDetail_OpeningRecordSet(object sender, OpeningRecordSetEventArgs e)
{
        someObject = e.?????????????
        DataTable tableDetail = new DataTable();
        tableDetail.Columns.Add("Value");
        for(int i=0; i<10; i++)
        {
                DataRow row = tableDetail.NewRow();
                row["Value"] = someObject.DetailValue[i];
                tableDetail.Rows.Add(row);
        }
        e.RecordSet = new DataTableRecordSet(tableDetail);
}
 Oct 16 2007 9:43 AM
Posted by a ceTe Software moderator
Hello,

Can you please send a mail to our Support Team so that they can send you a sample example which displays the records in the main report and matching records in a subreport.

Thanks,
ceTe Software Support Team.
 Mar 10 2016 6:05 AM
Thanks for solving an issue without telling details to others.
 Mar 10 2016 12:06 PM
Posted by a ceTe Software moderator
Hello,

There are some specific scenarios/cases where we are unable to post details on the forum. For example in this case we might have sent a sample project which includes the DPLX file to the customer.  Since we cannot add DPLX or other files types on the forum, we have asked the customer to send an email to support.

If you are facing any problems while using our DynamicPDF products, you can either post all the details on the forum or send an email to support@cete.com including all the details so we can look into it further.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 3:46 AM.