ToolCollection/ToolCollection/ClassNIVerknüpfung.vb

122 lines
5.9 KiB
VB.net

Public Class ClassNIVerknüpfung
Public Shared xmlNIConfigFile As String
Public Index As String
Public Spalte As String
Public From As String
Public SelectAnweisung As String
Public vktins_state As Integer
Public ExSQL As String
Public Desk_index As String
Private _OriginalSelectAnweisung As String
Sub New(ByVal vindex As String, ByVal vspalte As String, ByVal vfrom As String, ByVal vselectanweisung As String, ByVal vktstate As Integer)
xmlNIConfigFile = My.Application.Info.DirectoryPath & "\" & My.Settings.vNIConfigDatei
Me.Index = vindex
Me.Spalte = vspalte
Me.From = vfrom
Me.SelectAnweisung = vselectanweisung
Me.vktins_state = vktstate
Me._OriginalSelectAnweisung = vselectanweisung
End Sub
Public Function SaveLink(ByVal profilname As String, NI_Typ As String)
Select Case NI_Typ
Case "db"
Return Save_DB_Link(profilname)
Case "activedirectory"
Return Save_DB_Link(profilname)
Case "xml"
Return Save_DB_Link(profilname)
Case "fulltext"
Dim xml As New Xml.XmlDocument()
Dim xmlProfil As Xml.XmlElement
xml.Load(xmlNIConfigFile)
xmlProfil = xml.SelectSingleNode("//Settings/Profile/Profil[@profilname='" & profilname & "']/Link[@index='" & Me.Index & "'][@spalte='" & Me.Spalte & "'][@from='" & Me.From & "']")
xmlProfil.Attributes("select").Value = Me.SelectAnweisung
xmlProfil.Attributes("vktstate").Value = Me.vktins_state
xml.Save(xmlNIConfigFile)
Me._OriginalSelectAnweisung = Me.SelectAnweisung
Return True
End Select
End Function
Public Function Save_DB_Link(ByVal profilname As String)
' wenn ein Profilname für dieses Profil gesetzt ist
If Me.SelectAnweisung.ToLower.Contains("select") Then
'If Me.SelectAnweisung IsNot Nothing And Me.SelectAnweisung.StartsWith("SELECT [%spalte] FROM [%view] WHERE ") And Me.SelectAnweisung.Length > "SELECT [%spalte] FROM [%view] WHERE ".Length Then
Dim xml As New Xml.XmlDocument()
Dim xmlProfil As Xml.XmlElement
xml.Load(xmlNIConfigFile)
xmlProfil = xml.SelectSingleNode("//Settings/Profile/Profil[@profilname='" & profilname & "']/Link[@index='" & Me.Index & "'][@spalte='" & Me.Spalte & "'][@from='" & Me.From & "']")
xmlProfil.Attributes("select").Value = Me.SelectAnweisung
xmlProfil.Attributes("vktstate").Value = Me.vktins_state
xml.Save(xmlNIConfigFile)
Me._OriginalSelectAnweisung = Me.SelectAnweisung
' MsgBox("1: Die Verknüpfung wurde erfolgreich gespeichert!", MsgBoxStyle.Information, "Erfolgsmeldung:")
Return True
ElseIf Me.SelectAnweisung = "" And Me.SelectAnweisung <> Me._OriginalSelectAnweisung Then
Dim result As MsgBoxResult = MsgBox("Die Select-Anweisung wurde zurückgesetzt! Möchten Sie diesen Zustand jetzt speichern?", MsgBoxStyle.YesNoCancel, "Änderungen übernehmen?")
If result = MsgBoxResult.Yes Then
Dim xml As New Xml.XmlDocument()
Dim xmlProfil As Xml.XmlElement
xml.Load(xmlNIConfigFile)
xmlProfil = xml.SelectSingleNode("//Settings/Profile/Profil[@profilname='" & profilname & "']/Link[@index='" & Me.Index & "'][@spalte='" & Me.Spalte & "'][@from='" & Me.From & "']")
xmlProfil.Attributes("select").Value = Me.SelectAnweisung
xml.Save(xmlNIConfigFile)
Me._OriginalSelectAnweisung = Me.SelectAnweisung
'MsgBox("2: Die Verknüpfung wurde erfolgreich gespeichert!", MsgBoxStyle.Information, "Erfolgsmeldung:")
Return True
End If
Else
MsgBox("Command must at least contain a 'select' to verify and store!", MsgBoxStyle.Exclamation, "No Saving possible!")
Return False
'If Me.SelectAnweisung.Contains("=") = False Or Me.SelectAnweisung.Contains("where") = False Then
' MsgBox("Die Verknüpfung konnte nicht gespeichert werden weil weder ein '=' oder 'where' vorhanden sind. Bitte überprüfen Sie die Verknüpfung " & Me.Index & " <-> " & Me.Spalte & " (in " & Me.From & ").", MsgBoxStyle.Information, "Verknüpfung konnte nicht gespeichert werden")
'Else
' MsgBox("Eine Verknüpfung konnte nicht gespeichert werden. " & vbNewLine & "Es sind evtl. ungültige Zeichen enthalten!" & vbNewLine & _
' "Bitte überprüfen Sie die Verknüpfung " & Me.Index & " <-> " & Me.Spalte & " (in " & Me.From & ").", MsgBoxStyle.Information, "Verknüpfung konnte nicht gespeichert werden")
' Return False
'End If
End If
End Function
Public Sub setSelectAnweisung(ByVal selectAnweisung As String)
' Select-Anweisung setzen
Me.SelectAnweisung = selectAnweisung
End Sub
Public Sub setSpalte(ByVal Spalte As String)
' Spalte setzen
Me.Spalte = Spalte
End Sub
Public Sub setvktIns(ByVal vktinsvalue As Integer)
' Spalte setzen
Me.vktins_state = vktinsvalue
End Sub
Public Function getSelectAnweisung()
' Select-Anweisung zurückgeben
If Me.SelectAnweisung Is Nothing Then
Return ""
Else
Return Me.SelectAnweisung
End If
End Function
Public Function getvktInsState()
' Art des Vektorverhaltens
Return Me.vktins_state
End Function
Public Function getOriginalSelectAnweisung()
' originale Select-Anweisung zurückgeben
Return Me._OriginalSelectAnweisung
End Function
Public Sub SetBackToOriginal()
Me.SelectAnweisung = Me._OriginalSelectAnweisung
End Sub
End Class