Option Strict On Option Explicit On Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Imports System.ComponentModel Imports UtilityLibrary.Win32 Public Class frmReporting Inherits System.Windows.Forms.Form #Region " Vom Windows Form Designer generierter Code " Public Sub New() MyBase.New() ' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() ' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen End Sub ' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu bereinigen. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Für Windows Form-Designer erforderlich Private components As System.ComponentModel.IContainer 'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer erforderlich 'Sie kann mit dem Windows Form-Designer modifiziert werden. 'Verwenden Sie nicht den Code-Editor zur Bearbeitung. Friend WithEvents reportDocument1 As CrystalDecisions.CrystalReports.Engine.ReportDocument Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar Friend WithEvents ImageList1 As System.Windows.Forms.ImageList Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton Friend WithEvents crviewer As CrystalDecisions.Windows.Forms.CrystalReportViewer Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmReporting)) Me.reportDocument1 = New CrystalDecisions.CrystalReports.Engine.ReportDocument() Me.ToolBar1 = New System.Windows.Forms.ToolBar() Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton() Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.crviewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer() Me.SuspendLayout() ' 'reportDocument1 ' Me.reportDocument1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation Me.reportDocument1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize Me.reportDocument1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper Me.reportDocument1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default ' 'ToolBar1 ' Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1}) Me.ToolBar1.DropDownArrows = True Me.ToolBar1.ImageList = Me.ImageList1 Me.ToolBar1.Name = "ToolBar1" Me.ToolBar1.ShowToolTips = True Me.ToolBar1.Size = New System.Drawing.Size(912, 25) Me.ToolBar1.TabIndex = 1 ' 'ToolBarButton1 ' Me.ToolBarButton1.ImageIndex = 4 ' 'ImageList1 ' Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'crviewer ' Me.crviewer.ActiveViewIndex = -1 Me.crviewer.Dock = System.Windows.Forms.DockStyle.Fill Me.crviewer.Location = New System.Drawing.Point(0, 25) Me.crviewer.Name = "crviewer" Me.crviewer.ReportSource = Nothing Me.crviewer.ShowCloseButton = False Me.crviewer.ShowGroupTreeButton = False Me.crviewer.ShowRefreshButton = False Me.crviewer.Size = New System.Drawing.Size(912, 484) Me.crviewer.TabIndex = 2 ' 'frmReporting ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(912, 509) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.crviewer, Me.ToolBar1}) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Name = "frmReporting" Me.Text = "frmReporting" Me.WindowState = System.Windows.Forms.FormWindowState.Maximized Me.ResumeLayout(False) End Sub #End Region #Region " Declaration " Dim i As Integer Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo Dim m_sWindowTitel As String 'Crystal Reports Definitionen Dim rpt As New ReportDocument() Dim crParameterValues As ParameterValues Dim crParameterDiscreteValue As ParameterDiscreteValue Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim s As String #End Region #Region " Property " Property WindowTitel() As String Get Return m_sWindowTitel End Get Set(ByVal Value As String) m_sWindowTitel = Value End Set End Property #End Region #Region " Formularfunktionen " Private Sub frmReporting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub #End Region #Region " Show Reports " Public Function show_reportWithParameter(ByVal ReportName As String, ByVal param As String) As Boolean '=============================================================================== 'Desc : Anziegen des gewählten report 'Input : Reportname 'Kriterium : Der Report muss im Verzeichenis welches in der Tabelle Applikation ' hinterlegt ist, vorhanden sein 'Erstellt : bud 25.05.2005 'Geaendert : '=============================================================================== Dim sReportpath As String If m_sWindowTitel <> "" Then Me.Text = m_sWindowTitel End If Try sReportpath = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_temporaer_dokumente"), String) If Microsoft.VisualBasic.Right(sReportpath, 1) <> "\" Then sReportpath = sReportpath & "\" End If '============================================= 'Fileprüfung '============================================= If FileExist(sReportpath, ReportName) = True Then rpt.Load(sReportpath & ReportName) Me.Cursor = System.Windows.Forms.Cursors.WaitCursor '*************************************************** '*************************************************** Dim intCounter As Integer intCounter = rpt.DataDefinition.ParameterFields.Count If intCounter = 1 Then If InStr(rpt.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then intCounter = 0 End If End If Dim strParValPair() As String Dim strVal() As String Dim index As Integer Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue() Dim currValue As CrystalDecisions.Shared.ParameterValues Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo() Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument() Dim intCounter1 As Integer If intCounter > 0 And Trim(param) <> "" Then strParValPair = param.Split(CType("&", Char)) For index = 0 To UBound(strParValPair) If InStr(strParValPair(index), "=") > 0 Then strVal = strParValPair(index).Split(CType("=", Char)) paraValue.Value = strVal(1) currValue = rpt.DataDefinition.ParameterFields(strVal(0)).CurrentValues currValue.Add(paraValue) rpt.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue) End If Next End If ConInfo.ConnectionInfo.UserID = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("user_report"), String) ConInfo.ConnectionInfo.Password = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("passwort_report"), String) ConInfo.ConnectionInfo.ServerName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_server"), String) ConInfo.ConnectionInfo.DatabaseName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_db"), String) For intCounter = 0 To rpt.Database.Tables.Count - 1 rpt.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo) Next For index = 0 To rpt.ReportDefinition.Sections.Count - 1 For intCounter = 0 To rpt.ReportDefinition.Sections(index).ReportObjects.Count - 1 With rpt.ReportDefinition.Sections(index) If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject) mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName) For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1 mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo) mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo) Next End If End With Next Next Dim crReportDocument As ReportDocument 'Untyped report object Me.crviewer.ReportSource = rpt Me.crviewer.Zoom(2) Me.Cursor = System.Windows.Forms.Cursors.Default show_reportWithParameter = True Exit Function End If Catch Exp As LoadSaveReportException show_reportWithParameter = False Me.Cursor = System.Windows.Forms.Cursors.Default Catch Exp As Exception show_reportWithParameter = False Me.Cursor = System.Windows.Forms.Cursors.Default End Try End Function Public Function show_report(ByVal ReportName As String, ByVal ParameterCollection As Collection) As Boolean '=============================================================================== 'Desc : Anziegen des gewählten report 'Input : Reportname 'Kriterium : Der Report muss im Verzeichenis welches in der Tabelle Applikation ' hinterlegt ist, vorhanden sein 'Erstellt : koe 10.11.2003 'Geaendert : '=============================================================================== Dim sReportpath As String If m_sWindowTitel <> "" Then Me.Text = m_sWindowTitel End If Try sReportpath = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_temporaer_dokumente"), String) If Microsoft.VisualBasic.Right(sReportpath, 1) <> "\" Then sReportpath = sReportpath & "\" End If '============================================= 'Fileprüfung '============================================= If FileExist(sReportpath, ReportName) = True Then rpt.Load(sReportpath & ReportName) Me.Cursor = System.Windows.Forms.Cursors.WaitCursor report_login(rpt) 'Get the collection of parameters from the report crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields '============================================= 'Parameter aus Report auslesn '============================================= For i = 0 To crParameterFieldDefinitions.Count - 1 crParameterFieldDefinition = crParameterFieldDefinitions.Item(i) crParameterValues = crParameterFieldDefinition.CurrentValues crParameterDiscreteValue = New ParameterDiscreteValue() '============================================= 'Leere String Parameter werden nicht übergeben '============================================= Try If CStr(ParameterCollection(UCase(crParameterFieldDefinitions.Item(i).Name))) <> "" Then crParameterDiscreteValue.Value = ParameterCollection(UCase(crParameterFieldDefinitions.Item(i).Name)) show_report = True End If 'Debug.Write(crParameterDiscreteValue.Value) 'Debug.Write(Len(crParameterDiscreteValue.Value)) 'Debug.Write(vbCr) 'Debug.Write(crParameterFieldDefinitions.Item(i).Name) 'Debug.Write(vbCr) crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) Catch ex As Exception Debug.Write(ex.Message) Debug.Write(vbCr) Debug.Write(Len(crParameterDiscreteValue.Value)) Debug.Write(vbCr) Debug.Write(crParameterFieldDefinitions.Item(i).Name) Debug.Write(vbCr) End Try Next Dim crReportDocument As ReportDocument 'Untyped report object Me.crviewer.ReportSource = rpt Me.crviewer.Zoom(2) Me.Cursor = System.Windows.Forms.Cursors.Default End If Catch Exp As LoadSaveReportException Me.Cursor = System.Windows.Forms.Cursors.Default MsgBox("Incorrect path for loading report.", _ MsgBoxStyle.Critical, "Load Report Error") Catch Exp As Exception Me.Cursor = System.Windows.Forms.Cursors.Default MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error") End Try End Function Public Sub show_report(ByVal ReportNr As Long) 'Dim dt As New DataTable() Try 'dt = Generic_Select(1, ReportNr) 'Me.Text = Globals.MyTxt.gettext(21000) 'rpt.Load("c:\edoka\edoka\reporting\Reports\dokumenttyp.rpt") 'rpt.Load(CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_reportdateien"), String) & "\dokumenttyp.rpt") rpt.Load(CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_temporaer_dokumente"), String) & "\dokumenttyp.rpt") report_login(rpt) 'Get the collection of parameters from the report crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields 'Access the specified parameter from the collection For i = 0 To 0 crParameterFieldDefinition = crParameterFieldDefinitions.Item(0) crParameterValues = crParameterFieldDefinition.CurrentValues crParameterDiscreteValue = New ParameterDiscreteValue() crParameterDiscreteValue.Value = ReportNr crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) Next Me.crviewer.ReportSource = rpt Me.crviewer.Zoom(2) Catch Exp As LoadSaveReportException MsgBox("Incorrect path for loading report.", _ MsgBoxStyle.Critical, "Load Report Error") Catch Exp As Exception MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error") End Try End Sub Public Sub show_report_dokumenttyp(ByVal Dokumenttypnr As Long) Dim dt As New DataTable() Try dt = Generic_Select(1, Dokumenttypnr) Me.Text = Globals.MyTxt.gettext(21000) 'rpt.Load("c:\edoka\edoka\reporting\Reports\dokumenttyp.rpt") 'rpt.Load(CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_reportdateien"), String) & "\dokumenttyp.rpt") rpt.Load(CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_temporaer_dokumente"), String) & "\dokumenttyp.rpt") report_login(rpt) 'Get the collection of parameters from the report crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields 'Access the specified parameter from the collection For i = 0 To 0 crParameterFieldDefinition = crParameterFieldDefinitions.Item(i) crParameterValues = crParameterFieldDefinition.CurrentValues crParameterDiscreteValue = New ParameterDiscreteValue() crParameterDiscreteValue.Value = Dokumenttypnr crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) Next Me.crviewer.ReportSource = rpt Me.crviewer.Zoom(2) Catch Exp As LoadSaveReportException MsgBox("Incorrect path for loading report.", _ MsgBoxStyle.Critical, "Load Report Error") Catch Exp As Exception MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error") End Try End Sub Public Sub show_report_dokumenttypVFelder(ByVal dokumenttypnr As Long, ByVal id As String) Try Me.Text = Globals.MyTxt.gettext(21001) rpt.Load(CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("pfad_reportdateien"), String) & "\dokumenttypVFelder.rpt") ' rpt.Load("l:\edoka\Reports\dokumenttypVFelder.rpt") report_login(rpt) 'Get the collection of parameters from the report crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields 'Access the specified parameter from the collection crParameterFieldDefinition = crParameterFieldDefinitions.Item("@id") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterDiscreteValue = New ParameterDiscreteValue() crParameterDiscreteValue.Value = id crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) Me.crviewer.ReportSource = rpt Me.crviewer.Zoom(2) Catch Exp As LoadSaveReportException MsgBox("Incorrect path for loading report.", _ MsgBoxStyle.Critical, "Load Report Error") Catch Exp As Exception MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error") End Try End Sub #End Region #Region " Menue Funktionen " Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Me.Close() End Sub #End Region #Region " Extras Funktionen" Private Function FileExist(ByVal FilePath As String, ByVal FileName As String) As Boolean '=============================================================================== 'Ermittelt ob eine Datei vorhanden ist. 'Input : Verzeichnis 'Output: True/False 'Erstellt : koe 20.10.2003 'Geaendert : '=============================================================================== Try If Microsoft.VisualBasic.Right(FilePath, 1) <> "\" Then FilePath = FilePath + "\" End If If System.IO.Directory.Exists(FilePath) Then If System.IO.File.Exists(FilePath & FileName) Then FileExist = True Else MyMsg.show_standardmessage_ReplaceText(210, MsgBoxStyle.Exclamation, FilePath & " " & FileName, "") 'Datei #1 nicht gefunden! FileExist = False End If Else MyMsg.show_standardmessage_ReplaceText(210, MsgBoxStyle.Exclamation, FilePath, "") '"Verzeichnis " & FilePath & " nicht gefunden! FileExist = False End If Catch ex As Exception MessageBox.Show(ex.Message, "Reportdatei", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) FileExist = False End Try End Function Private Function Generic_Select(ByVal typ As Integer, ByVal xvalue As Long) As DataTable Dim scmCmdToExecute As SqlCommand = New SqlCommand() Select Case typ Case 1 scmCmdToExecute.CommandText = "dbo.SP_reporting_dokart_tree" Case Else End Select scmCmdToExecute.CommandType = CommandType.StoredProcedure Dim dtToReturn As DataTable = New DataTable() Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute) scmCmdToExecute.Connection = conn.scoDBConnection Try Select Case typ Case 1 scmCmdToExecute.Parameters.Add(New SqlParameter("@iroot", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, xvalue)) End Select If typ = 1 Then End If sdaAdapter.Fill(dtToReturn) Return dtToReturn Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("Dokumenterstellung::Generic_Select::" & scmCmdToExecute.CommandText & "::Error occured." & ex.Message, ex) Finally scmCmdToExecute.Dispose() sdaAdapter.Dispose() End Try End Function #End Region 'Public Sub report_login() ' For Each tbCurrent In rpt.Database.Tables ' tliCurrent = tbCurrent.LogOnInfo ' With tliCurrent.ConnectionInfo ' .ServerName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_server"), String) ' .UserID = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("user_report"), String) ' .Password = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("passwort_report"), String) ' .DatabaseName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_db"), String) ' End With ' tbCurrent.ApplyLogOnInfo(tliCurrent) ' Next tbCurrent ' 'Loop through each report object looking for sub reports ' Dim _reportObject As ReportObject ' Dim _subReport As SubreportObject ' For Each _reportObject In rpt.ReportDefinition.ReportObjects ' 'Check the report object type ' If TypeOf (_reportObject) Is SubreportObject Then ' _subReport = CType(_reportObject, SubreportObject) ' report_login(_subReport.OpenSubreport(_subReport.SubreportName)) ' End If ' Next 'End Sub Public Sub report_login(ByVal _report As ReportDocument) For Each tbCurrent In _report.Database.Tables tliCurrent = tbCurrent.LogOnInfo With tliCurrent.ConnectionInfo .ServerName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_server"), String) .UserID = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("user_report"), String) .Password = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("passwort_report"), String) .DatabaseName = CType(Globals.Applikationsdaten.Rows(Globals.AppldataRow).Item("report_db"), String) End With tbCurrent.ApplyLogOnInfo(tliCurrent) Next (tbCurrent) 'Loop through each report object looking for sub reports Dim _reportObject As ReportObject Dim _subReport As SubreportObject For Each _reportObject In _report.ReportDefinition.ReportObjects 'Check the report object type If TypeOf (_reportObject) Is SubreportObject Then _subReport = CType(_reportObject, SubreportObject) report_login(_subReport.OpenSubreport(_subReport.SubreportName)) End If Next End Sub End Class