views:

53

answers:

2

I want to create a report that can be printed, exported as PDF or Word document.

All of the reporting frameworks I've seen so far, insist on creating a connection to database directly which is absurd.

My data comes from WCF service inform of an object.

Following is the structure of object.

ReportData
{
   public UserInformation BasicInfo {get; }
   public ProductInformation ProductInfo {get; }
   public List<Installment> Installments {get; }
}

I want to print UserInformation Then repeated entries of Installments And finally ProductInfo

I want my report to have a watermark image.

Ideally I want to create a window in xaml and databind the controls to this ReportData object.

Is there any commercial, free or any control that helps me achieve all of the above?

A: 

My goal with this answer is to point in a possible direction as there is no way within the space of an answer that I can provide all the details required. Plus I suspect you will not want to use Crystal Reports that come free with Visual Studio, but that said Crystal, after learning it, worked great. The key part of this answer is to point out that I was able to set the DataSource in code; hopefully, you can find a similair way with your report control. Finally the benefits of Crystal included the ability to print and save to PDF that I got for free.

I did this project a few years ago so I used Winforms.

Here are some of the key code fragments that made it possible.

Here are two Crystal Reports classes that I used:

  private CrystalReportViewer crystalReportViewer_;
  private CrystalReport1 crpt_;

Here I load the Crystal Report in my code by building my own Data Source:

  // I omited how to fill the data set.
  DataSet ds = new DataSet();

  crpt_.SetDataSource(ds.Tables[0]);
  crystalReportViewer_.ReportSource = crpt_;

  // need to load parametes after setting the report data source
  // to prevent the enter parameters dialog from opening...
  LoadParameterValues(crpt_);

  crystalReportViewer_.Show();

Here is an example of how to load parameters in the Crystal Report:

  private void LoadParameterValues(CrystalReport1 crpt)
  {
     ParameterValues currentParameterValues = new ParameterValues();
     ParameterFieldDefinitions parameterFieldDefinitions = crpt.DataDefinition.ParameterFields;

     ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();
     parameterDiscreteValue1.Value = statementDate.Value;
     currentParameterValues.Add(parameterDiscreteValue1);
     ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions["statementDate"];
     parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);

     ParameterDiscreteValue parameterDiscreteValue2 = new ParameterDiscreteValue();
     parameterDiscreteValue2.Value = dueDate.Value;
     currentParameterValues.Add(parameterDiscreteValue2);
     ParameterFieldDefinition parameterFieldDefinition2 = parameterFieldDefinitions["dueDate"];
     parameterFieldDefinition2.ApplyCurrentValues(currentParameterValues);
  }

I can provide more detail if you go down this path.

Zamboni
So you're suggesting that I create a dataset out of my object and feed it into report.
Hasan Khan
Yes, hopefully whatever reporting control you use supports this.
Zamboni
+1  A: 

I think I'll have to use FixedDocument or a FlowDocument (With custom paginator). It will support databinding in xaml but I won't be able to do all the conversions. I can use MS Word API to save the output of the document as xps and then convert it to a .doc or pdf.

Hasan Khan
This is a good approach. Here is a good writeup of one way to do it: http://janrep.blog.codeplant.net/WPF-Multipage-Reports--Part-I.aspx
codekaizen