This project is read-only.
Plug-Ins

I was repeatedly asked a question that, since this software is already used in production, which use method to generate reports?
Abstracting the general concept of "missing" components I introduced the possibility of integragre plug-ins as long as meet certain rules.
In many use Crystal Reports for prints ... that's how I handled it:

Imports CrystalDecisions
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource


Imports System.Reflection


Public Class Crystalvb
    Public GC_events As New Collection
    Public GC_Implement As String = ""
    Public GC_Implemented As Boolean = False

    Public Parametri As New Collection
    Public Class CRParametro
        Public parametro As String
        Public valore As String
    End Class

    Public _filename As String
    Dim pReportInfo As ReportDocument = Nothing
    Public reporttype As String = ""
    Public tofile As String = ""
    Public copie As Integer = 0




    Public Sub AddParameter(lparametro As String, lvalore As String)
        If Parametri.Contains(lparametro) Then
            Parametri.Remove(lparametro)
        End If
        Dim crp As New CRParametro
        crp.parametro = lparametro
        crp.valore = lvalore
        Try
            Parametri.Add(crp, lparametro)
        Catch
            MsgBox("PARAMETRO '" & lparametro & "' per il report '" & Me.Name & "' duplicato", MsgBoxStyle.Information)
        End Try
        GC.Collect()
    End Sub

    Public Sub SetParameter(lparametro As String, lvalore As String)
        If IsNothing(pReportInfo) Then
            pReportInfo = New ReportDocument
        End If
        pReportInfo.SetParameterValue(lparametro, lvalore)
    End Sub

    Public Sub ClearParameters()
        Parametri.Clear()
    End Sub

    Public Sub RefreshReport()
        If _filename = "" Then
            Exit Sub
        End If


        If Parametri.Count > 0 Then
            For Each p As CRParametro In Parametri
                CrystalReportViewer1.ParameterFieldInfo(p.parametro).CurrentValues.Clear()
                CrystalReportViewer1.ParameterFieldInfo(p.parametro).CurrentValues.AddValue(p.valore)
            Next
        End If

        CrystalReportViewer1.RefreshReport()
        'pReportInfo.Refresh()
        'CrystalReportViewer1.ReportSource = pReportInfo


    End Sub



    Public Function Print(ReportName As String, Utente As String, password As String, nomeserver As String, nomedbaziendale As String, Optional ByVal DS As DataSet = Nothing, Optional ByVal StringOptionalSelectionFormula As String = "")
        Print = Nothing

        CrystalReportViewer1.TabIndex = 0
        CrystalReportViewer1.TabStop = False
        pReportInfo = New ReportDocument
        '*****************************************************************
        '***************************************************
        'SE QUALCOSA NON FUNZIONA...........GUARDA LA IF DS IS NOTHING 
        'CREATA PER I REPORT CARICATI CON DATASET :p :p
        '***************************************************
        '******************************************************************
        ' MsgBox(StringOptionalSelectionFormula)
        '  DS.Tables(0).WriteXml("c:\rtm\applicazioni\pippo.xml", True, True)
        '  DS.Tables(0).WriteXmlSchema("C:\rtm\applicazioni\pippo.xsd")
        Try
            _filename = ReportName
            'Dim cr As New ReportClass
            'cr.FileName = _filename
            'cr.Load()
            'cr.SetDataSource(DS.Tables(0))
            '  pReportInfo.ResourceName = "C:\RTM\IMGS\REPIMGDINA.RPT"
            'pReportInfo.SetDataSource(DS.Tables(0))
            With pReportInfo
                .Load(_filename, OpenReportMethod.OpenReportByDefault)
                '.Load( APPLICATIONPATH & ReportName)
                '******************************************************
                'REPORT PRINCIPALE    
                '******************************************************
                If DS Is Nothing Then

                    .SetDatabaseLogon(Utente, password, nomeserver, nomedbaziendale, True)

                    For i As Integer = 0 To .DataSourceConnections.Count - 1
                        .DataSourceConnections(i).SetConnection(nomeserver, nomedbaziendale, _
                                                                Utente, password)
                        .DataSourceConnections(i).IntegratedSecurity = False

                    Next i

                    'Questa parte qui sotto è necessaria per i sottoreport.
                    'Nel file di crystal report è necessario impostare come OLE DB Provider
                    'quello di SQLServer, niente SQLNCLI.1 o SQLNCLI.10.1
                    'Per quanto riguarda il report principale, quetsa parte sotto sembra 
                    'non essere necessaria in quanto funziona correttamente anxhe senza.
                    'Per ogni evenienza non la commento.
                    ' ''MsgBox("prima DI TABLES")
                    '----------------------------------
                    If 1 = 1 Then
                        For Each t As Table In .Database.Tables

                            Dim logonInfo As New TableLogOnInfo()

                            logonInfo = t.LogOnInfo
                            logonInfo.ConnectionInfo.ServerName = nomeserver
                            logonInfo.ConnectionInfo.DatabaseName = nomedbaziendale
                            logonInfo.ConnectionInfo.UserID = Utente
                            logonInfo.ConnectionInfo.Password = password


                            t.ApplyLogOnInfo(logonInfo)

                            If InStr(t.Location, ".") = 0 Then
                                t.Location = nomedbaziendale & ".dbo." & t.Location
                            End If
                        Next


                        ' ''MsgBox("DOPO TABLES")
                        '******************************************************
                        'SUBREPORT
                        '******************************************************
                        'For Each sbr As Engine.ReportClass In report.Subreports

                        For Each sbr As Engine.ReportDocument In .Subreports

                            sbr.SetDatabaseLogon(Utente, password, _
                                              nomeserver, nomedbaziendale, True)

                            For i As Integer = 0 To .DataSourceConnections.Count - 1
                                sbr.DataSourceConnections(i).SetConnection(nomeserver, nomedbaziendale, _
                                                                          Utente, password)
                                sbr.DataSourceConnections(i).IntegratedSecurity = False
                            Next i

                            'Questa parte qui sotto è necessaria per i sottoreport.
                            'Vedi nota sopra.

                            For Each t As Table In sbr.Database.Tables
                                Dim LogOnInfo As New CrystalDecisions.Shared.TableLogOnInfo
                                With LogOnInfo.ConnectionInfo 't.LogOnInfo.ConnectionInfo
                                    '.AllowCustomConnection = True
                                    .DatabaseName = nomedbaziendale
                                    .ServerName = nomeserver
                                    .UserID = Utente
                                    .Password = password
                                    .IntegratedSecurity = False
                                End With
                                '07/04/2011
                                t.ApplyLogOnInfo(LogOnInfo)
                                t.Location = nomedbaziendale & ".dbo." & t.Location
                            Next

                        Next
                    End If
                End If
                '------------------------------



                '******************************************************
                'SELECTION FORMULA
                '******************************************************
                'If pReportInfo.RecordSelectionFormula IsNot Nothing Then
                '    .RecordSelectionFormula = pReportInfo.RecordSelectionFormula
                'End If
                If StringOptionalSelectionFormula <> "" Then
                    .RecordSelectionFormula = StringOptionalSelectionFormula
                End If

                '******************************************************
                'PARAMETRI
                '******************************************************

                If Parametri.Count > 0 Then
                    For Each p As CRParametro In Parametri
                        '.SetParameterValue(p.NomeParametro, p.Valore)
                        '   MsgBox(p.parametro & " " & p.valore)
                        .ParameterFields(p.parametro).CurrentValues.Clear()
                        .ParameterFields(p.parametro).CurrentValues.AddValue(p.valore)
                    Next
                End If

                '******************************************************
                'FORMULE
                '******************************************************
                'If pReportInfo.Formule IsNot Nothing Then
                '    For Each f As CRFormula In pReportInfo.Formule
                '        .DataDefinition.FormulaFields(f.NomeFormula).Text = f.Valore
                '    Next
                'End If

            End With

            If DS IsNot Nothing Then
                '   Try


                pReportInfo.SetDataSource(DS.Tables(0))
                pReportInfo.Refresh()
                ' Catch ex As Exception
                'MsgBox(ex.Message.ToString)
                '    End Try
            End If
            'pReportInfo.Report.VerifyDatabase()
            'pReportInfo.Report.Refresh()

            Select Case reporttype
                Case Is = "PREVIEW"
                    CrystalReportViewer1.ReportSource = pReportInfo
                Case Is = "PRINT"
                    If UCase(tofile) <> "DEFAULT" Then
                        pReportInfo.PrintOptions.PrinterName = tofile
                    End If
                    pReportInfo.PrintToPrinter(Val(copie), False, 1, 9999)
                Case Is = "EXPORT"
                    Dim endswith As String = UCase(Mid(tofile, InStrRev(tofile, ".") + 1))
                    Select Case endswith
                        Case Is = "RTF"
                            pReportInfo.ExportToDisk(ExportFormatType.EditableRTF, tofile)

                        Case Is = "PDF"
                            pReportInfo.ExportToDisk(ExportFormatType.PortableDocFormat, tofile)

                        Case Is = "XLS"
                            pReportInfo.ExportToDisk(ExportFormatType.ExcelRecord, tofile)

                        Case Else
                            pReportInfo.ExportToDisk(ExportFormatType.NoFormat, tofile)
                    End Select


            End Select
            ' pReportInfo.Close()
            GC.Collect()
        Catch es As Exception
            MsgBox("Crystal report '" & ReportName & "'" & vbCrLf & es.Message.ToString)
        End Try
        '  selectionformula = ""


    End Function

    Public Function PrintFromDatabase(dbase As Object, filename As String, ds As DataSet, stampaformula As String)
        PrintFromDatabase = Nothing
        PrintFromConnectionString(filename, dbase.ConnectionString, ds, stampaformula)
    End Function

    Public Function PrintFromUserPassword(filename As String, username As String, Pass As String, LREPORTTYPE As String) As String
        PrintFromUserPassword = ""
        Print(filename, username, Pass, Nothing, Nothing, Nothing, Nothing)
        'pReportInfo = New ReportDocument
        'pReportInfo.FileName = filename
        'pReportInfo.Load(filename)
        'pReportInfo.Refresh()
        'pReportInfo.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4
        'pReportInfo.SetDatabaseLogon(username, Pass)
        'If LREPORTTYPE <> "" Then
        '    reporttype = UCase(LREPORTTYPE)
        'End If
        'Select Case reporttype
        '    Case Is = "PREVIEW"
        '        CrystalReportViewer1.ReportSource = pReportInfo
        '    Case Is = "PRINT"
        '        If UCase(tofile) <> "DEFAULT" Then
        '            pReportInfo.PrintOptions.PrinterName = tofile
        '        End If
        '        pReportInfo.PrintToPrinter(Val(copie), False, 1, 9999)
        '    Case Is = "EXPORT"
        '        Dim endswith As String = UCase(Mid(tofile, InStrRev(tofile, ".") + 1))
        '        Select Case endswith
        '            Case Is = "RTF"
        '                pReportInfo.ExportToDisk(ExportFormatType.EditableRTF, tofile)

        '            Case Is = "PDF"
        '                pReportInfo.ExportToDisk(ExportFormatType.PortableDocFormat, tofile)

        '            Case Is = "XLS"
        '                pReportInfo.ExportToDisk(ExportFormatType.ExcelRecord, tofile)

        '            Case Else
        '                pReportInfo.ExportToDisk(ExportFormatType.NoFormat, tofile)
        '        End Select


        'End Select


   


        Return Nothing

    End Function

    Public Function PrintFromConnectionString(filename As String, stringaconn As String, ds As DataSet, stampaformula As String) As String
        Dim valori As String() = Split(stringaconn, ";")
        Dim t As Integer = 0
        Dim ldatasource As String = ""
        Dim linitialcatalog As String = ""
        Dim luserid As String = ""
        Dim lpassword As String = ""
        For t = 0 To UBound(valori)
            Dim attributi As String() = Split(valori(t), "=")
            Select Case UCase(attributi(0))
                Case Is = "DATA SOURCE"
                    ldatasource = attributi(1)
                Case Is = "INITIAL CATALOG"
                    linitialcatalog = attributi(1)
                Case Is = "USER ID"
                    luserid = attributi(1)
                Case Is = "PASSWORD"
                    lpassword = attributi(1)
            End Select
        Next

        Print(filename, luserid, lpassword, ldatasource, linitialcatalog, ds, stampaformula)
        Return Nothing
    End Function

    Public Function PrintFromConnectionUserNamePassword(filename As String, stringaconn As String) As String
        Dim valori As String() = Split(stringaconn, ";")
        Dim t As Integer = 0
        Dim ldatasource As String = ""
        Dim linitialcatalog As String = ""
        Dim luserid As String = ""
        Dim lpassword As String = ""
        For t = 0 To UBound(valori)
            Dim attributi As String() = Split(valori(t), "=")
            Select Case UCase(attributi(0))
                Case Is = "DATA SOURCE"
                    ldatasource = attributi(1)
                Case Is = "INITIAL CATALOG"
                    linitialcatalog = attributi(1)
                Case Is = "USER ID"
                    luserid = attributi(1)
                Case Is = "PASSWORD"
                    lpassword = attributi(1)
            End Select
        Next

        PrintFromUserPassword(filename, luserid, lpassword, reporttype)
        Return Nothing
    End Function

    Private Sub Crystalvb_Load(sender As Object, e As System.EventArgs) Handles Me.Load



    End Sub

    Public Sub close()
        pReportInfo.Close()
    End Sub
End Class




Clearly, the code assumes a forms containing the "preview" of the crystal.
I added the plug-in full in the downloads section.
But how to use it in the Minotaur?

Globals {

Imports "C:\MyPlugIns\CrystalReportPlugIn\CrystalReportPlugIn\bin\CrystalReportPlugIn.dll" 
               as Crystal instanceof "CrystalReportPlugIn.ICrystalReport";


}



The full path to the plug-in is not required you can (indeed recommend using) a relative path.
Minotaur research in the path "original" in the current path and the plug-in.


    Crystal.ClearParameters();
    Crystal.AddParameter("sessione", gTabUtenti.CodUtente);
    Crystal.PrintFromConnectionString(InternalReflection.GetDbStringConnection("Progetti") , 
                 NomeFile, Nothing, "", "PREVIEW");
    Crystal.PrintPreview.ShowDialog();
    Crystal.Close();

Last edited Oct 17, 2016 at 7:02 AM by ciaociao72, version 2