You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
374 lines
14 KiB
374 lines
14 KiB
Imports System.IO
|
|
Imports System.Data
|
|
Imports System.Data.SqlClient
|
|
Imports System.Data.SqlTypes
|
|
|
|
'''<summary>Funktionen für d4as Einlesen der Indexdaten aus einer XML- oder
|
|
'''Textdatei</summary>
|
|
'''<remarks>Die Funktion liest je nach Inhalt der Inputdatei (Indexfilename) als
|
|
'''XML oder als TXT (Komma-getrennt) die Indexwerte aus der Datei und liefert
|
|
'''diese im Property IndexData zurück.</remarks>
|
|
'''<author>Stefan Hutter</author>
|
|
Public Class clsIndexData
|
|
|
|
#Region "Deklarationen"
|
|
|
|
'''<summary>Interne Variable für IndexFilenName</summary>
|
|
Dim m_indexfilename As String
|
|
'''<summary>Enthält der Name der Inputdatei mit den Indexdaten (XML oder
|
|
'''TXT)</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
Property IndexFileName() As String
|
|
Get
|
|
Return m_indexfilename
|
|
End Get
|
|
Set(ByVal Value As String)
|
|
m_indexfilename = Value
|
|
End Set
|
|
End Property
|
|
|
|
'''<summary>Interne Variable für IndexData</summary>
|
|
Dim m_Indexdata As DataTable
|
|
'''<summary>Datentabelle mit den geladenen Indexwerten</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
Property Indexdata() As DataTable
|
|
Get
|
|
Return m_Indexdata
|
|
End Get
|
|
Set(ByVal Value As DataTable)
|
|
m_Indexdata = Value
|
|
End Set
|
|
End Property
|
|
|
|
'''<summary>Temporäre Collection mit den getrennten Indexdaten aus der
|
|
'''txt-Input-Datei</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
Dim Splitline As Collection
|
|
|
|
#End Region
|
|
|
|
|
|
'''<summary>Angelieferte Indexdaten auslesen und in die Datentabele Indexdata
|
|
'''speichern. Abhängig vom angelieferten Format, XML-Datei einlesen oder
|
|
'''Komma-getrennte Textdatei auslesen</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
Public Function getindexdata() As Boolean
|
|
Index_Datei_Sichern(Me.IndexFileName)
|
|
Try
|
|
Dim s As String = ""
|
|
FileOpen(1, Me.IndexFileName, OpenMode.Input)
|
|
Input(1, s)
|
|
FileClose(1)
|
|
If UCase(Microsoft.VisualBasic.Left(s, 5)) = "<?XML" Or UCase(s.Substring(3, 5)) = "<?XML" Then
|
|
'XML-Datenstrom verarbeiten
|
|
xmlinput()
|
|
Return True
|
|
Else
|
|
'Komma-Delimited-Datenstrom verarbeiten
|
|
Datentabelle_Erstellen()
|
|
Dim tr As TextReader
|
|
Dim hasdata As Boolean = True
|
|
tr = File.OpenText(Me.IndexFileName)
|
|
Try
|
|
While hasdata
|
|
s = tr.ReadLine
|
|
If s = "" Or s = Nothing Then
|
|
tr.Close()
|
|
FileSystem.Rename(Me.IndexFileName, Me.IndexFileName + "." + Format(Now, "yyyyMMddHHmmss"))
|
|
If Me.Indexdata.Rows.Count > 0 Then Return True
|
|
Exit Function
|
|
End If
|
|
Indexwerte_Einlesen(s)
|
|
End While
|
|
Catch
|
|
tr.Close()
|
|
Return False
|
|
End Try
|
|
Return True
|
|
End If
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", "", 16, "Fehler beim Öffnen der Inputdatei " + Me.IndexFileName, "", "")
|
|
Finally
|
|
Try
|
|
FileClose(1)
|
|
Catch
|
|
End Try
|
|
If Params.DeleteOriginalfiles = 0 Then
|
|
FileSystem.Rename(Me.IndexFileName, Me.IndexFileName + "." + Format(Now, "yyyyMMddHHmmss"))
|
|
Else
|
|
Try
|
|
File.SetAttributes(Me.IndexFileName, FileAttributes.Normal)
|
|
Catch
|
|
End Try
|
|
Try
|
|
File.Move(Me.IndexFileName, Params.sikind + Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(Me.IndexFileName))
|
|
'File.Delete(Me.IndexFileName)
|
|
Catch
|
|
End Try
|
|
End If
|
|
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub Index_Datei_Sichern(ByVal filename As String)
|
|
Try
|
|
Dim sqlstatement As String = "Select * from Import_Job where Import_JobNr = " + LTrim(Str(Journal.JournalNr))
|
|
Dim Connection As New SqlConnection()
|
|
Dim DA As New SqlDataAdapter(sqlstatement, Globals.sConnectionString_journale)
|
|
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(DA)
|
|
|
|
Dim dsDATEN As New DataSet()
|
|
Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
|
|
Dim mydata(fs.Length) As Byte
|
|
Try
|
|
fs.Read(mydata, 0, fs.Length)
|
|
fs.Close()
|
|
Connection.ConnectionString = Globals.sConnectionString_journale
|
|
Connection.Open()
|
|
DA.Fill(dsDATEN, "docs")
|
|
Dim myRow As DataRow
|
|
myRow = dsDATEN.Tables(0).Rows(0)
|
|
myRow.Item(7) = mydata
|
|
DA.Update(dsDATEN, "docs")
|
|
Catch ex As Exception
|
|
End Try
|
|
fs = Nothing
|
|
cb = Nothing
|
|
dsDATEN = Nothing
|
|
DA = Nothing
|
|
Connection.Close()
|
|
Connection = Nothing
|
|
Catch
|
|
End Try
|
|
|
|
End Sub
|
|
Private Sub map_iris_struktur(ByRef idxds As DataSet)
|
|
Dim tmpds As New DataSet
|
|
tmpds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + "\canonstruktur.xml")
|
|
Dim dr As DataRow = tmpds.Tables(0).NewRow
|
|
For Each col As DataColumn In tmpds.Tables(0).Columns
|
|
dr.Item(col.ColumnName) = ""
|
|
Next
|
|
For Each col As DataColumn In idxds.Tables(0).Columns
|
|
dr.Item(col.ColumnName) = idxds.Tables(0).Rows(0).Item(col.ColumnName)
|
|
|
|
Next
|
|
tmpds.Tables(0).Rows.Clear()
|
|
tmpds.Tables(0).Rows.Add(dr)
|
|
idxds.Tables.Clear()
|
|
|
|
idxds.Tables.Add(tmpds.Tables(0).Copy)
|
|
tmpds.Dispose()
|
|
End Sub
|
|
|
|
Private Sub map_iris_LSV(ByRef idxds As DataSet)
|
|
|
|
Dim tmpds As New DataSet
|
|
tmpds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + "\edkb08struktur.xml")
|
|
tmpds.Tables(0).Columns.Add("DOKUMENTWERT21")
|
|
tmpds.Tables(0).Columns.Add("DOKUMENTWERT22")
|
|
tmpds.Tables(0).Columns.Add("DOKUMENTWERT23")
|
|
tmpds.Tables(0).Columns.Add("DOKUMENTWERT24")
|
|
tmpds.Tables(0).Columns.Add("DOKUMENTWERT25")
|
|
tmpds.Tables(0).Columns.Add("Stapelkennung")
|
|
|
|
Dim dr As DataRow = tmpds.Tables(0).NewRow
|
|
For Each col As DataColumn In tmpds.Tables(0).Columns
|
|
dr.Item(col.ColumnName) = ""
|
|
Next
|
|
|
|
For Each col As DataColumn In idxds.Tables(0).Columns
|
|
Try
|
|
dr.Item(col.ColumnName) = idxds.Tables(0).Rows(0).Item(col.ColumnName)
|
|
Catch
|
|
End Try
|
|
Next
|
|
|
|
dr.Item("ersteller") = idxds.Tables(0).Rows(0).Item("Benutzer")
|
|
'dr.Item("DOKUMENTTYPNR") = idxds.Tables(0).Rows(0).Item("Dokumenttyp")
|
|
'//dr.Item("DOKUMENTWERT1") = "Scandatum;" + idxds.Tables(0).Rows(0).Item("Scandatum")
|
|
'dr.Item("DOKUMENTWERT2") = "Paginatornummer;" + idxds.Tables(0).Rows(0).Item("Paginatornummer")
|
|
'dr.Item("DOKUMENTWERT3") = "Status;" + idxds.Tables(0).Rows(0).Item("Status")
|
|
'dr.Item("DOKUMENTWERT4") = "IBAN;" + idxds.Tables(0).Rows(0).Item("IBAN")
|
|
|
|
|
|
For i As Integer = 11 To 33
|
|
dr.Item("DOKUMENTWERT" + (i - 10).ToString) = idxds.Tables(0).Columns(i).ColumnName + ";" + idxds.Tables(0).Rows(0).Item(i).ToString
|
|
Next
|
|
|
|
|
|
|
|
tmpds.Tables(0).Rows.Clear()
|
|
tmpds.Tables(0).Rows.Add(dr)
|
|
idxds.Tables.Clear()
|
|
|
|
|
|
idxds.Tables.Add(tmpds.Tables(0).Copy)
|
|
tmpds.Dispose()
|
|
End Sub
|
|
|
|
Private Function parsexml(ByVal istr As String) As String
|
|
istr = istr.Replace("&", "&")
|
|
Return istr
|
|
End Function
|
|
|
|
'''<summary>XML-Datei als Datatable einlesen</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
'''
|
|
Private Sub xmlinput()
|
|
Try
|
|
|
|
|
|
Dim idxds As New DataSet()
|
|
Try
|
|
idxds.ReadXml(Me.IndexFileName)
|
|
Catch
|
|
FileOpen(21, Me.IndexFileName, OpenMode.Input)
|
|
FileOpen(22, Me.IndexFileName + ".tmp", OpenMode.Output)
|
|
Dim il As String
|
|
Dim ol As String
|
|
While Not EOF(21)
|
|
Input(21, il)
|
|
|
|
ol = parsexml(il)
|
|
PrintLine(22, ol)
|
|
End While
|
|
FileClose(21)
|
|
FileClose(22)
|
|
File.Delete(Me.IndexFileName)
|
|
Rename(Me.IndexFileName + ".tmp", Me.IndexFileName)
|
|
idxds.ReadXml(Me.IndexFileName)
|
|
End Try
|
|
|
|
|
|
Try
|
|
If Globals.Canon_Herkunft(idxds.Tables(0).Rows(0).Item("Herkunftsapplikation")) Then
|
|
'20210816 - LSV
|
|
If idxds.Tables(0).Rows(0).Item("Herkunftsapplikation") = "IRIS_FORMS_LSV" Then
|
|
map_iris_LSV(idxds)
|
|
Else
|
|
|
|
map_iris_struktur(idxds)
|
|
End If
|
|
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
|
|
End Try 'canon-Mapping'
|
|
'Anpassungen EBES_LSV
|
|
Dim i As Integer
|
|
For i = 0 To idxds.Tables.Count - 1
|
|
'-- Canon von >20 auf > 5 geändert
|
|
If idxds.Tables(i).Columns.Count > 20 Then
|
|
Me.Indexdata = idxds.Tables(i)
|
|
Exit For
|
|
End If
|
|
Next
|
|
' Me.Indexdata = idxds.Tables(0)
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", Me.IndexFileName, 16, "Fehler beim einlesen der XML-Datei: " + ex.Message, "", "")
|
|
End Try
|
|
End Sub
|
|
|
|
'''<summary>Datentabelle "Indexdata" erstellen, damit die Komma-Getrennten
|
|
'''Datensätze eingelesen und zugewiesen werden können</summary>
|
|
'''<author>Stefan Hutter</author>
|
|
Private Sub Datentabelle_Erstellen()
|
|
Try
|
|
Dim idxds As New DataSet()
|
|
idxds.ReadXml(DivFnkt.ApplicationPath + "TabStruktur_Delimited_Import.xml")
|
|
Me.Indexdata = idxds.Tables(0)
|
|
Me.Indexdata.Rows(0).Delete()
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", "", 16, "Fehler beim Erstellen der Initialiseriungstabelle mit der XML-Struktur" + ex.Message, "", "")
|
|
End Try
|
|
End Sub
|
|
|
|
'''<summary>Einzele Indexwerte aus dem Inputfile auslesen und als Datensatz in der
|
|
'''Tabelle "Indexdata" speichern</summary>
|
|
'''<param name="s">Zeile der Inputdatei (Komma-getrennte Werte)</param>
|
|
'''<author>Stefan Hutter</author>
|
|
Private Sub Indexwerte_Einlesen(ByVal s As String)
|
|
Splitline = SplitDelimitedLine(s, ",", """")
|
|
Insert_Into_DB(Splitline)
|
|
End Sub
|
|
|
|
'''<summary>Datensatz in der Tabelle "Indexdata" einfügen. Die Anzahl der
|
|
'''Spalten in der Tabelle ist abhängig vom Default-XML, welches zur
|
|
'''Tabellenerstellung verwendet wird.</summary>
|
|
'''<param name="data"></param>
|
|
'''<author>Stefan Hutter</author>
|
|
Private Sub Insert_Into_DB(ByVal data As Collection)
|
|
Dim i As Integer
|
|
Try
|
|
Dim datacolumns As Integer = Me.Indexdata.Columns.Count
|
|
Dim RowVals(datacolumns - 1) As Object
|
|
|
|
For i = 0 To datacolumns - 1
|
|
RowVals(i) = ""
|
|
Next
|
|
For i = 1 To data.Count
|
|
RowVals(i - 1) = data.Item(i)
|
|
Next
|
|
Me.Indexdata.Rows.Add(RowVals)
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", "", 16, "Fehler beim Einlesen der Indexdaten: RecordNr:" + Str(i) + ": " + ex.Message, "", "")
|
|
End Try
|
|
End Sub
|
|
|
|
'''<summary>Splitfunktion</summary>
|
|
'''<param name="CurrentLine">Input-Zeile</param>
|
|
'''<param name="Delimiter">Trennzeichen der einzelnen werte (z.B. Komma,
|
|
'''Strichpunkt usw.)</param>
|
|
'''<param name="Qualifier">Qualiflyer, welcher die Werte umschliesst (z.B.
|
|
'''")</param>
|
|
'''<author>Stefan Hutter</author>
|
|
Private Function SplitDelimitedLine(ByVal CurrentLine As String, ByVal Delimiter As String, ByVal Qualifier As String) As Collection
|
|
Try
|
|
Dim i As Integer
|
|
Dim SplitString As New Collection()
|
|
Dim CountDelimiter As Boolean
|
|
Dim Total As Integer
|
|
Dim Ch As Char
|
|
Dim Section As String
|
|
CountDelimiter = True
|
|
Total = 0
|
|
Section = ""
|
|
For i = 1 To Len(CurrentLine)
|
|
Ch = Mid(CurrentLine, i, 1)
|
|
Select Case Ch
|
|
Case Qualifier
|
|
If CountDelimiter Then
|
|
CountDelimiter = False
|
|
Else
|
|
CountDelimiter = True
|
|
End If
|
|
|
|
Case Delimiter
|
|
If CountDelimiter Then
|
|
'SplitString.Add(New MySection(Section))
|
|
SplitString.Add(Section)
|
|
Section = ""
|
|
Total = Total + 1
|
|
End If
|
|
Case Else
|
|
Section = Section & Ch
|
|
End Select
|
|
Next
|
|
If CountDelimiter Then
|
|
'SplitString.Add(New MySection(Section))
|
|
SplitString.Add(Section)
|
|
End If
|
|
SplitDelimitedLine = SplitString
|
|
Catch ex As Exception
|
|
Journal.Insert_Journal("", "", "", "", 16, "Fehler beim Einlesen der Indexdaten: " + ex.Message, "", "")
|
|
Dim SplitString As New Collection()
|
|
SplitDelimitedLine = SplitString
|
|
End Try
|
|
End Function
|
|
|
|
|
|
|
|
End Class
|