283 lines
12 KiB
VB.net
283 lines
12 KiB
VB.net
Public Class ClassMoReDokumentarten
|
|
|
|
Private Shared _profiles() As ClassMoReDokumentart
|
|
Public Shared _windream As New ClassWindream_allgemein(CURR_LogConfig)
|
|
Public Shared xmlConfigFile As String
|
|
|
|
Public Shared Sub Init()
|
|
xmlConfigFile = My.Application.Info.DirectoryPath & "\" & My.Settings.vMoReConfigDatei
|
|
ClassMoReDokumentarten.LoadFromXmlFile()
|
|
' 3b. Windream initialisieren (Connection, Session, ... aufbauen)
|
|
_windream.Init()
|
|
End Sub
|
|
Public Shared Function IsXmlAccessable()
|
|
Dim xml As New Xml.XmlDocument
|
|
|
|
Try
|
|
' XML-Datei laden und speichern um Zugriff zu testen
|
|
xml.Load(xmlConfigFile)
|
|
xml.Save(xmlConfigFile)
|
|
|
|
Return True
|
|
|
|
Catch ex As Exception
|
|
Try
|
|
Dim fw As System.IO.StreamWriter = New System.IO.StreamWriter(xmlConfigFile)
|
|
|
|
fw.WriteLine("<?xml version=""1.0"" encoding=""ISO-8859-1"" standalone=""yes""?>")
|
|
fw.WriteLine("<Settings>")
|
|
fw.WriteLine("<Profile>")
|
|
fw.WriteLine("</Profile>")
|
|
fw.WriteLine("</Settings>")
|
|
|
|
fw.Close()
|
|
Return True
|
|
Catch e2 As Exception
|
|
Return False
|
|
End Try
|
|
|
|
End Try
|
|
End Function
|
|
Public Shared Sub LoadFromXmlFile()
|
|
Dim i As Integer = 0
|
|
Dim xml As Xml.XmlDocument
|
|
|
|
ClassMoReDokumentarten._profiles = Nothing
|
|
|
|
If xmlConfigFile Is Nothing Then Exit Sub
|
|
|
|
If Not xmlConfigFile = "" Then
|
|
|
|
If IsXmlAccessable() Then
|
|
|
|
xml = New Xml.XmlDocument()
|
|
xml.Load(xmlConfigFile)
|
|
|
|
' Anzahl der Profilelemente in der XML-Datei zählen
|
|
Dim anzProfile = xml.SelectNodes("Settings/Profile/Profil").Count
|
|
|
|
' wenn mindestens ein Profilelement eingetragen ist
|
|
If anzProfile > 0 Then
|
|
|
|
' alle Profile laden
|
|
Dim xmlNodes As Xml.XmlNodeList = xml.SelectNodes("Settings/Profile/Profil")
|
|
|
|
' alle Profile der XML-Datei durchlaufen
|
|
For Each xmlProfil As Xml.XmlNode In xmlNodes
|
|
|
|
' prüfen ob ein Profilname angegeben wurde
|
|
If xmlProfil.Attributes("profilname") IsNot Nothing And xmlProfil.Attributes("dokumentart") IsNot Nothing And _
|
|
xmlProfil.Attributes("windreamsuche") IsNot Nothing Then
|
|
|
|
' ein Element an Items anhängen
|
|
ReDim Preserve ClassMoReDokumentarten._profiles(i)
|
|
|
|
ClassMoReDokumentarten._profiles(i) = New ClassMoReDokumentart()
|
|
' das Profilobjekt erstellen
|
|
ClassMoReDokumentarten._profiles(i) = New ClassMoReDokumentart( _
|
|
xmlProfil.Attributes("profilname").Value, _
|
|
xmlProfil.Attributes("dokumentartindex").Value, _
|
|
xmlProfil.Attributes("dokumentart").Value, _
|
|
xmlProfil.Attributes("adressnrString").Value, _
|
|
xmlProfil.Attributes("windreamsuche").Value, _
|
|
xmlProfil.Attributes("namenskonvention").Value, _
|
|
xmlProfil.Attributes("zielort").Value)
|
|
' Zähler für Profile erhöhen
|
|
i += 1
|
|
End If
|
|
|
|
Next
|
|
End If
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
' erstellt ein neues Profil
|
|
Public Shared Sub Add(ByVal vprofilname As String, ByVal vdokumentartindex As String, ByVal vdokumentartString As String, ByVal vidxadressnrString As String, ByVal vwindreamSuche As String, _
|
|
ByVal vnamenskonvention As String, ByVal vZielort As String)
|
|
|
|
Try
|
|
If Not ClassMoReDokumentarten.Exists(vprofilname) Then
|
|
Dim xml As New Xml.XmlDocument
|
|
Dim xmlProfil As Xml.XmlElement
|
|
|
|
If ClassMoReDokumentarten.IsXmlAccessable() Then
|
|
|
|
' XML-Datei laden
|
|
xml.Load(xmlConfigFile)
|
|
|
|
Try
|
|
' versuchen die XML-Beschreibung zu schreiben
|
|
xml.InsertBefore(xml.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes"), xml.ChildNodes(0))
|
|
Catch ex As Exception
|
|
' wenn dies nicht funktioniert, ist die Beschreibung schon vorhanden
|
|
End Try
|
|
|
|
' wenn die Hauptknoten noch nicht eingetragen wurden, sollen diese angelegt werden
|
|
If xml.DocumentElement Is Nothing Then xml.AppendChild(xml.CreateElement("Settings"))
|
|
If xml.SelectSingleNode("Settings/Profile") Is Nothing Then xml.SelectSingleNode("Settings").AppendChild(xml.CreateElement("Profile"))
|
|
|
|
|
|
' dann ein neues Profil anlegen
|
|
xmlProfil = xml.CreateElement("Profil")
|
|
|
|
' dem Profil die Attribute zuweisen
|
|
xmlProfil.SetAttribute("profilname", vprofilname)
|
|
xmlProfil.SetAttribute("dokumentartindex", vdokumentartindex)
|
|
xmlProfil.SetAttribute("dokumentart", vdokumentartString)
|
|
xmlProfil.SetAttribute("adressnrString", vidxadressnrString)
|
|
xmlProfil.SetAttribute("windreamsuche", vwindreamSuche)
|
|
xmlProfil.SetAttribute("namenskonvention", vnamenskonvention)
|
|
xmlProfil.SetAttribute("zielort", vZielort)
|
|
|
|
' und in den Hauptknoten 'Profile' einhängen
|
|
xml.SelectSingleNode("Settings/Profile").AppendChild(xmlProfil)
|
|
|
|
' XML-Datei speichern
|
|
xml.Save(xmlConfigFile)
|
|
|
|
' die Liste der Profile im Objekt vergrößern
|
|
ReDim Preserve ClassMoReDokumentarten._profiles(ClassMoReDokumentarten.Count)
|
|
|
|
|
|
' das Profilobjekt erstellen
|
|
ClassMoReDokumentarten._profiles(ClassMoReDokumentarten.Count - 1) = New ClassMoReDokumentart( _
|
|
vprofilname, _
|
|
vdokumentartindex, _
|
|
vdokumentartString, _
|
|
vidxadressnrString, _
|
|
vwindreamSuche, _
|
|
vnamenskonvention, _
|
|
vZielort)
|
|
MsgBox("Das Profil '" & vprofilname & "' wurde erfolgreich angelegt!", MsgBoxStyle.Information, "Erfolgsmeldung:")
|
|
|
|
End If
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Anlegen eines Profils")
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
|
|
Public Shared Function DeleteProfil(ByVal profilname As String) As Boolean
|
|
|
|
Try
|
|
If ClassMoReDokumentarten.Exists(profilname) Then
|
|
|
|
' XML-Objekt initialisieren
|
|
Dim xml As New Xml.XmlDocument
|
|
|
|
If ClassMoReDokumentarten.IsXmlAccessable() Then
|
|
|
|
' XML-Datei laden
|
|
xml.Load(xmlConfigFile)
|
|
|
|
|
|
' ***** Zuerst einmal das Profil heraus löschen ***** '
|
|
|
|
' XML-Element auswählen
|
|
Dim node As Xml.XmlElement = xml.SelectSingleNode("Settings/Profile/Profil[@profilname='" & profilname & "']")
|
|
|
|
If node IsNot Nothing Then
|
|
' Element löschen
|
|
node.ParentNode.RemoveChild(node)
|
|
|
|
' XML-Datei speichern
|
|
xml.Save(xmlConfigFile)
|
|
End If
|
|
|
|
|
|
If ClassMoReDokumentarten.Exists(profilname) Then
|
|
' temporäres Array erzeugen
|
|
Dim tempItems() As ClassMoReDokumentart = ClassMoReDokumentarten._profiles
|
|
ClassMoReDokumentarten._profiles = Nothing
|
|
Dim i As Integer = 0
|
|
|
|
|
|
' alle Verknüpfungen durchlaufen
|
|
For Each item As ClassMoReDokumentart In tempItems
|
|
|
|
' wenn es sich nicht um das gelöschte handelt
|
|
If Not item.OriginalProfilname = profilname Then
|
|
|
|
' Größe anpassen
|
|
ReDim Preserve ClassMoReDokumentarten._profiles(i)
|
|
|
|
' die Verknüpfung in das Items-Array übertragen
|
|
ClassMoReDokumentarten._profiles(i) = item
|
|
|
|
' Counter hochzählen
|
|
i += 1
|
|
End If
|
|
Next
|
|
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Else
|
|
Return False
|
|
End If
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Löschen eines Profils")
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
|
|
Public Shared Function Exists(ByVal profilname As String)
|
|
|
|
If ClassMoReDokumentarten.Count > 0 Then
|
|
For Each profil As ClassMoReDokumentart In ClassMoReDokumentarten._profiles
|
|
If profil.OriginalProfilname = profilname Then
|
|
Return True
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
Return False
|
|
|
|
End Function
|
|
|
|
' gibt ein einzelnes Profil-Objekt zurück
|
|
Public Shared Function getProfilByName(ByVal profilname As String) As ClassMoReDokumentart
|
|
|
|
' alle Profile durchlaufen
|
|
For Each profil As ClassMoReDokumentart In _profiles
|
|
|
|
' wenn der aktuelle Profilname mit dem gesuchten Profilnamen übereinstimmt
|
|
If profil.Profilname = profilname Then
|
|
|
|
' das Profil zurückgeben
|
|
Return profil
|
|
End If
|
|
Next
|
|
|
|
' sonst nichts zurückgeben
|
|
Return Nothing
|
|
|
|
End Function
|
|
Public Shared ReadOnly Property Profile() As ClassMoReDokumentart()
|
|
Get
|
|
Return ClassMoReDokumentarten._profiles
|
|
End Get
|
|
End Property
|
|
Public Shared ReadOnly Property Count() As Integer
|
|
Get
|
|
' Anzahl der Profile zurückgeben
|
|
If ClassMoReDokumentarten._profiles IsNot Nothing Then
|
|
Return ClassMoReDokumentarten._profiles.Length
|
|
Else
|
|
Return 0
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
End Class
|