Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I've never used Crystal Reports and it's quite interesting what you can do with it. But I'm struggling when creating a report for a single client. So, let me explain what I really have and what I want for this to be possible to make.

Firstly, I have 2 tables, one regarding client data(including a photo) and the other is regarding a subscription added to that client. If so, How can I get the client data to all the parameters and then show the subscription data regarding that client on the same report?

I've never used crystal reports so I only can display single datasets on columns. But that's not what I want. I simply want the client data like (C_ID, Name, City, Address, Email and Photo on the parameters, as well as the System.DateTime.Now() on a different parameter) and then under all that data I would like to set up a table to get the values from the subscription table according to the same client chosen for all the parameters. I've seen 3/4 tutorials on the youtube but none of them was too explicit causing me to understand less than what I knew already(A solid 0). Any idea on how to solve this problem?


My 2 tables:
[Tables]

PS: I really need some good tutorials regarding this problem, either articles or videos.

What I have tried:

Followed all the tutorials regarding passing textbox to parameters but none of them seem to fit my needs. Neither the tutorials related to getting the table values based on a specific client value.
Posted
Updated 1-Jul-17 9:47am
v2
Comments
[no name] 8-Aug-17 7:43am    
What type of filtration you want in reports?

1 solution

From what you've wrote I assume you have little experience with preparing reports. You are mentioning Crystal Reports, but let me suggest to take a look at what the good old MS Word can do for you. One nice thing about MS Word is that you can prepare a template document and format it as needed. Then put placeholders into it where you want your data to appear.

In your .NET application you then read the data from your database into .NET data objects or XML. The last step is to merge the data and the template. Take a look at these examples to learn more. And here is some code, to help you get started (the data is read from the database using Entity Framework):

C#
using Docentric.Documents.Reporting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace clientReport
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var context = new clientsEntities())
            {
                string templateDocument = @"C:\Temp\ClientsTemplate.docx";
                string finalDocument = @"C:\Temp\ClientsReport.docx";

                ClientLst cl = new ClientLst();
                cl.Data = new List<ClientOutput>();

                var q = context.Clients.ToList<Client>();

                foreach (Client c in q)
                {
                    ClientOutput co = new ClientOutput();
                    co.Cid = c.C_ID;
                    co.Name = c.Name;
                    co.Address = c.Address;
                    co.City = c.City;
                    co.Email = c.Email;
                    co.Picture = c.Picture;

                    cl.Data.Add(co);
                }
                
                Console.WriteLine("Count of records read ..." + cl.Data.Count.ToString());

                DocumentGenerator dg = new DocumentGenerator(cl);
                DocumentGenerationResult result = dg.GenerateDocument(templateDocument, finalDocument, SaveOptions.Pdf);

                Console.Write("Press any key to continue ...");
                Console.ReadKey();
            }
        }        
    }
    public class ClientOutput
    {
        public int Cid { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Email { get; set; }
        public byte[] Picture { get; set; }
    }
    public class ClientLst
    {
        public List<ClientOutput> Data { get; set; }
    }
}

This code reads the data from the database, fills .NET data objects (ClientOutput and ClientList) and generates the final document as plain MS Word docx file (other supported output formats are pdf, xps and image). You can see that the code is very simple, yet powerful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900