Using Crystal Reports in Visual Studio 2005 (C# .NET Windows App)

后端 未结 4 1466
眼角桃花
眼角桃花 2021-02-08 16:48

I need to create reports in a C# .NET Windows app. I\'ve got an SQL Server 2005 database, Visual Studio 2005 and am quite OK with creating stored procedures and datasets.

<
相关标签:
4条回答
  • 2021-02-08 17:01

    You can use the report viewer with client side reporting built into vs.net (ReportBuilder/ReportViewer control). You can create reports the same way as you do for sql reporting services, except you dont need sql server(nor asp.net). Plus you have complete control over them(how you present, how you collect data, what layer they are generated in, what you do with them after generating, such as mailing them, sending to ftp, etc). You can also export as PDF and excel.

    And in your case building up a report from data and user input, this may work great as you can build up your own datasource and data as you go along. Once your data is ready to be reported on, bind it to your report.

    The reports can easily be built in Visual Studio 2005 (Add a report to your project), and be shown in a Winforms app using the ReportViewer control.

    Here is a great book i recommend to everyone to look at if interested in client side reports. It gives a lot of great info and many different scenarios and ways to use client side reporting.

    http://www.apress.com/book/view/9781590598542

    0 讨论(0)
  • 2021-02-08 17:05

    Crystal is one possible option for creating reports. It has been around a long time and a lot of people seem to like it.

    You might want to take a look at SQL reporting services. I have used both but my preferance is SQL reporting services. Its pretty well integrated into studio and works similar to the other microsoft projects. Its also free with the sql express etc.

    This is a good article on beginning reporting services: http://www.simple-talk.com/sql/learn-sql-server/beginning-sql-server-2005-reporting-services-part-1/

    0 讨论(0)
  • 2021-02-08 17:08

    I have managed to make this work now.

    Brief Overview

    It works by having a 'data class' which is just a regular C# class containing variables and no code. This is then instantiated and filled with data and then placed inside an ArrayList. The ArrayList is bound to the report viewer, along with the name of the report to load. In the report designer '.Net Objects' are used, rather than communicating with the database.

    Explanation

    I created a class to hold the data for my report. This class is manually filled by me by manually retrieving data from the database. How you do this doesn't matter, but here's an example:

    DataSet ds = GeneratePickingNoteDataSet(id);
    foreach (DataRow row in ds.Tables[0].Rows) {
        CPickingNoteData pickingNoteData = new CPickingNoteData();
    
        pickingNoteData.delivery_date = (DateTime)row["delivery_date"];
        pickingNoteData.cust_po = (int)row["CustomerPONumber"];
        pickingNoteData.address = row["CustomerAddress"].ToString();
        // ... and so on ...
    
        rptData.Add(pickingNoteData);
    }
    

    The class is then put inside an ArrayList. Each element in the arraylist corresponds to one 'row' in the finished report.

    The first element in the list can also hold the report header data, and the last element in the list can hold the report footer data. And because this is an ArrayList, normal Array access can be used to get at them:

    ((CPickingNoteData)rptData[0]).header_date = DateTime.Now;
    ((CPickingNoteData)rptData[rptData.Count-1]).footer_serial = GenerateSerialNumber();
    

    Once you have an arraylist full of data, bind it to your report viewer like this, where 'rptData' is of type 'ArrayList'

    ReportDocument reportDoc = new ReportDocument();
    reportDoc.Load(reportPath);
    reportDoc.SetDataSource(rptData);
    crystalReportViewer.ReportSource = reportDoc;
    

    Now you will need to bind your data class to the report itself. You do this inside the designer:

    1. Open the Field Explorer tab (which might be under the 'View' menu), and right-click "Database Fields"
    2. Click on 'Project Data'
    3. Click on '.NET Objects'
    4. Scroll down the list to find your data class (if it isn't there, compile your application)
    5. Press '>>' and then OK
    6. You can now drag the class members onto the report and arrange them as you want.
    0 讨论(0)
  • 2021-02-08 17:10

    I second alex's recommendation to look at sql reporting services - if you have a sql developer license, then you probably already have reporting services

    i don't like crystal reports, too much tedium in the designer (editing expressions all the time) too many server-deployment issues (check those license files!)

    0 讨论(0)
提交回复
热议问题