0
votes

So here is the thing ..

I wrote a c# application to generate monthly Attendance Reports for each employee with his own details I want to be able to do this once for all employees and view the report grouped by name so when I select the customer name from the crystal report sub tree I get his monthly Attendance Report

I don't really know how to use the sub tree in crystal report ... is it possible to something like that ?


the goal from all this is to be able to print all reports at once in one click

2
I think you can use the Report Viewer without actually showing it somewhere, so basically you can load the first report, print it, load the second report, print it, etc. But i'm sure there is a nicer way of doing this.Adrian Fâciu
thats why im asking .. i need an optimized solution because i have a lot of employees thanks man3oon

2 Answers

0
votes

This is not exactly what you asked for but I am going to post it because it may work for you. I did for me in a similar situation. Also sorry about the VB syntax

This will allow you to create your reports as PDFs using the Crystal Reports engine. Basically it will allow you to create multiple PDF using a loop, which can then be printed automatically.The Export PDF Sub will write the file to disk and then open it with the default pdf reader. The print PDF function will automaticaly print the PDF files that were saved to disk. This is not a perfect solution but I hope that it at least gets you closer to what you are trying to accomplish.

Public Class PDFCR

Private Const SW_SHOWNORMAL As Integer = 2
<DllImport("shell32")> _
Public Shared Function ShellExecute(ByVal hWnd As IntPtr, _
                                    ByVal lpOperation As String, _
                                    ByVal lpFile As String, _
                                    ByVal lpParameters As String, _
                                    ByVal lpDirectory As String, _
                                    ByVal nShowCmd As Integer) As IntPtr
End Function

Public Shared Sub ExportPDF(ByVal crDOC As ReportDocument, ByVal FilePath As String)
    Dim CrExportOptions As ExportOptions
    Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
    Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
    CrDiskFileDestinationOptions.DiskFileName = FilePath
    CrExportOptions = crDOC.ExportOptions
    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
    CrExportOptions.FormatOptions = CrFormatTypeOptions
    crDOC.Export()
    Process.Start(FilePath)
End Sub

Public Shared Function PrintPDF(ByVal FilePath As String) As Boolean
    If IO.File.Exists(FilePath) Then
        If ShellExecute(CType(1, IntPtr), "Print", FilePath, "", _
        Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32 <= 32 Then
            Return False
        Else
            Return True
        End If
    Else
        Return False
    End If
End Function

End Class

I was having trouble getting the Imports to show in this code block so here they are in plain text.

Imports System.IO

Imports System.Management

Imports CrystalDecisions.Shared

Imports System.Runtime.InteropServices

Imports CrystalDecisions.CrystalReports.Engine

0
votes

If you add a GROUP to your report on your Employee Name field, this will (by default) create the group tree you are looking for.

From there, code-wise, it can be turned off, but you should see the group tree by default if your report has any groups in it.

The problem seems to be with the report not being grouped on Employee Name.