Initial
This commit is contained in:
164
edkb08/log_report/Export.vb
Normal file
164
edkb08/log_report/Export.vb
Normal file
@@ -0,0 +1,164 @@
|
||||
Imports System
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
Imports System.Xml
|
||||
Imports System.Xml.Xsl
|
||||
Imports System.Threading
|
||||
'Imports CrystalDecisions.CrystalReports.Engine
|
||||
'Imports CrystalDecisions.Shared
|
||||
|
||||
'''<summary>Funktionen für den Export der Journaldaten</summary>
|
||||
Public Class Export
|
||||
|
||||
Dim filename As String
|
||||
'''<summary>Auswertung erstellen und ggf. mittels DTO versenden</summary>
|
||||
'''<param name="dt">Datentabelle mit den Auswertungsdaten der Applikation</param>
|
||||
'''<param name="format">Format der Auswertung (txt, csv, xls, doc, pdf,
|
||||
'''xml)</param>
|
||||
Public Function Create_Report(ByVal dt As DataTable, ByVal format As String, ByVal Applikation As String) As String
|
||||
Try
|
||||
filename = Params.TempPfad + Applikation + "_" + Microsoft.VisualBasic.Format(Now, "yyyyMMddHHmmss") + "_EDKB08_Log"
|
||||
Select Case UCase(format)
|
||||
Case "PDF"
|
||||
filename = filename + ".pdf"
|
||||
'CR_Report(dt, format) 20140204 MNK Ausbau CrystalReport Funktion
|
||||
Case "XLS"
|
||||
filename = filename + ".xls"
|
||||
'CR_Report(dt, format) 20140204 MNK Ausbau CrystalReport Funktion
|
||||
Case "DOC"
|
||||
filename = filename + ".doc"
|
||||
'CR_Report(dt, format) 20140204 MNK Ausbau CrystalReport Funktion
|
||||
Case "CSV"
|
||||
filename = filename + ".csv"
|
||||
Extract_CSV(dt)
|
||||
Case "TXT"
|
||||
filename = filename + ".txt"
|
||||
Extract_TXT(dt)
|
||||
Case "XML"
|
||||
filename = filename + ".xml"
|
||||
Dim ds As New DataSet()
|
||||
ds.Tables.Add(dt.Copy)
|
||||
ds.WriteXml(filename)
|
||||
ds.Dispose()
|
||||
End Select
|
||||
Return filename
|
||||
Catch ex As Exception
|
||||
PrintOut("Fehler Crystal:" + ex.Message, EventLogEntryType.Error)
|
||||
Return ""
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
'''<summary>Journaldatei als CSV-Datei erstellen</summary>
|
||||
'''<param name="dt">Journaldaten</param>
|
||||
Private Sub Extract_CSV(ByVal dt As DataTable)
|
||||
Dim s As String
|
||||
Dim i As Integer
|
||||
Dim c As Integer
|
||||
|
||||
Dim tw As TextWriter
|
||||
tw = New StreamWriter(New FileStream(filename, FileMode.Create))
|
||||
s = ""
|
||||
For i = 0 To dt.Columns.Count - 1
|
||||
s = s + dt.Columns(i).ColumnName + ";"
|
||||
Next
|
||||
tw.WriteLine(s)
|
||||
s = ""
|
||||
For i = 0 To dt.Rows.Count - 1
|
||||
For c = 0 To dt.Columns.Count - 1
|
||||
Try
|
||||
s = s + CType(dt.Rows(i).Item(c), String) + ";"
|
||||
Catch
|
||||
s = s + ""
|
||||
End Try
|
||||
Next
|
||||
tw.WriteLine(s)
|
||||
s = ""
|
||||
Next
|
||||
tw.Flush()
|
||||
tw.Close()
|
||||
End Sub
|
||||
|
||||
'''<summary>Journaldatei als TXT-Datei erstellen</summary>
|
||||
'''<param name="dt">Journaldaten</param>
|
||||
Private Sub Extract_TXT(ByVal dt As DataTable)
|
||||
Dim s As String
|
||||
Dim i As Integer
|
||||
Dim c As Integer
|
||||
|
||||
Dim tw As TextWriter
|
||||
tw = New StreamWriter(New FileStream(filename, FileMode.Create))
|
||||
s = ""
|
||||
For i = 0 To dt.Columns.Count - 1
|
||||
s = s + """" + dt.Columns(i).ColumnName + """" + ";"
|
||||
Next
|
||||
tw.WriteLine(s)
|
||||
s = ""
|
||||
For i = 0 To dt.Rows.Count - 1
|
||||
For c = 0 To dt.Columns.Count - 1
|
||||
Try
|
||||
s = s + """" + CType(dt.Rows(i).Item(c), String) + """" + ";"
|
||||
Catch
|
||||
s = s + ""
|
||||
End Try
|
||||
Next
|
||||
tw.WriteLine(s)
|
||||
s = ""
|
||||
Next
|
||||
tw.Flush()
|
||||
tw.Close()
|
||||
End Sub
|
||||
|
||||
'''<summary>Crystal-Report-Druck</summary>
|
||||
'''<param name="dt">Datentabelle, welche an Crystal zum Druck übergeben
|
||||
'''wird</param>
|
||||
'''<param name="format">Zu Exportierendes Format (XLS, DOC, PDF)</param>
|
||||
' Private Sub CR_Report(ByVal dt As DataTable, ByVal format As String)
|
||||
' Try
|
||||
' Dim CrystalReportDocument As ReportDocument
|
||||
' Dim CrystalExportOptions As ExportOptions
|
||||
' Dim CrystalDiskFileDestinationOptions As DiskFileDestinationOptions
|
||||
' Dim ds As New DataSet()
|
||||
' ds.Tables.Add(dt.Copy)
|
||||
|
||||
' CrystalReportDocument = New ReportDocument()
|
||||
' CrystalReportDocument.Load(DivFnkt.ApplicationPath + "Journal1.rpt")
|
||||
' CrystalReportDocument.SetDataSource(dt)
|
||||
|
||||
' CrystalReportDocument.SetDataSource(ds.Tables(0))
|
||||
|
||||
' CrystalDiskFileDestinationOptions = New DiskFileDestinationOptions()
|
||||
' CrystalDiskFileDestinationOptions.DiskFileName = filename
|
||||
' CrystalExportOptions = CrystalReportDocument.ExportOptions
|
||||
' With CrystalExportOptions
|
||||
' .DestinationOptions = CrystalDiskFileDestinationOptions
|
||||
' .ExportDestinationType = ExportDestinationType.DiskFile
|
||||
' Select Case UCase(format)
|
||||
' Case "PDF"
|
||||
' .ExportFormatType = ExportFormatType.PortableDocFormat
|
||||
' Case "XLS"
|
||||
' .ExportFormatType = ExportFormatType.Excel
|
||||
' Case "DOC"
|
||||
' .ExportFormatType = ExportFormatType.WordForWindows
|
||||
' End Select
|
||||
' End With
|
||||
' CrystalReportDocument.Export()
|
||||
' Try
|
||||
' 'sorry for this code (RS 2006-11-14)
|
||||
' CrystalReportDocument = Nothing
|
||||
' CrystalDiskFileDestinationOptions = Nothing
|
||||
' CrystalExportOptions = Nothing
|
||||
' Catch ex As Exception
|
||||
' PrintOut("Export.CR_Report()" + ex.Message, EventLogEntryType.Error)
|
||||
' End Try
|
||||
'Catch ex As Exception
|
||||
' PrintOut("Aufbereitung Crystal:" + ex.Message, EventLogEntryType.Error)
|
||||
' End Try
|
||||
' End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user